
org.sonar.plugins.vbnet.S3603.html Maven / Gradle / Ivy
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
- Microsoft Learn - PureAttribute Class
© 2015 - 2025 Weber Informatics LLC | Privacy Policy