errorf
What it does
Section titled “What it does”errors.New(fmt.Sprintf(...)) is fmt.Errorf(...) (the t.Error(fmt.Sprintf(...)) form on a *testing.T needs types and is not read).
Why it matters
Section titled “Why it matters”fmt.Errorf formats and wraps (%w) in one call, and go vet knows its format string. errors.New(fmt.Sprintf(...)) formats a string first and then wraps it in an error, which is longer and cannot wrap another error with %w.
To fix, call fmt.Errorf with the same format and arguments.
Example
Section titled “Example”package a
func f() { _ = errors.New(fmt.Sprintf("x %d", 1)) _ = errors.New(fmt.Sprint("x"), 1) _ = errors.New("x") _ = fmt.Errorf("x %d", 1)...Configuration
Section titled “Configuration”go: lint: rules: errorf: warn # off (default), warn, errorEnabled by the presets: go/revive.
Suppress one line with sudsy-disable-next-line errorf in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| revive | errorf |
full |