Search code examples
c#.net-6.0stylecopeditorconfig

Change the severity of all StyleCop rules using .editorconfig


How can I change the severity of all StyleCop rules using .editorconfig?

Configuring individual rules works:

dotnet_diagnostic.SA1202.severity = error

However, I'm looking for a global change that affects every rule.


Solution

  • If you want all rules for all analyzers to be set, use this:

    dotnet_analyzer_diagnostic.severity = error
    

    If you want just the Stylecop.Analyzers package rules to be set, use this:

    dotnet_analyzer_diagnostic.category-StyleCop.CSharp.AlternativeRules.severity = error
    dotnet_analyzer_diagnostic.category-StyleCop.CSharp.DocumentationRules.severity = error
    dotnet_analyzer_diagnostic.category-StyleCop.CSharp.LayoutRules.severity = error
    dotnet_analyzer_diagnostic.category-StyleCop.CSharp.MaintainabilityRules.severity = error
    dotnet_analyzer_diagnostic.category-StyleCop.CSharp.NamingRules.severity = error
    dotnet_analyzer_diagnostic.category-StyleCop.CSharp.OrderingRules.severity = error
    dotnet_analyzer_diagnostic.category-StyleCop.CSharp.ReadabilityRules.severity = error
    dotnet_analyzer_diagnostic.category-StyleCop.CSharp.SpacingRules.severity = error
    dotnet_analyzer_diagnostic.category-StyleCop.CSharp.SpecialRules.severity = error
    

    Individual rules can then be individually overridden, like this:

    dotnet_diagnostic.SA1400.severity = warning