[英]Angular Eslint config is not extending Project Eslint config
I have an angular 12.x project and it uses eslint, this is the current root configuration file:我有一个 angular 12.x 项目,它使用 eslint,这是当前的根配置文件:
{
"env": {
"browser": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.base.json",
"sourceType": "module"
},
"plugins": [
"eslint-plugin-import",
"@angular-eslint/eslint-plugin",
"@angular-eslint/eslint-plugin-template",
"@typescript-eslint"
],
"extends": ["prettier", "eslint:recommended"],
"rules":{... lots of rules}
}
One of the rules I need to work is the member-ordering as described on their docs .我需要工作的规则之一是他们的文档中描述的成员排序。
I have a libs (created using NX) that are re-usable components, let me use MyComponent for this example.我有一个库(使用 NX 创建)是可重用的组件,让我在此示例中使用 MyComponent。 That component has its own eslintrc which extends the root one, below its contents:
该组件有自己的 eslintrc,它扩展了根目录,在其内容下方:
{
"extends": ["../../../.eslintrc.json"], //path to the root eslintrc
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@nrwl/nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "suppressed",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "suppressed",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nrwl/nx/angular-template"],
"rules": {}
}
]
}
And this is MyComponent
that uses uses the above eslintrc:这是使用上述 eslintrc 的
MyComponent
:
export class MyComponent implements OnInit, OnDestroy {
constructor() {}
ngOnInit(): void {}
@Dispatch()
clearState() {
return new ViewActions.ClearState();
}
private functio() {
return null;
}
static handle() {}
ngOnDestroy(): void {
this.clearState();
}
}
Based on the default config of the rule as per the doc I linked, the code above should have errors starting on the @Dispatch()
all the way to the destroy()
due to violation of the rule.根据我链接的文档中规则的默认配置,由于违反了规则,上面的代码应该有从
@Dispatch()
开始一直到destroy()
的错误。
But the output is different from the expected:但输出与预期不同:
Now, if I add the rule config as per the docs, into my component eslintrc.json, it will work as expected which is: Method clearState
will have the error, as it is annotated and it is expected to come before a non-annotated method, in this ngOnInit
and errors for the private one as well.现在,如果我按照文档将规则配置添加到我的组件 eslintrc.json 中,它将按预期工作,即:方法
clearState
将有错误,因为它已被注释,并且预计会出现在未注释之前方法,在这个ngOnInit
和私有的错误也是如此。
The actual problem is that the very first line on my component eslintrc.json has extends
targeting the root eslintrc, and I wanted to have all my rules overridden on that file.实际问题是我的组件 eslintrc.json 的第一行
extends
针对根 eslintrc,我希望在该文件上覆盖我的所有规则。 If I change the member-ordering to the root eslintrc, the rule stops working and it is reverted to that error of the image added.如果我将成员排序更改为根 eslintrc,规则将停止工作,并恢复为添加的图像的错误。
Also, when running npx eslint --print-config .\\my-component.ts
from my component directory, I get following config for member-ordering being applied:此外,当从我的组件目录运行
npx eslint --print-config .\\my-component.ts
,我得到以下用于成员排序的配置:
"@typescript-eslint/member-ordering": [
"error",
{
"default": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
I really don't know where that is coming from.我真的不知道这是从哪里来的。
Does anyone know why my component eslint is not extending the rules from the root eslintrc?有谁知道为什么我的组件 eslint 没有从根 eslintrc 扩展规则?
===== Update ========== ======更新==========
Eslint related dependencies on package.json package.json 上的 Eslint 相关依赖
"@angular-eslint/eslint-plugin": "1.1.0",
"@angular-eslint/eslint-plugin-template": "1.1.0",
"@angular-eslint/template-parser": "12.3.0",
"@nrwl/eslint-plugin-nx": "12.9.0",
"@typescript-eslint/eslint-plugin": "4.28.5",
"@typescript-eslint/eslint-plugin-tslint": "4.12.0",
"@typescript-eslint/parser": "4.28.5",
"eslint": "7.32.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-cypress": "2.10.3",
"eslint-plugin-import": "2.24.0",
"@angular-eslint/schematics": "12.3.1",
May be this helps.可能这有帮助。 I think you should in general tend to use "root": true in the projects.
我认为您通常应该在项目中使用"root": true 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.