Naming Style
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 (e.g. 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, etc.
These rules are taken into account when Rider suggests symbol names in code completion, generates new members, applies code templates and performs refactorings. Rider also helps you detect and fix violations of naming rules. If necessary, the automatic checkup of naming rules can be configured or disabled.
Configuring naming rules
Out of the box, Rider provides a naming rule for each type of identifier. These rules are based on the Microsoft Naming Guidelines and best practices. However, if your personal preferences or company standards differ from 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.
To modify a default naming rule
- In Rider settings (Ctrl+Alt+S), go to and open the Naming tab.
- Select the desired rule in the list on the left.
- On the right of the page, check the existing style for the rule.
- If the existing style is acceptable, but you would like to allow other styles for this rule, click Add . When there are several styles for a single rule, Rider does not detect code style violation if a corresponding symbol name matches at least one of these styles. Otherwise 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 and Move Down buttons.
- To configure a specific style, select it in the list and configure prefix, suffix, and choose a naming style.
- To remove an unnecessary style, select it in the list and click Remove .
- If necessary, you can disable detection of code style violations associated with this rule, allowing Rider to detect other code style violations. To do so, clear the Enable inspections check box.
- Click Save to apply the modifications and let Rider choose where to save them, or save the modifications to a specific settings layer using the Save To drop-down list. For more information, see layer-based settings.
Ignoring uppercase abbreviations that conflict with a CamelCase naming style
Sometimes you may want to use uppercase abbreviations (acronyms) in CamelCase symbol names. By default, Rider detects it as inconsistent camel casing and reports a problem:
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.
To add an abbreviation to the ignore list
- In the editor, set the caret at a highlighted symbol that uses the abbreviation in its name.
- Press Alt+Enter or click on the action indicator to the left of the caret to open the action list.
- Choose Inspection 'Inconsistent Naming' | Add [abbreviation] to the abbreviations list
if necessary, you can select where to save this preference. For more information, see Layer-Based Settings
Detecting and fixing violations of naming rules
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, Rider highlights this name and informs you about the problem when you hover the mouse over it:
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.
To find naming style violations in a specific scope
- In the editor, set the caret at a highlighted symbol that has inconsistent naming.
- Press Alt+Enter or click on the action indicator to the left of the caret to open the action list.
- Choose Inspection 'Inconsistent Naming' | Find similar issues in file and then select the desired scope.
- All found naming style violations will be displayed in the Inspection Results window.
- You can double-click the detected problems to navigate to the code of the corresponding symbols.
For most of the naming style violation highlighted in the editor, Rider suggest a quick-fix with a conforming name, e.g., you can press Alt+Enter and choose Rename to [conforming name] in the action list.
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.
Configuring and disabling automatic naming rules checkup
If you do not want 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 Rider helps you produce new code with code completion, generation, refactorings, and templates.
To disable automatic checkup of naming style
To disable automatic checkup of a specific naming rule
- In Rider settings (Ctrl+Alt+S), go to and open the Naming tab.
- Select the desired rule in the list on the left.
- In the Edit Rule Settings dialog that opens, clear the Enable inspections check box.
- Click Save to apply the modifications and let Rider choose where to save them, or save the modifications to a specific settings layer using the Save To drop-down list. For more information, see layer-based settings.
See Also
Procedures:
- Naming Style
- Managing and Applying Code Formatting Rules
- File and Type Layout
- File Header Style
- Code Syntax Style: Namespace Imports
- Code Syntax Style: Implicit/Explicit Typing
- Using Auto-Properties
- Making Fields Readonly
- Code Syntax Style: Multiple Attributes
- Code Syntax Style: Modifiers
- Code Syntax Style: Optional Member Qualifiers
- Reformatting XML Doc Comments
- Removing Code Redundancies