简体   繁体   English

typescript-eslint 未使用 tsconfig

[英]tsconfig not used by typescript-eslint

In a new project, I installed typescript , eslint , @typescript-eslint/parser , @typescipt-eslint/eslint-plugin .在一个新的项目,我安装了typescripteslint@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 ,我有两个:

  • error TS7006: Parameter 'a' implicitly has an 'any' type.错误 TS7006:参数“a”隐式具有“任何”类型。
  • error TS7006: Parameter 'b' implicitly has an 'any' type.错误 TS7006:参数“b”隐式具有“任何”类型。

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.

相关问题 为什么@typescript-eslint/parser 包含在我的 tsconfig.json 中配置的文件之外的文件? - Why is @typescript-eslint/parser including files outside of those configured in my tsconfig.json? eslint 缩进和@typescript-eslint/indent 冲突 - eslint indent and @typescript-eslint/indent conflict 如何将 typescript-eslint 规则添加到 eslint - How to add typescript-eslint rules to eslint @typescript-eslint/eslint-plugin 错误:定义了“路由”但从未使用过(no-unused-vars) - @typescript-eslint/eslint-plugin error: 'Route' is defined but never used (no-unused-vars) TypeScript:在定义@typescript-eslint/no-use-before-define 之前使用了“handleFirstTab” - TypeScript: 'handleFirstTab' was used before it was defined @typescript-eslint/no-use-before-define ESLint 与 eslint-plugin-import 和 typescript-eslint 冲突 - ESLint conflicts with eslint-plugin-import and typescript-eslint ESLint 无法识别“@typescript-eslint/eslint-plugin” - ESLint is not recognizing "@typescript-eslint/eslint-plugin" 即使使用了变量,也会出现 @typescript-eslint/no-unused-vars 警告 - Getting @typescript-eslint/no-unused-vars warning occurs even though the variable is used 如何配置@typescript-eslint 规则 - How to configure @typescript-eslint rules 如何禁用来自@typescript-eslint 的警告? - How to disable warnings from @typescript-eslint?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM