2

我正在编写一个 editorconfig 文件来强制执行一些编码样式,并且我想强制常量应该是大写的,所以我在 editorConfig 文件中创建了以下规则:

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

我正在使用以下代码对此进行测试:

namespace XYZ
{
    public class Foo
    {
        public const string Bar = "bar";
    }
}

但是,Visual Studio 并不表示该行不正确。是错误还是我的文件不正确?

4

1 回答 1

4

如果其他人像我一样偶然发现这个问题,请将其留在这里。

这些是我认为用于强制大写常量的 .editorconfig 行:

# 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
于 2019-08-08T00:30:55.177 回答