57 lines
929 B
Plaintext
57 lines
929 B
Plaintext
include::../description.adoc[]
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
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
|
|
|
|
----
|
|
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[]
|