![](/img/trans.png)
[英]ESLint is not recognizing "@typescript-eslint/eslint-plugin"
[英]How to add typescript-eslint rules to eslint
我正在使用 NX 構建 Angular 個應用程序,並且我已將其配置為使用 ESLint。 我們能夠配置內置規則,例如no-console
但@typescript-eslint/no-inferrable-types
不接受我們的覆蓋。 我們甚至嘗試將規則移動到overrides
部分的變量條目中,但沒有任何效果。
我們在哪里指定typescript-eslint
規則?
我們的根級別.eslintrc.json
:
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nrwl/nx"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nrwl/nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [
{ "sourceTag": "*", "onlyDependOnLibsWithTags": ["*"] }
]
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nrwl/nx/typescript"],
"parserOptions": { "project": "./tsconfig.*?.json" },
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nrwl/nx/javascript"],
"rules": {}
}
],
"rules": {
"no-console":"warn",
"@typescript-eslint/no-inferrable-types": "off"
}
}
根據我對 NX linting 工作原理的理解,我認為您可以將規則添加到覆蓋部分。
在下面的 JSON 中,您可以看到no-console
已添加到覆蓋數組元素的“規則”中,該數組元素具有與 *.ts 和 *.tsx 的文件匹配。
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nrwl/nx"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nrwl/nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [
{ "sourceTag": "*", "onlyDependOnLibsWithTags": ["*"] }
]
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nrwl/nx/typescript"],
"parserOptions": { "project": "./tsconfig.*?.json" },
"rules": {
"no-console":"warn"
}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nrwl/nx/javascript"],
"rules": {}
}
],
"rules": {
"@typescript-eslint/no-inferrable-types": "off"
}
}
重要的是哪個覆蓋了你放入規則的數組元素。我遇到了類似的問題,你可以在https://stackoverflow.com/a/71230627/990642的答案中看到我嘗試過的不同方法的完整解釋。
值得注意的是,似乎人們運氣好壞參半,覆蓋已經在plugins
或extends
中指定的規則。
您的插件引用數組中缺少插件。因此只有“@nrwl/nx”規則和其他沒有命名空間的規則將適用。 試試這個:“插件”:[“@nrwl/nx”,“@typescript-eslint”]。 哦,如果您只想將其應用於某種文件(例如 .ts 或 .tsx 文件),或者/和更改處理解析器,您也可以將其添加到“覆蓋”部分中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.