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

checkers: add At() for httpNoBody checker #1164

Merged
merged 1 commit into from Dec 7, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion checkers/checkers_test.go
Expand Up @@ -199,7 +199,7 @@ func TestExternal(t *testing.T) {
continue
}
if diff := cmp.Diff(want, have); diff != "" {
t.Errorf("%s output mismatches:\n%s", proj.Name(), diff)
t.Errorf("%s output mismatches (+have -want):\n%s", proj.Name(), diff)
continue
}
}
Expand Down
6 changes: 4 additions & 2 deletions checkers/rules/rules.go
Expand Up @@ -118,12 +118,14 @@ func httpNoBody(m dsl.Matcher) {
m.Match("http.NewRequest($method, $url, $nil)").
Where(m["nil"].Text == "nil").
Suggest("http.NewRequest($method, $url, http.NoBody)").
Report("http.NoBody should be preferred to the nil request body")
Report("http.NoBody should be preferred to the nil request body").
At(m["nil"])

m.Match("http.NewRequestWithContext($ctx, $method, $url, $nil)").
Where(m["nil"].Text == "nil").
Suggest("http.NewRequestWithContext($ctx, $method, $url, http.NoBody)").
Report("http.NoBody should be preferred to the nil request body")
Report("http.NoBody should be preferred to the nil request body").
At(m["nil"])
}

//doc:summary Detects expressions like []rune(s)[0] that may cause unwanted rune slice allocation
Expand Down