dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.02k stars 4.03k forks source link

Refactor suggestion: Remove unnecessary (Value As String) in VB.NET property setters #72373

Open tats-u opened 7 months ago

tats-u commented 7 months ago

Brief description:

In VB.NET, the setter definition in a property declaration often specifies (value As String) unnecessarily, even though value is the default name for the setter parameter. While some coding rules may enforce this specification, it can lead to confusion among new developers and clutter the code unnecessarily.

Languages applicable:

VB Only

Code example that the analyzer should report:

Private _name As String

Public Property Name() As String
    Get
        Return _name
    End Get
    Set (value As String) ' Variable name specification as `value` is redundant.
      ' ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ (lighten the colors)
        _name = value
        NotifyOnSomewhereElse()
    End Set
End Property

Additional information:

Documentation requirements:

paul1956 commented 7 months ago

Would love to see that, it would make code so much more consistent but I would also like to see the opposite for code bases that prefer the more explicit style and an EditorConfig setting for preference.On Mar 3, 2024, at 4:50 PM, Tatsunori Uchino @.***> wrote:

Brief description: In VB.NET, the setter definition in a property declaration often specifies (value As String) unnecessarily, even though value is the default name for the setter parameter. While some coding rules may enforce this specification, it can lead to confusion among new developers and clutter the code unnecessarily. Languages applicable: VB Only Code example that the analyzer should report: Private _name As String

Public Property Name() As String Get Return _name End Get Set (value As String) ' Variable name specification as value is redundant. ' ~~~~~ (lighten the colors) _name = value NotifyOnSomewhereElse() End Set End Property Additional information: Documentation requirements:

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

tats-u commented 7 months ago

but I would also like to see the opposite for code bases that prefer the more explicit style and an EditorConfig setting for preference.

Fine. A new EditorConfig preference is mandatory. As C# is forced to use value, I think removal should be the default behavior.