editorConfig命名约定不起作用c#visual Studio 2019 16.4.2

时间:2019-12-30 07:30:16

标签: c# visual-studio naming-conventions editorconfig

我正在尝试在解决方案级别使用.editorconfig为其中的两个C#项目定义命名约定。我拥有最新的Visual Studio,截止日期为今天的16.4.2。 它在不期望的地方发出警告。例如,对于类名,属性名,枚举名,它表示应以小写开头,而按照我在editorconfig中的约定,应在pa​​scal情况下使用它们。类似地,对于班级中的私有字段,我已经定义了字段名,以下划线(_)字符开头,但它在那里也报告错误。

我确定它正在使用我的editorconfig文件,因为如果我故意更改某些部分只是为了查看是否有影响,我会看到消息中的更改。但是,结果并不符合预期。

是否需要进行更多设置?我的editorconfig输入中有错误吗?

这是我的editorconfig文件的相关内容。

# Naming rules definitions

dotnet_naming_rule.interfacesPascalWithI.symbols = interfaces
dotnet_naming_rule.interfacesPascalWithI.style = IP
dotnet_naming_rule.interfacesPascalWithI.severity = suggestion

dotnet_naming_rule.publicMethodsPascal.symbols = pubMethods
dotnet_naming_rule.publicMethodsPascal.style = P
dotnet_naming_rule.publicMethodsPascal.severity = suggestion

dotnet_naming_rule.defaultMethodsCamel.symbols = methods
dotnet_naming_rule.defaultMethodsCamel.style = c
dotnet_naming_rule.defaultMethodsCamel.severity = suggestion

dotnet_naming_rule.staticFieldsPascal.symbols = staticFields
dotnet_naming_rule.staticFieldsPascal.style = c
dotnet_naming_rule.staticFieldsPascal.severity = warning

dotnet_naming_rule.constFieldsPascal.symbols = constFields
dotnet_naming_rule.constFieldsPascal.style = c
dotnet_naming_rule.constFieldsPascal.severity = warning

dotnet_naming_rule.privateFieldsUnderscore.symbols = prvFields
dotnet_naming_rule.privateFieldsUnderscore.style = _c
dotnet_naming_rule.privateFieldsUnderscore.severity = suggestion

dotnet_naming_rule.defaultFieldsCamel.symbols = fields
dotnet_naming_rule.defaultFieldsCamel.style = c
dotnet_naming_rule.defaultFieldsCamel.severity = suggestion

dotnet_naming_rule.defaultPascal.symbols = default
dotnet_naming_rule.defaultPascal.style = P
dotnet_naming_rule.defaultPascal.severity = suggestion

# Style Definitions
dotnet_naming_style.P.capitalization = pascal_case

dotnet_naming_style.IP.capitalization = pascal_case
dotnet_naming_style.IP.required_prefix = I

dotnet_naming_style.c.capitalization = camel_case

dotnet_naming_style._c.capitalization = camel_case
dotnet_naming_style._c.required_prefix = _

# Symbols Definitions
dotnet_naming_symbols.default.applicable_kinds = *
dotnet_naming_symbols.default.applicable_accessibilities = *

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

dotnet_naming_symbols.pubMethods.applicable_kinds = method
dotnet_naming_symbols.pubMethods..applicable_accessibilities = public

dotnet_naming_symbols.methods.applicable_kinds = method
dotnet_naming_symbols.methods.applicable_accessibilities = *

dotnet_naming_symbols.staticFields.applicable_kinds = field
dotnet_naming_symbols.staticFields.applicable_accessibilities = *
dotnet_naming_symbols.staticFields.required_modifiers = static

dotnet_naming_symbols.constFields.applicable_kinds = field
dotnet_naming_symbols.constFields.applicable_accessibilities = *
dotnet_naming_symbols.constFields.required_modifiers = const

dotnet_naming_symbols.prvFields.applicable_kinds = field
dotnet_naming_symbols.prvFields.applicable_accessibilities = private

dotnet_naming_symbols.fields.applicable_kinds = field
dotnet_naming_symbols.fields.applicable_accessibilities = *

1 个答案:

答案 0 :(得分:0)

我已经测试过您的代码,并且这个问题也发生在我这一边。然后,我检查代码,似乎“ dotnet_naming_rule”找不到指定的符号,这导致规则适应所有情况。然后,我按照您的代码复制official code sample来逐一重写,就像这样,之后它就可以在我这边工作了。 enter image description here

您也可以尝试使用新代码。

# Naming rules definitions

dotnet_naming_rule.interfacesPascalWithI.symbols = interfaces
dotnet_naming_rule.interfacesPascalWithI.style = _c
dotnet_naming_rule.interfacesPascalWithI.severity = warning

dotnet_naming_rule.publicMethodsPascal.symbols = public_method
dotnet_naming_rule.publicMethodsPascal.style = _c
dotnet_naming_rule.publicMethodsPascal.severity = warning

dotnet_naming_rule.defaultMethodsCamel.symbols = methods
dotnet_naming_rule.defaultMethodsCamel.style = c
dotnet_naming_rule.defaultMethodsCamel.severity = warning

dotnet_naming_rule.staticFieldsPascal.symbols = static_filed
dotnet_naming_rule.staticFieldsPascal.style = c
dotnet_naming_rule.staticFieldsPascal.severity = warning

dotnet_naming_rule.constFieldsPascal.symbols = const_field
dotnet_naming_rule.constFieldsPascal.style = c
dotnet_naming_rule.constFieldsPascal.severity = warning

dotnet_naming_rule.privateFieldsUnderscore.symbols = private_field
dotnet_naming_rule.privateFieldsUnderscore.style = _c
dotnet_naming_rule.privateFieldsUnderscore.severity = warning

dotnet_naming_rule.defaultFieldsCamel.symbols = fields
dotnet_naming_rule.defaultFieldsCamel.style = c
dotnet_naming_rule.defaultFieldsCamel.severity = warning

dotnet_naming_rule.defaultPascal.symbols = default
dotnet_naming_rule.defaultPascal.style = P
dotnet_naming_rule.defaultPascal.severity = warning

# Style Definitions
dotnet_naming_style.P.capitalization = pascal_case

dotnet_naming_style.IP.capitalization = pascal_case
dotnet_naming_style.IP.required_prefix = I

dotnet_naming_style.c.capitalization = camel_case

dotnet_naming_style._c.capitalization = camel_case
dotnet_naming_style._c.required_prefix = _

# Symbols Definitions
dotnet_naming_symbols.default.applicable_kinds = *
dotnet_naming_symbols.default.applicable_accessibilities = *

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

dotnet_naming_symbols.public_method.applicable_kinds  = method
dotnet_naming_symbols.public_method.applicable_accessibilities = public

dotnet_naming_symbols.methods.applicable_kinds = method
dotnet_naming_symbols.methods.applicable_accessibilities = *

dotnet_naming_symbols.static_filed.applicable_kinds  = field
dotnet_naming_symbols.static_filed.applicable_accessibilities = *
dotnet_naming_symbols.static_filed.required_modifiers = static

dotnet_naming_symbols.const_field.applicable_kinds  = field
dotnet_naming_symbols.const_field.applicable_accessibilities = *
dotnet_naming_symbols.const_field.required_modifiers = const

dotnet_naming_symbols.private_field.applicable_kinds  = field
dotnet_naming_symbols.private_field.applicable_accessibilities = private

dotnet_naming_symbols.fields.applicable_kinds = field
dotnet_naming_symbols.fields.applicable_accessibilities = *