Reputation: 173
I try to use .editorconfig, the new VS feature to set up my own code styling. But part of it doesn't work. I heard about Roslyn bugs, processing naming styles, but I don't know what the problem is. My .editorconfig:
root = true
#################################
# .NET Coding Conventions #
#################################
[*.cs]
# Code files
indent_style = tab
insert_final_newline = true
charset = utf-8-bom
# this. preferences
dotnet_style_qualification_for_field = false:warning
dotnet_style_qualification_for_property = false:warning
dotnet_style_qualification_for_method = false:warning
dotnet_style_qualification_for_event = false:warning
# Language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
dotnet_style_predefined_type_for_member_access = true:warning
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning
csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async:warning
dotnet_style_readonly_field = true:suggestion
# Expression-level preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:warning
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:warning
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
# Null checking preferences
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
# Implicit and explicit types
###############
csharp_style_var_when_type_is_apparent = true:warning
csharp_style_var_elsewhere = false:none
# Expression-bodied members
csharp_style_expression_bodied_methods = when_on_single_line:none
csharp_style_expression_bodied_constructors = when_on_single_line:none
csharp_style_expression_bodied_operators = when_on_single_line:none
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_expression_bodied_indexers = true:suggestion
csharp_style_expression_bodied_accessors = true:suggestion
# Pattern matching C# 7.0+
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
csharp_style_pattern_matching_over_as_with_null_check = true:warning
# Inlined variable declarations C# 7.0+
csharp_style_inlined_variable_declaration = true:warning
# Expression-level preferences C# 7.0+
csharp_prefer_simple_default_expression = true:warning
csharp_style_deconstructed_variable_declaration = true:warning
csharp_style_pattern_local_over_anonymous_function = true:suggestion
# Null checking preferences
csharp_style_throw_expression = true:warning
csharp_style_conditional_delegate_call = true:warning
# Code block preferences
csharp_prefer_braces =true:none
# Organize usings
dotnet_sort_system_directives_first = true
# Newline 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
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = no_change
#Spacing options
csharp_space_after_cast = true
csharp_space_after_keywords_in_control_flow_statements = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_method_call_parameter_list_parentheses = false
#csharp_space_between_parentheses
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
#Wrapping options
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true
# Naming
# Common rule
dotnet_naming_rule.members_and_types_common_name.symbols = members_and_types_identifier
dotnet_naming_rule.members_and_types_common_name.style = pascal_case_style
dotnet_naming_rule.members_and_types_common_name.severity = error
dotnet_naming_symbols.members_and_types_identifier.applicable_kinds = class,struct,interface,enum,property,method,field,event,delegate
dotnet_naming_symbols.members_and_types_identifier.applicable_accessibilities = *
dotnet_naming_symbols.members_and_types_identifier.required_modifiers =
dotnet_naming_style.pascal_case_style.required_prefix =
dotnet_naming_style.pascal_case_style.required_suffix =
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
dotnet_naming_style.pascal_case_style.word_separator =
# Async methods should have "Async" suffix
dotnet_naming_rule.async_methods_end_in_async.symbols = any_async_methods
dotnet_naming_rule.async_methods_end_in_async.style = end_in_async
dotnet_naming_rule.async_methods_end_in_async.severity = error
dotnet_naming_symbols.any_async_methods.applicable_kinds = method
dotnet_naming_symbols.any_async_methods.applicable_accessibilities = *
dotnet_naming_symbols.any_async_methods.required_modifiers = async
dotnet_naming_style.end_in_async.required_prefix =
dotnet_naming_style.end_in_async.required_suffix = Async
dotnet_naming_style.end_in_async.capitalization = pascal_case
dotnet_naming_style.end_in_async.word_separator =
csharp_style_var_for_built_in_types = true:error
# Interfaces
dotnet_naming_rule.interface_i_prefix.symbols = interfaces_identifier
dotnet_naming_rule.interface_i_prefix.style = i_prefix_style
dotnet_naming_rule.interface_i_prefix.severity = error
dotnet_naming_symbols.interfaces_identifier.applicable_kinds = interface
dotnet_naming_style.i_prefix_style.capitalization = pascal_case
dotnet_naming_style.i_prefix_style.required_prefix = _
# Parameter
dotnet_naming_rule.parameters_in_camel.symbols = parameters_identifier
dotnet_naming_rule.parameters_in_camel.style = camel_case_style
dotnet_naming_rule.parameters_in_camel.severity = error
dotnet_naming_symbols.parameters_identifier.applicable_kinds = parameter
dotnet_naming_style.camel_case_style.capitalization = camel_case
Look at the section "# Naming" and at the screenshot below. As you can see "# Common rule" and "csharp_style_var_for_built_in_types" work fine - lines 17 and 21. But "# Async methods should have "Async" suffix", "# Interfaces" and parameters don't work(lines 19, 13 and 30).
Upvotes: 1
Views: 747
Reputation: 5218
This is because
Naming conventions should be ordered from most-specific to least-specific in the .editorconfig file. The first rule encountered that can be applied is the only rule that is applied.
Reference: https://learn.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2017
So in the case of DisplayResultAync
, the members_and_types_common_name
rule is matched and applied and the rest of the naming rules are skipped. The solution is to simply change the order. In this case, it looks like you should just put the "common rule" last.
Upvotes: 1