ReSharper 2021.1 Help

Profiles

ReSharper | Options | Code Editing | Code Cleanup | Profiles

This page of ReSharper options allows you to manage and configure custom cleanup profiles, as well as to assign a cleanup profile for the silent code cleanup. The two default profiles (Full Cleanup, Reformat & Apply Syntax Style and Reformat Code) are also shown here. You cannot modify them, but you can clone them to make new custom profiles.

Toolbar controls

Use the following controls to configure the selected cleanup profile:

Themed icon code cleanup option page screen gray Set as defaultClick this button to use the selected profile for silent cleanup. The profile used for silent cleanup is marked with the Themed icon code cleanup option page screen gray icon.
Themed icon duplicate screen gray DuplicateClick this button to create a copy of the selected profile. If you have default settings, you will need to duplicate one of the default cleanup profiles to create a custom cleanup profile. As soon as a new profile is created, it opens in the editing mode, where you can configure the list of cleanup tasks.
Themed icon behaivior screen gray ConfigureClick this button to enable the editing mode for the selected custom profile. Note that default profiles (Full Cleanup, Reformat & Apply Syntax Style and Reformat Code) cannot be edited.
Themed icon edit screen gray RenameClick this button to rename the selected custom profile. Note that default profiles (Full Cleanup, Reformat & Apply Syntax Style and Reformat Code) cannot be renamed.
Themed icon remove screen gray RemoveClick this button to remove the selected custom profile. Note that default profiles (Full Cleanup, Reformat & Apply Syntax Style and Reformat Code) cannot be removed.
Themed icon success screen gray DoneClick this button to exit the editing mode and go back to the preview of the selected profile. Note that your modifications will not be applied unless you click Save.

Code cleanup tasks for selected profile

These tasks become configurable when you switch the editing mode (Themed icon behaivior screen gray Configure) for the selected custom cleanup profile. Initially, there are no custom profiles and tasks of the default profiles cannot be edited. You can click Themed icon duplicate screen gray Duplicate to create an editable copy of one of the default profiles and then edit its tasks.

C#

Apply file layoutReorders type members in files according to the rules configurable on the Code Editing | C# | File Layout page of ReSharper options(Alt+R, O). For more information, see Rearrange Members with File and Type Layout Patterns.
Update file headerInserts or updates the file header comment that you can configure on the Code Editing | File Header Text page of ReSharper options. For more information, see File Header Style.
Syntax Styles
Apply 'var' styleApplies the rules for 'var' usage during the cleanup. The rules are configurable on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O).
Use explicit or implicit modifier definition for typesApplies the rule for type modifiers - whether on not to use the internal modifier explicitly. The rule is configurable on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Code Syntax Style: Modifiers.
Use explicit or implicit modifier definition for type membersApplies the rule for type member modifiers - whether on not to use the private modifier explicitly. The rule is configurable on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Code Syntax Style: Modifiers.
Sort modifiersApplies the preferred order of type/member modifiers. The rule is configurable on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Code Syntax Style: Modifiers.
Apply arguments style (named | positional)Applies the preferences for named/positional arguments for specific types of parameters. The preferences are configurable on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Code Syntax Style: Named/Positional Arguments.
Remove redundant parenthesesRemoves redundant optional parentheses in cases specified on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Code Syntax Style: Optional Parentheses.
Add parentheses to explicitly specify operation precedenceAdds optional parentheses to clarify precedence of operations in cases specified on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Code Syntax Style: Optional Parentheses.
Add/remove braces around single statementsAdds or removes optional braces around single nested statements as specified on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Code Syntax Style: Braces for Single Nested Statements.
Arrange attributesApplies the rules for multiple attributes as specified on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Code Syntax Style: Multiple Attributes.
Apply code body styleApplies preferences for bodies of type members (expression body | statement body) as specified on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Code Syntax Style: Bodies of Type Members.
Arrange trailing commasApplies preferences for trailing commas in declarations with multiple items and similar constructs (object, array, and collection initializers, as well as enums and switch expressions) as specified on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Code Syntax Style: Trailing Commas.
Apply object creation style ('new()' vs 'new T()')Applies preferences for using the target-typed new operator in C# 9.0 and later as specified on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Code Syntax Style: Object Creation ('new()' vs 'new T()').
Apply default value style ('default' vs 'default(T)')Applies preferences for using optional type specification in default value expressions as specified on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Code Syntax Style: Default Value Expressions ('default' vs 'default(T)').
Remove code redundancies

On the Code Inspection | Inspection Severity page of ReSharper options(Alt+R, O), in the Redundancies in Code categories for most languages, ReSharper lists over 50 redundancies that have associated code inspections. Some of them require special attention, and you cannot process them in the 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. For more information, see Use Auto-Properties.
Make field read-only, if possible Adds the 'readonly' keyword to fields that are assigned in the declaration or in a constructor and only have read usages. For more information, see Make Fields Readonly.
Make auto-property get-only, if possibleRemoves the redundant set accessor on auto-properties that are initialized from the constructor/initializer and have no write usages. Note that this task only works for C# 6.0. By default, ReSharper automatically detects C# version based on the associated compiler. However, you can specify the target C# version explicitly — right-click the project in the Solution Explorer, choose Edit project item properties from the context menu and use the C# Language Level selector.
Arrange qualifiersApplies the rules for qualifying type members. The rules are configurable on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Code Syntax Style: Optional Member Qualifiers.
Fix built-in type referencesApplies the rule for built-in type names (C# keyword or CLR type name). The rule is configurable on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Code Syntax Style: Built-In Type References.
Usings

Includes the following configurable options:

  • Optimize 'using' directives
    Removes unused namespace import directives by implementing the rules that you can configure on the Code Editing | C# | Namespace Imports and Code Editing | C# | Syntax Style options pages and sorts the namespace import directives: all System.* namespaces go first, sorted alphabetically by the second word after the dot; all other namespaces go next, in alphabetical order.. For more information, see Code Syntax Style: Namespace Imports.

  • Embrace 'using' directives in region
    If this checkbox is selected, a new region for wrapping all namespace import directives is created during cleanup.

  • Region name
    Allows specifying a name for the region wrapping namespace import directives.

Shorten qualified referencesReplaces fully qualified names with short names when possible by importing namespaces, implementing settings configured on the Code Editing | C# | Syntax Style page of ReSharper options(Alt+R, O).
Reformat codeReformats your code according to the preferences that you can configure on the Code Editing | C# | Formatting Style page of ReSharper options(Alt+R, O). For more information, see Manage and Apply Code Formatting Rules.
Reformat embedded XML doc commentsReformats XML doc comments according to options configurable on the Code Editing | XML Doc Comments | Formatting Style page of ReSharper options(Alt+R, O).

Note that ReSharper does not reformat plain comments like:
// A plain single-line comment
or
/* A plain multi-line comment */

XAML

Collapse empty tagsRemoves the closing tag if the tag body is empty.
Remove redundant attributesRemoves attributes, such as Freeze, modifiers, name, span, UpdateSourceTrigger, Mode if they are redundant in the context
Remove redundant resourceRemoves resource references that are not used
Remove redundant property settersRemoves unused setters for the following properties: property, attached, style.
Remove redundant namespace aliasRemove all redundant namespace aliases in the scope of cleanup. Redundant aliases are also detected with the code inspection and can be removed with a quick-fix.
Remove redundant definitionsRemoves definitions if they are redundant in the context
Remove forbidden attributesRemoves attributes, such as name, span if they are forbidden in the context

XML

Reformat codeReformats your code according to the preferences that you can configure on the Code Editing | XML | Formatting Style page of ReSharper options(Alt+R, O). For more information, see Manage and Apply Code Formatting Rules.

C++

C++ code styles and code redundancies
  • Add 'override' specifier to overriding functions

  • Add required 'typename' and 'template' keywords

  • Fix slashes in include file paths

  • Join declarations and assignments

  • Make member functions 'const' when possible

  • Make member functions 'static' when possible

  • Remove redundant 'else' keywords

  • Remove redundant member initializers

  • Remove redundant parentheses

  • Remove redundant qualifiers

  • Remove redundant specifiers

  • Remove redundant statements

  • Remove redundant 'typename' and 'template' keywords

  • Remove unreachable code

  • Remove unused #include directives

  • Replace C-style casts with static casts

  • Make local variables const

  • Replace constants in boolean context with boolean literals

  • Replace explicit types with 'auto' where possible

  • Replace if statements with constant conditions with 'if constexpr'

  • Replace postfix operators with prefix variants

  • Replace smart pointer constructors with make functions

  • Replace throw expressions with rethrow where possible

  • Replace zero valued expressions in pointer context with nullptr

  • Sort #include directives

  • Sort member initializers by the order of initialization

Apply Clang-tidy fix-its

In this node, you can choose all or specific fixes that will be applied according to the Clang-Tidy checks.

The selected fixes will be applied even if the corresponding inspections are turned off on the Code Inspection | Inspection Severity page of ReSharper options(Alt+R, O). Be careful when enabling too many checks at once — code cleanup runs Clang-Tidy only once for a given file, so if multiple fixes touch the same block of code, the changes might conflict with each other.

Reformat codeReformats your code according to the preferences that you can configure on the Code Editing | C++ | Formatting Style page of ReSharper options(Alt+R, O). For more information, see Manage and Apply Code Formatting Rules.
Update file headerInserts or updates the file header comment that you can configure on the Code Editing | File Header Text page of ReSharper options. For more information, see File Header Style.

VB.NET

Remove code redundanciesRemoves redundant code the same way as for C# Language
Optimize 'import' directivesRemoves unused namespace import directives implementing rules configured on the Code Editing | Visual Basic .NET | Namespace Imports page of ReSharper options.
Shorten qualified referencesReplaces fully qualified names with short names when possible by importing namespaces, implementing settings configured on the Code Editing | Visual Bascic.NET | Syntax Style page of ReSharper options(Alt+R, O).
Reformat codeReformats your code according to the preferences that you can configure on the Code Editing | VB.NET | Formatting Style page of ReSharper options(Alt+R, O). For more information, see Manage and Apply Code Formatting Rules.
Reformat embedded XML doc commentsReformats XML doc comments according to options configurable on the Code Editing | XML Doc Comments | Formatting Style page of ReSharper options(Alt+R, O).

Note that ReSharper does not reformat plain comments like:
// A plain single-line comment
or
/* A plain multi-line comment */

CSS

Alphabetize propertiesRearranges CSS properties in the alphabetical order.
Reformat codeReformats your code according to the preferences that you can configure on the Code Editing | CSS | Formatting Style page of ReSharper options(Alt+R, O). For more information, see Manage and Apply Code Formatting Rules.

JavaScript-like languages

Apply statement terminationAdds the optional semicolon ; at the end of statements in JavaScript, TypeScript, and JSON.

JavaScript

Normalize quotes around string literalApplies the preferred quote style: single quote (') or double quote ("). The preference can be configured on the Code Editing | TypeScript | Syntax Style page of ReSharper options(Alt+R, O). For more information, see Quotes style.
Correct 'var' to 'let'/'const' where possible

let and const are supported in the following cases:

  • In JavaScript code, if the target JavaScript language level is ECMAScript 6 (you can choose it on the Code Editing | JavaScript | Inspections page of ReSharper options(Alt+R, O))

  • In TypeScript 1.4, if the target ECMAScript 6 is selected in the project properties.

  • In TypeScript 1.5 or later.

Move let/const to most possible inner scopesMoves variables defined outside of a function/compound statement, and so on closer to their usages if there are no other usages in outer scopes.
Convert string concatenations to template stringsIn JavaScript code, if the target JavaScript language level is ECMAScript 6 (you can choose it on the Code Editing | JavaScript | Inspections page of ReSharper options(Alt+R, O)), as well as in TypeScript 1.4 or later, this option will convert string concatenations to template strings. For example:
var str1 = "Hello,"; var str2 = "Test: " + str1 + " World1";
will be converted to
const str1 = "Hello, "; const str2 = `Test: ${str1} World1`;
Reformat codeReformats your code according to the preferences that you can configure on the Code Editing | JavaScript | Formatting Style page of ReSharper options(Alt+R, O). For more information, see Manage and Apply Code Formatting Rules.
Reformat embedded XML doc commentsReformats XML doc comments according to options configurable on the Code Editing | XML Doc Comments | Formatting Style page of ReSharper options(Alt+R, O).

Note that ReSharper does not reformat plain comments like:
// A plain single-line comment
or
/* A plain multi-line comment */

TypeScript

Remove redundant qualifiersUse this option to remove redundant type name qualifiers.
Optimize 'import' statementsUse this option to remove redundant 'import' statements or fully-qualified names according to the settings configurable on the Code Editing | TypeScript | Inspections page of ReSharper options(Alt+R, O).
Optimize reference commentsUse this option to remove redundant reference comments.
Synchronize 'public' presence with code styleThis option lets you add or remove explicit 'public' modifier according to settings configurable on the Code Editing | TypeScript | Inspections page of ReSharper options(Alt+R, O).
Add explicit 'any' type annotation if neededThis option lets you add explicit 'any' annotation to types according to settings configurable on the Code Editing | TypeScript | Inspections page of ReSharper options(Alt+R, O).
Synchronize type annotation presence with code styleThis option lets you enforce explicit/implicit typing according to settings configurable on the Code Editing | TypeScript | Inspections page of ReSharper options(Alt+R, O).
Fix relative path style in 'require' if neededApplies the Relative file reference style in 'require' code style preference for relative paths in the require keyword. For example, import X = require("file1") or import X = require("./file1"). You can configure this preference on the Code Editing | TypeScript | Inspections page of ReSharper options(Alt+R, O).
Use 'as' instead of type assertionsReplaces
var bar = <string> foo;
with
var bar = foo as string;
which is a recommended way to avoid ambiguity with JSX syntax.

HTML

Reformat codeReformats your code according to the preferences that you can configure on the Code Editing | HTML | Formatting Style page of ReSharper options(Alt+R, O). For more information, see Manage and Apply Code Formatting Rules.
Normalize quotes around attribute valueApplies the preferred quote style: single quote (') or double quote ("), configurable on the Code Editing | HTML | Syntax Style page of ReSharper options.

ASP.NET

Optimize @Register directivesRemoves unused @Register directives.
Last modified: 12 July 2021