Andreas Reiff
Andreas Reiff

Reputation: 8404

Stylecop: getting too many errors like SA1400 when using a parent settings file

I have a (company-given) stylecop settings file with a handful of rules.

This I placed into the parent folder for my project (test project, local, no source control - stylecop settings still say "Merge with settings file found in parent folders").

When running Stylecop (4.7.42, Rescan All), I get several warnings like SA1400, SA1200 and so on, that I have not defined.

On the other hand, I have

<Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.MaintainabilityRules">
  <Rules>
    <Rule Name="ArithmeticExpressionsMustDeclarePrecedence">
      <RuleSettings>
        <BooleanProperty Name="Enabled">True</BooleanProperty>
      </RuleSettings>
    </Rule>
  </Rules>
  <AnalyzerSettings />
</Analyzer>

and

i = i * 2 + 3 * 6;

and get no warning for that. (Rule explanation: http://stylecop.soyuz5.com/SA1407.html . Actually, setting True or False here results in no message.)

Also, when opening the settings editor, all settings are checked, though I only specify a few in my settings file.

I assume my settings file has little to do with what Stylecop reports?!

How to fix?

Upvotes: 0

Views: 1630

Answers (1)

Mightymuke
Mightymuke

Reputation: 5144

I think you're looking for this: https://stackoverflow.com/a/13434198/1505426


Copied from linked answer:

By default your settings files are merged into parent settings, and this could be causing you some issues. Try stopping the merging at the solution root by adding the following setting:

<GlobalSettings>
    <StringProperty Name="MergeSettingsFiles">NoMerge</StringProperty>
</GlobalSettings>

This will ensure that StyleCop acts the same on all development and build machines, regardless of the settings configured higher up the hierarchy (such as the one in the StyleCop application folder). However if you do this, make sure you copy all the required settings from the files no longer being merged.

Upvotes: 1

Related Questions