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
772 stars 226 forks source link

S2365: Fix VB.Net implementation #7360

Open gregory-paidis-sonarsource opened 1 year ago

gregory-paidis-sonarsource commented 1 year ago

The description of the visual basic variant for S2365 is correct on RSPEC, but the implementation is not.

The implementation checks almost only that the property's type is IArraySymbol, and not what happens inside the body of the getter/setter:

// Current implementation
if (property.ImplementsClause is null
    && !property.Modifiers.Any(x => x.IsKind(SyntaxKind.OverridesKeyword))
    && c.SemanticModel.GetDeclaredSymbol(property) is IPropertySymbol symbol
    && !symbol.IsAutoProperty()
    && symbol.Type is IArrayTypeSymbol)

There is no reference to Clone or the other methods that should be avoided, which even simple cases raise. Example:

Public Interface IBase
    Property Evil As Byte()    ' Noncompliant: passes all the checks above
End Interface

Expected behavior

Refactor the visual basic implementation to be semantically the same as the C# implementation.

gregory-paidis-sonarsource commented 1 year ago

setting priority to high, because it is SonarWay