rspec/rules/S1192/csharp/rule.adoc

65 lines
1.1 KiB
Plaintext
Raw Normal View History

2020-06-30 12:47:33 +02:00
include::../description.adoc[]
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,csharp]
2020-06-30 12:47:33 +02:00
----
public class Foo
{
private string name = "foobar"; // Noncompliant
public string DefaultName { get; } = "foobar"; // Noncompliant
2021-01-23 04:07:47 +00:00
public Foo(string value = "foobar") // Noncompliant
2020-06-30 12:47:33 +02:00
{
var something = value ?? "foobar"; // Noncompliant
}
}
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,csharp]
2020-06-30 12:47:33 +02:00
----
public class Foo
{
private const string Foobar = "foobar";
private string name = Foobar;
public string DefaultName { get; } = Foobar;
2021-01-23 04:07:47 +00:00
public Foo(string value = Foobar)
2020-06-30 12:47:33 +02:00
{
var something = value ?? Foobar;
}
}
----
== Exceptions
The following are ignored:
2020-06-30 12:47:33 +02:00
* literals with fewer than 5 characters
* literals matching one of the parameter names
* literals used in attributes
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::../parameters.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]