github.com/Johnny2210/revive@v1.0.8-0.20210625134200-febf37ccd0f5/testdata/golint/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(...)) with 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 t.Error(fmt.Sprintf("something %d", x)) // MATCH /should replace t.Error(fmt.Sprintf(...)) with t.Errorf(...)/ 30 } 31 if x > 5 { 32 t.Error(g("blah")) // ok 33 } 34 if x > 4 { 35 t.Error("something else") // ok 36 } 37 return nil 38 } 39 40 func g(s string) string { return "prefix: " + s }