editorconfig - 无法使命名约定起作用 [英] editorconfig - cannot get naming conventions to work

查看:69
本文介绍了editorconfig - 无法使命名约定起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 C# 创建了以下设置.

I created the following setup for C#.

我们的想法是让所有私有的名称都以驼峰命名,所有的公共和受保护的都以大写字母命名.

The idea is to have everything that's private named in camelCase and everything public and protected in UpperCase.

这是我的 .editorconfig 设置(简化版):

Here's my .editorconfig setup (simplified):

[*.{cs,cshtml}]
# styles
dotnet_naming_style.camel_case.capitalization = camel_case
dotnet_naming_style.first_upper.capitalization = first_word_upper

# symbols
dotnet_naming_symbols.private_symbols.applicable_accessibilities = private
dotnet_naming_symbols.public_symbols.applicable_accessibilities = public, protected

# rules
dotnet_naming_rule.camel_case_for_private.severity = warning
dotnet_naming_rule.camel_case_for_private.symbols  = private_symbols
dotnet_naming_rule.camel_case_for_private.style = camel_case

dotnet_naming_rule.first_upper_for_public.severity = warning
dotnet_naming_rule.first_upper_for_public.symbols  = public_symbols
dotnet_naming_rule.first_upper_for_public.style = first_upper

它似乎不适用于私人:消息 IDE1006 违反命名规则:这些词必须以大写字符开头:composeEmail

It doesn't seem to work for private: Message IDE1006 Naming rule violation: These words must begin with upper case characters: composeEmail

公共似乎工作正常.

这里是完整的 .editorconfig,以防错误在别处:

Here's the full .editorconfig in case the error is elsewhere:

# top-most EditorConfig file
root = true

[*]
end_of_line              = crlf
charset                  = utf-8
trim_trailing_whitespace = true
insert_final_newline     = true
max_line_length = 170

[*.xml]
indent_style = space

[*.{cs,cshtml}]
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
dotnet_style_predefined_type_for_member_access = true:warning
dotnet_style_explicit_tuple_names = true:warning
dotnet_style_null_propagation = true:warning
csharp_style_var_when_type_is_apparent = true:warning
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
csharp_style_pattern_matching_over_as_with_null_check = true:warning
csharp_style_inlined_variable_declaration = true:warning

csharp_prefer_simple_default_expression = true
csharp_style_throw_expression = false:warning
csharp_prefer_braces = true
dotnet_sort_system_directives_first = true

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_indent_case_contents = true
csharp_indent_switch_labels = true

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 = false

csharp_preserve_single_line_statements = false
csharp_preserve_single_line_blocks = true

### naming conventions

# styles
dotnet_naming_style.camel_case.capitalization = camel_case
dotnet_naming_style.first_upper.capitalization = first_word_upper

# prefix_interface_interface_with_i - Interfaces must be PascalCase and the first character of an interface must be an 'I'
dotnet_naming_style.prefix_interface_interface_with_i.capitalization = first_word_upper
dotnet_naming_style.prefix_interface_interface_with_i.required_prefix = I

# symbols
dotnet_naming_symbols.private_symbols.applicable_accessibilities = private
dotnet_naming_symbols.public_symbols.applicable_accessibilities = public, protected
dotnet_naming_symbols.interface_types.applicable_kinds = interface


# rules
dotnet_naming_rule.camel_case_for_private.severity = warning
dotnet_naming_rule.camel_case_for_private.symbols  = private_symbols
dotnet_naming_rule.camel_case_for_private.style = camel_case

dotnet_naming_rule.first_upper_for_public.severity = warning
dotnet_naming_rule.first_upper_for_public.symbols  = public_symbols
dotnet_naming_rule.first_upper_for_public.style = first_upper

# Interfaces must be FirstUpper and start with an 'I'
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.severity = warning
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.symbols = interface_types
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.style = prefix_interface_interface_with_i

也许我还应该提到我正在使用 Resharper,但我禁用了它以确认警告仍然存在.

Maybe I should also mention that I'm using Resharper, but I disabled it to confirm that the warning still stays.

推荐答案

IDE1006 部分似乎对我有用.它可能已修复(我现在运行的是 Visual Studio Enterprise 2017 版本 15.8.8)或某些冲突.

The IDE1006 portions appear to be working for me. It might have been fixed (I'm running Visual Studio Enterprise 2017 Version 15.8.8 right now) or something conflicts.

这是我添加到我的 .editorconfig 中的内容(我之前有其他东西):

Here is what I added to my .editorconfig (I had other things before):

#IDE1006
dotnet_naming_style.camel_case.capitalization = camel_case
dotnet_naming_symbols.private_symbols.applicable_accessibilities = private
dotnet_naming_rule.camel_case_for_private.severity = warning
dotnet_naming_rule.camel_case_for_private.symbols  = private_symbols
dotnet_naming_rule.camel_case_for_private.style = camel_case

这里是完整的文件:

root = true

[*]
indent_style = tab
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

#[*.cs]
#IDE1006
dotnet_naming_style.camel_case.capitalization = camel_case
dotnet_naming_symbols.private_symbols.applicable_accessibilities = private
dotnet_naming_rule.camel_case_for_private.severity = warning
dotnet_naming_rule.camel_case_for_private.symbols  = private_symbols
dotnet_naming_rule.camel_case_for_private.style = camel_case
#IDE0018
csharp_style_inlined_variable_declaration = false:none
#IDE0039
csharp_style_pattern_local_over_anonymous_function = false:none
#IDE0019
csharp_style_pattern_matching_over_as_with_null_check = false:none
#IDE0011
csharp_prefer_braces = true:suggestion
#IDE0017
dotnet_style_object_initializer = false:none
#IDE0028
dotnet_style_collection_initializer = false:none
#IDE0037
dotnet_prefer_inferred_anonymous_type_member_names = false:none
#IDE0016
csharp_style_throw_expression = false:none

[*.md]
max_line_length = off
trim_trailing_whitespace = false

这篇关于editorconfig - 无法使命名约定起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆