Skip to content

.editorconfig

View on GitHub ยท Raw

# awesome-humans/dotnet template | targets: net11.0, csharp-15 | last-reviewed: 2026-11-14 | sources: meziantou, ms-learn
# Copy to the repository root. Remove a rule only after you've decided you disagree with it.

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.{json,jsonc,yml,yaml,props,targets,csproj,fsproj,slnx,slnf,xml,config}]
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[*.{cs,fs}]
dotnet_analyzer_diagnostic.severity = warning

[*.cs]
# --- C# style: explicit types, expression bodies, and current syntax ---
csharp_style_var_for_built_in_types = false:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = false:suggestion
csharp_style_expression_bodied_methods = when_on_single_line:suggestion
# Constructors too. Left unset, the option defaults to block bodies, and the bulk severity above
# raises IDE0021 to a warning that fails every expression-bodied constructor.
csharp_style_expression_bodied_constructors = when_on_single_line:suggestion
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_namespace_declarations = file_scoped:warning
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_prefer_switch_expression = true:warning
csharp_style_pattern_matching_over_as_with_null_check = true:warning
csharp_style_prefer_null_check_over_type_check = true:warning
csharp_prefer_simple_using_statement = true:warning
csharp_style_prefer_top_level_statements = true:suggestion
csharp_style_prefer_method_group_conversion = true:suggestion
csharp_using_directive_placement = outside_namespace:warning

# Prefer auto-implemented properties over trivial hand-written backing fields. Set the severity
# here, and leave it off dotnet_style_prefer_auto_properties below, which is the same rule. The
# build reports IDE0032 at the lower of the two, so `true:suggestion` there turns this warning off.
dotnet_diagnostic.IDE0032.severity = warning

# The bulk severity above raises IDE0058 (unused expression value) to a warning, which requires
# `_ =` on every discarded result, including each Assert.Throws in a test project. Keep it silent.
dotnet_diagnostic.IDE0058.severity = silent

# The bulk severity also raises IDE0072 (populate switch), which asks for a discard arm on a
# switch expression over a union or a closed hierarchy. The compiler already checks those for
# exhaustiveness (CS8509), and the arm would hide a case added later (opinions/csharp.md).
# The severity can't be scoped by type, so enum switches lose IDE0072 too: an enum switch
# that ends in a throwing `_` arm gets no warning when a member is added.
dotnet_diagnostic.IDE0072.severity = silent

# The one globalization rule AnalysisLevel=latest-recommended leaves silent: string.Equals
# without a StringComparison. CA1304/1305/1309/1310/1311 already warn (opinions/globalization.md).
dotnet_diagnostic.CA1307.severity = warning

# The one Meziantou.Analyzer TimeProvider rule that ships disabled: prefer overloads taking a
# TimeProvider. MA0166/MA0188 ship enabled at info severity and are raised to warnings by the
# bulk dotnet_analyzer_diagnostic.severity above (opinions/datetime.md).
dotnet_diagnostic.MA0167.severity = warning

# MA0038 (make method static) and MA0041 (make property static) are deprecated in favour of
# CA1822, which latest-recommended enables. Both report instance members of a C# 14 extension
# block, which can't be made static and still extend an instance.
dotnet_diagnostic.MA0038.severity = none
dotnet_diagnostic.MA0041.severity = none

# --- .NET style: modifiers, initializers, and null checks ---
dotnet_style_require_accessibility_modifiers = always:warning
dotnet_style_readonly_field = true:warning
dotnet_style_prefer_auto_properties = true # severity: IDE0032 above
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_collection_expression = true:warning
dotnet_style_object_initializer = true:suggestion
dotnet_style_coalesce_expression = true:warning
dotnet_style_null_propagation = true:warning

# --- Naming: standard .NET conventions ---
dotnet_naming_rule.interfaces_begin_with_i.severity = warning
dotnet_naming_rule.interfaces_begin_with_i.symbols = interfaces
dotnet_naming_rule.interfaces_begin_with_i.style = prefix_i
dotnet_naming_symbols.interfaces.applicable_kinds = interface
dotnet_naming_style.prefix_i.required_prefix = I
dotnet_naming_style.prefix_i.capitalization = pascal_case

# Constants take PascalCase. A rule with required_modifiers is more specific than the private-field
# rule below, so it wins for consts; without it, a private const needs an underscore prefix.
dotnet_naming_rule.constants_pascal_case.severity = warning
dotnet_naming_rule.constants_pascal_case.symbols = constants
dotnet_naming_rule.constants_pascal_case.style = pascal_case
dotnet_naming_symbols.constants.applicable_kinds = field, local
dotnet_naming_symbols.constants.applicable_accessibilities = *
dotnet_naming_symbols.constants.required_modifiers = const
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_rule.private_fields_camel_underscore.severity = warning
dotnet_naming_rule.private_fields_camel_underscore.symbols = private_fields
dotnet_naming_rule.private_fields_camel_underscore.style = underscore_camel
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
dotnet_naming_style.underscore_camel.required_prefix = _
dotnet_naming_style.underscore_camel.capitalization = camel_case