rspec/rules/S1125/csharp/rule.adoc

69 lines
1.4 KiB
Plaintext
Raw Normal View History

2023-10-13 13:50:06 +02:00
:true: true
:false: false
:ops: !, &&, ||, ==, !=
== Why is this an issue?
include::../description.adoc[]
2023-12-22 10:07:51 +01:00
== How to fix it
include::../how-to-fix-it.adoc[]
2023-10-13 13:50:06 +02:00
=== Code examples
2023-10-13 13:50:06 +02:00
==== Noncompliant code example
[source,csharp,diff-id=1,diff-type=noncompliant]
----
if (booleanMethod() == true) { /* ... */ }
if (booleanMethod() == false) { /* ... */ }
if (booleanMethod() || false) { /* ... */ }
doSomething(!false);
doSomething(booleanMethod() == true);
booleanVariable = booleanMethod() ? true : false;
booleanVariable = booleanMethod() ? true : exp;
booleanVariable = booleanMethod() ? false : exp;
booleanVariable = booleanMethod() ? exp : true;
booleanVariable = booleanMethod() ? exp : false;
for (var x = 0; true; x++)
{
...
}
----
2023-10-13 13:50:06 +02:00
==== Compliant solution
2023-10-13 13:50:06 +02:00
[source,csharp,diff-id=1,diff-type=compliant]
----
if (booleanMethod()) { /* ... */ }
if (!booleanMethod()) { /* ... */ }
if (booleanMethod()) { /* ... */ }
doSomething(true);
doSomething(booleanMethod());
booleanVariable = booleanMethod();
booleanVariable = booleanMethod() || exp;
booleanVariable = !booleanMethod() && exp;
booleanVariable = !booleanMethod() || exp;
booleanVariable = booleanMethod() && exp;
for (var x = 0; ; x++)
{
...
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
endif::env-github,rspecator-view[]