
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.
82 lines
1.4 KiB
Plaintext
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[]
|