visual-studio-code - 级联eslint配置文件

标签 visual-studio-code eslint prettier

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

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

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

  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"

最佳答案

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

关于visual-studio-code - 级联eslint配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62225824/

相关文章:

javascript - 共享 eslint 配置找不到节点模块

spring - 在VS代码中将spring应用程序部署到azure时,访问应用程序的端点是什么?

typescript - 如何隐藏函数参数缺失类型通知?

javascript - Eslint 未定义导入问题

reactjs - 保存困惑的 .jsx 文件时采用更漂亮的格式

javascript - 对象中最后一行后的尾随逗号

visual-studio-code - 如何在 VS Code 中将文件扩展名与某种语言关联

visual-studio-code - WSL2 终端无法识别 Visual Studio Code

javascript - Eslint 内联注释允许在 javascript 文件中使用双引号

eslint - 使用 eslint 强制缩进属性?