简体   繁体   中英

Find useless dependencies injection in Angular project

I try to use Eslint to find useless dependencies injection in my Angular/Ionic components.

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?

My.eslintrc.json so far is:

{
    "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.

Thanks!

There is no lint ESLint rule which does analysis of TS's private class properties.

TS itself can do this though via its noUnusedLocals compiler option. Though note that this will also match unused variables.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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