来自基于 Glob 模式的配置
glob 特定配置的工作方式几乎与任何其他 ESLint 配置相同。覆盖块可以包含在常规配置中有效的任何配置选项,root 和 ignorePatterns 除外。
在您的 eslint 配置文件中,您可以添加一个overrides
作为对象数组的部分。每个对象都需要有files
定义 glob 模式的键。任何匹配的文件都将使用覆盖的配置。例子:
{
// estree parser
"env": {
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:security/recommended"
],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"plugins": [
"security"
],
"rules": {
"indent": [ "error", 4 ]
},
// rest of your "normal" configuration here
"overrides": [{
// for files matching this pattern
"files": ["*.ts"],
// following config will override "normal" config
"parser": "babel-eslint",
"parserOptions": {
// override parser options
},
"plugins": [
"@babel/plugin-proposal-optional-chaining"
],
"rules": [
// override rules
],
},
}]
}
但是,如果您已经使用了@typescript-eslint/parser
,那么您可能已经匹配 *.ts 文件,并且覆盖只会使每个 *.ts 文件babel-eslint
改为使用,这并不能解决您的问题。
我假设您希望两个解析器(typescript-eslint 和 babel)都针对同一个文件运行,但我不知道简单的解决方案。