【问题标题】:Cascading eslint config file级联 eslint 配置文件
【发布时间】:2020-09-25 06:41:50
【问题描述】:

我有几个关于级联 eslint 配置文件的问题:

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

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

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

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

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"

【问题讨论】:

    标签: visual-studio-code eslint prettier


    【解决方案1】:
    root: true
    parser: "@typescript-eslint/parser"
    extends:
      - "eslint:recommended"
      - "plugin:@typescript-eslint/recommended"
      - “./path/your_other_config”
      - "prettier"
      - "prettier/@typescript-eslint"
    

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 2014-12-18
        • 2016-05-31
        • 2019-01-08
        • 1970-01-01
        • 1970-01-01
        • 2021-12-09
        • 2020-11-20
        • 1970-01-01
        • 2020-07-04
        相关资源
        最近更新 更多