Repository navigation
Description
Summary
The new httpstatuscode linter (registered 36th in cmd/linters/main.go:72) decides whether an integer-literal comparison is an HTTP status comparison via isHTTPStatusContext (pkg/linters/httpstatuscode/httpstatuscode.go:173-195). That gate is a hardcoded allow-list of identifier/field spellings rather than a domain/type test, which produces both false negatives and false positives. The two branches are also inconsistent — the selector branch type-resolves to an integer, the identifier branch performs no type check at all.
Root cause
func isHTTPStatusContext(pass *analysis.Pass, expr ast.Expr) bool {
switch e := expr.(type) {
case *ast.Ident:
return e.Name == "status" || e.Name == "statusCode" // name-only, no type check
case *ast.SelectorExpr:
if e.Sel.Name != "StatusCode" { // only the field spelling "StatusCode"
return false
}
// ... type-resolves to integer (good)
}
return false
}Three spellings are accepted (status, statusCode, and field .StatusCode); everything else is rejected, and nothing about the value or type being an HTTP status is verified on the identifier path.
False negatives (coverage gap)
HTTP status codes held in any other-named variable or field escape entirely. The gap is visible in this repository:
pkg/cli/firewall_policy.go:56and:65declareStatus int(an HTTP status field). A directentry.Status == 200is not flagged, because the selector branch only accepts.StatusCode, not.Status. The code atfirewall_policy.go:236-241only gets linted because the author first copies it into a local namedstatus(status := entry.Status). Inline the field access and the diagnostic vanishes.pkg/cli/gateway_logs_timeline.go:99declaresHTTPStatus int // HTTP response status code— a field that can never be matched.- Common local spellings (
code,httpStatus,respStatus,sc,wantStatus,gotStatus) are all missed.
False positives
Any non-HTTP integer named status/statusCode (process/exit status, job-state enum, custom protocol code, state-machine value) compared against a literal in 100–599 is wrongly flagged — with a hard-asserting, misleading message ("use http.StatusX instead of magic HTTP status code N") and a wrong fix suggestion. The identifier branch does not confirm the operand's type the way the selector branch does. The testdata implicitly acknowledges this fragility: compareNonHTTP (testdata :49-54) stays silent only because the operand is named buildNumber — rename it to status and it becomes a false positive.
Why this matters
This is the recurring syntactic_match / pattern_set_too_narrow family (cf. #40243, #40244, #40581) applied to a brand-new linter. Because detection hinges on naming convention, the linter's effectiveness is coupled to how engineers happen to name variables, and its precision degrades silently as code is refactored (field-access → local-var changes behavior).
Recommendation
Replace spelling-based gating with type/context resolution, matching the rigor already present in the selector branch:
- Identifier path: resolve the operand's type via
pass.TypesInfoand confirm it is an integer; ideally also require an HTTP-related origin (assigned fromresp.StatusCode, compared againsthttp.Status*elsewhere, or a field/param whose declared type/name indicates HTTP). At minimum add the integer-type check the selector branch already performs, and broaden the accepted name set deliberately rather than the current two-name list. - Selector path: accept HTTP status fields named
Status/HTTPStatus(with the existing integer-type guard), not onlyStatusCode, so fields likeAuditLogEntry.Statusand theHTTPStatusfield are covered. - Add testdata for:
entry.Status == 200(field namedStatus), anHTTPStatusfield comparison, a non-HTTPstatus intenum that must stay silent, and an HTTP code in a differently-named local (e.g.code := resp.StatusCode; if code == 404).
Before / after intent
- Before:
entry.Status == 200silent;jobStatus == 200(non-HTTP, namedstatus) flagged. - After: HTTP status fields/locals flagged regardless of spelling; non-HTTP integers not coerced into HTTP diagnostics.
Validation checklist
-
entry.Status == 200(fieldStatus int, HTTP) is flagged. - A field
HTTPStatus intcomparison is flagged. - A non-HTTP
status int(state enum) compared to 200/404 is not flagged. - An HTTP code in a non-
status-named local is flagged. - Existing testdata +
firewall_policy.go/firewall_log.gotrue positives still pass.
Effort
Small–medium: single file (httpstatuscode.go) plus testdata. Mirror the type-resolution already in the selector branch and widen both name gates.
Evidence
pkg/linters/httpstatuscode/httpstatuscode.go:173-195(isHTTPStatusContext),:104-136(run).pkg/cli/firewall_policy.go:56,65,236-241;pkg/cli/gateway_logs_timeline.go:99.- Registered at
cmd/linters/main.go:72.
References:
Generated by 🤖 Sergo - Serena Go Expert · 226.5 AIC · ⌖ 13.7 AIC · ⊞ 5.9K · ◷
- expires on Jul 4, 2026, 9:17 PM UTC-08:00
Activity
github-actions commentedon Jun 28, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
github-actions commentedon Jul 5, 2026
This issue was automatically closed because it expired on 2026-07-05T05:17:29.217Z.