I have a class named Article
in my project. I want to find all its methods that are unused in the project. For a particular method I can press Alt+F7
and see where it's used, and if it's not used anywhere, I can delete it safely. Is it possible to automate the process and find all methods of the class that are unused without pressing Alt+F7
for each method?
Just use Analyze | Inspect Code with appropriate inspection enabled (Unused declaration under Declaration redundancy group). @CrazyCoder This shows unused fields and methods too, any way to show only unused classes? My 2 cents: on IntelliJ 2016.3. 4 the option is under Analyze > Run Inspection By Name.
Vulture - Find dead code. Vulture finds unused code in Python programs. This is useful for cleaning up and finding errors in large code bases. If you run Vulture on both your library and test suite you can find untested code.
PyCharm doesn't offer this feature since it isn't possible to reliably determine that a method is unused, because there are simply too many ways to call it dynamically.
But you may use Vulture to find most of dead code in a project. Refer to the following commands:
$ pip install -U vulture $ vulture path_of_project $ # Use --exclude for excluding particular files (e.g. virtualenv files) $ vulture --exclude=env path_of_project
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