Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bazel: set correct flags for printf analyzer #90812

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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