All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.vbnet.S3603.html Maven / Gradle / Ivy

There is a newer version: 10.5.0.109200
Show newest version

Why is this an issue?

Marking a method with the Pure attribute indicates that the method doesn’t make any visible state changes. Therefore, a Pure method should return a result. Otherwise, it indicates a no-operation call.

Using Pure on a void method is either by mistake or the method is not doing a meaningful task.

How to fix it

Code examples

Noncompliant code example

Class Person
    Private age As Integer

    <Pure> ' Noncompliant: The method makes a state change
    Private Sub ConfigureAge(ByVal age As Integer)
        Me.age = age
    End Sub

    <Pure>
    Private Sub WriteAge() ' Noncompliant
        Console.WriteLine(Me.age)
    End Sub

End Class

Compliant solution

Class Person
    Private age As Integer

    Private Sub ConfigureAge(ByVal age As Integer)
        Me.age = age
    End Sub

    <Pure>
    Private Function Age() As Integer
        Return Me.age
    End Function

    ' or remove Pure attribute from the method

    Private Sub WriteAge()
        Console.WriteLine(Me.age)
    End Sub

End Class

Resources

Documentation





© 2015 - 2025 Weber Informatics LLC | Privacy Policy