Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an extension or CLI command to find all deprecated methods used in a project?

While working on individual files if a deprecated method is used VS Code puts a helpful strikethrough over it. Is there a way to do a search of a whole project (Angular in my case) to flag all deprecated methods that are currently being used without having to go through each and every file?

like image 706
Alex Marshall Avatar asked Sep 07 '25 05:09

Alex Marshall


1 Answers

You can indeed use the linter for that. If it doesn't show deprecated code, you will need to configure this in your linter first.

Check these links for more information on how, for ESLint & TSLint.

You want to add the mentioned configuration under "rules" in either tslint.json or .eslintrc.

In tslint.json:

"rules": {
    "deprecation": {
      "severity": "warning"
    },
}

In .eslintrc.json:

"overrides": [
    {
      "files": ["*.ts"],
      ...
      "plugins": ["deprecation"],
      ...
      "rules": {
        "deprecation/deprecation": "warn",
        ...
      }
      ...
]

Make sure to install this plugin first for ESLint.

npm i eslint-plugin-deprecation --save-dev

If you are creating a new project with Angular 12, you might first have to install a linter. I would suggest using ESLint, as TSLint has been deprecated by Palantir for almost a year now.

npm i @angular-eslint/schematics --save-dev

After that you can just run this in your terminal:

ng lint

Some, but not all rules can be fixed automatically with:

ng lint --fix

In your case though, fixing deprecated code will have to happen manually.

like image 129
H3AR7B3A7 Avatar answered Sep 09 '25 05:09

H3AR7B3A7