An HTTP status is written as a number instead of the constant net/http defines for it

tx0/go:http-status-literalstrictwarningstyle

What it finds

w.WriteHeader(404): net/http names every status code, as http.StatusNotFound, which reads as what it means and cannot be mistyped as another valid number.

Reported are integer literals of known status codes given to a method WriteHeader, as the code of http.Error or http.Redirect, in a file that imports net/http. The fix writes the constant, which has the same value, so it is safe when the file imports net/http under a name that can be used.

From the rule's source, http_status_literal.rs.

Example from the rule's tests
package p import "net/http" func handle(w http.ResponseWriter, r *http.Request) {	w.WriteHeader(404)tx0 reports: the status 404 has the name http.StatusNotFound	http.Error(w, "bad", 400)tx0 reports: the status 400 has the name http.StatusBadRequest	w.WriteHeader(http.StatusOK)	w.WriteHeader(299)}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:http-status-literal" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/go:http-status-literal] reason="..."

tx0 explain tx0/go:http-status-literal shows the same in the terminal. Found a false positive? Report it.