Skip to content

Commit

Permalink
bazel: set correct flags for printf analyzer
Browse files Browse the repository at this point in the history
Closes #80006.

Release note: None
Epic: CRDB-8349
  • Loading branch information
rickystewart committed Oct 28, 2022
1 parent 421aff1 commit 5144667
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 42 deletions.
3 changes: 3 additions & 0 deletions build/bazelutil/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
}
},
"printf": {
"analyzer_flags": {
"funcs": "ErrEvent,ErrEventf,Error,Errorf,ErrorfDepth,Event,Eventf,Fatal,Fatalf,FatalfDepth,Info,Infof,InfofDepth,AssertionFailedf,AssertionFailedWithDepthf,NewAssertionErrorWithWrappedErrf,DangerousStatementf,pgerror.New,pgerror.NewWithDepthf,pgerror.Newf,SetDetailf,SetHintf,Unimplemented,Unimplementedf,UnimplementedWithDepthf,UnimplementedWithIssueDetailf,UnimplementedWithIssuef,VEvent,VEventf,Warning,Warningf,WarningfDepth,Wrapf,WrapWithDepthf,redact.Fprint,redact.Fprintf,redact.Sprint,redact.Sprintf"
},
"only_files": {
"cockroach/pkg/.*$": "first-party code"
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/testutils/docker/single_node_docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ func cleanQueryResult(queryRes string) (string, error) {
r := regexp.MustCompile(`([\s\S]+)\n{3}Time:.+`)
res := r.FindStringSubmatch(formatted)
if len(res) < 2 {
return "", errors.Wrapf(errors.Newf("%s", queryRes), "cannot parse the query result: %#v")
return "", errors.Errorf("cannot parse the query result: %s", queryRes)
}
return res[1], nil

Expand Down
52 changes: 11 additions & 41 deletions pkg/testutils/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package lint
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"go/build"
"os"
Expand Down Expand Up @@ -2164,47 +2165,16 @@ func TestLint(t *testing.T) {
// A function may be a Printf or Print wrapper if its last argument is ...interface{}.
// If the next-to-last argument is a string, then this may be a Printf wrapper.
// Otherwise it may be a Print wrapper.
printfuncs := strings.Join([]string{
"ErrEvent",
"ErrEventf",
"Error",
"Errorf",
"ErrorfDepth",
"Event",
"Eventf",
"Fatal",
"Fatalf",
"FatalfDepth",
"Info",
"Infof",
"InfofDepth",
"AssertionFailedf",
"AssertionFailedWithDepthf",
"NewAssertionErrorWithWrappedErrf",
"DangerousStatementf",
"pgerror.New",
"pgerror.NewWithDepthf",
"pgerror.Newf",
"SetDetailf",
"SetHintf",
"Unimplemented",
"Unimplementedf",
"UnimplementedWithDepthf",
"UnimplementedWithIssueDetailf",
"UnimplementedWithIssuef",
"VEvent",
"VEventf",
"Warning",
"Warningf",
"WarningfDepth",
"Wrapf",
"WrapWithDepthf",
"redact.Fprint",
"redact.Fprintf",
"redact.Sprint",
"redact.Sprintf",
}, ",")

// Note we retrieve the list of printfuncs from nogo_config.json.
jsonFile, err := os.ReadFile(filepath.Join(crdb.Dir, "build", "bazelutil", "nogo_config.json"))
if err != nil {
t.Error(err)
}
var printSchema map[string]map[string]map[string]string
if err := json.Unmarshal(jsonFile, &printSchema); err != nil {
t.Error(err)
}
printfuncs := printSchema["printf"]["analyzer_flags"]["funcs"]
nakedGoroutineExceptions := `(` + strings.Join([]string{
`pkg/.*_test\.go`,
`pkg/acceptance/.*\.go`,
Expand Down

0 comments on commit 5144667

Please sign in to comment.