Simplify Boolean Expression
ID |
go.simplify_boolean_expression |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Code Smell |
Language |
Go |
Tags |
code-smell, readability |
Description
Reports a redundant double negation !!x, which evaluates to the same boolean value as x.
Rationale
The extra pair of ! operators adds nothing to the meaning of the expression and only makes it
harder to read. Dropping them is always behaviour-preserving for a boolean operand and leaves the
intent clearer.
The redundant comparison forms x == true / x == false and the if cond { return true } else
{ return false } statement form are reported by separate rules, so this rule stays focused on the
double-negation expression form.
x := !!a // FLAW — same as a
y := !a // OK — single negation
z := !(p && q) // OK — not a double negation