github.com/serversong/goreporter@v0.0.0-20200325104552-3cfaf44fd178/linters/golint/testdata/errorf.go (about) 1 // Test for not using fmt.Errorf or testing.Errorf. 2 3 // Package foo ... 4 package foo 5 6 import ( 7 "errors" 8 "fmt" 9 "testing" 10 ) 11 12 func f(x int) error { 13 if x > 10 { 14 return errors.New(fmt.Sprintf("something %d", x)) // MATCH /should replace.*errors\.New\(fmt\.Sprintf\(\.\.\.\)\).*fmt\.Errorf\(\.\.\.\)/ -> ` return fmt.Errorf("something %d", x)` 15 } 16 if x > 5 { 17 return errors.New(g("blah")) // ok 18 } 19 if x > 4 { 20 return errors.New("something else") // ok 21 } 22 return nil 23 } 24 25 // TestF is a dummy test 26 func TestF(t *testing.T) error { 27 x := 1 28 if x > 10 { 29 return t.Error(fmt.Sprintf("something %d", x)) // MATCH /should replace.*t\.Error\(fmt\.Sprintf\(\.\.\.\)\).*t\.Errorf\(\.\.\.\)/ 30 } 31 if x > 5 { 32 return t.Error(g("blah")) // ok 33 } 34 if x > 4 { 35 return t.Error("something else") // ok 36 } 37 return nil 38 } 39 40 func g(s string) string { return "prefix: " + s }