Created
March 1, 2024 22:52
-
-
Save AndreAugustoDev/a45e6e81d9781e8e6f08465e5d49fae3 to your computer and use it in GitHub Desktop.
EditorConfig for .NET / C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# EditorConfig is awesome: https://EditorConfig.org | |
# Version: 1.0.0 (Using https://semver.org) | |
# Updated: 2024-03-01 | |
# See https://editorconfig.org for more information about .editorconfig files. | |
# See for references used in this file: | |
# - https://github.com/RehanSaeed/EditorConfig | |
# - https://github.com/dotnet/runtime | |
# - https://learn.microsoft.com/pt-br/dotnet/fundamentals/code-analysis/overview | |
# - https://learn.microsoft.com/pt-br/dotnet/standard/design-guidelines | |
############################### | |
# Core EditorConfig Options # | |
############################### | |
root = true | |
# All files | |
[*] | |
indent_style = space | |
indent_size = 4 | |
insert_final_newline = true | |
trim_trailing_whitespace = true | |
# Generated code | |
[*{_AssemblyInfo.cs,.notsupported.cs,AsmOffsets.cs}] | |
generated_code = true | |
# Code files | |
[*.{cs,csx,vb,vbx}] | |
indent_size = 4 | |
insert_final_newline = true | |
charset = utf-8-bom | |
########################################## | |
# Default .NET code style severities | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/configuration-options#scope | |
########################################## | |
[*.{cs,csx,cake}] | |
# Default severity for all .NET code style rules below | |
dotnet_analyzer_diagnostic.severity = warning | |
########################################## | |
# Language rules | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules | |
########################################## | |
# .NET style rules | |
[*.{cs,csx,cake}] | |
# Expression-level preferences | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#expression-level-preferences | |
dotnet_style_object_initializer = true | |
dotnet_style_collection_initializer = true | |
dotnet_style_explicit_tuple_names = true | |
dotnet_style_coalesce_expression = true | |
dotnet_style_null_propagation = true | |
dotnet_style_prefer_is_null_check_over_reference_equality_method = true | |
dotnet_style_prefer_inferred_tuple_names = true | |
dotnet_style_prefer_inferred_anonymous_type_member_names = true | |
dotnet_style_prefer_auto_properties = true | |
dotnet_style_prefer_conditional_expression_over_assignment = true | |
dotnet_style_prefer_conditional_expression_over_return = true | |
dotnet_style_prefer_compound_assignment = true | |
dotnet_style_prefer_simplified_interpolation = true | |
dotnet_style_prefer_simplified_boolean_expressions = true | |
# Avoid "this." unless absolutely necessary | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#this-and-me-preferences | |
dotnet_style_qualification_for_field = false | |
dotnet_style_qualification_for_property = false | |
dotnet_style_qualification_for_method = false | |
dotnet_style_qualification_for_event = false | |
# Use language keywords instead of framework type names for type references | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#language-keyword-vs-framework-types-preferences | |
dotnet_style_predefined_type_for_locals_parameters_members = true | |
dotnet_style_predefined_type_for_member_access = true | |
# Modifier preferences | |
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async | |
dotnet_style_require_accessibility_modifiers = always | |
dotnet_style_readonly_field = true | |
# C# style rules | |
[*.{cs,csx,cake}] | |
# 'using' directive preferences | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#using-directive-preferences | |
csharp_using_directive_placement = outside_namespace | |
# Code block preferences | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#code-block-preferences | |
csharp_prefer_braces = when_multiline | |
csharp_prefer_simple_using_statement = true | |
csharp_style_prefer_method_group_conversion = true | |
csharp_style_prefer_top_level_statements = true | |
csharp_style_prefer_primary_constructors = true | |
# Expression-bodied members | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#expression-bodied-members | |
csharp_style_expression_bodied_constructors = true | |
csharp_style_expression_bodied_methods = true | |
csharp_style_expression_bodied_operators = true | |
csharp_style_expression_bodied_properties = true | |
csharp_style_expression_bodied_indexers = true | |
csharp_style_expression_bodied_accessors = true | |
csharp_style_expression_bodied_lambdas = true | |
csharp_style_expression_bodied_local_functions = true | |
# Expression-level preferences | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#expression-level-preferences | |
csharp_prefer_simple_default_expression = true | |
csharp_style_throw_expression = true | |
csharp_style_inlined_variable_declaration = true | |
csharp_style_pattern_local_over_anonymous_function = true | |
csharp_style_deconstructed_variable_declaration = true | |
csharp_style_prefer_index_operator = true | |
csharp_style_prefer_range_operator = true | |
csharp_style_implicit_object_creation_when_type_is_apparent = true | |
# Modifier preferences | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#modifier-preferences | |
csharp_prefer_static_local_function = true:suggestion | |
csharp_style_prefer_readonly_struct = true | |
csharp_style_prefer_readonly_struct_member = true | |
# "Null" checking preferences | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#null-checking-preferences | |
csharp_style_conditional_delegate_call = true | |
# Pattern matching preferences | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#pattern-matching-preferences | |
csharp_style_pattern_matching_over_is_with_cast_check = true | |
csharp_style_pattern_matching_over_as_with_null_check = true | |
csharp_style_prefer_switch_expression = true | |
csharp_style_prefer_pattern_matching = true | |
csharp_style_prefer_not_pattern = true | |
# "var" preferences | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/language-rules#var-preferences | |
csharp_style_var_for_built_in_types = false | |
csharp_style_var_when_type_is_apparent = false | |
csharp_style_var_elsewhere = false | |
########################################## | |
# Formatting rules | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules | |
########################################## | |
# .NET formatting rules | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/formatting-rules#net-formatting-rules | |
[*.{cs,csx,cake}] | |
# Using directive options | |
dotnet_sort_system_directives_first = true | |
dotnet_separate_import_directive_groups = false | |
# .NET namespace options | |
dotnet_style_namespace_match_folder = true:suggestion | |
dotnet_diagnostic.IDE0130.severity = suggestion | |
# C# formatting rules | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options | |
[*.{cs,csx,cake}] | |
# New line options | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options#new-line-options | |
csharp_new_line_before_open_brace = all | |
csharp_new_line_before_else = true | |
csharp_new_line_before_catch = true | |
csharp_new_line_before_finally = true | |
csharp_new_line_before_members_in_object_initializers = true | |
csharp_new_line_before_members_in_anonymous_types = true | |
csharp_new_line_between_query_expression_clauses = true | |
# Indentation options | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options#indentation-options | |
csharp_indent_block_contents = true | |
csharp_indent_braces = false | |
csharp_indent_case_contents = true | |
csharp_indent_case_contents_when_block = false | |
csharp_indent_labels = one_less_than_current | |
csharp_indent_switch_labels = true | |
# Spacing options | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options#spacing-options | |
csharp_space_after_cast = false | |
csharp_space_after_colon_in_inheritance_clause = true | |
csharp_space_after_comma = true | |
csharp_space_after_dot = false | |
csharp_space_after_keywords_in_control_flow_statements = true | |
csharp_space_after_semicolon_in_for_statement = true | |
csharp_space_around_binary_operators = before_and_after | |
csharp_space_around_declaration_statements = false | |
csharp_space_before_colon_in_inheritance_clause = true | |
csharp_space_before_comma = false | |
csharp_space_before_dot = false | |
csharp_space_before_open_square_brackets = false | |
csharp_space_before_semicolon_in_for_statement = false | |
csharp_space_between_empty_square_brackets = false | |
csharp_space_between_method_call_empty_parameter_list_parentheses = false | |
csharp_space_between_method_call_name_and_opening_parenthesis = false | |
csharp_space_between_method_call_parameter_list_parentheses = false | |
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false | |
csharp_space_between_method_declaration_name_and_open_parenthesis = false | |
csharp_space_between_method_declaration_parameter_list_parentheses = false | |
csharp_space_between_parentheses = false | |
csharp_space_between_square_brackets = false | |
# Wrap options | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/csharp-formatting-options#wrap-options | |
csharp_preserve_single_line_blocks = true | |
csharp_preserve_single_line_statements = false:none | |
# Namespace options | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0160-ide0161 | |
csharp_style_namespace_declarations = file_scoped:warning | |
########################################## | |
# .NET naming rules | |
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/naming-rules | |
########################################## | |
[*.{cs,csx,cake}] | |
########################################## | |
# Styles | |
########################################## | |
# pascal_case_style - Define PascalCase style | |
dotnet_naming_style.pascal_case_style.capitalization = pascal_case | |
# camel_case_style - Define camelCase style | |
dotnet_naming_style.camel_case_style.capitalization = camel_case | |
# static_prefix_style - Define static prefix style | |
dotnet_naming_style.static_prefix_style.required_prefix = s_ | |
dotnet_naming_style.static_prefix_style.capitalization = camel_case | |
# camel_case_underscore_style - Define _camelCase style | |
dotnet_naming_style.camel_case_underscore_style.required_prefix = _ | |
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case | |
# interface_prefix_style - Define interface prefix style | |
dotnet_naming_style.interface_prefix_style.required_prefix = I | |
dotnet_naming_style.interface_prefix_style.capitalization = pascal_case | |
# type_parameter_prefix_style - Define type parameter prefix style | |
dotnet_naming_style.type_parameter_prefix_style.required_prefix = T | |
dotnet_naming_style.type_parameter_prefix_style.capitalization = pascal_case | |
########################################## | |
# .NET Design Guideline Field Naming Rules | |
# Naming rules for fields follow the .NET Framework design guidelines | |
# https://learn.microsoft.com/dotnet/standard/design-guidelines/ | |
########################################## | |
# Name all constant fields using PascalCase | |
dotnet_naming_rule.constants_fields_should_be_pascal_case.severity = suggestion | |
dotnet_naming_rule.constants_fields_should_be_pascal_case.symbols = constants | |
dotnet_naming_rule.constants_fields_should_be_pascal_case.style = pascal_case_style | |
dotnet_naming_symbols.constants_fields.applicable_kinds = field | |
dotnet_naming_symbols.constants_fields.required_modifiers = const | |
# private/internal/private_protected static fields should have s_ prefix and be camelCase | |
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion | |
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields | |
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style | |
dotnet_naming_symbols.static_fields.applicable_kinds = field | |
dotnet_naming_symbols.static_fields.required_modifiers = static | |
dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected | |
# private and internal fields should be _camelCase | |
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion | |
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields | |
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style | |
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field | |
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal | |
# Local variables should be camelCase | |
dotnet_naming_symbols.local_fields_group.applicable_accessibilities = local | |
dotnet_naming_symbols.local_fields_group.applicable_kinds = local | |
dotnet_naming_rule.local_fields_should_be_camel_case_rule.symbols = local_fields_group | |
dotnet_naming_rule.local_fields_should_be_camel_case_rule.style = camel_case_style | |
dotnet_naming_rule.local_fields_should_be_camel_case_rule.severity = warning | |
########################################## | |
# Other naming rules | |
########################################## | |
# All of the following must be PascalCase: | |
# - Namespaces | |
# https://learn.microsoft.com/dotnet/standard/design-guidelines/names-of-namespaces | |
# - Classes and Enumerations | |
# https://learn.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces | |
# - Delegates | |
# https://learn.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces#names-of-common-types | |
# - Constructors, Properties, Events, Methods | |
# https://learn.microsoft.com/dotnet/standard/design-guidelines/names-of-type-members | |
dotnet_naming_symbols.element_group.applicable_kinds = namespace, class, enum, struct, delegate, event, method, property | |
dotnet_naming_rule.element_rule.symbols = element_group | |
dotnet_naming_rule.element_rule.style = pascal_case_style | |
dotnet_naming_rule.element_rule.severity = warning | |
# Interfaces use PascalCase and should be prefixed with uppercase 'I' | |
# https://learn.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces | |
dotnet_naming_symbols.interface_group.applicable_kinds = interface | |
dotnet_naming_rule.interface_rule.symbols = interface_group | |
dotnet_naming_rule.interface_rule.style = interface_prefix_style | |
dotnet_naming_rule.interface_rule.severity = warning | |
# Generics Type Parameters use PascalCase and should be prefixed with uppercase 'T' | |
# https://learn.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces#names-of-generic-type-parameters | |
dotnet_naming_symbols.type_parameter_group.applicable_kinds = type_parameter | |
dotnet_naming_rule.type_parameter_rule.symbols = type_parameter_group | |
dotnet_naming_rule.type_parameter_rule.style = type_parameter_prefix_style | |
dotnet_naming_rule.type_parameter_rule.severity = warning | |
# Parameter names use camelCase | |
# https://learn.microsoft.com/dotnet/standard/design-guidelines/naming-parameters | |
dotnet_naming_symbols.parameters_group.applicable_kinds = parameter | |
dotnet_naming_rule.parameters_rule.symbols = parameters_group | |
dotnet_naming_rule.parameters_rule.style = camel_case_style | |
dotnet_naming_rule.parameters_rule.severity = warning | |
# C++ Files | |
[*.{cpp,h,in}] | |
curly_bracket_next_line = true | |
indent_brace_style = Allman | |
# XML project files | |
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj,nativeproj,locproj}] | |
indent_size = 2 | |
# XML config files | |
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] | |
indent_size = 2 | |
[*.{csproj,vbproj,proj,nativeproj,locproj}] | |
charset = utf-8 | |
# XML build files | |
[*.builds] | |
indent_size = 2 | |
# XML files | |
[*.{xml,stylecop,resx,ruleset}] | |
indent_size = 2 | |
# XML config files | |
[*.{props,targets,config,nuspec}] | |
indent_size = 2 | |
# YAML config files | |
[*.{yml,yaml}] | |
indent_size = 2 | |
# Shell scripts | |
[*.sh] | |
end_of_line = lf | |
[*.{cmd,bat}] | |
end_of_line = crlf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment