Disable StyleCop for specific lines

后端 未结 5 628
無奈伤痛
無奈伤痛 2021-02-05 01:12

We\'re using StyleCop in our C# projects. In some cases we\'d like to avoid the rules though. I know you can add // in the beginning of the

5条回答
  •  北海茫月
    2021-02-05 01:38

    An old question I know but in looking for an answer I found that in stylecop 4.4 you can now put something like this - or one of these lines on a method:

    [SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "*", Justification = "Risky to change manually")]
    [SuppressMessage("Microsoft.StyleCop.CSharp.SpacingRules", "*", Justification = "Risky to change manually")]
    [SuppressMessage("Microsoft.StyleCop.CSharp.MaintainabilityRules", "*", Justification = "Risky to change manually")]
    [SuppressMessage("Microsoft.StyleCop.CSharp.LayoutRules", "*", Justification = "Risky to change manually")]
    [SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "*", Justification = "Risky to change manually")]
    [SuppressMessage("Microsoft.StyleCop.CSharp.ReadabilityRules‌​", "*", Justification = "Risky to change manually")]
    [SuppressMessage("Microsoft.StyleCop.CSharp.OrderingRules", "*", Justification = "Risky to change manually")]
    
    • Note: I might be missing one or two of the rule categories

提交回复
热议问题