[英]How do I override an eslint rule in my nx workspace?
How do I overrride the eslint rules in plugin:@nrwl/nx/typescript
?如何覆盖plugin:@nrwl/nx/typescript
中的 eslint 规则? I've made this change to the root of .eslintrc.json
.我已经对.eslintrc.json
的根进行了更改。
"rules": {
"@typescript-eslint/member-ordering": "warn"
},
and still get an error after introducing a demonstration violation of the rule并且在引入违反规则的演示后仍然出现错误
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.
I tried adding the rule change to the overrides
section for typescript too.我也尝试将规则更改添加到 typescript 的overrides
部分。
There is no way to set this on the root level as your project's .eslintrc.json
will always override those changes due to @nrwl/nx/typescript
being set in the overrides section.由于在覆盖部分设置了@nrwl/nx/typescript
,因此无法在根级别设置它,因为您的项目的.eslintrc.json
将始终覆盖这些更改。
You will unfortunately have to set this is every project in the overrides section.不幸的是,您必须将其设置为覆盖部分中的每个项目。
If you have multiple projects and/or multiple changes that need to be applied, you can extract it into eslint-custom-overrides
file and use it as the last in the extends
section:如果您有多个项目和/或需要应用多个更改,您可以将其提取到eslint-custom-overrides
文件中,并将其用作extends
部分中的最后一个:
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@nrwl/nx/typescript",
"../../eslintrc-custom-overrides.json"
],
},
...
],
...
}
Your eslintrc-custom-overrides.json
would look like this:你的eslintrc-custom-overrides.json
看起来像这样:
{
"overrides": [
{
"files": ["*.ts"],
"rules": {
"@typescript-eslint/member-ordering": "warn"
}
}
]
}
I have found a solution that works great for me that avoids any copy pasting (that I found unacceptable) and more or less goes against the "not possible" assertion in the accepted answer.我找到了一个对我很有用的解决方案,它可以避免任何复制粘贴(我认为这是不可接受的),并且或多或少地违背了已接受答案中的“不可能”断言。 The key for me was not using the file based overrides and do extends instead.对我来说,关键不是使用基于文件的覆盖,而是使用扩展。 It works great and does exactly what I want it to do (and not seeing any downsides).它工作得很好,并且完全符合我的要求(并且没有看到任何缺点)。 Hope it helps:希望能帮助到你:
A NextJS / React UI project一个 NextJS / React UI 项目
A config for a NodeJS GraphQL project NodeJS GraphQL 项目的配置
A config for all NextJS / UI Projects所有 NextJS / UI 项目的配置
A config for everything that can be overridden by anything above可以被上述任何内容覆盖的所有内容的配置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.