Removing unused imports in AngularJS project in bulk using Visual Studio Code

Viewed 3374

I'm tasked with cleaning our AngularJS project to remove unused imports and variables. I use VS Code and through TypeScript Hero extension I can do what I want to do one file at a time. However, is there a way to fix all typescript files in project?

1 Answers

For visual studio code, you can simply open your preference settings and add the following to your settings.json:

"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
  "source.organizeImports": true
}

You can also enable/disable on save per language using following setting.json:

"editor.formatOnSave": true,
"[typescript]": {
    "editor.codeActionsOnSave": {
        "source.organizeImports": true
    }
},

This new feature has been released since April last year in 2018. Hopefully this can be helpful!

Related