ESLint - 每次导入的“no-unused-vars”警告

时间:2021-07-26 08:24:31

标签: typescript eslint

我正在使用一个 Angular 项目,只是想再次将 ESLint 与 Prettier 一起使用。可悲的是有一个烦人的问题,每次导入都显示警告 'XYZ' is defined but never used. eslint(@typescript-eslint/no-unused-vars)

enter image description here

enter image description here

只有完全禁用此规则才能解决此问题。但是我不会像第 22 行那样得到未使用的 const 变量的提示。

我的 eslintrc.json:

{
  "parser": "@typescript-eslint/parser", // Specifies the ESLint parser
  "extends": [
    "plugin:angular/johnpapa", //ESLint rules for your angular project with checks for best-practices, conventions or potential errors.
    "plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
    "prettier", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
    "plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
  ],
  "parserOptions": {
    "ecmaVersion": 2020, // Allows for the parsing of modern ECMAScript features
    "sourceType": "module" // Allows for the use of imports
  },
  "settings": {
    "angular": {
      "version": "detect" // Tells eslint-plugin-react to automatically detect the version of React to use
    }
  },
  "root": true,
  "env": {
    "node": true,
    "jest": true
  },
  "rules": {
    // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
    "no-empty-function": "off",
    "@typescript-eslint/no-empty-function": ["off"],
  },
  "ignorePatterns": ["/*.*"]
}

使用的依赖项:

"@typescript-eslint/eslint-plugin": "^4.28.4",
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-angular": "^4.0.1",
"eslint-plugin-prettier": "^3.4.0",
"prettier": "^2.3.2",
"prettier-eslint": "^12.0.0",

0 个答案:

没有答案