简体   繁体   English

升级到 ESLint 时导入错误以定义规则

[英]Upgrading to ESLint with error at imports for definition of rules

I am working on a local project and I have upgrade Angular v9 to v10 together with TSLint to ESLint.我正在做一个本地项目,我已经将 Angular v9 升级到 v10 以及 TSLint 到 ESLint。 I referred to this github repo for migraiton https://github.com/angular-eslint/angular-eslint我提到了这个 github repo for migraiton https://github.com/angular-eslint/angular-eslint

So my project uses libs which means it does have more than one project.所以我的项目使用了库,这意味着它确实有多个项目。 I configured the eslintrc.json but I am occuring on errors.我配置了 eslintrc.json 但我发生了错误。 The first of the errors which is comming it is即将出现的第一个错误是

Definition for rule '@angular-eslint/component-selector' was not found  @angular-eslint/component-selector

Even though the @angular-eslint/component-selector is defined on every each first line of *.ts files it throws that error.即使在 *.ts 文件的每个第一行都定义了@angular-eslint/component-selector ,它也会引发该错误。

My Eslint of main lib it looks like this eslintrc.json我的主库的 Eslint 它看起来像这样 eslintrc.json

{
  "root": true,
  "ignorePatterns": [
    "!**/*"
  ],

  "overrides": [
    {
      "files": [
        "*.ts"
      ],
      "parserOptions": {
        "project": [
          "**/tsconfig.json"
        ],
        "createDefaultProgram": true
      },
      "extends": [
        "plugin:@typescript-eslint/eslint-recommended",
        "plugin:@typescript-eslint/recommended"
      ],

      "rules": {
        "@angular-eslint/component-selector": [
          "error",
          {
            "prefix": "lib",
            "style": "kebab-case"
          }
        ],
        "@angular-eslint/directive-selector": [
          "error",
          {
            "prefix": "lib",
            "style": "camelCase"
          }
        ],
        "max-len": ["error", { "code": 140 }],
        "@typescript-eslint/explicit-module-boundary-types": "off",
        "@typescript-eslint/ban-ts-comment": "off",
        "@typescript-eslint/naming-convention": [
          "error",
          {
            "selector": "variable",
            "format": ["camelCase", "UPPER_CASE", "PascalCase"]
          }
        ]
      }
    },
    {
      "files": [
        "*.html"
      ],
      "rules": {
        "arrow-body-style":"error",
        "@typescript-eslint/prefer-function-type":"error"
       }
    }
  ]
}

This is my eslintrc.json of one of the libs这是我的库之一的eslintrc.json

{
  "extends": "../../.eslintrc.json",
  "ignorePatterns": [
    "!**/*"
  ],
  "overrides": [
    {
      "files": [
        "*.ts"
      ],
      "parserOptions": {
        "project": [
          "apps/login/tsconfig.app.json",
          "apps/login/tsconfig.spec.json",
          "apps/login/tsconfig.json"
        ],
        "createDefaultProgram": true
      },
      "rules": {
        "@angular-eslint/directive-selector": [
          "error",
          {
            "type": "attribute",
            "prefix": "app"
          }
        ],
        "@angular-eslint/component-selector": [
          "error",
          {
            "type": "element",
            "prefix": "app"
          }
        ]
      }
    },
    {
      "files": [
        "*.html"
      ],
      "rules": {}
    }
  ]
}

For everyone so may know, I have found the error.对于每个可能知道的人,我发现了错误。 It is because at the plugins it needed to be added the angular-eslint plugin.这是因为在插件中需要添加 angular-eslint 插件。 I have added this one我添加了这个

 "plugin:@angular-eslint/recommended",

And it did the job.它完成了这项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 9 + eslint:找不到规则“@angular-eslint/…”的错误定义 - Angular 9 + eslint: error Definition for rule '@angular-eslint/…' was not found 升级到 EsLint:angular.json 出错(原理图:convert-tslint-to-eslint) - Upgrading to EsLint: Error with angular.json (schematics:convert-tslint-to-eslint) Eslint - 配置规则位置 - Eslint - configured rules location ESLint:忽略警告规则 - ESLint: ignore warning rules 如何将 typescript-eslint 规则添加到 eslint - How to add typescript-eslint rules to eslint “TSLint 仍然存在”=> 从 TSlint 升级到 ESLint - “TSLint still there” => upgrading from TSlint to ESLint 在我的 angular 项目中设置规则 'max-classes-per-file'。 ESLint 触发的错误是“文件有太多类” - Setting rules 'max-classes-per-file' in my angular project. Error trigger by ESLint is '"File has too many classes" 升级 Angular 9 后共享模块的导入在共享组件中不起作用 - Imports of Shared Module not working in Shared components after upgrading Angular 9 有没有办法在 Angular 项目中列出所有活动的 ESLint / Prettier 规则? - Is there a way to list all active ESLint / Prettier rules in an Angular project? ESlint Angular - no-unused-vars 命中类型定义 - ESlint Angular - no-unused-vars hits type definition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM