Skip to content

Commit

Permalink
fix: allow %T verb to not be wrapped
Browse files Browse the repository at this point in the history
- closes #81
  • Loading branch information
ehsundar authored and polyfloyd committed Nov 13, 2024
1 parent b458386 commit 6dafa09
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion errorlint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions errorlint/testdata/src/fmterrorf/fmterrorf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down
12 changes: 12 additions & 0 deletions errorlint/testdata/src/fmterrorf/fmterrorf.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down

0 comments on commit 6dafa09

Please sign in to comment.