green-code-initiative / ecoCode

Reduce the environmental footprint of your software programs with SonarQube
https://ecocode.io
GNU General Public License v3.0
160 stars 78 forks source link

[EC69] is wrongly detected #348

Closed tisonv closed 3 months ago

tisonv commented 3 months ago

Describe the bug EC69 is wrongly reported

To Reproduce Steps to reproduce the behavior:

string? p = Path.GetDirectoryName(resource.RemotePath);

while (p != null && !p.Equals(@"S:\", StringComparison.OrdinalIgnoreCase))
{
      [ calls to various API with p as param ]

      p = Path.GetDirectoryName(p);
}

EC69 is detected on p.Equals(@"S:\", StringComparison.OrdinalIgnoreCase)

Expected behavior p mutates at each iteration. There's no invariant function in the loop. EC69 should not be fired.

Screenshots No screenshot

Software Versions

Additional context No additional context

Djoums commented 3 months ago

Right, the warning should not be triggered in this case, I'll look into it. Using string.Equals doesn't have that problem though.

while (!string.Equals(d, @"S:\", StringComparison.OrdinalIgnoreCase))
    d = Path.GetDirectoryName(d);
Djoums commented 3 months ago

The fix is available in version 1.5.1