简体   繁体   English

Angular Eslint 配置没有扩展 Project Eslint 配置

[英]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.

相关问题 用于删除行的 ESLint Lint 缩进配置 - ESLint Lint Indent Config for dropped lines eslint 错误 '$localize' 没有为 angular 项目定义 - eslint error '$localize' is not defined for angular project Angular项目返回类型的esLint规则 - esLint rule for return type of the Angular project 使用“typescript-eslint/recommended”和“@angular-eslint/recommended”扩展多个规则集可以吗? - Extending multiple rule-sets using "typescript-eslint/recommended" with "@angular-eslint/recommended" is this okay to do? Docker配置角度项目 - Docker config angular project Visual Studio 警告:(ESLint)无法加载配置“defaults/configurations/eslint”以扩展。 引用自 C:\Users\{用户名}\.eslintrc - visual studio warning: (ESLint) Failed to load config "defaults/configurations/eslint" to extend from. Referenced from C:\Users\{username}\.eslintrc 如何为 protractor 项目设置 angular-eslint? - How do I need to setup angular-eslint for a protractor project? 如何在角度项目中禁用 package.json 中的 eslint? - How to disable eslint from package.json on an angular project? 有没有办法在 Angular 项目中列出所有活动的 ESLint / Prettier 规则? - Is there a way to list all active ESLint / Prettier rules in an Angular project? 使用 Airbnb-Typescript-ESLint-Config 命名私有字段和冲突的成员排序 - Naming private fields and conflicted member ordering with the Airbnb-Typescript-ESLint-Config
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM