Skip to content

Commit

Permalink
lint: add test case to cover allowed errors.New(fmt.Sprintf()) cases
Browse files Browse the repository at this point in the history
Updates golang#350
  • Loading branch information
leonelquinteros committed Mar 5, 2018
1 parent 28f5755 commit 053e0ad
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions testdata/errorf-custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Test for allowed errors.New(fmt.Sprintf()) when a custom errors package is imported.

// Package foo ...
package foo

import (
"fmt"

"github.com/pkg/errors"
)

func f(x int) error {
if x > 10 {
return errors.New(fmt.Sprintf("something %d", x)) // OK
}
if x > 5 {
return errors.New(g("blah")) // OK
}
if x > 4 {
return errors.New("something else") // OK
}
return nil
}

func g(s string) string { return "prefix: " + s }

0 comments on commit 053e0ad

Please sign in to comment.