从Configuration Based on Glob Patterns
特定于全局的配置的工作原理与任何其他ESLint配置几乎相同。覆盖块可以包含常规配置中有效的任何配置选项,但root和ignorePatterns除外。
在您的eslint配置文件中,您可以添加overrides
节,该节是对象数组。每个对象都必须具有files
键,以在其中定义全局模式。然后,任何匹配的文件都将使用替代配置。示例:
{
// 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)都针对同一个文件运行,但是我不知道简单的解决方案。
本文链接:https://www.f2er.com/3153470.html