簡體   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