ReSharper Help

Naming Style

ReSharper 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 ReSharper suggest symbol names in code completion, generates new members, applies code templates and performs refactorings. ReSharper also helps you detect and fix violations of naming rules. If necessary, the automatic checkup of naming rules can be configured or disabled.

In this topic:

Configuring naming rules

Out of the box, ReSharper 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 ReSharper defaults, you can configure the naming style in a flexible way: for each 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 shared 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

  1. Do one of the following:
    • Press Alt+Enter on a highlighted symbol with inconsistent naming, then choose Inspection 'Inconsistent Naming' | Change settings for naming rule '[rule name]' .
    • On the main menu, choose ReSharper | Options | [Language] | Naming Style, select the desired rule, and click Edit Coding_Assistance__Naming_Style__options__Edit_button or just double-click it.
  2. In the Edit Rule Settings dialog box that opens, check the existing style for the rule.
  3. If the existing style is acceptable, but you would like to allow other styles for this rule, click Add Coding_Assistance__Naming_Style__Options__Add_button. When there are several styles for a single rule, ReSharper does not detect code style violation if a corresponding symbol name matches at least one of these styles. Otherwise ReSharper 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 Coding_Assistance__Naming_Style__Options__Move_Up and Move Down Coding_Assistance__Naming_Style__Options__Move_Down buttons.
  4. To configure a specific style, select it in the list and configure prefix, suffix and name style.
  5. To remove an unnecessary style, select it in the list and click Remove Coding_Assistance__Naming_Style__Options__Remove.
  6. If necessary, you can disable detection of code style violations associated with this rule, allowing ReSharper to detect other code style violations. To do so, clear the Enable inspections check box.
  7. Click Set to close the Edit Rule Settings dialog box if it was opened from the options page.
  8. Click Save to apply the modifications and let ReSharper 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 Managing and Sharing ReSharper Settings.

If the existing rules do not cover all aspects of your naming convention, you can create custom rules. For example, you may want that enums had upper camel case capitalization and the 'E' prefix.

To create a custom naming rule

  1. On the main menu, choose ReSharper | Options | C# | Naming Style and click Advanced settings.
  2. In the Advanced Naming Settings dialog box that opens, click Add Coding_Assistance__Naming_Style__Options__Add_button to create a custom naming rule.
    Coding_Assistance__Naming_Style__Options__Advanced_Settings
  3. In the Edit Extended Naming Rule dialog box that appears, configure the new rule: specify a name for the new rule in the Rule Description field, select the target identifiers in the Affected entities area, use Access rights and Static/non-static areas to further constrain the scope of the rule.
  4. In the Naming style section, configure one or more styles for the rule as described in the procedure above.
    Coding_Assistance__Naming_Style__Options__Edit_Extended_Naming_Rule
  5. Click OK to close the Edit Extended Naming Rule dialog box, and then again OK to close the Advanced Naming Settings dialog box.
  6. Click Save to apply the modifications and let ReSharper 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 Managing and Sharing ReSharper Settings.

Ignoring abbreviations that conflict with naming style

You may need to use abbreviations (acronyms) and keep them as they are in symbol names. By default, ReSharper detects it as inconsistent camel casing and reports a problem:

Coding_Assistance__Naming_Style__abbreviation

ReSharper lets you configure the list of abbreviations to be ignored by the naming style inspection.

To 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 on 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 Managing and Sharing ReSharper Settings

If you have many abbreviations that could be used in symbol names, you can edit the list of ignored abbreviations.

To edit the list of ignored abbreviations

  1. On the main menu, choose ReSharper | Options | C# | Naming Style and click Advanced settings.
  2. Add abbreviations that ReSharper should ignore to the Abbreviations field using spaces as delimiters.
  3. Click OK to close the Advanced Naming Settings dialog box.
  4. Click Save to apply the modifications and let ReSharper 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 Managing and Sharing ReSharper Settings.

Detecting and fixing violations of naming rules

ReSharper 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, ReSharper highlights this name and informs you about the problem when you hover the mouse over it:

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.

To 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 on the action indicator to the left of the caret to open the action list.
  3. Choose Inspection 'Inconsistent Naming' | Find all issues of this type in scope
    Using action list to find naming style issues
  4. In the Find Similar Issues dialog box that appears, specify the inspection scope and then click OK.
  5. All found naming style violations will be displayed in the Inspection Results window.
    Naming style violations in solution
  6. You can double-click the detected problems to navigate to the corresponding symbols n files.

For most of the naming style violation highlighted in the editor, ReSharper 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.

Quick-fix for naming style violation

Automatic correction of naming style violations can be also 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 ReSharper 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 ReSharper helps you produce new code with code completion, generation, refactorings, and templates.

To disable automatic checkup of naming style

  1. Do one of the following:
    • Press Alt+Enter on a highlighted symbol with inconsistent naming, then choose Inspection 'Inconsistent Naming' | Configure inspection severity.
    • In the Code Inspection | Inspection Severity page of ReSharper options, open the All tab, start typing 'Inconsistent Naming', and then select the corresponding code inspection.
  2. Set the inspection severity to Do not show.
  3. Click Save to apply the modifications and let ReSharper 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 Managing and Sharing ReSharper Settings.

To disable automatic checkup of a specific naming rule

  1. Do one of the following:
    • Press Alt+Enter on a highlighted symbol with inconsistent naming, then choose Inspection 'Inconsistent Naming' | Change settings for naming rule '[rule name]' .
    • On the main menu, choose ReSharper | Options | [Language] | Naming Style, select the desired rule, and click Edit Coding_Assistance__Naming_Style__options__Edit_button or just double-click it.
  2. In the Edit Rule Settings dialog box that opens, clear the Enable inspections check box.
  3. Click Set to close the Edit Rule Settings dialog box if it was opened from the options page.
  4. Click Save to apply the modifications and let ReSharper 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 Managing and Sharing ReSharper Settings.

Applicability in different languages

This feature is supported in the following languages/technologies:

C# VB.NET C++ HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
feature_availablefeature_availablefeature_availablefeature_availablefeature_availablefeature_availablefeature_available

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.

See Also

Last modified: 2 July 2015