繁体   English   中英

级联 eslint 配置文件

[英]Cascading eslint config file

我对级联 eslint 配置文件有几个问题:

  1. 我可以像tsconfig.json (在打字稿中)那样使用 eslint,我有一个根.eslintrc.yml并且我可以将它扩展/级联到每个文件夹(项目)的每个.eslintrc.yml吗? 我不确定这是否是这里的文档所说的。
  2. 如果我可以扩展根配置文件,它在extends选项的情况下如何工作,有时顺序很重要,例如在他们的文档中提到的eslint-config-prettier的情况下。 那里说:

确保把它放在最后,这样它就有机会覆盖其他配置。

  1. 如果我的理解是正确的,请纠正我,对于plugins选项,顺序并不重要,但在extends时,有时顺序很重要,就像我在问题 #2 中提到的那样。
  2. 如果extends选项的顺序很重要,当我有像eslint-plugin-prettier这样的扩展时,我如何确保它遵循顺序,当我不使用级联时它应该是最后一个。 例如:

如果我不使用级联,它应该像这里提到的那样:

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

如果我使用级联,我的设置将是这样的:

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

与此相关,我在子目录中创建.eslintrc.js文件后遇到了错误:

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

解决方案是在根配置中指定ignorePatterns: ['.eslintrc.js'],如此所述。

暂无
暂无

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

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