diff --git a/errorlint/lint.go b/errorlint/lint.go index 9ac465c..ed3dd0d 100644 --- a/errorlint/lint.go +++ b/errorlint/lint.go @@ -82,7 +82,7 @@ func LintFmtErrorfCalls(fset *token.FileSet, info types.Info, multipleWraps bool argIndex++ } - if verb.format == "w" { + if verb.format == "w" || verb.format == "T" { continue } if argIndex-1 >= len(args) { diff --git a/errorlint/testdata/src/fmterrorf/fmterrorf.go b/errorlint/testdata/src/fmterrorf/fmterrorf.go index 90e4153..916cc0b 100644 --- a/errorlint/testdata/src/fmterrorf/fmterrorf.go +++ b/errorlint/testdata/src/fmterrorf/fmterrorf.go @@ -15,6 +15,11 @@ func NonWrappingVerb() error { return fmt.Errorf("error: %v", err) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" } +func NonWrappingTVerb() error { + err := errors.New("oops") + return fmt.Errorf("error: %T", err) +} + func DoubleNonWrappingVerb() error { err := errors.New("oops") return fmt.Errorf("%v %v", err, err) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" @@ -27,6 +32,13 @@ func ErrorOneWrap() error { return fmt.Errorf("%v, %w, %v", err1, err2, err3) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" } +func ValidNonWrappingTVerb() error { + err1 := errors.New("oops1") + err2 := errors.New("oops2") + err3 := errors.New("oops3") + return fmt.Errorf("%w, %T, %w", err1, err2, err3) +} + func ErrorMultipleWraps() error { err1 := errors.New("oops1") err2 := errors.New("oops2") diff --git a/errorlint/testdata/src/fmterrorf/fmterrorf.go.golden b/errorlint/testdata/src/fmterrorf/fmterrorf.go.golden index 1b8f932..1bd0719 100644 --- a/errorlint/testdata/src/fmterrorf/fmterrorf.go.golden +++ b/errorlint/testdata/src/fmterrorf/fmterrorf.go.golden @@ -15,6 +15,11 @@ func NonWrappingVerb() error { return fmt.Errorf("error: %w", err) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" } +func NonWrappingTVerb() error { + err := errors.New("oops") + return fmt.Errorf("error: %T", err) +} + func DoubleNonWrappingVerb() error { err := errors.New("oops") return fmt.Errorf("%w %w", err, err) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" @@ -27,6 +32,13 @@ func ErrorOneWrap() error { return fmt.Errorf("%w, %w, %w", err1, err2, err3) // want "non-wrapping format verb for fmt.Errorf. Use `%w` to format errors" } +func ValidNonWrappingTVerb() error { + err1 := errors.New("oops1") + err2 := errors.New("oops2") + err3 := errors.New("oops3") + return fmt.Errorf("%w, %T, %w", err1, err2, err3) +} + func ErrorMultipleWraps() error { err1 := errors.New("oops1") err2 := errors.New("oops2")