Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"
}
like image 933
Laurent De Cant Avatar asked Jul 28 '19 22:07

Laurent De Cant


1 Answers

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.

like image 56
GOTO 0 Avatar answered Oct 12 '22 13:10

GOTO 0