Code Cleanup

  • 3 min to read

Code Cleanup allows you to specify which Refactorings and Code Formatters CodeRush should apply to a document during cleanup. This feature helps you refactor a large amount of code.

Configure Cleanup

  • Open the Editor | C# (Visual Basic) | Code Cleanup options page.

  • Choose rules CodeRush should apply when you call code cleanup and enable "Apply In Action".

  • Choose rules CodeRush should apply in code cleanup before a file is saved and enable "Apply on Save".

Note

CodeRush does not clean up a file when you close the unsaved file or solution.

  • Enable the Apply Code Cleanup when saving a document option to allow CodeRush to clean up a file before it is saved.

  • Click OK to save and apply the settings.

CRR_CodeCleanUp

Clean a File Up

Follow the steps below to execute code cleanup in an open file:

  • Place the caret anywhere in your code.
  • Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.
  • Choose Code Cleanup from the menu and press Enter.

The screencast below shows the code cleanup with applied Organize members and Format document rules.

CleanUpCall

You can also use the following methods to execute code cleanup:

  • Visual Studio menu

    Open the CodeRush | Edit menu and choose Cleanup Document.

    CleanUpCall

  • Visual Studio toolbar

    Click the Run Code Cleanup button on the CodeRush Visualize toolbar.

    CleanUpCall

Clean a File Up on Save

Click the Save button or press Ctrl + S in the editor.

The screencast below shows the code cleanup with applied Organize members and Format document rules.

CleanUpCall

Clean a Project Up

Follow the steps below to run code cleanup in a project:

  • Right-click the project you want to clean in the Solution Explorer.
  • Select CodeRush Cleanup in the context menu.

CleanUpProject

CodeRush shows a progress window when it calculates changes that Code Cleanup should apply in code.

Style_CleanUpProject

If you cancel the process, the code remains unchanged.

Note

Use Visual Studio's Undo action (Edit | Undo menu item) to undo the cleanup after its completion. This action is available when a document is open.

CodeRush applies the changes to documents when the calculation is finished.

ApplyClean

Clean a Folder Up

You can run Code Cleanup for a selected folder (folders) in the Solution Explorer.

Right-click the folder (folders) in which you want to clean files and select CodeRush Cleanup.

Style_CleanUpProject

You can cancel code cleanup while it is still in progress, all code remains unchanged.

Style_CleanUpProject

See Also