Domanda

I'm trying to run StyleCop (4.7.47) via the gradle sonarrunner plugin on a Jenkins client. It runs fine, but for some reason it does not use my Settings.StyleCop file in which I disable a number of rules, so Sonar (3.7) reports violations that I am not interested in.

The c# project has the following structure:

/Root
    Src/
        Project1/...
        Project2/...
        MySolution.sln
        Settings.StyleCop
    build.gradle

My Settings.StyleCop file looks like this:

<StyleCopSettings Version="105">
  <GlobalSettings>
    <StringProperty Name="MergeSettingsFiles">NoMerge</StringProperty>
  </GlobalSettings>
  <Analyzers>
    <Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
      <Rules>
        <Rule Name="ElementDocumentationMustBeSpelledCorrectly">
          <RuleSettings>
            <BooleanProperty Name="Enabled">False</BooleanProperty>
          </RuleSettings>
        </Rule>
      </Rules>
    </Analyzer>
  </Analyzers>
</StyleCopSettings>

And the sonar properties that I specify for the sonarrunner gradle plugin are:

property "sonar.language" , "cs"
property "sonar.sources" , "Src"
property "sonar.dotnet.visualstudio.solution.file" ,"Src/MySolution.sln"
property "sonar.dotnet.key.generation.strategy", "safe"
property "sonar.sourceEncoding" , "UTF-8"

I have also tried specifying the sonar.stylecop.analyzers.settings property, even though the Sonar FAQ mentioned that this cannot be used to specify active rules.

When I run StyleCop in VisualStudio it does use the correct rules.

Is there a way to verify where StyleCop gets its settings? Am I missing something obvious?

Any help appreciated.

È stato utile?

Soluzione

The rules for Sonar are enabled/disable (as well as setting the rule priority) through the Quality Profiles admin screens in Sonar.

Due to the architecture of Sonar, the rules must be populated before a plugin runs, so the plugins themselves cannot change the violations state or priority directly while analyzing code. The plugin populates the available rules at server start, but the Sonar StyleCop plugin does not provide a way to modify the rule settings from the defaults other than through the QualityProfile.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top