linters: add autofix for httpstatus
All checks were successful
CI / test (push) Successful in 33s

This commit is contained in:
2026-10-18 16:10:55 -07:00
parent 9f10798be1
commit f5b6076dce
4 changed files with 68 additions and 3 deletions

View File

@@ -2,9 +2,11 @@
package httpstatus
import (
"fmt"
"go/ast"
"go/constant"
"go/types"
"strconv"
"strings"
"golang.org/x/tools/go/analysis"
@@ -62,7 +64,19 @@ func NewAnalyzer(settings Settings) *analysis.Analyzer {
return
}
pass.Reportf(node.Pos(), "HTTP status code %d should use its integer literal", code)
pass.Report(analysis.Diagnostic{
Pos: node.Pos(),
End: node.End(),
Message: fmt.Sprintf("HTTP status code %d should use its integer literal", code),
SuggestedFixes: []analysis.SuggestedFix{{
Message: "Use the integer literal",
TextEdits: []analysis.TextEdit{{
Pos: node.Pos(),
End: node.End(),
NewText: []byte(strconv.Itoa(code)),
}},
}},
})
}
// Disallows sending non-typical response statuses