繁体   English   中英

出现 Angular Migrate TSLint to ESLint Banana-In-Box 错误

[英]Having Angular Migrate TSLint to ESLint Banana-In-Box Error

我的 Angular 项目从 TSLint 迁移到 ESLint 时遇到了重大问题。 我的工作方式是创建一个全新的项目(目前在 Angular 9 中),然后升级到 Angular 10.2。 我遵循了@angular-eslint/schematic process 中的指导方针,并且我已经运行了 npx tslint-to-eslint-config。 但是,当我尝试通过我的 Visual Studio Code 扩展程序运行 ESLint 时,我收到以下错误,因为它尝试 ESLint 我的 app.component.ts 文件:

Error while loading rule '@angular-eslint/template/banana-in-box': You have used a rule which requires '@angular-eslint/template-parser' to be used as the 'parser' in your ESLint config.

以下是 my.eslintrc.js 文件配置:

module.exports = {
"env": {
    "browser": true,
    "es6": true,
    "node": true
},
"extends": [
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"ignorePatterns": ["node_modules/**/*", "**/node_modules/**/*", "dist/**/*"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
    "project": "tsconfig.json",
    "sourceType": "module"
},
"plugins": [
    "eslint-plugin-import",
    "eslint-plugin-jsdoc",
    "@angular-eslint/eslint-plugin",
    "@angular-eslint/eslint-plugin-template",
    "eslint-plugin-prefer-arrow",
    "@typescript-eslint",
    "@typescript-eslint/tslint"
],
"rules": {
  ...
  "@angular-eslint/template/banana-in-box": "error",
  ...
},
root: true,
"overrides": [
  {
    "files": ["*.ts"],
    "parserOptions": {
      "project": [
        "tsconfig.*?.json",
        "e2e/tsconfig.json"
      ],
      "createDefaultProgram": true
    },
    "extends": [
      "plugin:@angular-eslint/recommended",
      "plugin:@angular-eslint/ng-cli-compat",
      "plugin:@angular-eslint/ng-cli-compat--formatting-add-on",
      "plugin:@angular-eslint/template/process-inline-templates"
    ],
    "rules": {
      "@angular-eslint/component-selector": [
        "error", { "type": "element", "prefix": "app", "style": "kebab-case" }
      ],
      "@angular-eslint/directive-selector": [
        "error", { "type": "attribute", "prefix": "app", "style": "camelCase" }
      ],
      "@typescript-eslint/explicit-member-accessibility": [
        "off", { "accessibility": "explicit" }
      ],
      "arrow-parens": [
        "off",
        "always"
      ],
      "import/order": "off"
    }
  },
  {
    "files": [
      "*.html"
    ],
    "extends": [
      "plugin:@angular-eslint/template/recommended"
    ],
    "rules": {}
  },
  {
    "files": ["*.component.html"],
    "extends": ["plugin:@angular-eslint/template/recommended"],
    "rules": {
      "max-len": ["error", { "code": 200 }]
    }
  },
  {
    "files": ["*.component.ts"],
    "extends": ["plugin:@angular-eslint/template/process-inline-templates"]
  }
]};

每次我尝试将该模板添加为扩展时,都会出现另一个错误。 唯一能阻止错误的是,如果我评论排除。 有人可以帮我弄清楚如何让这个规则起作用并消除这个错误吗?

替换部分parser对我有用:


你的配置:

"parser": "@typescript-eslint/parser",

应该替换为

"parser": "@angular-eslint/template-parser",

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM