简体   繁体   中英

tsconfig not used by typescript-eslint

In a new project, I installed typescript , eslint , @typescript-eslint/parser , @typescipt-eslint/eslint-plugin . I also added the following .eslintrc file:

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"]
}

and the following tsconfig.json file:

{
  "compilerOptions": {
    "strict": true
  }
}

The problem is that the option from tsconfig.json is not applied when I run the command eslint . It works as expected with the command tsc , though.

For example, with a file index.ts containing:

function sum(a, b) {}

If I run npx eslint index.js , I have no error while if I run tsc --noEmit , I have two:

  • error TS7006: Parameter 'a' implicitly has an 'any' type.
  • error TS7006: Parameter 'b' implicitly has an 'any' type.

I would like the eslint command to return the same errors as the tsc command. Any idea?

Edit I tried with and without the following in the .eslintrc :

"parserOptions": {
  "project": "./tsconfig.json"
}

typescript-eslint does not report compiler warnings. 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.

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.

The best approach for now is probably integrating the execution of tsc --noEmit it the lint process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM