78 lines
1.3 KiB
Plaintext
78 lines
1.3 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,csharp,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
public class Foo
|
|
{
|
|
private string name = "foobar"; // Noncompliant
|
|
|
|
public string DefaultName { get; } = "foobar"; // Noncompliant
|
|
|
|
public Foo(string value = "foobar") // Noncompliant
|
|
{
|
|
var something = value ?? "foobar"; // Noncompliant
|
|
}
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,csharp,diff-id=1,diff-type=compliant]
|
|
----
|
|
public class Foo
|
|
{
|
|
private const string Foobar = "foobar";
|
|
|
|
private string name = Foobar;
|
|
|
|
public string DefaultName { get; } = Foobar;
|
|
|
|
public Foo(string value = Foobar)
|
|
{
|
|
var something = value ?? Foobar;
|
|
}
|
|
}
|
|
----
|
|
|
|
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[]
|