From 73e3500f0daa9d53b678bececc55c82277ee57db Mon Sep 17 00:00:00 2001 From: Noah S-C Date: Mon, 18 Dec 2023 16:06:19 +0000 Subject: [PATCH] bazel: nicer error message for forbidigo patterns (#59081) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- dev/linters/forbidigo/forbidigo.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dev/linters/forbidigo/forbidigo.go b/dev/linters/forbidigo/forbidigo.go index 7a9a84f2c21..b834d7dd0e3 100644 --- a/dev/linters/forbidigo/forbidigo.go +++ b/dev/linters/forbidigo/forbidigo.go @@ -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 {