[英]ESLint - "no-unused-vars" warning for every import
我正在使用一個 Angular 項目,只是想再次將 ESLint 與 Prettier 一起使用。 可悲的是,有一個煩人的問題,即每次導入都顯示警告'XYZ' is defined but never used. eslint(@typescript-eslint/no-unused-vars)
'XYZ' is defined but never used. eslint(@typescript-eslint/no-unused-vars)
如果我完全禁用此規則,我只能解決此問題。 但是我不會像第 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",
似乎某些版本之間存在問題,並且缺少一個包。 包"@typescript-eslint/parser": "^4.19.0"
。
它現在適用於devDependencies
中的以下包:
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0",
"eslint": "^7.23.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-angular": "^4.0.1",
"prettier": "^2.3.2",
"prettier-eslint": "^12.0.0"
在此之前,eslint 軟件包的版本甚至更新:
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-angular": "^4.0.1",
"eslint-plugin-prettier": "^3.4.0"
所以我使用了 npm 命令npm update --save-dev
來更新所有的 dev 依賴項,這些依賴項降級了列出的依賴項並使其工作。
您可以使用import type { TranslateService } from "..."
來精確說明這僅用於鍵入,而不是代碼中的實際變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.