EditorConfig именование для VS не работает в VS 2017

Я пытаюсь использовать.editorconfig, новую функцию VS для настройки собственного стиля кода. Но часть этого не работает. Я слышал об ошибках Roslyn, обрабатывающих стили именования, но я не знаю, в чем проблема. Мой.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

Посмотрите на раздел "# Naming" и на скриншот ниже. Как видите, "# Common rule" и "csharp_style_var_for_built_in_types" работают нормально - строки 17 и 21. Но "# Async-методы должны иметь суффикс"Async ", "# Interfaces"и параметры не работают (строки 19, 13 и 30).

0 ответов

Это потому что

Соглашения об именах должны быть упорядочены от наиболее специфичных к наименее специфичным в файле.editorconfig. Первое правило, которое может быть применено, является единственным правилом, которое применяется.

Ссылка: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2017

Так что в случае DisplayResultAync, members_and_types_common_name правило сопоставляется и применяется, а остальные правила именования пропускаются. Решение состоит в том, чтобы просто изменить порядок. В этом случае, похоже, вы должны просто поставить "общее правило" последним.

Другие вопросы по тегам