简体   繁体   English

在Angular项目中查找无用的依赖注入

[英]Find useless dependencies injection in Angular project

I try to use Eslint to find useless dependencies injection in my Angular/Ionic components.我尝试使用 Eslint 在我的 Angular/Ionic 组件中查找无用的依赖项注入。

Example:例子:

import { BasicDataService } from '../../providers/basic-data.service';

@Component({
    selector: 'app-login',
    templateUrl: './login.page.html',
    styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {
    constructor(
        private bd: BasicDataService,
    ) {}
}

The property bd is defined in the constructor but then it is not used, how could Eslint highlight it?属性bd是在构造函数中定义的,但是没有被使用,Eslint 怎么会高亮呢?

My.eslintrc.json so far is: My.eslintrc.json 到目前为止是:

{
    "env": {
        "browser": true,
        "es2021": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:@typescript-eslint/eslint-recommended",
        "plugin:@typescript-eslint/recommended"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "plugins": ["@typescript-eslint"],
    "rules": {}
}


In one previous project, I used the rule @typescript-eslint/no-unused-vars-experimental but it seems it has been removed recently.在之前的一个项目中,我使用了规则@typescript-eslint/no-unused-vars-experimental ,但它似乎最近被删除了。

Thanks!谢谢!

There is no lint ESLint rule which does analysis of TS's private class properties.没有 lint ESLint 规则可以分析 TS 的私有 class 属性。

TS itself can do this though via its noUnusedLocals compiler option. TS 本身可以通过它的noUnusedLocals编译器选项来做到这一点。 Though note that this will also match unused variables.尽管请注意,这也将匹配未使用的变量。

https://www.typescriptlang.org/tsconfig#noUnusedLocals https://www.typescriptlang.org/tsconfig#noUnusedLocals

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

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