开发者

Suppressing the StyleCop Warnings at the global level

开发者 https://www.devze.com 2023-04-01 00:38 出处:网络
How to suppress the StyleCop warnings globally in the solution? The solution is continually built using Jenkins (continuous build and integration tool),开发者_如何学Python and it applies all the Styl

How to suppress the StyleCop warnings globally in the solution?

The solution is continually built using Jenkins (continuous build and integration tool),开发者_如何学Python and it applies all the StyleCop rules. The solution uses TAB character instead of 4 spaces as it is the standard taken by my dev team. Because of this, several SA1027 warnings are thrown by StlyeCop.

How do I remove SA1027 warning from Jenkins? That would also help.

Giving the SuppressMessage on every C# file would not look nice. That's why I am looking for a global suppression approach.


StyleCop doesn't support the notion of global suppression of a rule. It requires the SuppressMessage attribute be placed on the given code element.

From the Source Analysis Blog (Source)

StyleCop does not support the notion of global suppressions or file-level suppressions. Suppressions must be placed on a code element.

One option though is to simply turn off the rules that you aren't interested in. This is the preferred method of global suppression.


Seems that you probably need to change StyleCop configuration (settings) than to suppress some rules globally. StyleCop settings are "inherited through file system" so you could just create an appropriate settings file at the level of your solution folder.

Regarding your specific "tabs vs. spaces" subject, you could not only turn off StyleCop rules that requre spaces, but also to use some StyleCop plugins (like StyleCop+) that contains rules requiring tabs.


VS2015 + StyleCop Analyzers:

StyleCop.Settings does not get used anymore, but you can still do what JaredPar said and switch off specific warnings globally. Do this by modifying your current rule set (under the project's Properties GUI > Code Analysis > Open), and saving your changes as a new rule set.


File Settings.StyleCop should contain:

<StyleCopSettings Version="105">
  <Analyzers>
    <Analyzer AnalyzerId="StyleCop.CSharp.SpacingRules">
      <Rules>
        <Rule Name="TabsMustNotBeUsed">
          <RuleSettings>
            <BooleanProperty Name="Enabled">False</BooleanProperty>
          </RuleSettings>
        </Rule>
      </Rules>
      <AnalyzerSettings />
    </Analyzer>
  </Analyzers>
</StyleCopSettings>


Find your .ruleset file. (under Solution Items or wherever it is) Change the Action to None.

<Rule Id="SA1027" Action="None" />
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号