Code Cleanup
This page of JetBrains Rider 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:
Add | Click this button to create a new custom Code 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. |
Set as default | Click this button to use the selected profile for silent cleanup. |
Clone | Click 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. |
Rename | Click this button to rename the selected custom profile. Note that default profiles (Full Cleanup, Reformat & Apply Syntax Style and Reformat Code) cannot be renamed. |
Remove | Click this button to remove the selected custom profile. Note that default profiles (Full Cleanup, Reformat & Apply Syntax Style and Reformat Code) cannot be removed. |
Code cleanup tasks for selected profile
These tasks become configurable for the selected custom cleanup profile. Initially, there are no custom profiles and tasks of the default profiles cannot be edited. You can click Duplicate to create an editable copy of one of the default profiles and then edit its tasks.
C#
Apply file layout | Reorders type members in files according to the rules configurable on the Rearrange members with file and type layout patterns. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Update file header | Inserts or updates the file header comment . |
Syntax Styles | |
Apply 'var' style | Applies the rules for 'var' usage during the cleanup. The rules are configurable on the page of JetBrains Rider settings Ctrl+Alt+S. |
Use explicit or implicit modifier definition for types | Applies the rule for type modifiers - whether on not to use the |
Use explicit or implicit modifier definition for type members | Applies the rule for type member modifiers - whether on not to use the |
Sort modifiers | Applies the preferred order of type/member modifiers. The rule is configurable on the Code Syntax Style: Modifiers. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Apply arguments style (named | positional) | Applies the preferences for named/positional arguments for specific types of parameters. The preferences are configurable on the Code Syntax Style: Named/Positional Arguments. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Remove redundant parentheses | Removes redundant optional parentheses in cases specified on the Code Syntax Style: Optional Parentheses. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Add parentheses to explicitly specify operation precedence | Adds optional parentheses to clarify precedence of operations in cases specified on the Code Syntax Style: Optional Parentheses. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Add/remove braces around single statements | Adds or removes optional braces around single nested statements as specified on the Code Syntax Style: Braces for Single Nested Statements. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Add/remove brackets for attributes | Applies the rules for multiple attributes as specified on the Code Syntax Style: Multiple Attributes. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Apply code body style | Applies preferences for bodies of type members (expression body | statement body) as specified on the Code Syntax Style: Bodies of Type Members. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Arrange trailing commas | Applies 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 Syntax Style: Trailing Commas. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Apply object creation style ('new()' vs 'new T()') | Applies preferences for using the target-typed |
Apply default value style ('default' vs 'default(T)') | Applies preferences for using optional type specification in default value expressions as specified on the Code Syntax Style: Default Value Expressions ('default' vs 'default(T)'). page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Remove code redundancies | On the Redundancies in Code categories for most languages, JetBrains Rider 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. page of JetBrains Rider settings Ctrl+Alt+S, in theSpecifically, code cleanup:
|
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 possible | Removes the redundant By default, JetBrains Rider automatically detects C# version based on the associated compiler. However, you can specify the target C# version explicitly for a project — press Alt+Enter on the project in the Solution Explorer and use the Language version selector on the Application page of the Project Properties dialog. To set the C# version for all projects in your solution, specify it in a Directory.Build.props file in your solution directory as described here. |
Arrange qualifiers | Applies the rules for qualifying type members. The rules are configurable on the Code Syntax Style: Optional Member Qualifiers. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Fix built-in type references | Applies the rule for built-in type names (C# keyword or CLR type name). The rule is configurable on the Code Syntax Style: Built-In Type References. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Usings | Includes the following configurable options:
|
Shorten qualified references | Replaces fully qualified names with short names when possible by importing namespaces, implementing settings configured on the page of JetBrains Rider settings Ctrl+Alt+S. |
Reformat code | Reformats your code according to the preferences that you can configure on the Manage and apply formatting rules. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Reformat embedded XML doc comments | Reformats XML doc comments according to options configurable on the page of JetBrains Rider settings Ctrl+Alt+S.Note that JetBrains Rider does not reformat plain comments like: // A plain single-line comment or /* A plain multi-line comment */ |
XAML
Collapse empty tags | Removes the closing tag if the tag body is empty. |
Remove redundant attributes | Removes attributes, such as |
Remove redundant resource | Removes resource references that are not used |
Remove redundant property setters | Removes unused setters for the following properties: |
Remove redundant namespace alias | Remove 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 definitions | Removes definitions if they are redundant in the context |
Remove forbidden attributes | Removes attributes, such as |
XML
Reformat code | Reformats your code according to the preferences that you can configure on the Manage and apply formatting rules. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
VB.NET
Remove code redundancies | Removes redundant code the same way as for C# Language |
Optimize 'import' directives | Removes unused namespace import directives . |
Shorten qualified references | Replaces fully qualified names with short names when possible by importing namespaces, implementing settings configured on the page of JetBrains Rider settings Ctrl+Alt+S. |
Reformat code | Reformats your code according to the preferences that you can configure on the Manage and apply formatting rules. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Reformat embedded XML doc comments | Reformats XML doc comments according to options configurable on the page of JetBrains Rider settings Ctrl+Alt+S.Note that JetBrains Rider does not reformat plain comments like: // A plain single-line comment or /* A plain multi-line comment */ |
CSS
Alphabetize properties | Rearranges CSS properties in the alphabetical order. |
Reformat code | Reformats your code according to the preferences that you can configure on the Manage and apply formatting rules. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
JavaScript-like languages
Apply statement termination | Adds the optional semicolon |
JavaScript
Normalize quotes around string literal | Applies the preferred quote style: single quote (') or double quote ("). The preference can be configured on the page of JetBrains Rider settings Ctrl+Alt+S. |
Correct 'var' to 'let'/'const' where possible |
|
Move let/const to most possible inner scopes | Moves 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 strings | In JavaScript code, if the target JavaScript language level is ECMAScript 6 (you can choose it on the template strings. For example: page of JetBrains Rider settings Ctrl+Alt+S), as well as in TypeScript 1.4 or later, this option will convert string concatenations to
var str1 = "Hello,";
var str2 = "Test: " + str1 + " World1";
will be converted to
const str1 = "Hello, ";
const str2 = `Test: ${str1} World1`;
|
Reformat code | Reformats your code according to the preferences that you can configure on the Manage and apply formatting rules. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Reformat embedded XML doc comments | Reformats XML doc comments according to options configurable on the page of JetBrains Rider settings Ctrl+Alt+S.Note that JetBrains Rider does not reformat plain comments like: // A plain single-line comment or /* A plain multi-line comment */ |
TypeScript
Remove redundant qualifiers | Use this option to remove redundant type name qualifiers. |
Optimize 'import' statements | Use this option to remove redundant 'import' statements or fully-qualified names according to the settings configurable on the page of JetBrains Rider settings Ctrl+Alt+S. |
Optimize reference comments | Use this option to remove redundant reference comments. |
Synchronize 'public' presence with code style | This option lets you add or remove explicit 'public' modifier according to settings configurable on the page of JetBrains Rider settings Ctrl+Alt+S. |
Add explicit 'any' type annotation if needed | This option lets you add explicit 'any' annotation to types according to settings configurable on the page of JetBrains Rider settings Ctrl+Alt+S. |
Synchronize type annotation presence with code style | This option lets you enforce explicit/implicit typing according to settings configurable on the page of JetBrains Rider settings Ctrl+Alt+S. |
Fix relative path style in 'require' if needed | Applies the Relative file reference style in 'require' code style preference for relative paths in the |
Use 'as' instead of type assertions | Replaces var bar = <string> foo; with var bar = foo as string; which is a recommended way to avoid ambiguity with JSX syntax. |
HTML
Reformat code | Reformats your code according to the preferences that you can configure on the Manage and apply formatting rules. page of JetBrains Rider settings Ctrl+Alt+S. For more information, see |
Normalize quotes around attribute value | Applies the preferred quote style: single quote (') or double quote ("). |
ASP.NET
Optimize @Register directives | Removes unused |