typescript-eslint 未使用 tsconfig

Lau*_*ant 5 typescript eslint typescript-eslint

在一个新项目中,我安装了typescript, eslint, @typescript-eslint/parser, @typescipt-eslint/eslint-plugin。我还添加了以下.eslintrc文件:

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"]
}
Run Code Online (Sandbox Code Playgroud)

和以下tsconfig.json文件:

{
  "compilerOptions": {
    "strict": true
  }
}
Run Code Online (Sandbox Code Playgroud)

问题是tsconfig.json当我运行命令时没有应用选项 from eslint。但是,它与命令一起按预期工作tsc

例如,文件index.ts包含:

function sum(a, b) {}
Run Code Online (Sandbox Code Playgroud)

如果我运行npx eslint index.js,我没有错误,而如果我运行tsc --noEmit,我有两个:

  • 错误 TS7006:参数“a”隐式具有“任何”类型。
  • 错误 TS7006:参数“b”隐式具有“任何”类型。

我希望eslint命令返回与命令相同的错误tsc。任何的想法?

编辑我尝试在以下情况下使用和不使用以下内容.eslintrc

"parserOptions": {
  "project": "./tsconfig.json"
}
Run Code Online (Sandbox Code Playgroud)

GOT*_*O 0 6

typescript-eslint 不报告编译器警告。它只报告由其自己的验证规则生成的警告。此外,strict在 TypeScript 中启用该选项对 typescript-eslint 执行的代码分析没有影响,它不依赖于项目设置。

已经有一些关于创建一个新@typescript-eslint/no-undef规则(以 ESLintno-undef规则为模型)的讨论,该规则至少可以通过严格的类型检查来捕获 tsc 编译器生成的一些警告。

目前最好的方法可能是将tsc --noEmit它的执行集成到 lint 进程中。