10

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"
}

1 Answer 1

12

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.

Sign up to request clarification or add additional context in comments.

3 Comments

could you provide an example of integrating the execution of tsc --noEmit in the lint process?
@olefrank I don't have an example that runs the tsc executable at hand, but in one of my projects, I'm using the TypeScript compiler API with a minimal set of options (including noEmit) to do exactly this kind of linting. The key is the function createProgram provided by the typescript module, that throws an error - thus stopping the build - when it cannon compile. The code of interest is here. I'll see if I can come up with a simplified example.
@GOTO0 any update on that simplified example? Maybe there has been some update on eslint-typescript regarding this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.