简体   繁体   中英

editorConfig Naming Convention not working c# visual studio 2019 16.4.2

I am trying to use .editorconfig at solution level to define naming conventions for the two C# projects in it. I have latest Visual Studio as of date, updated just today to 16.4.2. It is giving warnings where not expected. For example, for class names, property names, enum names it says that it should begin with lower case, whereas as per my convention in editorconfig, they are expected in pascal case. Similarly for private fields in class, I have defined field name to begin with underscore ("_") character but it is reporting error there also.

I am sure that it is using my editorconfig file because I see changes in messages if I deliberately change some parts just to see whether there is any impact. However, result is not as per expectation.

Are there more settings that need to be done? Is there an error in my editorconfig inputs?

Here is the relevant content of my editorconfig file.

# 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 = *

I have test you code, and this issue also occurs on my side. Then I check the code, it seems that the “dotnet_naming_rule” couldn't find specified symbol, which causes rule to adapts to all situations. Then I follow your code and copy official code sample to re-write it one by one, which is like this, after that it could work on my side. 在此处输入图片说明

And you could also try the new code on your side.

# 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 = *

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM