[英]tsconfig not used by typescript-eslint
In a new project, I installed typescript
, eslint
, @typescript-eslint/parser
, @typescipt-eslint/eslint-plugin
.在一个新的项目,我安装了typescript
, eslint
, @typescript-eslint/parser
, @typescipt-eslint/eslint-plugin
。 I also added the following .eslintrc
file:我还添加了以下.eslintrc
文件:
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"]
}
and the following tsconfig.json
file:以及以下tsconfig.json
文件:
{
"compilerOptions": {
"strict": true
}
}
The problem is that the option from tsconfig.json
is not applied when I run the command eslint
.问题是tsconfig.json
中的选项在我运行命令eslint
时没有应用。 It works as expected with the command tsc
, though.不过,它与命令tsc
一起按预期工作。
For example, with a file index.ts
containing:例如,文件index.ts
包含:
function sum(a, b) {}
If I run npx eslint index.js
, I have no error while if I run tsc --noEmit
, I have two:如果我运行npx eslint index.js
,我没有错误,而如果我运行tsc --noEmit
,我有两个:
I would like the eslint
command to return the same errors as the tsc
command.我希望eslint
命令返回与tsc
命令相同的错误。 Any idea?任何的想法?
Edit I tried with and without the following in the .eslintrc
:编辑我尝试在.eslintrc
使用和不使用以下.eslintrc
:
"parserOptions": {
"project": "./tsconfig.json"
}
typescript-eslint does not report compiler warnings. typescript-eslint 不报告编译器警告。 It only reports warnings generated by its own validation rules.它只报告由其自己的验证规则生成的警告。 Also, enabling the strict
option in TypeScript has no effect on the code analysis performed by typescript-eslint, which does not rely on the project settings.此外,在 TypeScript 中启用strict
选项对 typescript-eslint 执行的代码分析没有影响,它不依赖于项目设置。
There have been some discussions about creating a new @typescript-eslint/no-undef
rule (modeled on ESLint no-undef
rule) that would catch at least some of the warnings generated by the tsc compiler with strict type checking on.有一些关于创建新的@typescript-eslint/no-undef
规则(以 ESLint no-undef
规则为模型)的讨论,该规则至少可以捕获 tsc 编译器生成的一些警告,并进行严格的类型检查。
The best approach for now is probably integrating the execution of tsc --noEmit
it the lint process.目前最好的方法可能是将tsc --noEmit
的执行集成到 lint 进程中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.