question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@angular-eslint/schematics: missing "tsconfigRootDir" for nested projects in parserOptions

See original GitHub issue

Description

When adding ESLint with angular-eslint to a “nested” project, (i.e. projects in the “projects” folder), IDEs (tested with VS Code and IntelliJ can’t recognize the .eslintrc.json.

yarn lint <project> still works, but the highlighting in the IDE willl not.

Solution

Adding "tsconfigRootDir": "../../", to “parserOptions” solves the issue:

...
      "parserOptions": {
        "tsconfigRootDir": "../../",
        "project": [
          "projects/testlib/tsconfig.lib.json",
          "projects/testlib/tsconfig.spec.json"
        ],
        "createDefaultProgram": true
      },
...

Steps to reproduce

  • ng add testapp
  • ng g library testlib
  • ng add @angular-eslint/schematics
  • ng g @angular-eslint/schematics:add-eslint-to-project testapp
  • ng g @angular-eslint/schematics:add-eslint-to-project testlib

The configuration in projects/testlib/.eslintrc.json will be generated like this:

{
  "extends": "../../.eslintrc.json",
  "ignorePatterns": [
    "!**/*"
  ],
  "overrides": [
    {
      "files": [
        "*.ts"
      ],
      "parserOptions": {
        "project": [
          "projects/testlib/tsconfig.lib.json",
          "projects/testlib/tsconfig.spec.json"
        ],
        "createDefaultProgram": true
      },
      "rules": {
        "@angular-eslint/directive-selector": [
          "error",
          {
            "type": "attribute",
            "prefix": "lib",
            "style": "camelCase"
          }
        ],
        "@angular-eslint/component-selector": [
          "error",
          {
            "type": "element",
            "prefix": "lib",
            "style": "kebab-case"
          }
        ]
      }
    },
    {
      "files": [
        "*.html"
      ],
      "rules": {}
    }
  ]
}

The IDEs will now display the following:

IntelliJ

image

VS Code

image


With "tsconfigRootDir": "../../", applied, it works in both editors:

IntelliJ

image

VS Code

image

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:10

github_iconTop GitHub Comments

9reactions
sagrawal31commented, Feb 14, 2022

I also wasted my 4-5 hours trying to fix this issue with IntelliJ. Ultimately, I had to enable Manual ESLint configuration in IntelliJ with Working directories set to ./.

image

1reaction
guillermoarellanocommented, Aug 7, 2021

@ChristophRSG I solve this issue by following the steps described by @prabh-62 on this issue link: https://github.com/angular-eslint/angular-eslint/issues/462#issuecomment-858073819.

Hopefully, this helps you and others.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular-eslint/schematics: missing "tsconfigRootDir" for ...
Description. When adding ESLint with angular-eslint to a "nested" project, (i.e. projects in the "projects" folder), IDEs (tested with VS ...
Read more >
"parserOptions.project" has been set for @typescript-eslint ...
Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: /Users/Dan/site ...
Read more >
eslint parseroptions project | The AI Search Engine You Control
"parserOptions.project" has been set for @typescript-eslint/parser ... missing "tsconfigRootDir" for nested projects in parserOptions#609.
Read more >
WebStorm incorrectly builds the path to eslint's parserOptions ...
What steps will reproduce the problem? Set up a project with Typescript files and tsconfig.json in the /server directory. Add .eslintrc.js file to...
Read more >
Solve Typescript error "parserOptions.project" has been set for ...
Solve Typescript error "parserOptions.project" has been set for @typescript-eslint/parser. TL:DR: Add the file to the "include" array in your tsconfig.json.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found