Double logical negation cancels itself out
ID |
scala.correctness.no_double_operators |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Redundant Code |
Language |
Scala |
Description
Reports an expression negated twice with !, which yields exactly the value of the inner operand.
Rationale
The two negations cancel, so the code is longer than it needs to be while reading as though it performed a real inversion. It is usually the residue of an incomplete edit - a negation was added on the outside when the intent was to change the inner condition - which means the expression may not be doing what its author last meant it to do.
The following code illustrates the pattern detected by this rule:
class NoDoubleOperators {
val flag = true
def isEnabled(a: Boolean): Boolean = {
// FLAGGED: Double logical negation cancels itself out
!(!a)
}
}