Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is StyleCop SA1305 not respecting the allowed prefixes list in VS2010 (or MSBuild)?

I just upgraded a project from 2008 to 2010 Beta 2 and StyleCop is now reporting SA1305 (Hungarian notation) warnings on variable names with the prefix 'is'. 'Is' is definitely in the list of allowed prefixes.

Is this a known issue? Has anyone else run across this problem? The code was definitely compiling without any warnings in 2008.

Update: It turns out that this can work as expected in Visual Studio, but then fail through MSBuild. See the answer below for why.

like image 394
Jedidja Avatar asked Dec 01 '09 15:12

Jedidja


2 Answers

You can manually add the "is" exception to Settings.StyleCop:

<Analyzers>    
  <Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.NamingRules">
    <AnalyzerSettings>
      <CollectionProperty Name="Hungarian">
        <Value>is</Value>
      </CollectionProperty>
    </AnalyzerSettings>
  </Analyzer>
</Analyzers>
like image 132
Jenn Avatar answered Nov 23 '22 23:11

Jenn


I ran across a similar issue now when building with msbuild vs on a developer box. It turns out that the default Settings.StyleCop (C:\Program Files (x86)\MSBuild\Microsoft\StyleCop\v4.4) that is installed actually contains a bunch of values you will need to duplicate in your own file if either:

  • you are not installing StyleCop on the "other" (build) machine

or

  • you have "do not merge with any other settings files" enabled

Specifically - the StyleCop Settings Editor picks up the Hungarian notation excludes from the other file automatically, regardless of what the "Settings Files" tab says.

like image 20
Jedidja Avatar answered Nov 23 '22 23:11

Jedidja