Bug: Autofix of S1125 in C# is wrong and leads to bad results

  • Operating system: Microsoft Visual Studio Community 2022 (64-Bit) - Current
    Version 17.7.0
  • SonarLint plugin version: 9.8.0.76515
  • Programming language you’re coding in: C#
  • Is connected mode used: No
  • Link to GitHub-Issue

Hello,
we use SonarLint with StyleCop in our company. Because there are many small warning that could be autofixed on save, we use the feature “clean-code on save”.

Here is the problem:
The Autofix of S1125 is wrong. The rule and the description are definitely correct, but the autofix function is wrong. It changes if (testBool == false) to if (testBool). Screenshot are attached.

This is the fix:
Autofix should have this result:
if (!testBool)

We had some bugs because SonarLint changed it wrong and is missing the exclamation mark on negative boolean literals. Could you please fix this? We will use the rule quick then again. Thank you! :slight_smile:

Before:
sonarLint_s1125-before

After clean-code on save
sonarLint_s1125-after

Hello @urmel

I see you have also raised the issue on github. We will address the issue there, so I am closing this community thread.

Best,
Čaba

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