rspec/rules/S1192/vbnet/rule.adoc
2023-10-11 11:41:24 +02:00

82 lines
1.4 KiB
Plaintext

== Why is this an issue?
include::../description.adoc[]
=== Exceptions
The following are ignored:
* literals with fewer than 5 characters
* literals matching one of the parameter names
* literals used in attributes
== How to fix it
include::../howtofix.adoc[]
=== Code examples
==== Noncompliant code example
[source,vbnet,diff-id=1,diff-type=noncompliant]
----
Public Class Foo
Private Name As String = "foobar" ' Noncompliant
Public ReadOnly Property DefaultName As String = "foobar" ' Noncompliant
Public Sub New(Optional Value As String = "foobar") ' Noncompliant
Dim Something = If(Value, "foobar") ' Noncompliant
End Sub
End Class
----
==== Compliant solution
[source,vbnet,diff-id=1,diff-type=compliant]
----
Public Class Foo
Private Const Foobar As String = "foobar"
Private Name As String = Foobar
Public ReadOnly Property DefaultName As String = Foobar
Public Sub New(Optional Value As String = Foobar)
Dim Something = If(Value, Foobar)
End Sub
End Class
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Define a constant instead of using the literal "{string}" {number} times.
include::../parameters.adoc[]
=== Highlighting
primary: the class
secondaries: all instances of the string literal
'''
endif::env-github,rspecator-view[]