如何覆盖
plugin:@nrwl/nx/typescript
中的 eslint 规则?我已对 .eslintrc.json
的根进行了此更改。
"rules": {
"@typescript-eslint/member-ordering": "warn"
},
在引入违反规则的演示后仍然出现错误
D:\me\sample\apps\my-app\src\app\app.component.ts
16:3 error Member outOfOrder should be declared before all instance method definitions @typescript-eslint/member-ordering
✖ 1 problem (1 error, 0 warnings)
Lint errors found in the listed files.
我也尝试将规则更改添加到打字稿的
overrides
部分。
无法在根级别进行设置,因为您的项目的
.eslintrc.json
将始终覆盖这些更改,因为 @nrwl/nx/typescript
在覆盖部分中设置。
不幸的是,您必须在覆盖部分中将其设置为每个项目。
如果您有多个项目和/或需要应用多个更改,您可以将其提取到
eslint-custom-overrides
文件中并将其用作 extends
部分中的最后一个:
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@nrwl/nx/typescript",
"../../eslintrc-custom-overrides.json"
],
},
...
],
...
}
你的
eslintrc-custom-overrides.json
看起来像这样:
{
"overrides": [
{
"files": ["*.ts"],
"rules": {
"@typescript-eslint/member-ordering": "warn"
}
}
]
}
查看有关 NX 问题的更多详细信息。
这现在在全局级别起作用,因此在根 .eslintrc.json 文件中,您可以添加例外。
例如,我想要规范文件中除“no-explicit-any”之外的所有规则。此配置有效:
"overrides": [
{...},
{
"files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
"env": {
"jest": true
},
"rules": {
"@typescript-eslint/no-explicit-any": "off"
}
}
]