21

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?

4
  • An extension of which CLI command? If you mean ng, you can read about what the CLI offers here: angular.io/cli.
    – jonrsharpe
    Aug 12, 2021 at 15:31
  • 2
    i think ng lint command can show that. Aug 12, 2021 at 15:31
  • @AakashGarg I think that's what I'm looking for, thanks :) Aug 12, 2021 at 15:45
  • let me post it as answer then. Aug 12, 2021 at 15:48

2 Answers 2

19

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.

0
1

Use ng lint command, that will highlight all such things.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.