polyfloyd / go-errorlint

A source code linter that can be used to find code that will cause problems with Go's error wrapping scheme
MIT License
248 stars 19 forks source link

When argument repeated via explicit indexes in `fmt.Errorf`, fails error wrap check #21

Closed salkrr closed 2 years ago

salkrr commented 2 years ago

Examples:

func main() {
    fmt.Errorf("%[1]v %[1]v: %w", "value", errors.New("abc"))
}
func main() {
    fmt.Errorf("%[1]v: %[1]w", errors.New("abc"))
}

Linting fails with the error: non-wrapping format verb for fmt.Errorf. Use '%w' to format errors.

polyfloyd commented 2 years ago

Yup, that should be supported. Will investigate when I have time