Reputation: 5876
I'm writing an editorconfig file to enforce some coding styles and I'd like to enforce that constants should be uppercase, so I created the following rules in the editorConfig file:
dotnet_naming_rule.constants_must_be_uppercase.symbols = public_constants
dotnet_naming_symbols.public_constants.applicable_kinds = field
dotnet_naming_symbols.public_constants.applicable_accessibilities = *
dotnet_naming_symbols.public_constants.required_modifiers = const
dotnet_naming_rule.constants_must_be_uppercase.style = uppercase_with_underscore_separator
dotnet_naming_style.uppercase_with_underscore_separator.capitalization = all_upper
dotnet_naming_style.uppercase_with_underscore_separator.word_separator = _
dotnet_naming_rule.constants_must_be_uppercase.severity = warning
I'm testing this with the following code:
namespace XYZ
{
public class Foo
{
public const string Bar = "bar";
}
}
However, Visual Studio does not indicate that the line is not correct. Is it a bug or is my file incorrect?
Upvotes: 3
Views: 2469
Reputation: 377
Leaving this here for if other people stumble upon this question like I did.
These are the .editorconfig lines that I figured work for enforcing upper case constants:
# Constants are UPPERCASE
dotnet_naming_rule.constants_should_be_upper_case.severity = suggestion
dotnet_naming_rule.constants_should_be_upper_case.symbols = constants
dotnet_naming_rule.constants_should_be_upper_case.style = constant_style
dotnet_naming_symbols.constants.applicable_kinds = field, local
dotnet_naming_symbols.constants.required_modifiers = const
dotnet_naming_style.constant_style.capitalization = all_upper
Upvotes: 11