rspec/rules/S1125/scala/rule.adoc
2023-12-22 10:07:51 +01:00

53 lines
1.1 KiB
Plaintext

:true: true
:false: false
:ops: !, &&, ||, ==, !=
== Why is this an issue?
include::../description.adoc[]
== How to fix it
include::../how-to-fix-it.adoc[]
=== Code examples
==== Noncompliant code example
[source,scala,diff-id=1,diff-type=noncompliant]
----
if (booleanMethod() || false) { /* ... */ }
doSomething(!false)
booleanVariable = if (booleanMethod()) true else false
booleanVariable = if (booleanMethod()) true else exp
booleanVariable = if (booleanMethod()) false else exp
booleanVariable = if (booleanMethod()) exp else true
booleanVariable = if (booleanMethod()) exp else false
----
==== Compliant solution
[source,scala,diff-id=1,diff-type=compliant]
----
if (booleanMethod()) { /* ... */ }
doSomething(true)
booleanVariable = booleanMethod()
booleanVariable = booleanMethod() || exp
booleanVariable = !booleanMethod() && exp
booleanVariable = !booleanMethod() || exp
booleanVariable = booleanMethod() && exp
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
endif::env-github,rspecator-view[]