Skip to content

Commit 577e8ab

Browse files
feat: add lower HTTP method in issue (#36)
feat: add lower HTTP method in issue
1 parent af098fe commit 577e8ab

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

pkg/analyzer/analyzer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ func lookupFlag(pass *analysis.Pass, name string) bool {
168168
}
169169

170170
func checkHTTPMethod(pass *analysis.Pass, basicLit *ast.BasicLit) {
171-
currentVal := strings.ToUpper(getBasicLitValue(basicLit))
171+
currentVal := getBasicLitValue(basicLit)
172172

173-
if newVal, ok := mapping.HTTPMethod[currentVal]; ok {
173+
if newVal, ok := mapping.HTTPMethod[strings.ToUpper(currentVal)]; ok {
174174
report(pass, basicLit.Pos(), currentVal, newVal)
175175
}
176176
}

pkg/analyzer/internal/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func main() {
2424
template.New("template").
2525
Funcs(map[string]any{
2626
"quoteMeta": regexp.QuoteMeta,
27-
"lower": strings.ToLower,
27+
"toLower": strings.ToLower,
2828
}).
2929
ParseFS(templateDir, "template/*.tmpl"),
3030
)

pkg/analyzer/internal/template/test-issue32.go.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@ import "net/http"
66

77
var (
88
{{- range $key, $value := .Mapping }}
9-
_ = "{{ lower $key }}"
9+
_ = "{{ toLower $key }}"
1010
{{- end }}
1111
)
1212

1313
const (
1414
{{- range $key, $value := .Mapping }}
15-
_ = "{{ lower $key }}"
15+
_ = "{{ toLower $key }}"
1616
{{- end }}
1717
)
1818

1919
func _() {
2020
{{- range $key, $value := .Mapping }}
21-
_, _ = http.NewRequest("{{ lower $key }}", "", http.NoBody) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
21+
_, _ = http.NewRequest("{{ toLower $key }}", "", http.NoBody) // want `"{{ quoteMeta (toLower $key) }}" can be replaced by {{ quoteMeta $value }}`
2222
{{- end }}
2323
}
2424

2525
func _() {
2626
{{- range $key, $value := .Mapping }}
27-
_, _ = http.NewRequestWithContext(nil, "{{ lower $key }}", "", http.NoBody) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
27+
_, _ = http.NewRequestWithContext(nil, "{{ toLower $key }}", "", http.NoBody) // want `"{{ quoteMeta (toLower $key) }}" can be replaced by {{ quoteMeta $value }}`
2828
{{- end }}
2929
}
3030

3131
func _() {
3232
{{- range $key, $value := .Mapping }}
3333
_ = &http.Request{
34-
Method: "{{ lower $key }}", // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
34+
Method: "{{ toLower $key }}", // want `"{{ quoteMeta (toLower $key) }}" can be replaced by {{ quoteMeta $value }}`
3535
}
3636
{{- end }}
3737
}

pkg/analyzer/testdata/src/a/http/issue32.go

Lines changed: 27 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)