1

I am trying to use the rule "@typescript-eslint/naming-convention".

My understanding is that this rule requires linting with type information, described here: https://typescript-eslint.io/docs/linting/type-linting/

When trying to use 'plugin:@typescript-eslint/recommended-requiring-type-checking' I then get the following error:

You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.

However I cannot see how parserOptions.project this should work when using a Nx monorepo.

In the monorepo, there is a variety of different files created for each project. At the top level there is a tsconfig.base.json, then each project has a tsconfig.json, and its own .eslintrc.json. I have tried a variety of combinations (including some great advice here) but I haven't managed to get anything working yet.

If changes to individual project files are required, I could add some custom generator logic, but ideally I'd work with global rules.

Also searching GitHub doesn't bring up any example repositories either.

Q: May anyone advise me how to use TypeScript linter rules which require type information with a Nx monorepo?

Adam Marshall
  • 3,010
  • 9
  • 42
  • 80

1 Answers1

0

So it looks like you can use

      "parserOptions": {
        "project": ["./tsconfig.base.json"]
      },

with Nx and that seems to work at the top level, meaning that you shouldn't need to edit individual .eslintrc files for each project.

You do also need to just apply the "parserOptions" and the "extends": ["plugin:@typescript-eslint/recommended-requiring-type-checking"] within the "overrides" array, just for TypeScript files only, as described in this answer: "parserOptions.project" has been set for @typescript-eslint/parser.

This was actually enough to get me working, running nx lint from the command line... my problem was that I also have an issue with WebStorm settings on top of all this too, which was obscuring things further. It might be this open issue, https://youtrack.jetbrains.com/issue/WEB-47201, but that is really a completely different question... my original question is answered.

Adam Marshall
  • 3,010
  • 9
  • 42
  • 80