coderushforroslyn-115683-code-style-assistance-code-cleanup.md
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.
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”.
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.
You can specify files and regions that contain generated code on the Editor | All Languages | Generated Code page.
CodeRush skips the specified items in code cleanup and code analysis.
Note
The Generated Code page already includes commonly used file masks and regions for generated code (for example, the “*.Designer.cs” file).
Follow the steps below to run code cleanup in an open file:
The screencast below shows the code cleanup with applied Organize members and Format document rules.
You can also use the following methods to execute code cleanup:
Visual Studio menu
Open the CodeRush | Edit menu and choose Cleanup Document.
Visual Studio toolbar
Click the Run Code Cleanup button on the CodeRush Visualize toolbar.
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.
Follow the steps below to run code cleanup in a project:
CodeRush shows a progress window when it calculates changes that Code Cleanup should apply in code.
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.
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.
You can cancel code cleanup while it is still in progress, all code remains unchanged.
See Also