Automatically remove unused code with Resharper

Anatolii Humennyi

I clicked "Find Code Issues", then Resharper showed me list of unused classes and methods. But I can't find how to automatically remove all them. List of unused classes and methods contains thousands of lines, so сlicking on each line and delete method manually is not real. How to do it automatically?

I tried to use "Code Cleanup", but it doesn't remove unused classes and methods

The version of Resharper: JetBrains ReSharper 8.2.1 Full Edition Build 8.2.1000.4556 on 2014-05-19T09:12:38

Daniel Roberts

Unfortunately Resharper does not provide this feature as it can be unsafe.

To partially automate the deletion you can try installing AutoHotkey. This program will allow you to automate the entry of hotkeys and therefore 'automate' repetitive Resharper tasks like deleting unused code detected by Code Issues.

The following script automatically goes to the next code issue and attempts to 'Safely Delete'. If this takes too long it cancels it with {Escape} as this is generally means Resharper has found a conflict or usage.

#d::
    Loop {
        Send !{Del}
        Sleep, 500
        Send {Enter}
        Sleep, 1000
        Send {Escape}
        Sleep, 500
        Send {F8}
        Sleep, 500
    }
Return

To use this script click on the first item under the Type Or Member is Never Used category then hit the Win-D hot key. The script will then cycle through all the issues deleting the methods which do not have conflicts. To break the loop select outside of Visual Studio & Reload the script.

If you remove the Loop & {Escape} then you can use this as a single shortcut to delete & move to the next issue.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Automatically remove unused code with Resharper

From Dev

ReSharper remove unused directives In file adds summary and header to methods and parameters

From Dev

Scala tool to remove all unused code

From Java

Is there a way to remove unused imports for Python in VS Code?

From Dev

Remove unused C# code in Visual Studio

From Dev

Is there a way to remove unused imports for Python in VS Code?

From Dev

ReSharper "Remove Unused References" feature does not remove references added through NuGet packages

From Dev

Automatically remove unused parameters from constructor (Eclipse, Java)

From Dev

Remove unused variable declarations automatically - Android Studio/Inteiij

From Dev

Android : Automatically remove unused images from project bundle

From Dev

Automatically remove unused parameters from constructor (Eclipse, Java)

From Dev

Remove unused code / files from project in Xamarin Studio

From Dev

Delete Unused Languages Automatically

From Dev

Resharper - Disable notification for unused public methods

From Dev

Resharper marks my NUnit tests as unused

From Dev

Resharper marks my NUnit tests as unused

From Dev

Remove unused css classes

From Dev

Check for and remove unused PPAs

From Dev

Remove Unused Cells in Arrayformula

From Dev

Check for and remove unused PPAs

From Dev

Remove unused css classes

From Dev

Remove unused packages

From Dev

Remove unused classes in css

From Dev

Automatically add imports with ReSharper templates

From Dev

How To Remove unused CSS rules

From Dev

Remove unused Font Awesome icons

From Dev

Remove unused localizations from APK

From Java

Remove unused imports in Android Studio

From Dev

Remove separator from unused UITableViewCells

Related Related

HotTag

Archive