Skip to content

Commit

Permalink
checkers/httpNoBody: warn on using "nil" instead of "http.NoBody" on …
Browse files Browse the repository at this point in the history
…(net/http/httptest).NewRequest (#1345)
  • Loading branch information
leonklingele committed May 19, 2023
1 parent 59f8a39 commit d97daec
Show file tree
Hide file tree
Showing 4 changed files with 669 additions and 643 deletions.
5 changes: 5 additions & 0 deletions checkers/rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func httpNoBody(m dsl.Matcher) {
Where(m["nil"].Text == "nil").
Suggest("http.NewRequestWithContext($ctx, $method, $url, http.NoBody)").
Report("http.NoBody should be preferred to the nil request body")

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

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

0 comments on commit d97daec

Please sign in to comment.