New CodeRush Plugin – Cleanup File and Namespaces

This plugin wraps up 2 existing tasks (The ‘CleanupFile’ command and the ‘Optimize Namespace References’) in to a single new command ‘CleanupFileAndNamespaces’.

In order to use this plugin:

Step 0 – Requirements

This plugin requires version 13.2 of CodeRush and a non-express version of Visual Studio version 2010 or higher.
If you have a current CodeRush subscription, you can download the latest version through our download centre.
If not, you can download a 30 day trial of all of our .Net products, including CodeRush.

Step 1 – Download

This plugin is hosted on GitHub and is available as either VSIX or as Sourcecode

VISX_CleanupFileAndNamespaceCleanupFileAndNamespacesSourceCode

Step 2- Install

If you have downloaded the source, you will have to compile the plugin yourself, and then install from the VISX which the compile process creates.

Once you have the VISX, (via download or compilation) simply double click it, and follow the prompts.

CleanupFileAndNamespacesInstaller

Step 3 - Configuration

All that is necessary to configure this plugin, is to assign a key to the new ‘CleanupFileandNamespaces’ command.

This is done via the Shortcuts options page.

  • To open the options screen either choose DevExpress\CodeRush\Options from the main menu, or use the Ctrl+Shift+Alt+O shortcut.
    To locate the shortcuts options page, locate the IDE\Shortcuts item in the tree on the left, or use the ShortcutsPageIcon icon in the upper right of the options screen.
  • CleanupFileAndNamespacesNewShortcut  Create a new shortcut by right clicking in an appropriate folder and choosing ‘New Keyboard Shortcut’ or ‘New Mouse Shortcut’.
  • CleanupFileAndNamespacesShortcutKeysThen choose a suitable key or mouse combination based on your preferences and previous choice. I usually pick Ctrl+T for testing purposes.

 

 

CleanupFileAndNamespacesCommand Next choose the ‘CleanupFileAndNamespaces‘ command from the commands dropdown.

Finally you should set the context of this command to make it only available when you are within a .vb or .cs file. CleanupFileAndNamespacesContext

Finally click OK to accept your changes.

Create a new shortcut and assign it to the the ‘CleanupFileAndNamespaces’ command.

Step 4 – Usage

  • Place your caret in any .cs or .vb file. and invoke using the configured shortcut. CodeRush will run the ‘Optimize Namespace References’ refactoring and follow that by running any configured Code Clean operations.

For example:

The following is a fresh C# Library project, with a single unused variable declared.

SimpleClassLibraryWithUnusedDeclaration

Assuming that you have the default settings for Code Cleanup, and you trigger CleanupFileAndNamespaces from this start position, CodeRush will remove the unused using directive and the unused declaration:

SimpleClassLibraryWithUnusedDeclarationAfterCleanup

This simple plugin links together 2 often used features so that they can operate as one.

In my next post I’ll explain how this plugin works in detail.

2 comment(s)
Glen Harvy
Glen Harvy

Hi,

VS2013:

Followed instructions explicitly. Placed caret at top of test class file containing same code as in blog except "unused = string.Empty".

The using reference was removed virtually immediately however "Code cleanup" has now been running for over 4 minutes. It is a largish project. This has created over 58 errors "Identifier expected" and the test code has not been removed.

Have removed temporary shortcut but am unable to remove from Plug-Ins.

16 December, 2013
Rory Becker (DevExpress)
Rory Becker (DevExpress)

Hey Glen

The excessive length of time for "Code Cleanup" seems like a bug. If you could report this in the Support Center (www.devexpress.com/.../Center) that would be very helpful.

Additionally, plugins installed via VISX are not found in the same place as other plugins. Instead they are uninstallable via the "Tools\Extensions and Updates..."

16 December, 2013

Please login or register to post comments.