linters: add httpstatus linter
This commit is contained in:
29
pkg/httpstatus/testdata/src/configured/configured.go
vendored
Normal file
29
pkg/httpstatus/testdata/src/configured/configured.go
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
package configured
|
||||
|
||||
import "net/http"
|
||||
|
||||
const created = http.StatusCreated // want `HTTP status code 201 should use its integer literal`
|
||||
const ok = http.StatusOK
|
||||
|
||||
func response(w http.ResponseWriter, r *http.Request, code int) {
|
||||
http.Error(w, "teapot", 418) // want `non-typical HTTP status code 418 is not allowed`
|
||||
http.Error(w, "created", 201)
|
||||
http.Error(w, "variable", code)
|
||||
|
||||
w.WriteHeader(200) // want `non-typical HTTP status code 200 is not allowed`
|
||||
w.WriteHeader(code)
|
||||
http.ResponseWriter.WriteHeader(w, 400) // want `non-typical HTTP status code 400 is not allowed`
|
||||
|
||||
http.NotFound(w, r)
|
||||
_, _ = w.Write([]byte("response"))
|
||||
http.Redirect(w, r, "/moved", 301)
|
||||
http.Redirect(w, r, "/created", http.StatusCreated) // want `HTTP status code 201 should use its integer literal`
|
||||
}
|
||||
|
||||
type unrelatedWriter struct{}
|
||||
|
||||
func (unrelatedWriter) WriteHeader(int) {}
|
||||
|
||||
func unrelated(writer unrelatedWriter) {
|
||||
writer.WriteHeader(418)
|
||||
}
|
||||
22
pkg/httpstatus/testdata/src/default/default.go
vendored
Normal file
22
pkg/httpstatus/testdata/src/default/default.go
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
package cases
|
||||
|
||||
import "net/http"
|
||||
|
||||
const ok = http.StatusOK // want `HTTP status code 200 should use its integer literal`
|
||||
const teapot = http.StatusTeapot
|
||||
|
||||
func response(w http.ResponseWriter, r *http.Request, code int) {
|
||||
_ = http.StatusNotFound // want `HTTP status code 404 should use its integer literal`
|
||||
|
||||
http.Error(w, "bad request", http.StatusBadRequest) // want `HTTP status code 400 should use its integer literal`
|
||||
http.Error(w, "teapot", http.StatusTeapot)
|
||||
http.Error(w, "created", 201)
|
||||
w.WriteHeader(http.StatusGatewayTimeout) // want `HTTP status code 504 should use its integer literal`
|
||||
w.WriteHeader(code)
|
||||
|
||||
http.NotFound(w, r)
|
||||
_, _ = w.Write([]byte("response"))
|
||||
|
||||
http.Redirect(w, r, "/login", http.StatusFound) // want `HTTP status code 302 should use its integer literal`
|
||||
http.Redirect(w, r, "/other", http.StatusMovedPermanently)
|
||||
}
|
||||
Reference in New Issue
Block a user