dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.12k stars 4.04k forks source link

EditorConfig editor never works #69445

Open vsfeedback opened 1 year ago

vsfeedback commented 1 year ago

This issue has been moved from a ticket on Developer Community.


[severity:It bothers me. A fix would be nice] image.png

# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true

# C# files
[*.cs]

#### Core EditorConfig Options ####

# Indentation and spacing
indent_size = 4
indent_style = space
tab_width = 4

# New line preferences
end_of_line = crlf
insert_final_newline = false

#### .NET Coding Conventions ####

# Organize usings
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = true
file_header_template = unset

# this. and Me. preferences
dotnet_style_qualification_for_event = false
dotnet_style_qualification_for_field = false
dotnet_style_qualification_for_method = false
dotnet_style_qualification_for_property = false

# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true
dotnet_style_predefined_type_for_member_access = true

# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_other_operators = never_if_unnecessary
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion

# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members

# Expression-level preferences
dotnet_style_coalesce_expression = true
dotnet_style_collection_initializer = true
dotnet_style_explicit_tuple_names = true
dotnet_style_namespace_match_folder = true
dotnet_style_null_propagation = true
dotnet_style_object_initializer = true
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_prefer_auto_properties = true
dotnet_style_prefer_compound_assignment = true
dotnet_style_prefer_conditional_expression_over_assignment = true:warning
dotnet_style_prefer_conditional_expression_over_return = true:warning
dotnet_style_prefer_inferred_anonymous_type_member_names = true
dotnet_style_prefer_inferred_tuple_names = true
dotnet_style_prefer_is_null_check_over_reference_equality_method = true
dotnet_style_prefer_simplified_boolean_expressions = true
dotnet_style_prefer_simplified_interpolation = true

# Field preferences
dotnet_style_readonly_field = true

# Parameter preferences
dotnet_code_quality_unused_parameters = all

# Suppression preferences
dotnet_remove_unnecessary_suppression_exclusions = IDE0005

# New line preferences
dotnet_style_allow_multiple_blank_lines_experimental = true
dotnet_style_allow_statement_immediately_after_block_experimental = true

#### C# Coding Conventions ####

# var' preferences (IDE0007 and IDE0008)
dotnet_diagnostic. IDE0007.severity = none
dotnet_diagnostic. IDE0008.severity = none

# Expression-bodied members
csharp_style_expression_bodied_accessors = true
csharp_style_expression_bodied_constructors = false
csharp_style_expression_bodied_indexers = true
csharp_style_expression_bodied_lambdas = true
csharp_style_expression_bodied_properties = true

# Use expression body for methods (IDE0022)
dotnet_diagnostic. IDE0022.severity = none

# Use expression body for operators (IDE0023 and IDE0024)
dotnet_diagnostic. IDE0023.severity = none
dotnet_diagnostic. IDE0024.severity = none

# Use expression body for local functions (IDE0061)
dotnet_diagnostic. IDE0061.severity = none

# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true
csharp_style_pattern_matching_over_is_with_cast_check = true
csharp_style_prefer_not_pattern = true
csharp_style_prefer_pattern_matching = true
csharp_style_prefer_switch_expression = true

# Null-checking preferences
csharp_style_conditional_delegate_call = true

# Modifier preferences
csharp_prefer_static_local_function = true
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async

# Code-block preferences
csharp_prefer_braces = when_multiline
csharp_prefer_simple_using_statement = true

# Expression-level preferences
csharp_prefer_simple_default_expression = true
csharp_style_deconstructed_variable_declaration = true
csharp_style_implicit_object_creation_when_type_is_apparent = true
csharp_style_inlined_variable_declaration = true
csharp_style_pattern_local_over_anonymous_function = true
csharp_style_prefer_index_operator = true
csharp_style_prefer_null_check_over_type_check = true
csharp_style_prefer_range_operator = true
csharp_style_throw_expression = true
csharp_style_unused_value_assignment_preference = discard_variable
csharp_style_unused_value_expression_statement_preference = discard_variable

# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:suggestion

# New line preferences
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
csharp_style_allow_embedded_statements_on_same_line_experimental = true

#### C# Formatting Rules ####

# New line preferences
csharp_new_line_before_catch = true
csharp_new_line_before_else = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = all
csharp_new_line_between_query_expression_clauses = true

# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true

# Space preferences
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

# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true

# Formatting rule (IDE0055) csharpier does formatting for us
dotnet_diagnostic. IDE0055.severity = none

#### Naming styles ####
# Additional required suffixes: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1710#additional-required-suffixes
dotnet_code_quality. CA1710.additional_required_suffixes = ICommandHandler->CommandHandler|ICommand->Command|IQueryHandler->QueryHandler|IQuery->Query|IEventHandler->EventHandler|IEvent->Event|IEnumerable->{}|ICollection->{}
dotnet_code_quality. CA1710.exclude_indirect_base_types = false

dotnet_code_quality.ca1711.allowed_suffixes = Collection
# Naming rules

dotnet_naming_rule.private_or_internal_field_should_be__camecalse.severity = suggestion
dotnet_naming_rule.private_or_internal_field_should_be__camecalse.symbols = private_or_internal_field
dotnet_naming_rule.private_or_internal_field_should_be__camecalse.style = _camecalse

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

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

dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field
dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected
dotnet_naming_symbols.private_or_internal_field.required_modifiers = 

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

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers = 

# Naming styles

dotnet_naming_style.pascal_case.required_prefix = 
dotnet_naming_style.pascal_case.required_suffix = 
dotnet_naming_style.pascal_case.word_separator = 
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix = 
dotnet_naming_style.begins_with_i.word_separator = 
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style._camecalse.required_prefix = _
dotnet_naming_style._camecalse.required_suffix = 
dotnet_naming_style._camecalse.word_separator = 
dotnet_naming_style._camecalse.capitalization = camel_case

##############################################################################
## Microsoft.CodeAnalysis.NetAnalyzers settings. See: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/categories

# Portability rules support portability across different platforms. Interoperability rules support interaction with COM clients.
dotnet_analyzer_diagnostic.category-Interoperability.severity = none

# Globalization rules support world-ready libraries and applications.
dotnet_analyzer_diagnostic.category-Globalization.severity = silent

# Design rules support adherence to the .NET Framework Design Guidelines.
dotnet_analyzer_diagnostic.category-Design.severity = warning

# Maintainability rules support library and application maintenance.
dotnet_analyzer_diagnostic.category-Maintainability.severity = warning

# Naming rules support adherence to the naming conventions of the .NET design guidelines.
dotnet_analyzer_diagnostic.category-Naming.severity = warning

# Performance rules support high-performance libraries and applications.
dotnet_analyzer_diagnostic.category-Performance.severity = warning

# Reliability rules support library and application reliability, such as correct memory and thread usage.
dotnet_analyzer_diagnostic.category-Reliability.severity = warning

# Security rules support safer libraries and applications. These rules help prevent security flaws in your program.
dotnet_analyzer_diagnostic.category-Security.severity = warning

# Style rules support consistent code style in your codebase. These rules start with the "IDE" prefix.
dotnet_analyzer_diagnostic.category-Style.severity = warning

# Usage rules support proper usage of .NET.
dotnet_analyzer_diagnostic.category-Usage.severity = warning

##############################################################################

# CA1031: Do not catch general exception types
dotnet_diagnostic. CA1031.severity = suggestion

# CA2007: Consider calling ConfigureAwait on the awaited task
dotnet_diagnostic. CA2007.severity = none

# Calling ConfigureAwait is not needed in ASP.NET CORE. Unnecessary code adds confusion. 
# RCS1090: Add call to 'ConfigureAwait' (or vice versa). (inverted)
dotnet_diagnostic. RCS1090.severity = warning
roslynator_configure_await = false

# RCS1118: Mark local variable as const.
dotnet_diagnostic. RCS1118.severity = warning

# RCS1047: Non-asynchronous method name should not end with 'Async'.
dotnet_diagnostic. RCS1047.severity = warning

# CA1505: Avoid unmaintainable code
dotnet_diagnostic. CA1505.severity = warning

# CS1591: Missing XML comment for publicly visible type or member
dotnet_diagnostic. CS1591.severity = none

# CA1303: Do not pass literals as localized parameters
dotnet_diagnostic. CA1303.severity = silent

# IDE0161: Use file scoped namespace
csharp_style_namespace_declarations = file_scoped:warning

# CA2007: Do not directly await a Task
dotnet_diagnostic. CA2007.severity = none

# CA2016: Forward the 'CancellationToken' parameter to methods
dotnet_diagnostic. CA2016.severity = warning

# CS0618: 'member' is obsolete: 'text'
dotnet_diagnostic. CS0618.severity = warning
dotnet_diagnostic. CS0618.level = 0

# CA1806: Do not ignore method results (https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1806)
dotnet_diagnostic. CA1806.severity = warning

# RCS1227: Validate arguments correctly.
dotnet_diagnostic. RCS1227.severity = warning

# RCS1163: Unused parameter.
dotnet_diagnostic. RCS1163.severity = warning

# IDE0250: Make struct 'readonly'
dotnet_diagnostic. IDE0250.severity = warning

# IDE0059: Unnecessary assignment of a value
dotnet_diagnostic. IDE0059.severity = warning

# IDE0052: Remove unread private members
dotnet_diagnostic. IDE0052.severity = warning

# IDE0017: Simplify object initialization
dotnet_diagnostic. IDE0017.severity = warning

# CS4014: Because this call is not awaited, execution of the current method continues before the call is completed
# Either await or use discard (_ = SomethingAsync())
dotnet_diagnostic. CS4014.severity = warning

# IDE0074: Use compound assignment
dotnet_diagnostic. IDE0074.severity = warning

# IDE0029: Use coalesce expression
dotnet_diagnostic. IDE0029.severity = warning

# IDE0045: Convert to conditional expression
dotnet_diagnostic. IDE0045.severity = warning

# IDE0060: Remove unused parameter
# We already have: "RCS1163: Unused parameter"
dotnet_diagnostic. IDE0060.severity = none

# IDE0046: Convert to conditional expression
dotnet_diagnostic. IDE0046.severity = warning

# CA2208: Instantiate argument exceptions correctly
dotnet_diagnostic. CA2208.severity = warning

# CS1998: Async method lacks 'await' operators and will run synchronously
# TODO: should be error but too many cases now.
dotnet_diagnostic. CS1998.severity = warning

# IDE0072: Add missing cases
dotnet_diagnostic. IDE0072.severity = warning

# CA2254: Template should be a static expression
dotnet_diagnostic. CA2254.severity = warning

# CA1822: Mark members as static
dotnet_diagnostic. CA1822.severity = warning

# CA2211: Non-constant fields should not be visible
dotnet_diagnostic. CA2211.severity = warning

# IDE0018: Inline variable declaration
dotnet_diagnostic. IDE0018.severity = warning

# CS8629: Nullable value type may be null.
dotnet_diagnostic. CS8629.severity = warning

# RCS1213: Remove unused member declaration.
dotnet_diagnostic. RCS1213.severity = warning

# CA1842: Do not use 'WhenAll' with a single task
dotnet_diagnostic. CA1842.severity = warning

# RCS1136: Merge switch sections with equivalent content.
dotnet_diagnostic. RCS1136.severity = warning

# CA1041: Provide ObsoleteAttribute message
dotnet_diagnostic. CA1041.severity = warning

# IDE0028: Simplify collection initialization
dotnet_diagnostic. IDE0028.severity = warning

# RCS1006: Merge 'else' with nested 'if'
dotnet_diagnostic. RCS1006.severity = suggestion

# RCS1015: Use nameof operator
dotnet_diagnostic. RCS1015.severity = warning

# RCS1020: Simplify Nullable<T> to T?
dotnet_diagnostic. RCS1020.severity = warning

# RCS1061: Merge 'if' with nested 'if'
dotnet_diagnostic. RCS1061.severity = warning

# RCS1073: Convert 'if' to 'return' statement
dotnet_diagnostic. RCS1073.severity = warning

# RCS1084: Use coalesce expression instead of conditional expression
dotnet_diagnostic. RCS1084.severity = warning

# RCS1103: Convert 'if' to assignment
dotnet_diagnostic. RCS1103.severity = warning

# RCS1104: Simplify conditional expression
dotnet_diagnostic. RCS1104.severity = warning

# RCS1113: Use 'string. IsNullOrEmpty' method
dotnet_diagnostic. RCS1113.severity = warning

# RCS1128: Use coalesce expression
dotnet_diagnostic. RCS1128.severity = warning

# RCS1130: Bitwise operation on enum without Flags attribute
dotnet_diagnostic. RCS1130.severity = warning

# RCS1134: Remove redundant statement
dotnet_diagnostic. RCS1134.severity = warning

# RCS1146: Use conditional access
dotnet_diagnostic. RCS1146.severity = warning

# RCS1157: Composite enum value contains undefined flag
dotnet_diagnostic. RCS1157.severity = warning

# RCS1160: Abstract type should not have public constructors
dotnet_diagnostic. RCS1160.severity = warning

# RCS1166: Value type object is never equal to null
dotnet_diagnostic. RCS1166.severity = warning

# RCS1173: Use coalesce expression instead of 'if'
dotnet_diagnostic. RCS1173.severity = warning

# RCS1186: Use Regex instance instead of static method
dotnet_diagnostic. RCS1186.severity = suggestion

# RCS1197: Optimize StringBuilder.Append/AppendLine call
dotnet_diagnostic. RCS1197.severity = suggestion

# RCS1199: Unnecessary null check
dotnet_diagnostic. RCS1199.severity = suggestion

# RCS1200: Call 'Enumerable.ThenBy' instead of 'Enumerable.OrderBy'
dotnet_diagnostic. RCS1200.severity = suggestion

# RCS1201: Use method chaining
dotnet_diagnostic. RCS1201.severity = suggestion

# RCS1206: Use conditional access instead of conditional expression
dotnet_diagnostic. RCS1206.severity = suggestion

# RCS1220: Use pattern matching instead of combination of 'is' operator and cast operator
dotnet_diagnostic. RCS1220.severity = warning

# IDE0051: Remove unused private member -- We already have RCS1213:Remove unused member declaration.
dotnet_diagnostic. IDE0051.severity = none

# CA1725: Parameter names should match base declaration
dotnet_diagnostic. CA1725.severity = none

# CA1716: Identifiers should not match keywords
dotnet_diagnostic. CA1716.severity = none

# API1000: Action method returns undeclared status code 'xxx'
dotnet_diagnostic. API1000.severity = suggestion

# S6605: Collection-specific "Exists" method should be used instead of the "Any" extension
dotnet_diagnostic. S6605.severity = none # Performance difference is negligible

# S3358: Ternary operators should not be nested
dotnet_diagnostic. S3358.severity = none

# S3459: Unassigned members should be removed
dotnet_diagnostic. S3459.severity = none

# RCS1168: Parameter name differs from base name
# S927: Parameter names should match base declaration and other partial definitions
dotnet_diagnostic. RCS1168.severity = silent # silent Because its not very important
dotnet_diagnostic. S927.severity = none  # RCS1168 has an auto-fix.

# S6608: Prefer indexing instead of "Enumerable" methods on types implementing "IList"
dotnet_diagnostic. S6608.severity = none # Performance difference is negligible

# S4456: Parameter validation in yielding methods should be wrapped
dotnet_diagnostic. S4456.severity = none # we already have RCS1227: Validate arguments correctly

# S1123: "Obsolete" attributes should include explanations
dotnet_diagnostic. S1123.severity = none # we already have CA1041: Provide ObsoleteAttribute message

# S6603: The collection-specific "TrueForAll" method should be used instead of the "All" extension
dotnet_diagnostic. S6603.severity = none # Performance difference is negligible

# S6602: "Find" method should be used instead of the "FirstOrDefault" extension
dotnet_diagnostic. S6602.severity = none # Performance difference is negligible

# RCS1123: Add parentheses when necessary
dotnet_diagnostic. RCS1123.severity = warning

# CS0472: The result of the expression is always 'value1' since a value of type 'value2' is never equal to 'null' of type 'value3'
dotnet_diagnostic. RCS1123.severity = error

# IDE0004: Remove unnecessary cast
# S1905: Redundant casts should not be used
dotnet_diagnostic. IDE0004.severity = warning # Has an auto-fix.
dotnet_diagnostic. S1905.severity = none

# S1121: Assignments should not be made from within sub-expressions
dotnet_diagnostic. S1121.severity = none

# S3236: Caller information arguments should not be provided explicitly
dotnet_diagnostic. S3236.severity = none # sometimes it should be overridden

Analyzers

    <ItemGroup>
        <PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.3">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="Roslynator.Analyzers" Version="4.4.0">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="SonarAnalyzer.CSharp" Version="9.7.0.75501">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
    </ItemGroup>

This has never worked for me. Even after reinstall etc.


Original Comments

Feedback Bot on 8/8/2023, 09:12 PM:

(private comment, text removed)


Original Solutions

(no solutions)

paul-michalik commented 1 year ago

I have to say that I am too very close to giving up on finding a working configuration. The behavior of the tooling is indeed not as expected. Not sure if it's too many moving parts or if we are missing something obvious?

gewarren commented 8 months ago

Do you actually have spaces before the rule IDEs in your editorconfig file? You shouldn't:

dotnet_diagnostic. IDE0055.severity = none