JetBrains Rider 2020.1 Help

Naming Style

JetBrains Rider helps you define, control, and apply naming style for symbols in your code. Naming style is implemented as a set of rules, each of which targets specific identifiers with the set of constraints (for example, a rule can target static private readonly fields) . Each rule can have one or more associated styles that define suffixes, prefixes, capitalization of compound words, and so on.

These rules are taken into account when JetBrains Rider produces new code with code completion and code generation features, applies code templates and performs refactorings. JetBrains Rider also helps you detect and fix violations of naming rules. If necessary, the automatic checkup of naming rules can be configured or disabled.

Configure naming rules

Out of the box, JetBrains Rider provides a naming rule for each type of identifier. These rules are based on the Microsoft Naming Guidelines, .NET Platform Coding Style, and various best practices.
Note that there is no strict correspondence between JetBrains Rider naming-rule defaults and any of the above mentioned guidelines.

If your personal preferences or company standards differ from JetBrains Rider defaults, you can configure the naming style in a flexible way: for each type of identifier you can choose capitalization rules, prefixes and suffixes, variations for different access rights, abbreviations to preserve, and more.

Your naming style preferences are saved using the mechanism of layer-based settings. Among other things, this mechanism allows you to maintain different preferences for different solutions as well as to keep these preferences under a VCS and automatically share them with your team members.

Modify a default naming rule

  1. In Rider settings Ctrl+Alt+S, go to Editor | Code Style | C# and open the Naming tab.

  2. Select the desired rule in the list on the left.

  3. On the right of the page, check the existing style for the rule.

  4. If the existing style is acceptable, but you would like to allow other styles for this rule, click Add ThemedIcon AddedParameter Screen Gray png. When there are several styles for a single rule, JetBrains Rider does not detect code style violation if a corresponding symbol name matches at least one of these styles. Otherwise JetBrains Rider detects a code style violation and suggests renaming the symbol according to the default style (the first style in the list). To change the default style, use Move Up ThemedIcon Up Screen Gray png and Move Down ThemedIcon Down Screen Gray png buttons.

  5. To configure a specific style, select it in the list and configure prefix, suffix, and choose a naming style.

  6. To remove an unnecessary style, select it in the list and click Remove ThemedIcon Delete Screen Gray png.

  7. If necessary, you can disable detection of code style violations associated with this rule, allowing JetBrains Rider to detect other code style violations. To do so, clear the Enable inspections checkbox.

  8. Click Save to apply the modifications and let JetBrains Rider choose where to save them, or save the modifications to a specific settings layer using the Save To list. For more information, see Layer-Based Settings.

Use EditorConfig to configure naming rules

If you use EditorConfig to maintain code styles for your project, you can also configure naming rules from .editorconfig files.

To configure naming rules from EditorConfig, you have to select the Read settings from editorconfig, project settings and rule sets checkbox on the Editor | Inspection Settings page of JetBrains Rider options Ctrl+Alt+S.

You can also export naming styles that you already configured in JetBrains Rider settings to an .editorconfig file.

Naming style settings in .editorconfig files are configured using the properties of .NET naming conventions for EditorConfig.

As EditorConfig convention suggests, JetBrains Rider will apply naming rules defined in files named .editorconfig in the directory of the current file and in all its parent directories until it reaches the root filepath or finds an EditorConfig file with root=true. File masks specified in .editorconfig files, for example *Test.cs are also taken into account.

Ignore uppercase abbreviations that conflict with a CamelCase naming style

Sometimes you may want to use uppercase abbreviations (acronyms) in CamelCase symbol names. By default, JetBrains Rider detects it as inconsistent camel casing and reports a problem:

JetBrains Rider: Nming style. abbreviations

In this case, you can configure the list of abbreviations to be ignored by the naming style inspection.

It is important to note that uppercase abbreviations should not contradict the naming style defined for specific kind of identifier.
For example, if you added MS to the ignored abbreviations, MSBuilder will be an acceptable name for identifiers with the UpperCamelCase style, but not for identifiers with lowerCamelCase or all_lower naming styles.
Similarly, myMSBuilder will be OK for lowerCamelCase- but not for UpperCamelCase-styled identifiers.

Add an abbreviation to the ignore list

  1. In the editor, set the caret at a highlighted symbol that uses the abbreviation in its name.

  2. Press Alt+Enter or click the action indicator to the left of the caret to open the action list.

  3. Choose Inspection 'Inconsistent Naming' | Add [abbreviation] to the abbreviations list

    Adding an abbreviation to the ignore list

    if necessary, you can select where to save this preference. For more information, see Layer-Based Settings

Detect and fix violations of naming rules

JetBrains Rider uses the 'Inconsistent Naming' code inspection to detect violations of naming rules in your code. By default, this inspection is always applied during the design-time code inspection and highlights the detected violations as warnings in the editor. For example, according to the default style, names of interfaces should have 'I' prefix. If an interface name does not match this rule, JetBrains Rider highlights this name and informs you about the problem when you hover the mouse over it:

JetBrains Rider: Highlighted violation of the naming style

If you want to find naming style violations beyond the current file, you can run the 'Inconsistent Naming' inspection in the project or in the entire solution.

Find naming style violations in a specific scope

  1. In the editor, set the caret at a highlighted symbol that has inconsistent naming.

  2. Press Alt+Enter or click the action indicator to the left of the caret to open the action list.

  3. Choose Inspection 'Inconsistent Naming' | Find similar issues in file and then select the desired scope.

    JetBrains Rider: Using action list to find naming style issues

  4. All found naming style violations will be displayed in the Inspection Results window.

    JetBrains Rider: Naming style violations in solution

  5. You can double-click the detected problems to navigate to the code of the corresponding symbols.

For most of the naming style violations highlighted in the editor, JetBrains Rider suggests a quick-fix with a conforming name. You can press Alt+Enter and choose Rename to [conforming name] in the action list.

Quick-fix for naming style violation

Automatic correction of naming style violations can also be performed in the current file, project or solution using the fix in scope feature.

However, if the symbol with the calculated conforming name already exists in the same namespace, the quick-fix is not suggested. You can fix the naming of such symbol with the Rename refactoring.

Configure and disable automatic naming rules checkup

If you do not want JetBrains Rider to check naming style in the existing codebase, you can either disable the code inspection that is responsible for it, or disable the automatic checkup of a specific rule. However, even if the automatic checkup is disabled, all naming rules will be respected when JetBrains Rider helps you produce new code with code completion, generation, refactorings, and templates.

Disable automatic checkup of naming style

  • On the Editor | Inspection Severity page of JetBrains Rider options Ctrl+Alt+S, start typing 'Inconsistent Naming', and then clear the checkbox next to the corresponding code inspection.

Disable automatic checkup of a specific naming rule

  1. In Rider settings Ctrl+Alt+S, go to Editor | Code Style | C# and open the Naming tab.

  2. Select the desired rule in the list on the left.

  3. In the Edit Rule Settings dialog that opens, clear the Enable inspections checkbox.

  4. Click Save to apply the modifications and let JetBrains Rider choose where to save them, or save the modifications to a specific settings layer using the Save To list. For more information, see Layer-Based Settings.

Use C# naming rules from existing code

If you check out a solution from a public repo or temporarily join a team where a different code naming style is established, you will probably want to follow naming rules in this solution but in ths same time not to change your globally configured naming rules.

JetBrains Rider will handle such situations automatically — when you open a new solution where symbol naming differs from your global settings, it will detect the naming rules that diverge from your global settings, modify these rules accordingly, and then save the modified rules to the 'Solution personal' settings layer (.sln.DotSettings.user file next to the solution).

If this happens when you open a new solution, JetBrains Rider will show a notification in the editor:

JetBrains Rider: Naming rules auto-detection notification

You can click Undo to revert these modifications or Configure to open the corresponding settings page (Editor | Code Style | C# | Naming). On this settings page, the rules that were changed based on the solution code are highlighted with yellow. If you want to use JetBrains Rider's default naming rules or configure naming style in your own way, clear the Use auto-detected rules checkbox.

JetBrains Rider highlighting automatically-set naming rules with yellow
Last modified: 05 August 2020