Pierre
Pierre

Reputation: 1246

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!

Upvotes: 0

Views: 1029

Answers (1)

Brad Zacher
Brad Zacher

Reputation: 3243

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

Upvotes: 1

Related Questions