Angular 和 eslint - 未找到规则 '@typescript-eslint/space-infix-ops' 的定义

标签 angular typescript eslint

我最近从我的 Angular 项目中删除了 tslint - 我读到它已经贬值了,所以我想我最好亲自动手并切换到 eslint。

因此,我删除了 tslint 文件,运行 ng add @angular-eslint/schematics 来安装 lint 原理图,安装了 airbnb typescript linter,修改了 ng lint 任务像这样运行...

"lint": "eslint -c .eslintrc.js --ext .ts ./src/app"

我添加了一个 .eslintrc.js 文件并使用以下内容填充它

module.exports = {
  root: true,
  extends: [
    'airbnb-typescript/base',
    'plugin:@angular-eslint/recommended'
  ],
  ignorePatterns: [
    'node_modules/',
    'build/',
    'dist/',
    'e2e/'
  ],
  rules: {
    'comma-dangle': ['error', 'only-multiline'],
    'max-len': ['error', {code: 120, tabWidth: 4}],
    'no-underscore-dangle': 'off',
    'no-await-in-loop': 'off',
    'import/prefer-default-export': 'off',
    'no-param-reassign': ['error', {props: false}],
    'strict': ['error', 'global'],
    'func-names': 'off', // I use a lot of unnamed functions
    'global-require': 'off',
    'class-methods-use-this': 'off', // Disabled for Angular Controllers,
    'import/extensions': [
      'error',
      'ignorePackages',
      {
        js: 'never',
        ts: 'never',
      }
    ]
  },
  plugins: [
    '@angular-eslint/eslint-plugin'
  ],
  parserOptions: {
    project: 'tsconfig.json',
    sourceType: 'module'
  }
}

一切都运行得很好...但是当我运行 ng lint 时,我收到以下错误...

1:1 错误 找不到规则“@typescript-eslint/space-infix-ops”的定义 @typescript-eslint/space-infix-ops 1:1 错误未找到规则“@typescript-eslint/object-curly-spacing”的定义@typescript-eslint/object-curly-spacing

这很奇怪,因为我没有在 .eslintrc.js 文件中包含这些规则?然后我运行 npm update 希望可以解决问题,但没有解决?我目前正在通过 stackoverflow 寻找答案,但如果有人有直接答案,请告诉我该怎么做,我们将不胜感激。

我不确定这是否有帮助,但这是我的 package.json 上的内容

"@angular-devkit/build-angular": "^0.1102.3",
"@angular-eslint/builder": "1.2.0",
"@angular-eslint/eslint-plugin": "1.2.0",
"@angular-eslint/eslint-plugin-template": "1.2.0",
"@angular-eslint/schematics": "1.2.0",
"@angular-eslint/template-parser": "1.2.0",
"@angular/animations": "^11.2.4",
"@angular/cli": "^11.2.3",
"@angular/common": "^11.2.4",
"@angular/compiler": "^11.2.4",
"@angular/compiler-cli": "^11.2.4",
"@angular/core": "^11.2.4",
"@angular/forms": "^11.2.4",
"@angular/http": "~7.0.0",
"@angular/language-service": "^11.2.4",
"@angular/platform-browser": "^11.2.4",
"@angular/platform-browser-dynamic": "^11.2.4",
"@angular/router": "^11.2.4",
"@compodoc/compodoc": "^1.1.11",
"@types/jasmine": "^2.8.17",
"@types/jasminewd2": "^2.0.8",
"@types/node": "^8.10.66",
"@typescript-eslint/eslint-plugin": "4.3.0",
"@typescript-eslint/parser": "4.3.0",
"codelyzer": "~4.5.0",
"core-js": "^2.6.9",
"eslint": "^7.6.0",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "30.7.6",
"eslint-plugin-prefer-arrow": "1.2.2",
"eslint-plugin-prettier": "^3.3.1",
"is-docker": "^1.1.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^2.0.6",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"material-design-icons": "^3.0.1",
"ng-packagr": "^11.2.4",
"ngx-highlightjs": "^4.1.3",
"prettier": "^2.2.1",
"protractor": "^5.4.4",
"roboto-fontface": "^0.10.0",
"rxjs": "~6.6.6",
"scss-bundle": "^2.5.1",
"tsickle": "^0.33.1",
"tslint": "~5.11.0",
"typescript": "~4.1.5",
"zone.js": "~0.11.4"

最佳答案

我设法通过强制版本 "@typescript-eslint/eslint-plugin": "^4.17.0" 解决了这个问题 - 仅使用 npm update 似乎不起作用

关于Angular 和 eslint - 未找到规则 '@typescript-eslint/space-infix-ops' 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66561002/

相关文章:

reactjs - Ant Design- autocomplete 不需要显示值

javascript - 我应该如何重构这段代码以防止函数在定义之前被使用

javascript - Angular v5 问题编译 Bootstrap4 样式

node.js - 在 AWS EC2 上部署 Angular 5 应用程序

Angular2 为什么异步管道

javascript - 在 Node ,js( typescript )中打开文件对话框

angular - 多个自动完成 Material Angular 显示相同的下拉菜单

node.js - 输出到另一个目录时,如何在 Typescript 编译过程中包含 .html 文件

reactjs - 由于弹出后出现 lint 警告,无法编译 create-react-app

reactjs - React 使用 TypeScript,不要使用 {} 作为类型。 {