【问题标题】:Enforcing upper case for const under Visual Studio with editoconfig在 Visual Studio 下使用 editoconfig 强制 const 大写
【发布时间】:2019-04-16 07:38:12
【问题描述】:

我正在编写一个 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 并不表示该行不正确。是错误还是我的文件不正确?

【问题讨论】:

    标签: visual-studio editorconfig


    【解决方案1】:

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

    这些是我认为用于强制大写常量的 .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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多