isemaj
isemaj

Reputation: 587

Cascading eslint config file

I have few questions about cascading eslint config file:

  1. Can I use eslint like a tsconfig.json (in typescript) where I have a root .eslintrc.yml and I can extend/cascade that to each .eslintrc.yml for each folder (project)? I'm not sure if this is what the documentation says here.
  2. If I can extend a root config file how does it work on the case of extends option where sometimes the order is important like on the case of eslint-config-prettier as mentioned on their docs. There it says:

Make sure to put it last, so it gets the chance to override other configs.

  1. Correct me if my understanding is correct that with plugins option the order is not important but on extends sometimes the order is important like what I mentioned on question #2.
  2. If the order is important on extends option, how can I make sure that it follows the order when I have an extension like eslint-plugin-prettier where it should be the last when I'm not using cascading. For example:

If I'm not using cascading it should be like this as what is mentioned here:

extends:
  - "some-other-config-you-use"
  - "prettier"
  - "prettier/@typescript-eslint"
  - "prettier/react"

If I'm using cascading my setup will be like this:

# root

root: true
parser: "@typescript-eslint/parser"
extends:
  - "eslint:recommended"
  - "plugin:@typescript-eslint/recommended"
  - "prettier"
  - "prettier/@typescript-eslint"
# sub-folder

env:
  browser: true
extends: 
  - "plugins:react/recommended"
  - "plugins:jsx-a11y/recommended"
  - "prettier/react"

Upvotes: 3

Views: 1295

Answers (2)

blwinters
blwinters

Reputation: 2191

Related to this, I was running into an error after creating the .eslintrc.js file in a subdirectory:

Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config

The solution was to specify ignorePatterns: ['.eslintrc.js'], in the root config, as discussed here.

Upvotes: 0

David Bradshaw
David Bradshaw

Reputation: 13077

root: true
parser: "@typescript-eslint/parser"
extends:
  - "eslint:recommended"
  - "plugin:@typescript-eslint/recommended"
  - “./path/your_other_config”
  - "prettier"
  - "prettier/@typescript-eslint"

Upvotes: 1

Related Questions