Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enforcing upper case for const under Visual Studio with editoconfig

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?

like image 491
ssougnez Avatar asked Sep 19 '25 15:09

ssougnez


1 Answers

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
like image 176
Milan Karman Avatar answered Sep 23 '25 10:09

Milan Karman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!