Skip to content

Lint com informação de tipos (“type-aware”)

Regras que dependem do sistema de tipos — promises não tratadas, atribuições inseguras etc. No Oxlint isso é fornecido pelo tsgolint, integrado à CLI e à configuração.

Cobertura atual: 59 de 61 regras type-aware do typescript-eslint; desempenho e compatibilidade seguem melhorando.

Visão geral

  • Oxlint (Rust)
    Percursos de arquivos, ignores, config, regras sem tipo, relatório.

  • tsgolint (Go)
    Monta programas TypeScript com typescript-go, executa regras type-aware e devolve diagnósticos ao Oxlint.

Instalação

Dependência extra:

sh
npm add -D oxlint-tsgolint@latest
sh
pnpm add -D oxlint-tsgolint@latest
sh
yarn add -D oxlint-tsgolint@latest
sh
bun add -D oxlint-tsgolint@latest

Rodando

  • CLI: --type-aware
  • Config raiz: options.typeAware: true

CLI:

bash
oxlint --type-aware

Config raiz:

json
{
  "options": {
    "typeAware": true
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  options: {
    typeAware: true,
  },
});

Com isso rodam regras normais + regras typescript/*.

--type-aware ganha da config CLI+arquivo mesmo que o arquivo diga false.

options.typeAware e options.typeCheck na raiz — configs aninhadas não devem defini-los.

Integrações editor/LSP: opção typeAware; veja Editores.

Monorepos e builds

Precisa de informação de tipo resolvida:

  • gere pacotes dependentes (.d.ts)
  • dependências instaladas
bash
pnpm install
pnpm -r build
oxlint --type-aware

Diagnósticos de verificação de tipos (type-check)

Erros TS junto ao lint:

bash
oxlint --type-aware --type-check

Ou na raiz:

json
{
  "options": {
    "typeAware": true,
    "typeCheck": true
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  options: {
    typeAware: true,
    typeCheck: true,
  },
});

--type-check também sobrescreve arquivo de config.

Pode substituir tsc --noEmit no CI:

bash
# antes
tsc --noEmit
oxlint

# depois
oxlint --type-aware --type-check

Configurar regras type-aware

Igual às outras regras Oxlint:

json
{
  "plugins": ["typescript"],
  "rules": {
    "typescript/no-floating-promises": "error",
    "typescript/no-unsafe-assignment": "warn"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["typescript"],
  rules: {
    "typescript/no-floating-promises": "error",
    "typescript/no-unsafe-assignment": "warn",
  },
});

Opções iguais às do typescript-eslint:

json
{
  "plugins": ["typescript"],
  "rules": {
    "typescript/no-floating-promises": ["error", { "ignoreVoid": true }]
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["typescript"],
  rules: {
    "typescript/no-floating-promises": ["error", { ignoreVoid: true }],
  },
});

Comentários de desabilitar

ts
// oxlint-disable-next-line typescript/no-floating-promises
doSomethingAsync();

Comentários de disable não usados:

bash
oxlint --type-aware --report-unused-disable-directives

Compatibilidade TypeScript

Baseado em typescript-go:

  • precisa TypeScript 7.0+
  • algumas opções legadas de tsconfig não são suportadas (ex.: baseUrl)
  • migre opções depreciadas/removidas (TS 6 → 7) antes type-check acusa opções inválidas

Migração TypeScript, ferramenta ts5to6 para tsconfig.

Estabilidade

  • Cobertura de regras ainda não total (mas bem próxima)
  • Codebases gigantes podem usar muita memória
  • Desempenho em evolução

Solução de problemas

Desempenho e debug

  1. Atualize oxlint e oxlint-tsgolint.
  2. Log de debug:
bash
OXC_LOG=debug oxlint --type-aware

Interpretação do log:

  • Mapeamento de arquivos (Starting to assign files...): associação a projetos tsconfig — normalmente rápido; se lento, abra issue.
  • Por programa ([N/M] Running linter on program...): cada projeto TS lintado à parte — demora extra pode indicar resolução de tipos pesada ou projeto enorme.

include gigante na raiz

tsconfig.json
json
{
  "include": ["**/*"] // ❌ puxa demais
}

Correção: inclua só fonte e liste exclude explícitos:

tsconfig.json
json
{
  "include": ["src/**/*"],
  "exclude": ["dist", "build", "coverage"]
}

Monorepo na raiz, evite incluir código-fonte direto no tsconfig da raiz quando não for o caso:

tsconfig.json
json
{
  "files": []
}

Diagnóstico: no log debug, procure Program created with com número absurdamente alto de arquivos — revise include/exclude.

Próximos passos