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?
2 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.
ng
, you can read about what the CLI offers here: angular.io/cli.