Skip to main content

Code Cleanup Rules

  • 4 minutes to read

Code Style

Title Description C# VB[1]
Collapse property accessors Converts all property accessors into a single-line form. CRR_IconPassed
Expand property accessors Converts all property accessors into a multi-line form. CRR_IconPassed
Format document[2] Runs the Document Formatting (C#) feature. CRR_IconPassed
Make properties auto-implemented Converts properties with fully described accessors to auto-implemented properties. CRR_IconPassed CRR_IconPassed
Use ‘nameof’ Converts string literals containing a variable or class member name to the nameof expression with the corresponding variable/member as an argument. CRR_IconPassed CRR_IconPassed

Layout

Title Description C# VB[1]
Add copyright header Adds a copyright comment at the file’s beginning. (configuration) CRR_IconPassed CRR_IconPassed
Move types to separate files Moves all types or selected types from one file to new separate files. CRR_IconPassed CRR_IconPassed
Organize members Sorts member declarations in the class and removes the redundant line breaks. CRR_IconPassed CRR_IconPassed
Sort namespace references Sorts namespace references alphabetically or by length. CRR_IconPassed CRR_IconPassed
Sync Namespace with Folder Structure Renames namespaces within a project, so they match the project’s folder structure. CRR_IconPassed CRR_IconPassed

Programming Style

Title Description C# VB[1]
Apply the ‘Attribute lists’ style[2] Combines attributes into a list or breaks attribute lists apart (according to the corresponding style rule). CRR_IconPassed CRR_IconPassed
Apply the ‘Attribute lists’ style to assembly-level attributes[2] Combines assembly-level attributes into a list or breaks attribute lists apart (according to the corresponding style rule). CRR_IconPassed CRR_IconPassed
Apply the ‘Braces in statements’ style Adds or removes optional block delimiters to/from all single-statement blocks (according to the corresponding style rule). CRR_IconPassed
Apply the built-in type style[2] Converts explicitly-typed variable declarations to implicit or vice versa (according to the corresponding style rule). The related Code Action is Make Implicit/Explicit. CRR_IconPassed CRR_IconPassed
Apply the expression body styles Converts single-statement properties and methods into expression-bodied structures. CRR_IconPassed
Apply namespace declaration style Applies the namespace declaration preferences specified in the Visual Studio style option or the .editorconfig file. This setting defines the file-scoped or block-scoped namespace body styles for C# 10. CRR_IconPassed
Apply the ‘Optional parenthesis’ style to attributes[2] Adds or removes optional parenthesis to/from the selected attributes (according to the corresponding style rule). CRR_IconPassed CRR_IconPassed
Apply the ‘Optional parenthesis’ style to the new object creation (for C#). Apply the ‘Optional parenthesis’ style to invocations (a constructor, method or property) (for Visual Basic).[2] Adds or removes optional parenthesis to/from the new object creation (for C#) or invocations (for Visual Basic) according to the corresponding style rule. CRR_IconPassed CRR_IconPassed
Apply the ‘Optional parenthesis’ style to explicitly specify the order of operations[2] Adds or removes optional parenthesis to explicitly specify the order of operations (according to the corresponding style rule). CRR_IconPassed CRR_IconPassed
Apply the ‘this’/‘Me’ qualifier style[2] Adds ‘this’/ ‘Me’ qualifier where required or removes it where possible (according to the corresponding style rule). CRR_IconPassed CRR_IconPassed
Apply the variable declaration style Converts CLR types to their keyword aliases or vice versa (according to the corresponding style rule). CRR_IconPassed CRR_IconPassed
Apply the visibility style[2] Adds type/member visibility modifiers where required or removes them where possible (according to the corresponding style rule). CRR_IconPassed CRR_IconPassed
Remove redundant braces in blocks without parent statement[2] Deletes optional block delimiters in “floating” code blocks. CRR_IconPassed
Sort modifiers[2] Sorts type/member visibility modifiers according to the corresponding style rule. This CRR_IconPassed

Redundant Code Removal

Title Description C# VB[1]
Remove all comments, excluding XML comments[2] Cleans the code from the non-XML comments. CRR_IconPassed CRR_IconPassed
Remove all regions[2] Cleans the code from the #region preprocessor directives. CRR_IconPassed CRR_IconPassed
Remove the redundant ‘base’/ ‘MyBase’ qualifier[2] Deletes the ‘base’/ ‘MyBase’ qualifier in all member references where it can be omitted. CRR_IconPassed CRR_IconPassed
Remove the redundant type cast[2] Deletes type casts in the places where they can be omitted. CRR_IconPassed CRR_IconPassed
Remove redundant type qualifiers[2] Deletes type qualifiers in the places where they can be omitted and adds the required using/Imports statements. CRR_IconPassed CRR_IconPassed

Strings

Title Description C# VB[1]
Convert to String Interpolation Converts all formatted strings into the string interpolations. CRR_IconPassed CRR_IconPassed
Convert to string.Empty[2] Converts all empty string literals (“”) into the string.Empty system constant. CRR_IconPassed CRR_IconPassed

Unused Code Removal

Title Description C# VB[1]
Remove unused members Deletes unused members. CRR_IconPassed CRR_IconPassed
Remove unused namespace references Deletes the unused namespace references. CRR_IconPassed CRR_IconPassed
Remove unused parameters Deletes unused method parameters. CRR_IconPassed CRR_IconPassed
Remove unused private types Deletes unused private nested types. CRR_IconPassed CRR_IconPassed
Remove unused types Deletes “internal”, “private” and “private protected” nested types, and “internal” regular types. CRR_IconPassed CRR_IconPassed
Remove unused variables Deletes unused variables. CRR_IconPassed CRR_IconPassed
Replace unused variables with discard Replaces unused variables with discard. CRR_IconPassed
Footnotes
  1. Visual Basic

  2. This Code Action is available separately.

See Also