Shi*_*sad 11 javascript typescript eslint typescript-eslint
我正在开发一个混合了 TypeScript 和 JavaScript 文件的项目,并且我正在尝试为它们设置 linting 规则。我使用 ESLint 来 lint JS 文件,并使用typescript eslint 插件来 lint typescript 文件。由于我要添加 linting 的代码库相当大,我不得不关闭 JS 和 TS 的一些规则。当我尝试为 ESLint 创建配置文件时,这被证明是有点问题。在我的配置文件中。我有 JS 文件的主要规则集,然后为 *.ts 文件创建了一个覆盖部分,我可以在其中使用 typescript lint 规则。我的配置文件如下所示(规则部分只是代表性的)。
{
"extends": "eslint:recommended",
"rules": {
"no-unused-vars": "off",
"no-undef": "error",
"max-classes-per-file": "off"
},
"env": {
"es6": true,
"browser": true
},
"parserOptions": {
"ecmaVersion": 10
},
"overrides": [
{
"files": [
"*.ts"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-member-access": "off"
},
"parserOptions": {
"project": "tsconfig.json"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
我必须为 TS 文件创建一个覆盖部分,因为并非所有 JS 文件都包含在 tsconfig.json 中,这在尝试通过相同配置对所有 JS 和 TS 文件进行 lint 时会出现问题。
我现在遇到的问题是,为 TS 文件创建覆盖部分现在完全忽略了我在 JS 部分中所做的规则覆盖,最终我必须在 JS 配置和我为.TS 文件。有没有办法可以在覆盖中合并父部分中的规则,以便仅添加其他规则而不是完全替换它们?
GOT*_*O 0 14
您可以为 *.js 和 *.ts 文件添加第二个覆盖,并禁用其中的规则,即:
{
"extends": "eslint:recommended",
"rules": {
"no-undef": "error"
},
"env": {
"es6": true,
"browser": true
},
"parserOptions": {
"ecmaVersion": 10
},
"overrides": [
{
"files": [
"*.ts"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-member-access": "off"
},
"parserOptions": {
"project": "tsconfig.json"
}
},
{
"files": [
"*.js",
"*.ts"
],
"rules": {
"no-unused-vars": "off",
"max-classes-per-file": "off"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16148 次 |
| 最近记录: |