Skip to content

Instantly share code, notes, and snippets.

@kurnakovv
Last active November 16, 2025 03:47
Show Gist options
  • Select an option

  • Save kurnakovv/b396696805339988a547c6d53a0d0254 to your computer and use it in GitHub Desktop.

Select an option

Save kurnakovv/b396696805339988a547c6d53a0d0254 to your computer and use it in GitHub Desktop.
Favorite Code-style (IDExxxx) rules in .editorconfig
[*.cs]
##
## Code-style (IDExxxx) rules
##
# All rules here https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules
dotnet_analyzer_diagnostic.category-Style.severity = error
dotnet_analyzer_diagnostic.category-CodeQuality.severity = error
### ! Language rules ! ###
# Rules that pertain to the C# or Visual Basic language. For example, you can specify rules that regard the use of var when defining variables, or whether expression-bodied members are preferred. This category also includes rules that find unnecessary code, for example, unreachable code within methods or unused private fields, properties, or methods.
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/language-rules
### 'using' directive preferences ###
# Require file header (IDE0073)
file_header_template = unset
dotnet_diagnostic.IDE0073.severity = none
# Remove unnecessary using directives (IDE0005)
dotnet_diagnostic.IDE0005.severity = error # >= warning only if <GenerateDocumentationFile>true</GenerateDocumentationFile> in csproj
dotnet_diagnostic.CS1573.severity = none # CS1573: Parameter has no matching param tag in the XML comment (but other parameters do)
dotnet_diagnostic.CS1591.severity = none # CS1591: No XML docs
### Code-block preferences ###
# Namespace declaration preferences (IDE0160, IDE0161)
csharp_style_namespace_declarations = file_scoped
dotnet_diagnostic.IDE0160.severity = none
# Remove unnecessary lambda expression (IDE0200)
csharp_style_prefer_method_group_conversion = false
dotnet_diagnostic.IDE0200.severity = none
# Convert to top-level statements (IDE0210) / Convert to 'Program.Main' style program (IDE0211)
dotnet_diagnostic.IDE0211.severity = none
csharp_style_prefer_top_level_statements = false
# Use primary constructor (IDE0290)
csharp_style_prefer_primary_constructors = false
dotnet_diagnostic.IDE0290.severity = none
### Expression-bodied members ###
dotnet_diagnostic.IDE0004.severity = none # Remove unnecessary cast (IDE0004)
# Use expression body for operators (IDE0023, IDE0024)
csharp_style_expression_bodied_operators = when_on_single_line
# Use expression body for indexers (IDE0026)
csharp_style_expression_bodied_indexers = when_on_single_line
# Use expression body for lambdas (IDE0053)
csharp_style_expression_bodied_lambdas = when_on_single_line
### Expression-level preferences ###
# Use inferred member names (IDE0037)
dotnet_style_prefer_inferred_anonymous_type_member_names = false
# Use conditional expression for assignment (IDE0045)
dotnet_style_prefer_conditional_expression_over_assignment = false
dotnet_diagnostic.IDE0045.severity = none
# Use conditional expression for return (IDE0046)
dotnet_style_prefer_conditional_expression_over_return = false
dotnet_diagnostic.IDE0046.severity = none
dotnet_diagnostic.IDE0050.severity = none # (removed) Convert anonymous type to tuple (IDE0050)
dotnet_diagnostic.IDE0058.severity = none # Remove unnecessary expression value (IDE0058)
dotnet_diagnostic.IDE0059.severity = none # Remove unnecessary value assignment (IDE0059)
# Simplify 'default' expression (IDE0034)
csharp_prefer_simple_default_expression = false
dotnet_diagnostic.IDE0034.severity = none
# Use local function instead of lambda (IDE0039)
csharp_style_prefer_local_over_anonymous_function = false
dotnet_diagnostic.IDE0039.severity = none
# Use index operator (IDE0056)
csharp_style_prefer_index_operator = false
dotnet_diagnostic.IDE0056.severity = none
# Use range operator (IDE0057)
csharp_style_prefer_range_operator = false
dotnet_diagnostic.IDE0057.severity = none
# Add explicit cast in foreach loop (IDE0220)
dotnet_style_prefer_foreach_explicit_cast_in_source = always
# Use collection expression for builder (IDE0304)
dotnet_diagnostic.IDE0304.severity = none
# Use unbound generic type (IDE0340)
csharp_style_prefer_unbound_generic_type_in_nameof = false
dotnet_diagnostic.IDE0340.severity = none
# Use implicitly typed lambda (IDE0350)
csharp_style_prefer_implicitly_typed_lambda_expression = false
dotnet_diagnostic.IDE0350.severity = none
### Field preferences ###
# Nothing yet
### Language keyword vs. framework types preferences ###
# Nothing yet
### Modifier preferences ###
# Make local function static (IDE0062)
csharp_prefer_static_local_function = false
dotnet_diagnostic.IDE0062.severity = none
# Make anonymous function static (IDE0320)
csharp_prefer_static_anonymous_function = false
dotnet_diagnostic.IDE0320.severity = none
### New-line preferences ###
# Avoid multiple blank lines (IDE2000)┼
dotnet_style_allow_multiple_blank_lines_experimental = false
# Blank line required between block and subsequent statement (IDE2003)┼
dotnet_diagnostic.IDE2003.severity = none
# Embedded statements must be on their own line (IDE2001)┼
dotnet_diagnostic.IDE2001.severity = none
# Consecutive braces must not have blank line between them (IDE2002)┼
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
# Blank line not allowed after constructor initializer colon (IDE2004)┼
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false
# Blank line not allowed after conditional expression token (IDE2005)┼
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false
# Blank line not allowed after arrow expression clause token (IDE2006)┼
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false
dotnet_diagnostic.IDE2006.severity = none
### Null-checking preferences ###
# Nothing yet
### Parameter preferences ###
# Nothing yet
### Parentheses preferences ###
# Nothing yet
### Pattern-matching preferences ###
# Nothing yet
### Suppression preferences ###
# this and Me preferences (IDE0003, IDE0009)
dotnet_diagnostic.IDE0009.severity = none # VB
### var preferences ###
# 'var' preferences (IDE0007, IDE0008)
dotnet_diagnostic.IDE0007.severity = none
### ! Formatting rules ! ###
# Rules that pertain to the layout and structure of your code in order to make it easier to read. For example, you can specify a formatting option that defines whether spaces in control blocks are preferred or not.
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0055
dotnet_diagnostic.IDE0055.severity = error
dotnet_sort_system_directives_first = true
csharp_new_line_before_members_in_anonymous_types = false
csharp_indent_case_contents_when_block = false
### ! Naming rules ! ###
# Rules that pertain to the naming of code elements. For example, you can specify that async method names must have an "Async" suffix.
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/naming-rules
dotnet_diagnostic.IDE1006.severity = error
# Asynchronous methods must end with "Async"
# Note: This rule does not work for interface methods, a better solution is https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1046
dotnet_naming_rule.asynchronous_methods_must_end_with_async.severity = error
dotnet_naming_rule.asynchronous_methods_must_end_with_async.symbols = async_methods
dotnet_naming_rule.asynchronous_methods_must_end_with_async.style = async_method_style
dotnet_naming_symbols.async_methods.applicable_kinds = method
dotnet_naming_symbols.async_methods.required_modifiers = async
dotnet_naming_symbols.async_methods.applicable_accessibilities = *
dotnet_naming_style.async_method_style.required_suffix = Async
dotnet_naming_style.async_method_style.capitalization = pascal_case
# Interfaces must start with "I"
dotnet_naming_rule.interfaces_must_start_with_I.severity = error
dotnet_naming_rule.interfaces_must_start_with_I.symbols = interfaces
dotnet_naming_rule.interfaces_must_start_with_I.style = interface_style
dotnet_naming_symbols.interfaces.applicable_kinds = interface
dotnet_naming_symbols.interfaces.applicable_accessibilities = *
dotnet_naming_style.interface_style.required_prefix = I
dotnet_naming_style.interface_style.capitalization = pascal_case
# Constants are UPPER_CASE
dotnet_naming_rule.constants_are_upper_case.severity = error
dotnet_naming_rule.constants_are_upper_case.symbols = constants
dotnet_naming_rule.constants_are_upper_case.style = constant_style
dotnet_naming_symbols.constants.applicable_kinds = field, local
dotnet_naming_symbols.constants.required_modifiers = const
dotnet_naming_style.constant_style.capitalization = all_upper
# Private instance fields are camelCase and start with "_"
dotnet_naming_rule.private_instance_fields_are_camel_case_and_start_with_.severity = error
dotnet_naming_rule.private_instance_fields_are_camel_case_and_start_with_.symbols = private_instance_fields
dotnet_naming_rule.private_instance_fields_are_camel_case_and_start_with_.style = private_instance_field_style
dotnet_naming_symbols.private_instance_fields.applicable_kinds = field
dotnet_naming_symbols.private_instance_fields.applicable_accessibilities = private
dotnet_naming_style.private_instance_field_style.capitalization = camel_case
dotnet_naming_style.private_instance_field_style.required_prefix = _
# Static fields must start with "s_"
dotnet_naming_rule.static_fields_must_start_with_s_.severity = error
dotnet_naming_rule.static_fields_must_start_with_s_.symbols = static_fields
dotnet_naming_rule.static_fields_must_start_with_s_.style = static_field_style
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_style.static_field_style.capitalization = camel_case
dotnet_naming_style.static_field_style.required_prefix = s_
# Locals and parameters are camelCase
dotnet_naming_rule.locals_are_camel_case.severity = error
dotnet_naming_rule.locals_are_camel_case.symbols = locals_and_parameters
dotnet_naming_rule.locals_are_camel_case.style = local_and_parameter_style
dotnet_naming_symbols.locals_and_parameters.applicable_kinds = parameter, local
dotnet_naming_style.local_and_parameter_style.capitalization = camel_case
# Local functions are PascalCase
dotnet_naming_rule.local_functions_are_pascal_case.severity = error
dotnet_naming_rule.local_functions_are_pascal_case.symbols = local_functions
dotnet_naming_rule.local_functions_are_pascal_case.style = local_function_style
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_style.local_function_style.capitalization = pascal_case
# Generic Type parameters are PascalCase and start with "T"
dotnet_naming_rule.generic_type_parameters_are_pascal_case_and_start_with_t.severity = error
dotnet_naming_rule.generic_type_parameters_are_pascal_case_and_start_with_t.symbols = generic_type_parameters
dotnet_naming_rule.generic_type_parameters_are_pascal_case_and_start_with_t.style = generic_type_parameters_style
dotnet_naming_symbols.generic_type_parameters.applicable_kinds = type_parameter
dotnet_naming_style.generic_type_parameters_style.capitalization = pascal_case
dotnet_naming_style.generic_type_parameters_style.required_prefix = T
# All members are PascalCase
dotnet_naming_rule.all_members_are_pascal_case.severity = error
dotnet_naming_rule.all_members_are_pascal_case.symbols = all_members
dotnet_naming_rule.all_members_are_pascal_case.style = all_members_style
dotnet_naming_symbols.all_members.applicable_kinds = *
dotnet_naming_style.all_members_style.capitalization = pascal_case
### ! Miscellaneous rules ! ###
# Rules that do not belong in other categories.
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/miscellaneous-rules
# Implement with Copilot (IDE3000)
dotnet_diagnostic.IDE3000.severity = none
[**Controller.cs]
dotnet_naming_symbols.async_methods.applicable_accessibilities = private # This filter doesn't work for Rider
dotnet_diagnostic.CS1573.severity = error # CS1573: Parameter has no matching param tag in the XML comment (but other parameters do)
dotnet_diagnostic.CS1591.severity = error # CS1591: No XML docs
@kurnakovv
Copy link
Author

kurnakovv commented Sep 16, 2025

All the same rules, but clearly written

##
## Code-style rules 
##
# All rules here https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules



### ! Language rules ! ###
# Rules that pertain to the C# or Visual Basic language. For example, you can specify rules that regard the use of var when defining variables, or whether expression-bodied members are preferred. This category also includes rules that find unnecessary code, for example, unreachable code within methods or unused private fields, properties, or methods.
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/language-rules


### 'using' directive preferences ###

# Require file header (IDE0073)
file_header_template = unset
dotnet_diagnostic.IDE0073.severity = none

# Remove unnecessary using directives (IDE0005)
dotnet_diagnostic.IDE0005.severity = error # >= warning only if <GenerateDocumentationFile>true</GenerateDocumentationFile> in csproj
dotnet_diagnostic.CS1573.severity = none # CS1573: Parameter has no matching param tag in the XML comment (but other parameters do)
dotnet_diagnostic.CS1591.severity = none # CS1591: No XML docs

# 'using' directive placement (IDE0065)
csharp_using_directive_placement = outside_namespace # default
dotnet_diagnostic.IDE0065.severity = error


### Code-block preferences ###

# Add braces (IDE0011)
csharp_prefer_braces = true # default
dotnet_diagnostic.IDE0011.severity = error

# Use simple 'using' statement (IDE0063)
csharp_prefer_simple_using_statement = true # default
dotnet_diagnostic.IDE0063.severity = error

# Namespace declaration preferences (IDE0160, IDE0161)
csharp_style_namespace_declarations = file_scoped
dotnet_diagnostic.IDE0160.severity = none
dotnet_diagnostic.IDE0161.severity = error

# Remove unnecessary lambda expression (IDE0200)
csharp_style_prefer_method_group_conversion = false
dotnet_diagnostic.IDE0200.severity = none

# Convert to top-level statements (IDE0210) / Convert to 'Program.Main' style program (IDE0211)
csharp_style_prefer_top_level_statements = true # default
dotnet_diagnostic.IDE0210.severity = error
dotnet_diagnostic.IDE0211.severity = none

# Use primary constructor (IDE0290)
csharp_style_prefer_primary_constructors = false
dotnet_diagnostic.IDE0290.severity = none

# Prefer 'System.Threading.Lock' (IDE0330)
csharp_prefer_system_threading_lock = true # default
dotnet_diagnostic.IDE0330.severity = error


### Expression-bodied members ###

# Use expression body for constructors (IDE0021)
csharp_style_expression_bodied_constructors = false # default
dotnet_diagnostic.IDE0021.severity = error

# Use expression body for methods (IDE0022)
csharp_style_expression_bodied_methods = false # default
dotnet_diagnostic.IDE0022.severity = error

# Use expression body for operators (IDE0023, IDE0024)
csharp_style_expression_bodied_operators = when_on_single_line
dotnet_diagnostic.IDE0023.severity = error
dotnet_diagnostic.IDE0024.severity = error

# Use expression body for properties (IDE0025)
csharp_style_expression_bodied_properties = true # default
dotnet_diagnostic.IDE0025.severity = error

# Use expression body for indexers (IDE0026)
csharp_style_expression_bodied_indexers = when_on_single_line
dotnet_diagnostic.IDE0026.severity = error

# Use expression body for accessors (IDE0027)
csharp_style_expression_bodied_accessors = true # default
dotnet_diagnostic.IDE0027.severity = error

# Use expression body for lambdas (IDE0053)
csharp_style_expression_bodied_lambdas = when_on_single_line
dotnet_diagnostic.IDE0053.severity = error

# Use expression body for local functions (IDE0061)
csharp_style_expression_bodied_local_functions = false # default
dotnet_diagnostic.IDE0061.severity = error


### Expression-level preferences ###

dotnet_diagnostic.IDE0001.severity = error # Simplify name (IDE0001)
dotnet_diagnostic.IDE0002.severity = error # Simplify member access (IDE0002)
dotnet_diagnostic.IDE0004.severity = none # Remove unnecessary cast (IDE0004)
dotnet_diagnostic.IDE0010.severity = error # Add missing cases to switch statement (IDE0010)

# Use object initializers (IDE0017)
dotnet_style_object_initializer = true # default
dotnet_diagnostic.IDE0017.severity = error

# Use collection initializers (IDE0028)
dotnet_style_collection_initializer = true # default
dotnet_style_prefer_collection_expression = when_types_loosely_match # default
dotnet_diagnostic.IDE0028.severity = error

# Null check can be simplified (IDE0029, IDE0030, IDE0270)
dotnet_style_coalesce_expression = true # default
dotnet_diagnostic.IDE0029.severity = error
dotnet_diagnostic.IDE0030.severity = error
dotnet_diagnostic.IDE0270.severity = error

# Use null propagation (IDE0031)
dotnet_style_null_propagation = true # default
dotnet_diagnostic.IDE0031.severity = error

# Use auto-implemented property (IDE0032)
dotnet_style_prefer_auto_properties = true # default
dotnet_diagnostic.IDE0032.severity = error

# Use explicitly provided tuple name (IDE0033)
dotnet_style_explicit_tuple_names = true # default
dotnet_diagnostic.IDE0033.severity = error

dotnet_diagnostic.IDE0035.severity = error # Remove unreachable code (IDE0035) / Even if you enable code style rules on build, this rule is not enabled. It only surfaces in the IDE. My recommendation to use CS0162

# Use inferred member names (IDE0037)
dotnet_style_prefer_inferred_tuple_names = true # default
dotnet_style_prefer_inferred_anonymous_type_member_names = false
dotnet_diagnostic.IDE0037.severity = error

# Use 'is null' check (IDE0041)
dotnet_style_prefer_is_null_check_over_reference_equality_method = true # default
dotnet_diagnostic.IDE0041.severity = error

# Use conditional expression for assignment (IDE0045)
dotnet_style_prefer_conditional_expression_over_assignment = false
dotnet_diagnostic.IDE0045.severity = none

# Use conditional expression for return (IDE0046)
dotnet_style_prefer_conditional_expression_over_return = false
dotnet_diagnostic.IDE0046.severity = none

dotnet_diagnostic.IDE0050.severity = none # (removed) Convert anonymous type to tuple (IDE0050)
dotnet_diagnostic.IDE0051.severity = error # Remove unused private member (IDE0051)
dotnet_diagnostic.IDE0052.severity = error # Remove unread private member (IDE0052)

# Use compound assignment (IDE0054, IDE0074)
dotnet_style_prefer_compound_assignment = true # default
dotnet_diagnostic.IDE0054.severity = error
dotnet_diagnostic.IDE0074.severity = error

dotnet_diagnostic.IDE0058.severity = none # Remove unnecessary expression value (IDE0058)
dotnet_diagnostic.IDE0059.severity = none # Remove unnecessary value assignment (IDE0059)
dotnet_diagnostic.IDE0070.severity = error # Use 'System.HashCode.Combine' (IDE0070)

# Simplify interpolation (IDE0071)
dotnet_style_prefer_simplified_interpolation = true # default
dotnet_diagnostic.IDE0071.severity = error

# Simplify conditional expression (IDE0075)
dotnet_style_prefer_simplified_boolean_expressions = true # default
dotnet_diagnostic.IDE0075.severity = error

dotnet_diagnostic.IDE0082.severity = error # Convert typeof to nameof (IDE0082)
dotnet_diagnostic.IDE0100.severity = error # Remove unnecessary equality operator (IDE0100)
dotnet_diagnostic.IDE0120.severity = error # Simplify LINQ expression (IDE0120)
dotnet_diagnostic.IDE0121.severity = error # Simplify LINQ type check and cast (IDE0121)

# Namespace does not match folder structure (IDE0130)
dotnet_style_namespace_match_folder = true # default
dotnet_diagnostic.IDE0130.severity = error

# Use throw expression (IDE0016)
csharp_style_throw_expression = true # default
dotnet_diagnostic.IDE0016.severity = error

# Inline variable declaration (IDE0018)
csharp_style_inlined_variable_declaration = true # default
dotnet_diagnostic.IDE0018.severity = error

# Simplify 'default' expression (IDE0034)
csharp_prefer_simple_default_expression = false
dotnet_diagnostic.IDE0034.severity = none

# Use local function instead of lambda (IDE0039)
csharp_style_prefer_local_over_anonymous_function = false
dotnet_diagnostic.IDE0039.severity = none

# Deconstruct variable declaration (IDE0042)
csharp_style_deconstructed_variable_declaration = true # default
dotnet_diagnostic.IDE0042.severity = error

# Use index operator (IDE0056)
csharp_style_prefer_index_operator = false
dotnet_diagnostic.IDE0056.severity = none

# Use range operator (IDE0057)
csharp_style_prefer_range_operator = false
dotnet_diagnostic.IDE0057.severity = none

dotnet_diagnostic.IDE0072.severity = error # Add missing cases to switch expression (IDE0072)
dotnet_diagnostic.IDE0080.severity = error # Remove unnecessary suppression operator (IDE0080)

# Simplify new expression (IDE0090)
csharp_style_implicit_object_creation_when_type_is_apparent = true # default
dotnet_diagnostic.IDE0090.severity = error

dotnet_diagnostic.IDE0110.severity = error # Remove unnecessary discard (IDE0110)

# Prefer 'null' check over type check (IDE0150)
csharp_style_prefer_null_check_over_type_check = true # default
dotnet_diagnostic.IDE0150.severity = error

# Use tuple to swap values (IDE0180)
csharp_style_prefer_tuple_swap = true # default
dotnet_diagnostic.IDE0180.severity = error

# Add explicit cast in foreach loop (IDE0220)
dotnet_style_prefer_foreach_explicit_cast_in_source = always
dotnet_diagnostic.IDE0220.severity = error

# Use UTF-8 string literal (IDE0230)
csharp_style_prefer_utf8_string_literals = true # default
dotnet_diagnostic.IDE0230.severity = error

dotnet_diagnostic.IDE0240.severity = error # Nullable directive is redundant (IDE0240)
dotnet_diagnostic.IDE0241.severity = error # Nullable directive is unnecessary (IDE0241)

# IDE0300 - IDE0306
dotnet_style_prefer_collection_expression = when_types_loosely_match # default

# Use collection expression for array (IDE0300)
dotnet_diagnostic.IDE0300.severity = error

# Use collection expression for empty (IDE0301)
dotnet_diagnostic.IDE0301.severity = error

# Use collection expression for stack alloc (IDE0302)
dotnet_diagnostic.IDE0302.severity = error

# Use collection expression for Create() (IDE0303)
dotnet_diagnostic.IDE0303.severity = error

# Use collection expression for builder (IDE0304)
dotnet_diagnostic.IDE0304.severity = none

# Use collection expression for fluent (IDE0305)
dotnet_diagnostic.IDE0305.severity = error

# Use collection expression for new (IDE0306)
dotnet_diagnostic.IDE0306.severity = error

# Use unbound generic type (IDE0340)
csharp_style_prefer_unbound_generic_type_in_nameof = false
dotnet_diagnostic.IDE0340.severity = none

# Use implicitly typed lambda (IDE0350)
csharp_style_prefer_implicitly_typed_lambda_expression = false
dotnet_diagnostic.IDE0350.severity = none


### Field preferences ###

# Add readonly modifier (IDE0044)
dotnet_style_readonly_field = true # default
dotnet_diagnostic.IDE0044.severity = error


### Language keyword vs. framework types preferences ###

# Use language keywords instead of framework type names for type references (IDE0049)
dotnet_style_predefined_type_for_locals_parameters_members = true # default
dotnet_style_predefined_type_for_member_access = true # default
dotnet_diagnostic.IDE0049.severity = error # (IDE only or dotnet format)


### Modifier preferences ###

# Order modifiers (IDE0036)
csharp_preferred_modifier_order = public, private, protected, internal, file, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, required, volatile, async # default
dotnet_diagnostic.IDE0036.severity = error

# Add accessibility modifiers (IDE0040)
dotnet_style_require_accessibility_modifiers = for_non_interface_members # default
dotnet_diagnostic.IDE0040.severity = error

# Make local function static (IDE0062)
csharp_prefer_static_local_function = false
dotnet_diagnostic.IDE0062.severity = none

dotnet_diagnostic.IDE0064.severity = error # Make struct fields writable (IDE0064)

# Struct can be made 'readonly' (IDE0250)
csharp_style_prefer_readonly_struct = true # default
dotnet_diagnostic.IDE0250.severity = error

# Member can be made 'readonly' (IDE0251)
csharp_style_prefer_readonly_struct_member = true # default
dotnet_diagnostic.IDE0251.severity = error

# Make anonymous function static (IDE0320)
csharp_prefer_static_anonymous_function = false
dotnet_diagnostic.IDE0320.severity = none


### New-line preferences ###

# Avoid multiple blank lines (IDE2000)†
dotnet_style_allow_multiple_blank_lines_experimental = false
dotnet_diagnostic.IDE2000.severity = error

# Blank line required between block and subsequent statement (IDE2003)†
dotnet_style_allow_statement_immediately_after_block_experimental = true # default
dotnet_diagnostic.IDE2003.severity = none

# Embedded statements must be on their own line (IDE2001)†
csharp_style_allow_embedded_statements_on_same_line_experimental = true # default
dotnet_diagnostic.IDE2001.severity = none

# Consecutive braces must not have blank line between them (IDE2002)†
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
dotnet_diagnostic.IDE2002.severity = error

# Blank line not allowed after constructor initializer colon (IDE2004)†
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false
dotnet_diagnostic.IDE2004.severity = error

# Blank line not allowed after conditional expression token (IDE2005)†
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false
dotnet_diagnostic.IDE2005.severity = error

# Blank line not allowed after arrow expression clause token (IDE2006)†
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false
dotnet_diagnostic.IDE2006.severity = none


### Null-checking preferences ###
csharp_style_conditional_delegate_call = true # default
dotnet_diagnostic.IDE1005.severity = error


### Parameter preferences ###

# Remove unused parameter (IDE0060)
dotnet_code_quality_unused_parameters = all # default
dotnet_diagnostic.IDE0060.severity = error

dotnet_diagnostic.IDE0280.severity = error # Use 'nameof' (IDE0280)


### Parentheses preferences ###

# Parentheses preferences (IDE0047, IDE0048)
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity # default
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity # default
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity # default
dotnet_style_parentheses_in_other_operators = never_if_unnecessary # default
dotnet_diagnostic.IDE0047.severity = error
dotnet_diagnostic.IDE0048.severity = error


### Pattern-matching preferences ###

# Use pattern matching to avoid 'as' followed by 'null' check (IDE0019)
csharp_style_pattern_matching_over_as_with_null_check = true # default
dotnet_diagnostic.IDE0019.severity = error

# Use pattern matching to avoid 'is' check followed by a cast (IDE0020, IDE0038)
csharp_style_pattern_matching_over_is_with_cast_check = true # default
dotnet_diagnostic.IDE0020.severity = error
dotnet_diagnostic.IDE0038.severity = error

# Use switch expression (IDE0066)
csharp_style_prefer_switch_expression = true # default
dotnet_diagnostic.IDE0066.severity = error

# Use pattern matching (IDE0078 and IDE0260)
csharp_style_prefer_pattern_matching = true # default
dotnet_diagnostic.IDE0078.severity = none
dotnet_diagnostic.IDE0260.severity = none

# Use pattern matching (not operator) (IDE0083)
csharp_style_prefer_not_pattern = true # default
dotnet_diagnostic.IDE0083.severity = error

# Simplify property pattern (IDE0170)
csharp_style_prefer_extended_property_pattern = true # default
dotnet_diagnostic.IDE0170.severity = error


### Suppression preferences ###

# this and Me preferences (IDE0003, IDE0009)
dotnet_style_qualification_for_field = false # default
dotnet_style_qualification_for_property = false # default
dotnet_style_qualification_for_method = false # default
dotnet_style_qualification_for_event = false # default
dotnet_diagnostic.IDE0003.severity = error # CS (IDE only or dotnet format)
dotnet_diagnostic.IDE0009.severity = none # VB


### var preferences ###

# 'var' preferences (IDE0007, IDE0008)
csharp_style_var_for_built_in_types = false # default
csharp_style_var_when_type_is_apparent = false # default
csharp_style_var_elsewhere = false # default
dotnet_diagnostic.IDE0007.severity = none
dotnet_diagnostic.IDE0008.severity = error



### ! Formatting rules ! ###
# Rules that pertain to the layout and structure of your code in order to make it easier to read. For example, you can specify a formatting option that defines whether spaces in control blocks are preferred or not.
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0055

dotnet_diagnostic.IDE0055.severity = error

dotnet_sort_system_directives_first = true
csharp_new_line_before_members_in_anonymous_types = false
csharp_indent_case_contents_when_block = false



### ! Naming rules ! ###
# Rules that pertain to the naming of code elements. For example, you can specify that async method names must have an "Async" suffix.
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/naming-rules

dotnet_diagnostic.IDE1006.severity = error

# Asynchronous methods must end with "Async"
# Note: This rule does not work for interface methods, a better solution is https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1046
dotnet_naming_rule.asynchronous_methods_must_end_with_async.severity = error
dotnet_naming_rule.asynchronous_methods_must_end_with_async.symbols = async_methods
dotnet_naming_rule.asynchronous_methods_must_end_with_async.style = async_method_style

dotnet_naming_symbols.async_methods.applicable_kinds = method
dotnet_naming_symbols.async_methods.required_modifiers = async
dotnet_naming_symbols.async_methods.applicable_accessibilities = *

dotnet_naming_style.async_method_style.required_suffix = Async
dotnet_naming_style.async_method_style.capitalization = pascal_case


# Interfaces must start with "I"
dotnet_naming_rule.interfaces_must_start_with_I.severity = error
dotnet_naming_rule.interfaces_must_start_with_I.symbols = interfaces
dotnet_naming_rule.interfaces_must_start_with_I.style = interface_style

dotnet_naming_symbols.interfaces.applicable_kinds = interface
dotnet_naming_symbols.interfaces.applicable_accessibilities = *

dotnet_naming_style.interface_style.required_prefix = I
dotnet_naming_style.interface_style.capitalization = pascal_case


# Constants are UPPER_CASE
dotnet_naming_rule.constants_are_upper_case.severity = error
dotnet_naming_rule.constants_are_upper_case.symbols = constants
dotnet_naming_rule.constants_are_upper_case.style = constant_style

dotnet_naming_symbols.constants.applicable_kinds = field, local
dotnet_naming_symbols.constants.required_modifiers = const

dotnet_naming_style.constant_style.capitalization = all_upper


# Private instance fields are camelCase and start with "_"
dotnet_naming_rule.private_instance_fields_are_camel_case_and_start_with_.severity = error
dotnet_naming_rule.private_instance_fields_are_camel_case_and_start_with_.symbols = private_instance_fields
dotnet_naming_rule.private_instance_fields_are_camel_case_and_start_with_.style = private_instance_field_style

dotnet_naming_symbols.private_instance_fields.applicable_kinds = field
dotnet_naming_symbols.private_instance_fields.applicable_accessibilities = private

dotnet_naming_style.private_instance_field_style.capitalization = camel_case
dotnet_naming_style.private_instance_field_style.required_prefix = _


# Static fields must start with "s_"
dotnet_naming_rule.static_fields_must_start_with_s_.severity = error
dotnet_naming_rule.static_fields_must_start_with_s_.symbols = static_fields
dotnet_naming_rule.static_fields_must_start_with_s_.style = static_field_style

dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static

dotnet_naming_style.static_field_style.capitalization = camel_case
dotnet_naming_style.static_field_style.required_prefix = s_


# Locals and parameters are camelCase
dotnet_naming_rule.locals_are_camel_case.severity = error
dotnet_naming_rule.locals_are_camel_case.symbols = locals_and_parameters
dotnet_naming_rule.locals_are_camel_case.style = local_and_parameter_style

dotnet_naming_symbols.locals_and_parameters.applicable_kinds = parameter, local

dotnet_naming_style.local_and_parameter_style.capitalization = camel_case


# Local functions are PascalCase
dotnet_naming_rule.local_functions_are_pascal_case.severity = error
dotnet_naming_rule.local_functions_are_pascal_case.symbols = local_functions
dotnet_naming_rule.local_functions_are_pascal_case.style = local_function_style

dotnet_naming_symbols.local_functions.applicable_kinds = local_function

dotnet_naming_style.local_function_style.capitalization = pascal_case


# Generic Type parameters are PascalCase and start with "T"
dotnet_naming_rule.generic_type_parameters_are_pascal_case_and_start_with_t.severity  = error
dotnet_naming_rule.generic_type_parameters_are_pascal_case_and_start_with_t.symbols = generic_type_parameters
dotnet_naming_rule.generic_type_parameters_are_pascal_case_and_start_with_t.style = generic_type_parameters_style

dotnet_naming_symbols.generic_type_parameters.applicable_kinds = type_parameter

dotnet_naming_style.generic_type_parameters_style.capitalization = pascal_case
dotnet_naming_style.generic_type_parameters_style.required_prefix = T


# All members are PascalCase
dotnet_naming_rule.all_members_are_pascal_case.severity = error
dotnet_naming_rule.all_members_are_pascal_case.symbols = all_members
dotnet_naming_rule.all_members_are_pascal_case.style = all_members_style

dotnet_naming_symbols.all_members.applicable_kinds = *

dotnet_naming_style.all_members_style.capitalization = pascal_case



### ! Miscellaneous rules ! ###
# Rules that do not belong in other categories.
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/miscellaneous-rules

# Implement with Copilot (IDE3000)
dotnet_diagnostic.IDE3000.severity = none


[**Controller.cs]
dotnet_naming_symbols.async_methods.applicable_accessibilities = private # This filter doesn't work for Rider

dotnet_diagnostic.CS1573.severity = error # CS1573: Parameter has no matching param tag in the XML comment (but other parameters do)
dotnet_diagnostic.CS1591.severity = error # CS1591: No XML docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment