rspec/rules/S1125/rule.adoc

42 lines
1.0 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2020-06-30 12:48:07 +02:00
include::description.adoc[]
2023-10-13 13:50:06 +02:00
=== Code examples
2023-10-13 13:50:06 +02:00
==== Noncompliant code example
[source,text,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;
----
2023-10-13 13:50:06 +02:00
==== Compliant solution
2023-10-13 13:50:06 +02:00
[source,text,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;
----
2020-06-30 12:48:07 +02:00