A declared function is compared with nil, which it never is
What it finds
if handler != nil where handler is a function declared with func handler(...): a declared function is never nil, so the comparison is always the same. Usually a variable or field holding a function was meant, or the function was meant to be called, as in handler() != nil.
The name must resolve to a function declared in the file, and the other operand of == or != must be the predeclared nil.
From the rule's source, function_compared_with_nil.rs.
package p func handler() error { return nil } var hook func() func f() bool { if handler != nil {tx0 reports: the function handler is never nil, so this is always true return true } if nil == handler {tx0 reports: the function handler is never nil, so this is always false return false } return hook != nil || handler() != nil} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/go:function-compared-with-nil" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/go:function-compared-with-nil] reason="..."tx0 explain tx0/go:function-compared-with-nil shows the same in the terminal. Found a false positive? Report it.