EditorConfig is a configuration file format that standardizes coding styles and conventions across different IDEs and editors. By defining specific rules in a .editorconfig
file, teams can ensure consistency in code formatting and maintainability regardless of individual developer environments.
Core Features of EditorConfig
- Language-Agnostic Rules: Supports basic formatting rules like indentation, line endings, and trailing whitespace for all file types.
- Language-Specific Rules: Supports language-specific conventions, such as
.NET
coding standards. - IDE Integration: Supported natively or via plugins in most IDEs (e.g., Visual Studio, Rider, VS Code).
Structure of an EditorConfig File
root
: Marks the top-level.editorconfig
file.- File Matching: Specifies rules for files using glob patterns (e.g.,
[*.cs]
for C# files). - Settings: Key-value pairs to define coding styles.
Common Coding Standards
General Settings
indent_style
: Defines tabs or spaces (space
ortab
).indent_size
: Sets the number of spaces per indent.end_of_line
: Specifies line endings (lf
,crlf
, orcr
).trim_trailing_whitespace
: Removes unnecessary spaces at the end of lines.insert_final_newline
: Ensures files end with a newline.
Language-Specific Standards
- C# and .NET Standards:
- Organizing Usings: Sort
using
directives and position (inside
oroutside
namespace). - Modifier Preferences: Enforce accessibility modifiers and readonly fields.
- Naming Conventions: Define capitalization and prefix rules for constants, fields, methods, etc.
- Expression Preferences: Encourage modern patterns like null propagation, collection initializers, and auto-properties.
- Organizing Usings: Sort
Formatting Rules
- Control spaces, newlines, and indentation for constructs like braces, operators, and control flow statements.
C# & VB.Net Project coding standard editor config:
Add the File to the project and name it as .editorconfig
###############################
# Core EditorConfig Options #
###############################
root = true
[*]
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_readonly_field = true:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
dotnet_style_require_accessibility_modifiers = always:error
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
dotnet_code_quality_unused_parameters = all:error
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent
###############################
# C# Naming Conventions #
###############################
[*.cs]
# Use PascalCase for constant fields
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = error
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
# Name all non-public fields with camelCase
dotnet_naming_symbols.non_public_field_symbol.applicable_kinds = field
dotnet_naming_symbols.non_public_field_symbol.applicable_accessibilities = private,internal,protected,protected_internal
dotnet_naming_style.non_public_field_style.capitalization = camel_case
dotnet_naming_rule.non_public_fields_are_camel_case.symbols = non_public_field_symbol
dotnet_naming_rule.non_public_fields_are_camel_case.style = non_public_field_style
# Name all public fields with PascalCase
dotnet_naming_symbols.public_field_symbol.applicable_kinds = field
dotnet_naming_symbols.public_field_symbol.applicable_accessibilities = public
dotnet_naming_style.public_field_style.capitalization = pascal_case
dotnet_naming_rule.public_fields_are_pascal_case.severity = error
dotnet_naming_rule.public_fields_are_pascal_case.symbols = public_field_symbol
dotnet_naming_rule.public_fields_are_pascal_case.style = pascal_case_style
# All static fields must be PascalCase
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_rule.static_fields_must_be_pascal_case_rule.symbols = static_fields
dotnet_naming_rule.static_fields_must_be_pascal_case_rule.style = pascal_case_style
dotnet_naming_rule.static_fields_must_be_pascal_case_rule.severity = error
# Names of parameters must be camelCase
dotnet_naming_symbols.parameter_symbol.applicable_kinds = parameter
dotnet_naming_style.parameter_style.capitalization = camel_case
dotnet_naming_rule.parameters_are_camel_case.severity = error
dotnet_naming_rule.parameters_are_camel_case.symbols = parameter_symbol
dotnet_naming_rule.parameters_are_camel_case.style = parameter_style
# Non-interface types must use PascalCase
dotnet_naming_symbols.non_interface_type_symbol.applicable_kinds = class,struct,enum,delegate
dotnet_naming_style.non_interface_type_style.capitalization = pascal_case
dotnet_naming_rule.non_interface_types_are_pascal_case.severity = error
dotnet_naming_rule.non_interface_types_are_pascal_case.symbols = non_interface_type_symbol
dotnet_naming_rule.non_interface_types_are_pascal_case.style = pascal_case_style
# Interfaces must use PascalCase and start with a prefix of 'I'
dotnet_naming_symbols.interface_type_symbol.applicable_kinds = interface
dotnet_naming_style.interface_type_style.capitalization = pascal_case
dotnet_naming_style.interface_type_style.required_prefix = I
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.severity = error
dotnet_naming_rule.interface_types_must_be_prefixed_with_I.symbols = interface_type_symbol
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.style = interface_type_style
# Methods, Properties, and Events must use PascalCase
dotnet_naming_symbols.member_symbol.applicable_kinds = method,property,event
dotnet_naming_style.member_style.capitalization = pascal_case
dotnet_naming_rule.members_are_pascal_case.severity = error
dotnet_naming_rule.members_are_pascal_case.symbols = member_symbol
dotnet_naming_rule.members_are_pascal_case.style = pascal_case_style
###############################
# VB.NET Naming Conventions #
###############################
[*.vb]
# Use PascalCase for constant fields
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = error
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
# Name all non-public fields with camelCase
dotnet_naming_symbols.non_public_field_symbol.applicable_kinds = field
dotnet_naming_symbols.non_public_field_symbol.applicable_accessibilities = private,internal,protected,protected_internal
dotnet_naming_style.non_public_field_style.capitalization = camel_case
dotnet_naming_rule.non_public_fields_are_camel_case.symbols = non_public_field_symbol
dotnet_naming_rule.non_public_fields_are_camel_case.style = non_public_field_style
# Name all public fields with PascalCase
dotnet_naming_symbols.public_field_symbol.applicable_kinds = field
dotnet_naming_symbols.public_field_symbol.applicable_accessibilities = public
dotnet_naming_style.public_field_style.capitalization = pascal_case
dotnet_naming_rule.public_fields_are_pascal_case.severity = error
dotnet_naming_rule.public_fields_are_pascal_case.symbols = public_field_symbol
dotnet_naming_rule.public_fields_are_pascal_case.style = pascal_case_style
# All static fields must be PascalCase
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_rule.static_fields_must_be_pascal_case_rule.symbols = static_fields
dotnet_naming_rule.static_fields_must_be_pascal_case_rule.style = pascal_case_style
dotnet_naming_rule.static_fields_must_be_pascal_case_rule.severity = error
# Names of parameters must be camelCase
dotnet_naming_symbols.parameter_symbol.applicable_kinds = parameter
dotnet_naming_style.parameter_style.capitalization = camel_case
dotnet_naming_rule.parameters_are_camel_case.severity = error
dotnet_naming_rule.parameters_are_camel_case.symbols = parameter_symbol
dotnet_naming_rule.parameters_are_camel_case.style = parameter_style
# Non-interface types must use PascalCase
dotnet_naming_symbols.non_interface_type_symbol.applicable_kinds = class,struct,enum,delegate
dotnet_naming_style.non_interface_type_style.capitalization = pascal_case
dotnet_naming_rule.non_interface_types_are_pascal_case.severity = error
dotnet_naming_rule.non_interface_types_are_pascal_case.symbols = non_interface_type_symbol
dotnet_naming_rule.non_interface_types_are_pascal_case.style = pascal_case_style
# Interfaces must use PascalCase and start with a prefix of 'I'
dotnet_naming_symbols.interface_type_symbol.applicable_kinds = interface
dotnet_naming_style.interface_type_style.capitalization = pascal_case
dotnet_naming_style.interface_type_style.required_prefix = I
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.severity = error
dotnet_naming_rule.interface_types_must_be_prefixed_with_I.symbols = interface_type_symbol
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.style = interface_type_style
# Methods, Properties, and Events must use PascalCase
dotnet_naming_symbols.member_symbol.applicable_kinds = method,property,event
dotnet_naming_style.member_style.capitalization = pascal_case
dotnet_naming_rule.members_are_pascal_case.severity = error
dotnet_naming_rule.members_are_pascal_case.symbols = member_symbol
dotnet_naming_rule.members_are_pascal_case.style = pascal_case_style
###############################
# Naming Conventions (Unified) #
###############################
# Both C# and VB.NET rules
[*.{cs,vb}]
# Method names should be in PascalCase
dotnet_naming_rule.methods_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.methods_should_be_pascal_case.symbols = methods
dotnet_naming_rule.methods_should_be_pascal_case.style = pascal_case
# Local variables should be in camelCase
dotnet_naming_rule.local_variables_should_be_camel_case.severity = suggestion
dotnet_naming_rule.local_variables_should_be_camel_case.symbols = local_variables
dotnet_naming_rule.local_variables_should_be_camel_case.style = camel_case