Question on .editorconfig is correctly handled by SonarQube

We are currently observing a similar issue in our Azure Pipelines runs. We use the following steps:

  • SonarQubePrepare
  • dotnet restore
  • dotnet build
  • SonarQubeAnalyze
  • SonarQubePublish

For most analyzers, the .editorconfig is correctly handled by SonarQube. If I run the build locally, I get no warnings at all. If I remove SonarQube from the pipeline, I get no warnings at all. With SonarQube, at least the following analyzers begin to show up as warnings:

  • S6603
  • S1121
  • S1135
  • S6605
  • S6602
  • S3267
  • S107
  • S3776
  • S5332
  • S1075
  • S6444
dotnet_diagnostic.S1121.severity = suggestion

There are probably even more. During further testing I realized that changing the severity from “suggestion” to “none” actually removes it completely in my case. However that only worked for S1121. For other analyzers like S6605 this did have no impact.

There are no other editorconfig files which define rules for these analyzers. And since changing the severity of S1121 has an impact, I’m sure the file is correctly recognized.

We’re using .NET8 and SonarQubePrepare logs this:

SonarScanner for MSBuild 9.0.2
Using the .NET Core version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
15:32:58.603  Updating build integration targets...
15:32:59.475  Using SonarQube v10.4.1.88267.
15:32:59.548  Fetching analysis configuration settings...
15:33:00.109  Provisioning analyzer assemblies for cs...
15:33:00.11  Installing required Roslyn analyzers...
15:33:00.11  Processing plugin: csharp version 9.19.0.84025
15:33:00.259  Processing plugin: vbnet version 9.19.0.84025
15:33:00.299  Processing plugin: securitycsharpfrontend version 10.4.0.30099
15:33:00.552  Provisioning analyzer assemblies for vbnet...
15:33:00.552  Installing required Roslyn analyzers...
15:33:00.552  Processing plugin: csharp version 9.19.0.84025
15:33:00.553  Processing plugin: vbnet version 9.19.0.84025
15:33:00.561  Incremental PR analysis: Base branch parameter was not provided.
15:33:00.561  Cache data is empty. A full analysis will be performed.
15:33:00.59  WARNING: Multi-Language analysis is enabled. If this was not intended and you have issues such as hitting your LOC limit or analyzing unwanted files, please set "/d:sonar.scanner.scanAll=false" in the begin step.
15:33:00.63  Pre-processing succeeded.

I worked around this issue by adding this to my directory.build.targets:

  <Target Name="SonarQubeRestoreWarningsAsErrors"
        Condition=" $(SonarQubeTempPath) != '' "
        AfterTargets="OverrideRoslynCodeAnalysisProperties"
        BeforeTargets="CoreCompile">
    <PropertyGroup>      
      <NoWarn>$(NoWarn);S6605;S1121;...;</NoWarn>
    </PropertyGroup>
  </Target>
1 Like

Hi @lxb and welcome to the forum.

To clarify:

  • do you want to selectively disable the rule for only a portion of the code, not completely, which is only possible using an editorconfig file?
  • or do you want to disable a rule for a single project and not the whole solution?

Hi,
While we have multiple editorconfig files, the rules in question are set to suggestion in the global file at the root of the project. So for the whole solution with many projects.

Hello @lxb,

The Scanner for .NET does not seem to properly pick up the settings in the .editorconfig.
I have a created a ticket about your issue.

In the meantime, I would suggest to disable the rules by removing it from your quality profile on SonarQube Server since it can apply to your whole solution.
Otherwise, I hope that your workaround works for you while we get the time to fix this issue.

Whishing you a happy new year!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.