fmt.Errorf is called with a constant message and nothing to format
What it finds
fmt.Errorf("connection closed") parses its format at every call only to find nothing to substitute; errors.New("connection closed") says the same and makes clear that no formatting happens. A % in the message, meant literally, also behaves differently: it must be doubled for Errorf and not for New.
The call must be Errorf of fmt, resolved through the imports, with a single argument that is a constant string of the file without %. When the file imports errors, the fix calls errors.New and is safe.
From the rule's source, errorf_without_arguments.rs.
package p import ( "errors" "fmt") var ( errClosed = fmt.Errorf("connection closed")tx0 reports: fmt.Errorf has nothing to format here errLimit = fmt.Errorf("limit of %d reached", 10) errPct = fmt.Errorf("100%% done") errNew = errors.New("timeout")) Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/go:errorf-without-arguments" = "warning"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:errorf-without-arguments] reason="..."tx0 explain tx0/go:errorf-without-arguments shows the same in the terminal. Found a false positive? Report it.