Rule configuration is not active after migrating solution to V7

  • Operating system: Windows 11
  • Visual Studio version: 2022
  • SonarLint plugin version: 7.7
  • Programming language you’re coding in: C#
  • Is connected mode used: SonarQube 10.4

I’ve migrated a solution with SonarLint configuration from V6 to V7. All project files have been updated, the folder .sonarlint was cleared.
The configuration was moved to %AppData%\Roaming\SonarLint for Visual Studio\Bindings as expected, it seems to be correct.

But, the rule configuration does not (fully) apply.
E.g. S1451 now reports every file in the editor (not as compiler warning).
The current header is:

// <copyright>
//     Copyright (c) My Company GmbH. All rights reserved.
// </copyright>

The quickfix wants to change the header to

/*
 * <Your-Product-Name>
 * Copyright (c) <Year-From>-<Year-To> <Your-Company-Name>
 *
 * Please configure this header in your SonarCloud/SonarQube quality profile.
 * You can also set it in SonarLint.xml additional file for SonarLint or standalone NuGet analyzer.
 */

The regular expression is correctly configured in c:\Users\***\AppData\Roaming\SonarLint for Visual Studio\Bindings\***\CSharp\SonarLint.xml.

I’m wondering that there is no S1451 warning when the source gets compiled, while other Sonar warnings are present.

Interesting: The file SonarLint.xml is mentioned to be used to configure the rule, while it was removed automatically by the plugin!?

Hi Lukas,

You both mentioned regex and quickfixes but the rule does not support quickfixes when using regex. Could you please confirm “isRegularExpression” parameter for the rule is set to true?

Yes, the configuration has active IsRegularExpression.

    <Rule>
      <Key>S1451</Key>
      <Parameters>
        <Parameter>
          <Key>headerFormat</Key>
          <Value>//\s*&lt;copyright&gt;\s*//\s*Copyright \(c\) (***|***) GmbH. All rights reserved.\s*//\s*&lt;/copyright&gt;\s*</Value>
        </Parameter>
        <Parameter>
          <Key>isRegularExpression</Key>
          <Value>true</Value>
        </Parameter>
      </Parameters>
    </Rule>

These two should never happen together. When the rule is regex it does not have a quick fix, and we weren’t able to reproduce such a scenario.

Could you please SonarLint logs with verbose logging level.

To enable to verbose logging level you need to go to Extensions → SonarLint → Options and set the logging level to “Verbose”.

Today the problem is not reproducible anymore.
Maybe it was fixed with the plugin version 7.8 which was installed meanwhile.

2 Likes