SonarSource / sonar-dotnet

Code analyzer for C# and VB.NET projects
https://redirect.sonarsource.com/plugins/csharp.html
GNU Lesser General Public License v3.0
798 stars 229 forks source link

Fix S2953 FP: Implement `IDisposable.Dispose` on extension methods `static` class #9679

Closed manfred-brands closed 1 month ago

manfred-brands commented 1 month ago

Description

S2953 raised a false positive on a static class.

Repro steps

We have an extension method on Lazy to dispose it, but only if the value was created.

    public static class DisposableExtensions
    {
        public static void Dispose<T>(this Lazy<T> lazy)
            where T : class, IDisposable
        {
            if (lazy.IsValueCreated)
            {
                lazy.Value.Dispose();
            }
        }
    }

Expected behavior

S2953 is not raised.

Actual behavior

S2953 is raised.

Known workarounds

Suppress

Related information

CristianAmbrosini commented 1 month ago

Hi @manfred-brands! I confirm this as a FP. I already added the reproducer and fixed the issue; it was a low-hanging fruit. You will not experience it anymore starting from the next release, enjoy!

manfred-brands commented 1 month ago

@CristianAmbrosini Thanks, but I don't see neither a PR or changes to master with a fix so how can this be closed? Did you forgot to push your changes?