简体   繁体   English

级联 eslint 配置文件

[英]Cascading eslint config file

I have few questions about cascading eslint config file:我对级联 eslint 配置文件有几个问题:

  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)?我可以像tsconfig.json (在打字稿中)那样使用 eslint,我有一个根.eslintrc.yml并且我可以将它扩展/级联到每个文件夹(项目)的每个.eslintrc.yml吗? 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 .如果我可以扩展根配置文件,它在extends选项的情况下如何工作,有时顺序很重要,例如在他们的文档中提到的eslint-config-prettier的情况下。 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.如果我的理解是正确的,请纠正我,对于plugins选项,顺序并不重要,但在extends时,有时顺序很重要,就像我在问题 #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.如果extends选项的顺序很重要,当我有像eslint-plugin-prettier这样的扩展时,我如何确保它遵循顺序,当我不使用级联时它应该是最后一个。 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"
root: true
parser: "@typescript-eslint/parser"
extends:
  - "eslint:recommended"
  - "plugin:@typescript-eslint/recommended"
  - “./path/your_other_config”
  - "prettier"
  - "prettier/@typescript-eslint"

Related to this, I was running into an error after creating the .eslintrc.js file in a subdirectory:与此相关,我在子目录中创建.eslintrc.js文件后遇到了错误:

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 .解决方案是在根配置中指定ignorePatterns: ['.eslintrc.js'],如此所述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM