I and my team are working on an angular application from more than a year now. As part of our code refactoring process we want to delete unused or dead code from our repo.
Is there any technique or tool which automatically detects this unused code from our repo, the it would be helpful for us to it instead of wasting a lot of time and efforts detecting them manually?
The quickest way to find dead code is to use a good IDE. Delete unused code and unneeded files. In the case of an unnecessary class, Inline Class or Collapse Hierarchy can be applied if a subclass or superclass is used. To remove unneeded parameters, use Remove Parameter.
It is currently not possible to detect unused public methods in VSCode (you can check for updates here). However, if it's a private method, you can mark it as private and VSCode is able to look for whether it is used or not within the scope (although do remember: methods used in the HTML template are public).
To achieve this you can use the UglifyJS Plugin. With this setup, webpack will detect unused code and mark it as such however UglifyJS will actually cleanup that code and eliminate it from the bundle.
Thats very simple. if you run your application with " ng serve --aot "
cli command instead of " ng serve "
, it shows you a hole number of these dead codes(like when you leave " ng build --prod "
command).
For VS Code you can use this: https://eslint.org/docs/rules/no-unused-vars
What it does
: Variables that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such variables take up space in the code and can lead to confusion by readers.
There isn't something that delete the code for you, but I think this is a good extension to start with.
If you use sublime there is nothing since is just a text editor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With