ReSharper Web Help

ReSharper | Options | Code Editing | Code Cleanup

This page of ReSharper options allows you to manage and configure custom Code Cleanup profiles, as well as to assign a cleanup profile for silent code cleanup.

Note that ReSharper also provides two default cleanup profiles that you cannot modify and that are not displayed on this page: Full Cleanup and Reformat Code,

Item Description
Custom cleanup profiles List of available custom code cleanup profiles. See Creating Custom Profiles for more information.
Add Adds a new empty profile, prompting you to specify a name for it.
Delete Deletes the selected profile without prompting for confirmation.
Rename Renames the selected profile.
Selected profile settings Displays code cleanup settings of the selected cleanup profile.
Profile to use with silent cleanup Allows choosing one of the default cleanup profiles or a custom cleanup profile that will be used for silent code cleanup. ReSharper does not make a default selection of the silent cleanup profile. It means that until you select a profile by yourself, ReSharper will open the Code Cleanup dialog box whenever you launch silent code cleanup.

Code cleanup settings

Profile setting Description
ASP.NET
Optimize @Register directives Removes unused @Register directives.
HTML
Reformat code Reformats your code according to options configurable in the Formatting Style.
C#
Arrange 'this' qualifier Applies a rule selected in the Other | Force 'this.' qualifier for instance member drop-down list in the ReSharper | Options | Code Editing | C# | Formatting Style | Other and removes redundant this. qualifiers.
Remove code redundancies

In the ReSharper | Options | Code Inspection | Inspection Severity, ReSharper lists over 70 redundancies that have associated code inspections. Some of them require special attention, and you simply cannot process them in batch mode. That leaves Code Cleanup with about 30 redundancies that it is able to remove automatically whenever you select Remove code redundancies in your cleanup profile. Specifically, Code Cleanup:

  • Removes:
    • Redundant empty constructors.
    • Explicit integer type specifiers in enumerations.
    • true specifiers in for statements.
    • Redundant type casts.
    • Redundant parentheses from attributes without arguments.
    • Explicit calls to base class constructors without arguments.
    • Redundant boolean comparisons.
    • Redundant braces from collection initializers with a single expression.
    • Redundant explicit delegate creation expressions.
    • Empty argument lists from object/collection initializers.
    • Redundant new keywords.
    • Redundant partial modifiers on type declarations where a type has a single part.
    • Redundant unsafe contexts and statements.
    • Redundant object.ToString() calls (for example, in a concatenation with a string or as an argument of a string.Format() call).
    • Redundant string.ToCharArray() calls.
    • Redundant specifications of argument types.
    • Signatures in anonymous methods where its parameters are not used in the method body.
    • Non-referenced labels.
    • Redundant field initializers.
    • Redundant explicit names in anonymous type properties.
    • Redundant nullable types where value type is implicitly convertible to nullable.
  • Converts:
    • Nullable types to short form Nullable<T> to T?).
    • Static method invocations to extension method calls where extension methods are invoked as static methods.
    • To implicitly typed array creation expressions when array type can be inferred from initializer.
  • Fixes:
    • Occurrences where static members of a type are accessed via derived members of the type.
Use auto-property, if possible Replaces simple properties and corresponding backing fields with auto-properties.
Make field read-only, if possible Takes action upon "Field can be made readonly" code inspection item.
Use 'var' in declaration Provides the following configurable options:
  • Replace direction
    • Do not change
      If this value is selected, ReSharper neither converts explicit to implicit types, nor it does the opposite, even if the values of the following two settings imply such conversion.
    • Can change type usage to 'var'
      Only allows converting explicit to implicit types.
    • Can change 'var' to type usage
      Only allows converting implicit to explicit types).
    • Can change explicit to 'var' and vice versa
      Allows conversion in both directions - for example, you can opt to use explicit types in 'foreach' iterators and implicit types in local variables).
  • 'foreach' iterator declaration style
    • Always use explicit type
    • Always use 'var'
    • Use 'var' except for built-in types
      Implements implicit typing for all types except built-in .NET Framework types.
    • Use 'var' except for simple types
      Implements implicit typing for all types except for simple types (by 'simple types' we mean no arrays or pointers and without generic parameters). Note that the term 'simple types' is used differently in ReSharper's and MSDN documentation.
  • Local variable declaration style
    • Always use explicit type
    • Always use 'var'
    • Use 'var' except for built-in types
      Implements implicit typing for all types except built-in .NET Framework types.
    • Use 'var' except for simple types
      Implements implicit typing for all types except for simple types (by 'simple types' we mean no arrays or pointers and without generic parameters). Note that the term 'simple types' is used differently in ReSharper's and MSDN documentation.
    • Use 'var' only when initializer has type usage
      ( var p = new CodeCleanupProfile(false);
      but string n = c.Name;).
Update file header Inserts or updates file header that you can configure in the ReSharper | Options | Code Editing | File Header Text.
Optimize 'using' directives Provides the following configurable options:
  • Optimize 'using' directives
    Removes unused namespace import directives and implements rules configured in the ReSharper | Options | Code Editing | C# | Namespace Imports.
  • Embrace 'using' directives in region
    In every file that a particular Cleanup action covers, this setting creates a new region for holding all namespace import directives.
  • Region name
    Allows specifying a name for the namespace import region.
Shorten qualified references Replaces fully qualified names with short names where possible by importing namespaces, implementing settings configured in the ReSharper | Options | Code Editing | C# | Namespace Imports.
Reformat code Reformats your code according to options configurable in the Formatting Style.
Reformat embedded XML doc comments Reformats XML doc comments according to options configurable in the ReSharper | Options | Code Editing | XML Doc Comments | Formatting Style.
Reorder type members Reorders layout of type members according to a pattern configurable in the ReSharper | Options | Code Editing | C# | Type Members Layout.
VB.NET
Optimize 'import' directives Removes unused namespace import directives implementing rules configured in the ReSharper | Options | Code Editing | Visual Basic .NET | Namespace Imports.
Shorten qualified references Replaces fully qualified names with short names where possible by importing namespaces, implementing settings configured in the ReSharper | Options | Code Editing | Visual Basic .NET | Namespace Imports.
Reformat code Reformats your code according to options configurable in the Formatting Style.
Reformat embedded XML doc comments Reformats XML doc comments according to options configurable in the ReSharper | Options | Code Editing | XML Doc Comments | Formatting Style.
JavaScript/TypeScript
Terminates statements Terminates JavaScript statements with the semicolon.
Reformat code Reformats your code according to options configurable in the Formatting Style.
Reformat embedded XML doc comments Reformats XML doc comments according to options configurable in the ReSharper | Options | Code Editing | XML Doc Comments | Formatting Style.
CSS
Alphabetize properties Rearranges CSS properties in the alphabetical order.
Reformat code Reformats your code according to options configurable in the Formatting Style.
XML
Reformat code Reformats your code according to options configurable in the Formatting Style.

Note

ReSharper's settings are saved in settings layers that enable you to have different settings for different solutions as well as to share your settings with your team. To learn more, study the Managing and Sharing Options section.