T012
Negation operator should not be used in its short form
Description:
The negation operator (exclamation mark) reduces readability of the code due to its terseness. Prefer explicit logical comparisons or alternative tokens for increased readability:
if (!cond) // error-prone
if (cond == false) // better
if (not cond) // better (alternative keyword)
Compliance: Inspirel
Hide source code
# Negation operator should not be used in its short form
foreach file [getSourceFileNames] {
foreach negation [getTokens $file 1 0 -1 -1 {not}] {
set value [lindex $negation 0]
if {$value == "!"} {
set lineNumber [lindex $negation 1]
report $file $lineNumber "negation operator used in its short form"
}
}
}
Rule index