bazel: nicer error message for forbidigo patterns (#59081)

New output: `dev/linters/dbconn/dbconn.go:83:16: use of fmt.Errorf forbidden because “errors.Newf should be used instead” (forbidigo)`
Previous output: `dev/linters/dbconn/dbconn.go:83:16: use of fmt.Errorf forbidden by pattern ^fmt\.Errorf$ (forbidigo)`

## Test plan

Used `fmt.Errorf` in //dev/linters/dbconn` and ran bazel build on it
This commit is contained in:
Noah S-C 2023-12-18 16:06:19 +00:00 committed by GitHub
parent 6e3e54e86b
commit 73e3500f0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
package forbidigo
import (
"fmt"
"go/ast"
"github.com/ashanbrown/forbidigo/forbidigo"
@ -13,9 +14,11 @@ import (
// Analyzer is the analyzer nogo should use
var Analyzer = nolint.Wrap(analyzer.NewAnalyzer())
// defaultPatterns the patterns forbigigo should ban if they match
// defaultPatterns the patterns forbigigo should ban if they match.
// JSON based off the pattern struct:
// https://sourcegraph.com/github.com/ashanbrown/forbidigo@57bf5a72a4f5c3c28dce5a8aebb37a9be36bece7/-/blob/forbidigo/patterns.go?L13-29
var defaultPatterns = []string{
"^fmt\\.Errorf$", // Use errors.Newf instead
fmt.Sprintf(`{"p":"^fmt\\.Errorf$", "msg": "%s should be used instead"}`, "`errors.Newf`"),
}
var config = struct {