De Morgan Law
ID |
go.demorgan_law |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Code Smell |
Language |
Go |
Tags |
code-smell, readability |
Description
Reports a negation applied to a parenthesized boolean conjunction or disjunction — !(a && b)
or !(a || b). De Morgan’s laws give the equivalent distributed forms !a || !b and
!a && !b.
Rationale
A leading ! on a parenthesized && / || forces the reader to mentally distribute the
negation across the operands before they can tell what the expression is testing. Distributing
it in the source — and simplifying any double negations that fall out — usually expresses the
intent more directly and removes a common source of boolean-logic mistakes.
!(a && b) // FLAW — equivalent to !a || !b
!(a || b) // FLAW — equivalent to !a && !b
!a // OK — no parenthesized group
!(a) // OK — not a logical binary
Remediation
Apply De Morgan’s law: rewrite !(a && b) as !a || !b and !(a || b) as !a && !b, then
simplify any resulting double negations.