我在此文件中收到 ESlint 错误
酒吧.ts:
class Bar {
constructor(public foo: string) {}
hello(): string {
return this.foo;
}
}
export default Bar;
Run Code Online (Sandbox Code Playgroud)
我的 eslint 配置:
{
"env": {
"browser": true,
"commonjs": true,
"es2020": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"airbnb/base",
"eslint-config-prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 11
},
"plugins": ["@typescript-eslint/eslint-plugin", "eslint-plugin-prettier"],
"rules": {
"prettier/prettier": "error",
"no-unused-vars": "warn",
"@typescript-eslint/no-var-requires": "warn",
"func-names": "off",
"no-underscore-dangle": "off",
"class-methods-use-this": "off"
},
"overrides": [
{
"files": ["*.ts"],
"excludedFiles": ["*.js"],
"rules": {
"@typescript/no-var-requires": "off"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
Bar.ts 上的 Eslint 错误:
Useless constructor. eslint(no-useless-constructor)
Run Code Online (Sandbox Code Playgroud)
如果你好奇为什么我的 eslint 配置看起来是这个样子,那是因为我试图用 JS 和 TS 文件设置一个项目,并使 ESLint 分别适用于每种类型的文件。
我需要在我的 ESLint 配置中更改什么才能使其不抱怨完全相关的代码?
ano*_*ser 14
感谢@jonrsharpe,我发现问题出在extends块内。特别airbnb/base是针对 js 文件。我不得不把它替换为airbnb-typescript/base,然后出现了另一个更关键的问题:
要使用airbnb-typescript/base,我必须:
project在 my 中添加一个选项parserOptions,指向tsconfig熟悉 TS 和 ESlint 的人可能从一开始就注意到我的 eslint 配置缺少该选项。
我很确定我在这里遗漏了很多东西,这不是关于这个主题的最后一个问题,但现在错误已经消失,我可以继续前进。
| 归档时间: |
|
| 查看次数: |
3714 次 |
| 最近记录: |