Naming rules

Naming rules concern the naming of .NET programming language code elements, such as classes, properties, and methods. For example, you can specify that public members must be capitalized or that private fields must begin with _.

A naming rule has three parts:

• The group of symbols it applies to.
• The naming style to associate with the rule.
• The severity for enforcing the convention.

You define naming rules in an EditorConfig file.

General syntax

To define a naming rule, symbol group, or naming style, set one or more properties using the following syntax:

<prefix>.<title>.<propertyName> = <propertyValue>


Each property should only be set once, but some settings allow multiple, comma-separated values.

The order of the properties is not important.

<prefix>

<prefix> specifies which kind of element is being defined—naming rule, symbol group, or naming style—and must be one of the following:

To set a property for Use the prefix Example
Naming rule dotnet_naming_rule dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
Symbol group dotnet_naming_symbols dotnet_naming_symbols.interface.applicable_kinds = interface
Naming style dotnet_naming_style dotnet_naming_style.pascal_case.capitalization = pascal_case

Each type of definition—naming rule, symbol group, or naming style—has its own supported properties, as described in the following sections.

<title>

<title> is a descriptive name you choose that associates multiple property settings into a single definition. For example, the following properties produce two symbol group definitions, interface and types, each of which has two properties set on it.

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum, delegate
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected


Naming rule properties

All naming rule properties are required for a rule to take effect.

Property Description
symbols The title of the symbol group, defining the symbols to which this rule should be applied
style The title of the naming style which should be associated with this rule
severity Sets the severity with which to enforce the naming rule. Set the associated value to one of the available severity levels.1

Notes:

1. Severity specification within a naming rule is only respected inside development IDEs, such as Visual Studio. This setting is not understood by the C# or VB compilers, hence not respected during build. Instead, to enforce naming style rules on build, you should set the severity by using the rule ID-based severity configuration as explained in this section. For more information, see this GitHub issue.

Rule order

The order in which naming rules are defined in an EditorConfig file doesn't matter. The naming rules are automatically ordered according to the definition of the rules themselves. The EditorConfig Language Service extension can analyze an EditorConfig file and report cases where the rule ordering in the file is different to what the compiler will use at run time.

Note

If you're using a version of Visual Studio earlier than Visual Studio 2019 version 16.2, naming rules should be ordered from most-specific to least-specific in the EditorConfig file. The first rule encountered that can be applied is the only rule that is applied. However, if there are multiple rule properties with the same name, the most recently found property with that name takes precedence. For more information, see File hierarchy and precedence.

Symbol group properties

You can set the following properties for symbol groups, to limit which symbols are included in the group. To specify multiple values in a single property setting, separate them with a comma.

Property Description Allowed values Required
applicable_kinds Kinds of symbols in the group 1 * (use this value to specify all symbols)
namespace
class
struct
interface
enum
property
method
field
event
delegate
parameter
type_parameter
local
local_function
Yes
applicable_accessibilities Accessibility levels of the symbols in the group * (use this value to specify all accessibility levels)
public
internal or friend
private
protected
protected_internal or protected_friend
private_protected
local (for symbols defined within a method)
Yes
required_modifiers Only match symbols with all the specified modifiers 2 abstract or must_inherit
async
const
readonly
static or shared 3
No

Notes:

1. Tuple members aren't currently supported in applicable_kinds.
2. The symbol group matches all the modifiers in the required_modifiers property. If you omit this property, no specific modifiers are required for a match. This means a symbol's modifiers have no effect on whether or not this rule is applied.
3. If your group has static or shared in the required_modifiers property, the group will also include const symbols because they are implicitly static/Shared. However, if you don't want the static naming rule to apply to const symbols, you can create a new naming rule with a symbol group of const.

Naming style properties

A naming style defines the conventions you want to enforce with the rule. For example:

• Capitalize with PascalCase
• Starts with m_
• Ends with _g
• Separate words with __

You can set the following properties for a naming style:

Property Description Allowed values Required
capitalization Capitalization style for words within the symbol pascal_case
camel_case
first_word_upper
all_upper
all_lower
Yes1
required_prefix Must begin with these characters No
required_suffix Must end with these characters No
word_separator Words within the symbol need to be separated with this character No

Notes:

1. You must specify a capitalization style as part of your naming style, otherwise your naming style might be ignored.

Default naming styles

If you don't specify any custom naming rules, the following default styles are used:

• For classes, structs, enumerations, properties, and events with public, private, internal, protected, or protected_internal accessibility, the default naming style is Pascal case.

• For interfaces with public, private, internal, protected, or protected_internal accessibility, the default naming style is Pascal case with a required prefix of I.

Example

The following .editorconfig file contains a naming convention that specifies that public properties, methods, fields, events, and delegates must be capitalized. Notice that this naming convention specifies multiple kinds of symbol to apply the rule to, using a comma to separate the values.

[*.{cs,vb}]

# Defining the 'public_symbols' symbol group
dotnet_naming_symbols.public_symbols.applicable_kinds           = property,method,field,event,delegate
dotnet_naming_symbols.public_symbols.applicable_accessibilities = public

# Defining the first_word_upper_case_style naming style
dotnet_naming_style.first_word_upper_case_style.capitalization = first_word_upper

# Defining the public_members_must_be_capitalized naming rule, by setting the symbol group to the 'public symbols' symbol group,
dotnet_naming_rule.public_members_must_be_capitalized.symbols   = public_symbols
# setting the naming style to the first_word_upper_case_style naming style,
dotnet_naming_rule.public_members_must_be_capitalized.style    = first_word_upper_case_style
# and setting the severity.
dotnet_naming_rule.public_members_must_be_capitalized.severity = suggestion


Rule ID: "IDE1006" (Naming rule violation)

All naming options have rule ID IDE1006 and title Naming rule violation. You can configure the severity of naming violations globally in an EditorConfig file with the following syntax:

dotnet_diagnostic.IDE1006.severity = <severity value>


The severity value must be warning or error to be enforced on build. For all possible severity values, see severity level.