views:

463

answers:

2

Is it possible to suppress StyleCop rules in a more global what... in other words not just using source in-line attributes?

+2  A: 

You can disable certain stylecop rules with a Settings.StyleCop file. For example there's certain things built into stylecop that doesn't fit with our standard. For example in my Settings.StyleCop file we have:

<Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.ReadabilityRules">
  <Rules>
    <Rule Name="PrefixLocalCallsWithThis">
      <RuleSettings>
        <BooleanProperty Name="Enabled">False</BooleanProperty>
      </RuleSettings>
    </Rule>
  </Rules>
  <AnalyzerSettings />
</Analyzer>

Such that on a member variable or property we don't have to have "this." for each and every one.

McAden
And I'm getting downvoted why?
McAden
+1  A: 

Absolutely!

Source attributes should only be used in the rarest of circumstances, the vast majority of your StyleCop configuration should be done via the StyleCopSettingsEditor (right-click on a project, choose "StyleCop Settings", that'll open one up).

This will create a Settings.StyleCop file for that project in the project directory. That file can be hand-edited as the other answer mentions, but I would never suggest hacking XML in an editor. StyleCopSettingsEditor is definitely the way to go.

Once you've modified your StyleCop settings, you're not done!
Those settings will only apply to that one project, and that might definitely be insufficient.
I personally suggest moving that StyleCop.Settings file up one directory to the solution level and adding it as a "Solution Item". Then check that file into TFS (or whatever source control system you're using). Now those StyleCop settings are a part of the entire solution, and everyone will get them when they do a "Get Latest". If necessary, you can override the solution settings with project settings (a StyleCop.Settings file at the project level will override one at the solution level).

The only way to make your StyleCop settings more global than that is to either move them up even higher in the directory tree (up to the Team Project level if you're using TFS, unreliable since doing a GetLatest at the solution level won't distribute them to everyone), or to overwrite the Settings.StyleCop file in the StyleCop installation directory (even more unreliable since that can't be handled by source control and instead has to be emailed to everyone or something).

Overall there are definitely ways of making the specific StyleCop settings for your team as global as you want, you have lots of options.

Task