Duplicated string literals make the process of refactoring complex and error-prone, as any change would need to be propagated on all occurrences.
The following are ignored:
Use constants to replace the duplicated string literals. Constants can be referenced from many places, but only need to be updated in a single place.
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
}
}
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;
}
}