rspec/rules/S2589/csharp/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

82 lines
1.4 KiB
Plaintext

== Why is this an issue?
include::../description.adoc[]
=== Noncompliant code example
[source,csharp]
----
public void Sample(bool b, bool c, string s)
{
var a = true;
if (a) // Noncompliant
{
DoSomething();
}
if (b && a) // Noncompliant; "a" is always "true"
{
DoSomething();
}
if (c || !a) // Noncompliant; "!a" is always "false"
{
DoSomething();
}
string d = null;
var v1 = d ?? "value"; // Noncompliant, d is always null
var v2 = s ?? d; // Noncompliant, d is always null and the produced value is always equal to s. The condition to check the value of s is gratuitous.
}
----
=== Compliant solution
[source,csharp]
----
public void Sample(bool b, bool c, string s)
{
var a = true;
if (Foo(a))
{
DoSomething();
}
if (b)
{
DoSomething();
}
if (c)
{
DoSomething();
}
var v1 = "value";
var v2 = s;
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
* Change this condition so that it does not always evaluate to "[true|false]".
* Change this expression which always evaluates to "null".
include::../highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]