From 9b7cae20c4db83bf991a4fcc1f66d34d6bb299fa Mon Sep 17 00:00:00 2001 From: Sasha Melentyev Date: Fri, 5 Aug 2022 12:46:57 +0300 Subject: [PATCH] feat: add gen --- .github/workflows/ci.yaml | 3 - go.mod | 4 +- go.sum | 8 +- main.go | 2 + pkg/analyzer/analyzer.go | 16 +- pkg/analyzer/internal/gen.go | 107 +++ .../{ => internal/mapping}/mapping.go | 16 +- .../internal/template/test-httpmethod.go.tmpl | 37 + .../template/test-httpstatuscode.go.tmpl | 31 + .../internal/template/test-template.go.tmpl | 33 + pkg/analyzer/testdata/src/a/crypto/crypto.go | 199 ++++- pkg/analyzer/testdata/src/a/http/http.go | 45 - pkg/analyzer/testdata/src/a/http/method.go | 83 ++ .../testdata/src/a/http/statuscode.go | 817 ++++++++++++++++++ pkg/analyzer/testdata/src/a/rpc/rpc.go | 32 +- pkg/analyzer/testdata/src/a/time/layout.go | 145 ++++ pkg/analyzer/testdata/src/a/time/month.go | 113 +++ pkg/analyzer/testdata/src/a/time/time.go | 147 ---- pkg/analyzer/testdata/src/a/time/weekday.go | 73 ++ 19 files changed, 1651 insertions(+), 260 deletions(-) create mode 100644 pkg/analyzer/internal/gen.go rename pkg/analyzer/{ => internal/mapping}/mapping.go (96%) create mode 100644 pkg/analyzer/internal/template/test-httpmethod.go.tmpl create mode 100644 pkg/analyzer/internal/template/test-httpstatuscode.go.tmpl create mode 100644 pkg/analyzer/internal/template/test-template.go.tmpl delete mode 100644 pkg/analyzer/testdata/src/a/http/http.go create mode 100644 pkg/analyzer/testdata/src/a/http/method.go create mode 100644 pkg/analyzer/testdata/src/a/http/statuscode.go create mode 100644 pkg/analyzer/testdata/src/a/time/layout.go create mode 100644 pkg/analyzer/testdata/src/a/time/month.go delete mode 100644 pkg/analyzer/testdata/src/a/time/time.go create mode 100644 pkg/analyzer/testdata/src/a/time/weekday.go diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 44267a4..cf43d9c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -34,9 +34,6 @@ jobs: - name: Go Mod run: go mod download - - name: Go Generate - run: go generate ./... && git diff --exit-code - - name: Go Build run: go build -v ./... diff --git a/go.mod b/go.mod index b167696..097d4a3 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,9 @@ module github.com/sashamelentyev/usestdlibvars go 1.19 -require golang.org/x/tools v0.1.11 +require golang.org/x/tools v0.1.12 require ( golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect - golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect + golang.org/x/sys v0.0.0-20220804214406-8e32c043e418 // indirect ) diff --git a/go.sum b/go.sum index 7ec6d5e..044f4d3 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/tools v0.1.11 h1:loJ25fNOEhSXfHrpoGj91eCUThwdNX6u24rO1xnNteY= -golang.org/x/tools v0.1.11/go.mod h1:SgwaegtQh8clINPpECJMqnxLv9I09HLqnW3RMqW0CA4= +golang.org/x/sys v0.0.0-20220804214406-8e32c043e418 h1:9vYwv7OjYaky/tlAeD7C4oC9EsPTlaFl1H2jS++V+ME= +golang.org/x/sys v0.0.0-20220804214406-8e32c043e418/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/main.go b/main.go index 30fe81c..b8cde93 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,8 @@ import ( "github.com/sashamelentyev/usestdlibvars/pkg/analyzer" ) +//go:generate go run pkg/analyzer/internal/gen.go + func main() { singlechecker.Main(analyzer.New()) } diff --git a/pkg/analyzer/analyzer.go b/pkg/analyzer/analyzer.go index f892f78..d3ef70d 100644 --- a/pkg/analyzer/analyzer.go +++ b/pkg/analyzer/analyzer.go @@ -9,6 +9,8 @@ import ( "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/analysis/passes/inspect" "golang.org/x/tools/go/ast/inspector" + + "github.com/sashamelentyev/usestdlibvars/pkg/analyzer/internal/mapping" ) const ( @@ -158,7 +160,7 @@ func lookupFlag(pass *analysis.Pass, name string) bool { func checkHTTPMethod(pass *analysis.Pass, basicLit *ast.BasicLit) { currentVal := getBasicLitValue(basicLit) - if newVal, ok := httpMethod[currentVal]; ok { + if newVal, ok := mapping.HTTPMethod[currentVal]; ok { report(pass, basicLit.Pos(), currentVal, newVal) } } @@ -166,37 +168,37 @@ func checkHTTPMethod(pass *analysis.Pass, basicLit *ast.BasicLit) { func checkHTTPStatusCode(pass *analysis.Pass, basicLit *ast.BasicLit) { currentVal := getBasicLitValue(basicLit) - if newVal, ok := httpStatusCode[currentVal]; ok { + if newVal, ok := mapping.HTTPStatusCode[currentVal]; ok { report(pass, basicLit.Pos(), currentVal, newVal) } } func checkTimeWeekday(pass *analysis.Pass, pos token.Pos, currentVal string) { - if newVal, ok := timeWeekday[currentVal]; ok { + if newVal, ok := mapping.TimeWeekday[currentVal]; ok { report(pass, pos, currentVal, newVal) } } func checkTimeMonth(pass *analysis.Pass, pos token.Pos, currentVal string) { - if newVal, ok := timeMonth[currentVal]; ok { + if newVal, ok := mapping.TimeMonth[currentVal]; ok { report(pass, pos, currentVal, newVal) } } func checkTimeLayout(pass *analysis.Pass, pos token.Pos, currentVal string) { - if newVal, ok := timeLayout[currentVal]; ok { + if newVal, ok := mapping.TimeLayout[currentVal]; ok { report(pass, pos, currentVal, newVal) } } func checkCryptoHash(pass *analysis.Pass, pos token.Pos, currentVal string) { - if newVal, ok := cryptoHash[currentVal]; ok { + if newVal, ok := mapping.CryptoHash[currentVal]; ok { report(pass, pos, currentVal, newVal) } } func checkDefaultRPCPath(pass *analysis.Pass, pos token.Pos, currentVal string) { - if newVal, ok := defaultRPCPath[currentVal]; ok { + if newVal, ok := mapping.DefaultRPCPath[currentVal]; ok { report(pass, pos, currentVal, newVal) } } diff --git a/pkg/analyzer/internal/gen.go b/pkg/analyzer/internal/gen.go new file mode 100644 index 0000000..3a99322 --- /dev/null +++ b/pkg/analyzer/internal/gen.go @@ -0,0 +1,107 @@ +//go:build ignore +// +build ignore + +package main + +import ( + "bytes" + "embed" + "go/format" + "log" + "os" + "regexp" + "text/template" + + "github.com/sashamelentyev/usestdlibvars/pkg/analyzer/internal/mapping" +) + +//go:embed template/* +var templateDir embed.FS + +func main() { + t := template.Must( + template.New("template"). + Funcs(map[string]any{"quoteMeta": regexp.QuoteMeta}). + ParseFS(templateDir, "template/*.tmpl"), + ) + + operations := []struct { + mapping map[string]string + packageName string + templateName string + fileName string + }{ + { + mapping: mapping.CryptoHash, + packageName: "crypto_test", + templateName: "test-template.go.tmpl", + fileName: "pkg/analyzer/testdata/src/a/crypto/crypto.go", + }, + { + mapping: mapping.HTTPMethod, + packageName: "http_test", + templateName: "test-httpmethod.go.tmpl", + fileName: "pkg/analyzer/testdata/src/a/http/method.go", + }, + { + mapping: mapping.HTTPStatusCode, + packageName: "http_test", + templateName: "test-httpstatuscode.go.tmpl", + fileName: "pkg/analyzer/testdata/src/a/http/statuscode.go", + }, + { + mapping: mapping.DefaultRPCPath, + packageName: "rpc_test", + templateName: "test-template.go.tmpl", + fileName: "pkg/analyzer/testdata/src/a/rpc/rpc.go", + }, + { + mapping: mapping.TimeWeekday, + packageName: "time_test", + templateName: "test-template.go.tmpl", + fileName: "pkg/analyzer/testdata/src/a/time/weekday.go", + }, + { + mapping: mapping.TimeMonth, + packageName: "time_test", + templateName: "test-template.go.tmpl", + fileName: "pkg/analyzer/testdata/src/a/time/month.go", + }, + { + mapping: mapping.TimeLayout, + packageName: "time_test", + templateName: "test-template.go.tmpl", + fileName: "pkg/analyzer/testdata/src/a/time/layout.go", + }, + } + + for _, operation := range operations { + data := map[string]any{ + "PackageName": operation.packageName, + "Mapping": operation.mapping, + } + + if err := execute(t, operation.templateName, data, operation.fileName); err != nil { + log.Fatal(err) + } + } +} + +func execute(t *template.Template, templateName string, data any, fileName string) error { + var builder bytes.Buffer + + if err := t.ExecuteTemplate(&builder, templateName, data); err != nil { + return err + } + + sourceData, err := format.Source(builder.Bytes()) + if err != nil { + return err + } + + if err := os.WriteFile(fileName, sourceData, os.ModePerm); err != nil { + return err + } + + return nil +} diff --git a/pkg/analyzer/mapping.go b/pkg/analyzer/internal/mapping/mapping.go similarity index 96% rename from pkg/analyzer/mapping.go rename to pkg/analyzer/internal/mapping/mapping.go index f32bf61..56fae1b 100644 --- a/pkg/analyzer/mapping.go +++ b/pkg/analyzer/internal/mapping/mapping.go @@ -1,4 +1,4 @@ -package analyzer +package mapping import ( "crypto" @@ -8,7 +8,7 @@ import ( "time" ) -var cryptoHash = map[string]string{ +var CryptoHash = map[string]string{ crypto.MD4.String(): "crypto.MD4.String()", crypto.MD5.String(): "crypto.MD5.String()", crypto.SHA1.String(): "crypto.SHA1.String()", @@ -30,7 +30,7 @@ var cryptoHash = map[string]string{ crypto.BLAKE2b_512.String(): "crypto.BLAKE2b_512.String()", } -var httpMethod = map[string]string{ +var HTTPMethod = map[string]string{ http.MethodGet: "http.MethodGet", http.MethodHead: "http.MethodHead", http.MethodPost: "http.MethodPost", @@ -42,7 +42,7 @@ var httpMethod = map[string]string{ http.MethodTrace: "http.MethodTrace", } -var httpStatusCode = map[string]string{ +var HTTPStatusCode = map[string]string{ strconv.Itoa(http.StatusContinue): "http.StatusContinue", strconv.Itoa(http.StatusSwitchingProtocols): "http.StatusSwitchingProtocols", strconv.Itoa(http.StatusProcessing): "http.StatusProcessing", @@ -111,12 +111,12 @@ var httpStatusCode = map[string]string{ strconv.Itoa(http.StatusNetworkAuthenticationRequired): "http.StatusNetworkAuthenticationRequired", } -var defaultRPCPath = map[string]string{ +var DefaultRPCPath = map[string]string{ rpc.DefaultRPCPath: "rpc.DefaultRPCPath", rpc.DefaultDebugPath: "rpc.DefaultDebugPath", } -var timeWeekday = map[string]string{ +var TimeWeekday = map[string]string{ time.Sunday.String(): "time.Sunday.String()", time.Monday.String(): "time.Monday.String()", time.Tuesday.String(): "time.Tuesday.String()", @@ -126,7 +126,7 @@ var timeWeekday = map[string]string{ time.Saturday.String(): "time.Saturday.String()", } -var timeMonth = map[string]string{ +var TimeMonth = map[string]string{ time.January.String(): "time.January.String()", time.February.String(): "time.February.String()", time.March.String(): "time.March.String()", @@ -141,7 +141,7 @@ var timeMonth = map[string]string{ time.December.String(): "time.December.String()", } -var timeLayout = map[string]string{ +var TimeLayout = map[string]string{ time.Layout: "time.Layout", time.ANSIC: "time.ANSIC", time.UnixDate: "time.UnixDate", diff --git a/pkg/analyzer/internal/template/test-httpmethod.go.tmpl b/pkg/analyzer/internal/template/test-httpmethod.go.tmpl new file mode 100644 index 0000000..f2229d2 --- /dev/null +++ b/pkg/analyzer/internal/template/test-httpmethod.go.tmpl @@ -0,0 +1,37 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package {{ .PackageName }} + +import "net/http" + +var ( +{{- range $key, $value := .Mapping }} + _ = "{{ $key }}" +{{- end }} +) + +const ( +{{- range $key, $value := .Mapping }} + _ = "{{ $key }}" +{{- end }} +) + +func _() { +{{- range $key, $value := .Mapping }} + _, _ = http.NewRequest("{{ $key }}", "", nil) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}` +{{- end }} +} + +func _() { +{{- range $key, $value := .Mapping }} + _, _ = http.NewRequestWithContext(nil, "{{ $key }}", "", nil) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}` +{{- end }} +} + +func _() { +{{- range $key, $value := .Mapping }} + _ = &http.Request{ + Method: "{{ $key }}", // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}` + } +{{- end }} +} diff --git a/pkg/analyzer/internal/template/test-httpstatuscode.go.tmpl b/pkg/analyzer/internal/template/test-httpstatuscode.go.tmpl new file mode 100644 index 0000000..f5144cd --- /dev/null +++ b/pkg/analyzer/internal/template/test-httpstatuscode.go.tmpl @@ -0,0 +1,31 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package {{ .PackageName }} + +import "net/http" + +var ( +{{- range $key, $value := .Mapping }} + _ = {{ $key }} +{{- end }} +) + +const ( +{{- range $key, $value := .Mapping }} + _ = {{ $key }} +{{- end }} +) +{{ range $key, $value := .Mapping }} +func _() { + var w http.ResponseWriter + w.WriteHeader({{ $key }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}` +} +{{ end -}} + +{{ range $key, $value := .Mapping }} +func _() { + _ = &http.Response{ + StatusCode: {{ $key }}, // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}` + } +} +{{ end -}} diff --git a/pkg/analyzer/internal/template/test-template.go.tmpl b/pkg/analyzer/internal/template/test-template.go.tmpl new file mode 100644 index 0000000..3a612ef --- /dev/null +++ b/pkg/analyzer/internal/template/test-template.go.tmpl @@ -0,0 +1,33 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package {{ .PackageName }} + +import "fmt" + +var ( +{{- range $key, $value := .Mapping }} + _ = "{{ $key }}" // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}` +{{- end }} +) + +const ( +{{- range $key, $value := .Mapping }} + _ = "{{ $key }}" // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}` +{{- end }} +) + +func _() { +{{- range $key, $value := .Mapping }} + _ = func(s string)string{return s}("{{ $key }}") // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}` + _ = func(s string)string{return s}("text before key {{ $key }}") + _ = func(s string)string{return s}("{{ $key }} text after key") +{{- end }} +} + +func _() { +{{- range $key, $value := .Mapping }} + _ = fmt.Sprint("{{ $key }}") // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}` + _ = fmt.Sprint("text before key {{ $key }}") + _ = fmt.Sprint("{{ $key }} text after key") +{{- end }} +} diff --git a/pkg/analyzer/testdata/src/a/crypto/crypto.go b/pkg/analyzer/testdata/src/a/crypto/crypto.go index d36add6..8308319 100644 --- a/pkg/analyzer/testdata/src/a/crypto/crypto.go +++ b/pkg/analyzer/testdata/src/a/crypto/crypto.go @@ -1,52 +1,169 @@ -package crypto +// Code generated by usestdlibvars, DO NOT EDIT. + +package crypto_test import "fmt" var ( - _ = "MD4" // want `"MD4" can be replaced by crypto.MD4.String\(\)` - _ = "MD5" // want `"MD5" can be replaced by crypto.MD5.String\(\)` - _ = "SHA-1" // want `"SHA-1" can be replaced by crypto.SHA1.String\(\)` - _ = "SHA-224" // want `"SHA-224" can be replaced by crypto.SHA224.String\(\)` - _ = "SHA-256" // want `"SHA-256" can be replaced by crypto.SHA256.String\(\)` - _ = "SHA-384" // want `"SHA-384" can be replaced by crypto.SHA384.String\(\)` - _ = "SHA-512" // want `"SHA-512" can be replaced by crypto.SHA512.String\(\)` - _ = "MD5+SHA1" // want `"MD5\+SHA1" can be replaced by crypto.MD5SHA1.String\(\)` - _ = "RIPEMD-160" // want `"RIPEMD-160" can be replaced by crypto.RIPEMD160.String\(\)` - _ = "SHA3-224" // want `"SHA3-224" can be replaced by crypto.SHA3_224.String\(\)` - _ = "SHA3-256" // want `"SHA3-256" can be replaced by crypto.SHA3_256.String\(\)` - _ = "SHA3-384" // want `"SHA3-384" can be replaced by crypto.SHA3_384.String\(\)` - _ = "SHA3-512" // want `"SHA3-512" can be replaced by crypto.SHA3_512.String\(\)` - _ = "SHA-512/224" // want `"SHA-512/224" can be replaced by crypto.SHA512_224.String\(\)` - _ = "SHA-512/256" // want `"SHA-512/256" can be replaced by crypto.SHA512_256.String\(\)` - _ = "BLAKE2s-256" // want `"BLAKE2s-256" can be replaced by crypto.BLAKE2s_256.String\(\)` - _ = "BLAKE2b-256" // want `"BLAKE2b-256" can be replaced by crypto.BLAKE2b_256.String\(\)` - _ = "BLAKE2b-384" // want `"BLAKE2b-384" can be replaced by crypto.BLAKE2b_384.String\(\)` - _ = "BLAKE2b-512" // want `"BLAKE2b-512" can be replaced by crypto.BLAKE2b_512.String\(\)` + _ = "BLAKE2b-256" // want `"BLAKE2b-256" can be replaced by crypto\.BLAKE2b_256\.String\(\)` + _ = "BLAKE2b-384" // want `"BLAKE2b-384" can be replaced by crypto\.BLAKE2b_384\.String\(\)` + _ = "BLAKE2b-512" // want `"BLAKE2b-512" can be replaced by crypto\.BLAKE2b_512\.String\(\)` + _ = "BLAKE2s-256" // want `"BLAKE2s-256" can be replaced by crypto\.BLAKE2s_256\.String\(\)` + _ = "MD4" // want `"MD4" can be replaced by crypto\.MD4\.String\(\)` + _ = "MD5" // want `"MD5" can be replaced by crypto\.MD5\.String\(\)` + _ = "MD5+SHA1" // want `"MD5\+SHA1" can be replaced by crypto\.MD5SHA1\.String\(\)` + _ = "RIPEMD-160" // want `"RIPEMD-160" can be replaced by crypto\.RIPEMD160\.String\(\)` + _ = "SHA-1" // want `"SHA-1" can be replaced by crypto\.SHA1\.String\(\)` + _ = "SHA-224" // want `"SHA-224" can be replaced by crypto\.SHA224\.String\(\)` + _ = "SHA-256" // want `"SHA-256" can be replaced by crypto\.SHA256\.String\(\)` + _ = "SHA-384" // want `"SHA-384" can be replaced by crypto\.SHA384\.String\(\)` + _ = "SHA-512" // want `"SHA-512" can be replaced by crypto\.SHA512\.String\(\)` + _ = "SHA-512/224" // want `"SHA-512/224" can be replaced by crypto\.SHA512_224\.String\(\)` + _ = "SHA-512/256" // want `"SHA-512/256" can be replaced by crypto\.SHA512_256\.String\(\)` + _ = "SHA3-224" // want `"SHA3-224" can be replaced by crypto\.SHA3_224\.String\(\)` + _ = "SHA3-256" // want `"SHA3-256" can be replaced by crypto\.SHA3_256\.String\(\)` + _ = "SHA3-384" // want `"SHA3-384" can be replaced by crypto\.SHA3_384\.String\(\)` + _ = "SHA3-512" // want `"SHA3-512" can be replaced by crypto\.SHA3_512\.String\(\)` ) const ( - _ = "MD4" // want `"MD4" can be replaced by crypto.MD4.String\(\)` - _ = "MD5" // want `"MD5" can be replaced by crypto.MD5.String\(\)` - _ = "SHA-1" // want `"SHA-1" can be replaced by crypto.SHA1.String\(\)` - _ = "SHA-224" // want `"SHA-224" can be replaced by crypto.SHA224.String\(\)` - _ = "SHA-256" // want `"SHA-256" can be replaced by crypto.SHA256.String\(\)` - _ = "SHA-384" // want `"SHA-384" can be replaced by crypto.SHA384.String\(\)` - _ = "SHA-512" // want `"SHA-512" can be replaced by crypto.SHA512.String\(\)` - _ = "MD5+SHA1" // want `"MD5\+SHA1" can be replaced by crypto.MD5SHA1.String\(\)` - _ = "RIPEMD-160" // want `"RIPEMD-160" can be replaced by crypto.RIPEMD160.String\(\)` - _ = "SHA3-224" // want `"SHA3-224" can be replaced by crypto.SHA3_224.String\(\)` - _ = "SHA3-256" // want `"SHA3-256" can be replaced by crypto.SHA3_256.String\(\)` - _ = "SHA3-384" // want `"SHA3-384" can be replaced by crypto.SHA3_384.String\(\)` - _ = "SHA3-512" // want `"SHA3-512" can be replaced by crypto.SHA3_512.String\(\)` - _ = "SHA-512/224" // want `"SHA-512/224" can be replaced by crypto.SHA512_224.String\(\)` - _ = "SHA-512/256" // want `"SHA-512/256" can be replaced by crypto.SHA512_256.String\(\)` - _ = "BLAKE2s-256" // want `"BLAKE2s-256" can be replaced by crypto.BLAKE2s_256.String\(\)` - _ = "BLAKE2b-256" // want `"BLAKE2b-256" can be replaced by crypto.BLAKE2b_256.String\(\)` - _ = "BLAKE2b-384" // want `"BLAKE2b-384" can be replaced by crypto.BLAKE2b_384.String\(\)` - _ = "BLAKE2b-512" // want `"BLAKE2b-512" can be replaced by crypto.BLAKE2b_512.String\(\)` + _ = "BLAKE2b-256" // want `"BLAKE2b-256" can be replaced by crypto\.BLAKE2b_256\.String\(\)` + _ = "BLAKE2b-384" // want `"BLAKE2b-384" can be replaced by crypto\.BLAKE2b_384\.String\(\)` + _ = "BLAKE2b-512" // want `"BLAKE2b-512" can be replaced by crypto\.BLAKE2b_512\.String\(\)` + _ = "BLAKE2s-256" // want `"BLAKE2s-256" can be replaced by crypto\.BLAKE2s_256\.String\(\)` + _ = "MD4" // want `"MD4" can be replaced by crypto\.MD4\.String\(\)` + _ = "MD5" // want `"MD5" can be replaced by crypto\.MD5\.String\(\)` + _ = "MD5+SHA1" // want `"MD5\+SHA1" can be replaced by crypto\.MD5SHA1\.String\(\)` + _ = "RIPEMD-160" // want `"RIPEMD-160" can be replaced by crypto\.RIPEMD160\.String\(\)` + _ = "SHA-1" // want `"SHA-1" can be replaced by crypto\.SHA1\.String\(\)` + _ = "SHA-224" // want `"SHA-224" can be replaced by crypto\.SHA224\.String\(\)` + _ = "SHA-256" // want `"SHA-256" can be replaced by crypto\.SHA256\.String\(\)` + _ = "SHA-384" // want `"SHA-384" can be replaced by crypto\.SHA384\.String\(\)` + _ = "SHA-512" // want `"SHA-512" can be replaced by crypto\.SHA512\.String\(\)` + _ = "SHA-512/224" // want `"SHA-512/224" can be replaced by crypto\.SHA512_224\.String\(\)` + _ = "SHA-512/256" // want `"SHA-512/256" can be replaced by crypto\.SHA512_256\.String\(\)` + _ = "SHA3-224" // want `"SHA3-224" can be replaced by crypto\.SHA3_224\.String\(\)` + _ = "SHA3-256" // want `"SHA3-256" can be replaced by crypto\.SHA3_256\.String\(\)` + _ = "SHA3-384" // want `"SHA3-384" can be replaced by crypto\.SHA3_384\.String\(\)` + _ = "SHA3-512" // want `"SHA3-512" can be replaced by crypto\.SHA3_512\.String\(\)` ) func _() { - _ = fmt.Sprint("MD4") // want `"MD4" can be replaced by crypto.MD4.String\(\)` - _ = fmt.Sprint("MD4 is cryptographic hash function") + _ = func(s string) string { return s }("BLAKE2b-256") // want `"BLAKE2b-256" can be replaced by crypto\.BLAKE2b_256\.String\(\)` + _ = func(s string) string { return s }("text before key BLAKE2b-256") + _ = func(s string) string { return s }("BLAKE2b-256 text after key") + _ = func(s string) string { return s }("BLAKE2b-384") // want `"BLAKE2b-384" can be replaced by crypto\.BLAKE2b_384\.String\(\)` + _ = func(s string) string { return s }("text before key BLAKE2b-384") + _ = func(s string) string { return s }("BLAKE2b-384 text after key") + _ = func(s string) string { return s }("BLAKE2b-512") // want `"BLAKE2b-512" can be replaced by crypto\.BLAKE2b_512\.String\(\)` + _ = func(s string) string { return s }("text before key BLAKE2b-512") + _ = func(s string) string { return s }("BLAKE2b-512 text after key") + _ = func(s string) string { return s }("BLAKE2s-256") // want `"BLAKE2s-256" can be replaced by crypto\.BLAKE2s_256\.String\(\)` + _ = func(s string) string { return s }("text before key BLAKE2s-256") + _ = func(s string) string { return s }("BLAKE2s-256 text after key") + _ = func(s string) string { return s }("MD4") // want `"MD4" can be replaced by crypto\.MD4\.String\(\)` + _ = func(s string) string { return s }("text before key MD4") + _ = func(s string) string { return s }("MD4 text after key") + _ = func(s string) string { return s }("MD5") // want `"MD5" can be replaced by crypto\.MD5\.String\(\)` + _ = func(s string) string { return s }("text before key MD5") + _ = func(s string) string { return s }("MD5 text after key") + _ = func(s string) string { return s }("MD5+SHA1") // want `"MD5\+SHA1" can be replaced by crypto\.MD5SHA1\.String\(\)` + _ = func(s string) string { return s }("text before key MD5+SHA1") + _ = func(s string) string { return s }("MD5+SHA1 text after key") + _ = func(s string) string { return s }("RIPEMD-160") // want `"RIPEMD-160" can be replaced by crypto\.RIPEMD160\.String\(\)` + _ = func(s string) string { return s }("text before key RIPEMD-160") + _ = func(s string) string { return s }("RIPEMD-160 text after key") + _ = func(s string) string { return s }("SHA-1") // want `"SHA-1" can be replaced by crypto\.SHA1\.String\(\)` + _ = func(s string) string { return s }("text before key SHA-1") + _ = func(s string) string { return s }("SHA-1 text after key") + _ = func(s string) string { return s }("SHA-224") // want `"SHA-224" can be replaced by crypto\.SHA224\.String\(\)` + _ = func(s string) string { return s }("text before key SHA-224") + _ = func(s string) string { return s }("SHA-224 text after key") + _ = func(s string) string { return s }("SHA-256") // want `"SHA-256" can be replaced by crypto\.SHA256\.String\(\)` + _ = func(s string) string { return s }("text before key SHA-256") + _ = func(s string) string { return s }("SHA-256 text after key") + _ = func(s string) string { return s }("SHA-384") // want `"SHA-384" can be replaced by crypto\.SHA384\.String\(\)` + _ = func(s string) string { return s }("text before key SHA-384") + _ = func(s string) string { return s }("SHA-384 text after key") + _ = func(s string) string { return s }("SHA-512") // want `"SHA-512" can be replaced by crypto\.SHA512\.String\(\)` + _ = func(s string) string { return s }("text before key SHA-512") + _ = func(s string) string { return s }("SHA-512 text after key") + _ = func(s string) string { return s }("SHA-512/224") // want `"SHA-512/224" can be replaced by crypto\.SHA512_224\.String\(\)` + _ = func(s string) string { return s }("text before key SHA-512/224") + _ = func(s string) string { return s }("SHA-512/224 text after key") + _ = func(s string) string { return s }("SHA-512/256") // want `"SHA-512/256" can be replaced by crypto\.SHA512_256\.String\(\)` + _ = func(s string) string { return s }("text before key SHA-512/256") + _ = func(s string) string { return s }("SHA-512/256 text after key") + _ = func(s string) string { return s }("SHA3-224") // want `"SHA3-224" can be replaced by crypto\.SHA3_224\.String\(\)` + _ = func(s string) string { return s }("text before key SHA3-224") + _ = func(s string) string { return s }("SHA3-224 text after key") + _ = func(s string) string { return s }("SHA3-256") // want `"SHA3-256" can be replaced by crypto\.SHA3_256\.String\(\)` + _ = func(s string) string { return s }("text before key SHA3-256") + _ = func(s string) string { return s }("SHA3-256 text after key") + _ = func(s string) string { return s }("SHA3-384") // want `"SHA3-384" can be replaced by crypto\.SHA3_384\.String\(\)` + _ = func(s string) string { return s }("text before key SHA3-384") + _ = func(s string) string { return s }("SHA3-384 text after key") + _ = func(s string) string { return s }("SHA3-512") // want `"SHA3-512" can be replaced by crypto\.SHA3_512\.String\(\)` + _ = func(s string) string { return s }("text before key SHA3-512") + _ = func(s string) string { return s }("SHA3-512 text after key") +} + +func _() { + _ = fmt.Sprint("BLAKE2b-256") // want `"BLAKE2b-256" can be replaced by crypto\.BLAKE2b_256\.String\(\)` + _ = fmt.Sprint("text before key BLAKE2b-256") + _ = fmt.Sprint("BLAKE2b-256 text after key") + _ = fmt.Sprint("BLAKE2b-384") // want `"BLAKE2b-384" can be replaced by crypto\.BLAKE2b_384\.String\(\)` + _ = fmt.Sprint("text before key BLAKE2b-384") + _ = fmt.Sprint("BLAKE2b-384 text after key") + _ = fmt.Sprint("BLAKE2b-512") // want `"BLAKE2b-512" can be replaced by crypto\.BLAKE2b_512\.String\(\)` + _ = fmt.Sprint("text before key BLAKE2b-512") + _ = fmt.Sprint("BLAKE2b-512 text after key") + _ = fmt.Sprint("BLAKE2s-256") // want `"BLAKE2s-256" can be replaced by crypto\.BLAKE2s_256\.String\(\)` + _ = fmt.Sprint("text before key BLAKE2s-256") + _ = fmt.Sprint("BLAKE2s-256 text after key") + _ = fmt.Sprint("MD4") // want `"MD4" can be replaced by crypto\.MD4\.String\(\)` + _ = fmt.Sprint("text before key MD4") + _ = fmt.Sprint("MD4 text after key") + _ = fmt.Sprint("MD5") // want `"MD5" can be replaced by crypto\.MD5\.String\(\)` + _ = fmt.Sprint("text before key MD5") + _ = fmt.Sprint("MD5 text after key") + _ = fmt.Sprint("MD5+SHA1") // want `"MD5\+SHA1" can be replaced by crypto\.MD5SHA1\.String\(\)` + _ = fmt.Sprint("text before key MD5+SHA1") + _ = fmt.Sprint("MD5+SHA1 text after key") + _ = fmt.Sprint("RIPEMD-160") // want `"RIPEMD-160" can be replaced by crypto\.RIPEMD160\.String\(\)` + _ = fmt.Sprint("text before key RIPEMD-160") + _ = fmt.Sprint("RIPEMD-160 text after key") + _ = fmt.Sprint("SHA-1") // want `"SHA-1" can be replaced by crypto\.SHA1\.String\(\)` + _ = fmt.Sprint("text before key SHA-1") + _ = fmt.Sprint("SHA-1 text after key") + _ = fmt.Sprint("SHA-224") // want `"SHA-224" can be replaced by crypto\.SHA224\.String\(\)` + _ = fmt.Sprint("text before key SHA-224") + _ = fmt.Sprint("SHA-224 text after key") + _ = fmt.Sprint("SHA-256") // want `"SHA-256" can be replaced by crypto\.SHA256\.String\(\)` + _ = fmt.Sprint("text before key SHA-256") + _ = fmt.Sprint("SHA-256 text after key") + _ = fmt.Sprint("SHA-384") // want `"SHA-384" can be replaced by crypto\.SHA384\.String\(\)` + _ = fmt.Sprint("text before key SHA-384") + _ = fmt.Sprint("SHA-384 text after key") + _ = fmt.Sprint("SHA-512") // want `"SHA-512" can be replaced by crypto\.SHA512\.String\(\)` + _ = fmt.Sprint("text before key SHA-512") + _ = fmt.Sprint("SHA-512 text after key") + _ = fmt.Sprint("SHA-512/224") // want `"SHA-512/224" can be replaced by crypto\.SHA512_224\.String\(\)` + _ = fmt.Sprint("text before key SHA-512/224") + _ = fmt.Sprint("SHA-512/224 text after key") + _ = fmt.Sprint("SHA-512/256") // want `"SHA-512/256" can be replaced by crypto\.SHA512_256\.String\(\)` + _ = fmt.Sprint("text before key SHA-512/256") + _ = fmt.Sprint("SHA-512/256 text after key") + _ = fmt.Sprint("SHA3-224") // want `"SHA3-224" can be replaced by crypto\.SHA3_224\.String\(\)` + _ = fmt.Sprint("text before key SHA3-224") + _ = fmt.Sprint("SHA3-224 text after key") + _ = fmt.Sprint("SHA3-256") // want `"SHA3-256" can be replaced by crypto\.SHA3_256\.String\(\)` + _ = fmt.Sprint("text before key SHA3-256") + _ = fmt.Sprint("SHA3-256 text after key") + _ = fmt.Sprint("SHA3-384") // want `"SHA3-384" can be replaced by crypto\.SHA3_384\.String\(\)` + _ = fmt.Sprint("text before key SHA3-384") + _ = fmt.Sprint("SHA3-384 text after key") + _ = fmt.Sprint("SHA3-512") // want `"SHA3-512" can be replaced by crypto\.SHA3_512\.String\(\)` + _ = fmt.Sprint("text before key SHA3-512") + _ = fmt.Sprint("SHA3-512 text after key") } diff --git a/pkg/analyzer/testdata/src/a/http/http.go b/pkg/analyzer/testdata/src/a/http/http.go deleted file mode 100644 index b1097f8..0000000 --- a/pkg/analyzer/testdata/src/a/http/http.go +++ /dev/null @@ -1,45 +0,0 @@ -package http - -import "net/http" - -const foo = 404 - -func _200() { - _ = 200 -} - -func _200_1() { - var w http.ResponseWriter - w.WriteHeader(200) // want `"200" can be replaced by http\.StatusOK` -} - -func _GET() { - _ = "GET" -} - -func _GET_1() { - _, _ = http.NewRequest("GET", "", nil) // want `"GET" can be replaced by http\.MethodGet` -} - -func _GET_2() { - _, _ = http.NewRequestWithContext(nil, "GET", "", nil) // want `"GET" can be replaced by http\.MethodGet` -} - -func _GET_3() { - _, _ = http.NewRequestWithContext(nil, "GET", "", nil) // want `"GET" can be replaced by http\.MethodGet` -} - -func _GET_4() { - _ = &http.Request{ - Method: "GET", // want `"GET" can be replaced by http\.MethodGet` - Response: &http.Response{ - StatusCode: 200, // want `"200" can be replaced by http\.StatusOK` - }, - } -} - -func _GET_5() { - _ = &http.Response{ - StatusCode: 200, // want `"200" can be replaced by http\.StatusOK` - } -} diff --git a/pkg/analyzer/testdata/src/a/http/method.go b/pkg/analyzer/testdata/src/a/http/method.go new file mode 100644 index 0000000..b472bf4 --- /dev/null +++ b/pkg/analyzer/testdata/src/a/http/method.go @@ -0,0 +1,83 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package http_test + +import "net/http" + +var ( + _ = "CONNECT" + _ = "DELETE" + _ = "GET" + _ = "HEAD" + _ = "OPTIONS" + _ = "PATCH" + _ = "POST" + _ = "PUT" + _ = "TRACE" +) + +const ( + _ = "CONNECT" + _ = "DELETE" + _ = "GET" + _ = "HEAD" + _ = "OPTIONS" + _ = "PATCH" + _ = "POST" + _ = "PUT" + _ = "TRACE" +) + +func _() { + _, _ = http.NewRequest("CONNECT", "", nil) // want `"CONNECT" can be replaced by http\.MethodConnect` + _, _ = http.NewRequest("DELETE", "", nil) // want `"DELETE" can be replaced by http\.MethodDelete` + _, _ = http.NewRequest("GET", "", nil) // want `"GET" can be replaced by http\.MethodGet` + _, _ = http.NewRequest("HEAD", "", nil) // want `"HEAD" can be replaced by http\.MethodHead` + _, _ = http.NewRequest("OPTIONS", "", nil) // want `"OPTIONS" can be replaced by http\.MethodOptions` + _, _ = http.NewRequest("PATCH", "", nil) // want `"PATCH" can be replaced by http\.MethodPatch` + _, _ = http.NewRequest("POST", "", nil) // want `"POST" can be replaced by http\.MethodPost` + _, _ = http.NewRequest("PUT", "", nil) // want `"PUT" can be replaced by http\.MethodPut` + _, _ = http.NewRequest("TRACE", "", nil) // want `"TRACE" can be replaced by http\.MethodTrace` +} + +func _() { + _, _ = http.NewRequestWithContext(nil, "CONNECT", "", nil) // want `"CONNECT" can be replaced by http\.MethodConnect` + _, _ = http.NewRequestWithContext(nil, "DELETE", "", nil) // want `"DELETE" can be replaced by http\.MethodDelete` + _, _ = http.NewRequestWithContext(nil, "GET", "", nil) // want `"GET" can be replaced by http\.MethodGet` + _, _ = http.NewRequestWithContext(nil, "HEAD", "", nil) // want `"HEAD" can be replaced by http\.MethodHead` + _, _ = http.NewRequestWithContext(nil, "OPTIONS", "", nil) // want `"OPTIONS" can be replaced by http\.MethodOptions` + _, _ = http.NewRequestWithContext(nil, "PATCH", "", nil) // want `"PATCH" can be replaced by http\.MethodPatch` + _, _ = http.NewRequestWithContext(nil, "POST", "", nil) // want `"POST" can be replaced by http\.MethodPost` + _, _ = http.NewRequestWithContext(nil, "PUT", "", nil) // want `"PUT" can be replaced by http\.MethodPut` + _, _ = http.NewRequestWithContext(nil, "TRACE", "", nil) // want `"TRACE" can be replaced by http\.MethodTrace` +} + +func _() { + _ = &http.Request{ + Method: "CONNECT", // want `"CONNECT" can be replaced by http\.MethodConnect` + } + _ = &http.Request{ + Method: "DELETE", // want `"DELETE" can be replaced by http\.MethodDelete` + } + _ = &http.Request{ + Method: "GET", // want `"GET" can be replaced by http\.MethodGet` + } + _ = &http.Request{ + Method: "HEAD", // want `"HEAD" can be replaced by http\.MethodHead` + } + _ = &http.Request{ + Method: "OPTIONS", // want `"OPTIONS" can be replaced by http\.MethodOptions` + } + _ = &http.Request{ + Method: "PATCH", // want `"PATCH" can be replaced by http\.MethodPatch` + } + _ = &http.Request{ + Method: "POST", // want `"POST" can be replaced by http\.MethodPost` + } + _ = &http.Request{ + Method: "PUT", // want `"PUT" can be replaced by http\.MethodPut` + } + _ = &http.Request{ + Method: "TRACE", // want `"TRACE" can be replaced by http\.MethodTrace` + } +} diff --git a/pkg/analyzer/testdata/src/a/http/statuscode.go b/pkg/analyzer/testdata/src/a/http/statuscode.go new file mode 100644 index 0000000..b97cc22 --- /dev/null +++ b/pkg/analyzer/testdata/src/a/http/statuscode.go @@ -0,0 +1,817 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package http_test + +import "net/http" + +var ( + _ = 100 + _ = 101 + _ = 102 + _ = 103 + _ = 200 + _ = 201 + _ = 202 + _ = 203 + _ = 204 + _ = 205 + _ = 206 + _ = 207 + _ = 208 + _ = 226 + _ = 300 + _ = 301 + _ = 302 + _ = 303 + _ = 304 + _ = 305 + _ = 307 + _ = 308 + _ = 400 + _ = 401 + _ = 402 + _ = 403 + _ = 404 + _ = 405 + _ = 406 + _ = 407 + _ = 408 + _ = 409 + _ = 410 + _ = 411 + _ = 412 + _ = 413 + _ = 414 + _ = 415 + _ = 416 + _ = 417 + _ = 418 + _ = 421 + _ = 422 + _ = 423 + _ = 424 + _ = 425 + _ = 426 + _ = 428 + _ = 429 + _ = 431 + _ = 451 + _ = 500 + _ = 501 + _ = 502 + _ = 503 + _ = 504 + _ = 505 + _ = 506 + _ = 507 + _ = 508 + _ = 510 + _ = 511 +) + +const ( + _ = 100 + _ = 101 + _ = 102 + _ = 103 + _ = 200 + _ = 201 + _ = 202 + _ = 203 + _ = 204 + _ = 205 + _ = 206 + _ = 207 + _ = 208 + _ = 226 + _ = 300 + _ = 301 + _ = 302 + _ = 303 + _ = 304 + _ = 305 + _ = 307 + _ = 308 + _ = 400 + _ = 401 + _ = 402 + _ = 403 + _ = 404 + _ = 405 + _ = 406 + _ = 407 + _ = 408 + _ = 409 + _ = 410 + _ = 411 + _ = 412 + _ = 413 + _ = 414 + _ = 415 + _ = 416 + _ = 417 + _ = 418 + _ = 421 + _ = 422 + _ = 423 + _ = 424 + _ = 425 + _ = 426 + _ = 428 + _ = 429 + _ = 431 + _ = 451 + _ = 500 + _ = 501 + _ = 502 + _ = 503 + _ = 504 + _ = 505 + _ = 506 + _ = 507 + _ = 508 + _ = 510 + _ = 511 +) + +func _() { + var w http.ResponseWriter + w.WriteHeader(100) // want `"100" can be replaced by http\.StatusContinue` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(101) // want `"101" can be replaced by http\.StatusSwitchingProtocols` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(102) // want `"102" can be replaced by http\.StatusProcessing` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(103) // want `"103" can be replaced by http\.StatusEarlyHints` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(200) // want `"200" can be replaced by http\.StatusOK` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(201) // want `"201" can be replaced by http\.StatusCreated` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(202) // want `"202" can be replaced by http\.StatusAccepted` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(203) // want `"203" can be replaced by http\.StatusNonAuthoritativeInfo` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(204) // want `"204" can be replaced by http\.StatusNoContent` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(205) // want `"205" can be replaced by http\.StatusResetContent` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(206) // want `"206" can be replaced by http\.StatusPartialContent` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(207) // want `"207" can be replaced by http\.StatusMultiStatus` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(208) // want `"208" can be replaced by http\.StatusAlreadyReported` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(226) // want `"226" can be replaced by http\.StatusIMUsed` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(300) // want `"300" can be replaced by http\.StatusMultipleChoices` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(301) // want `"301" can be replaced by http\.StatusMovedPermanently` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(302) // want `"302" can be replaced by http\.StatusFound` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(303) // want `"303" can be replaced by http\.StatusSeeOther` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(304) // want `"304" can be replaced by http\.StatusNotModified` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(305) // want `"305" can be replaced by http\.StatusUseProxy` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(307) // want `"307" can be replaced by http\.StatusTemporaryRedirect` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(308) // want `"308" can be replaced by http\.StatusPermanentRedirect` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(400) // want `"400" can be replaced by http\.StatusBadRequest` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(401) // want `"401" can be replaced by http\.StatusUnauthorized` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(402) // want `"402" can be replaced by http\.StatusPaymentRequired` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(403) // want `"403" can be replaced by http\.StatusForbidden` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(404) // want `"404" can be replaced by http\.StatusNotFound` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(405) // want `"405" can be replaced by http\.StatusMethodNotAllowed` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(406) // want `"406" can be replaced by http\.StatusNotAcceptable` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(407) // want `"407" can be replaced by http\.StatusProxyAuthRequired` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(408) // want `"408" can be replaced by http\.StatusRequestTimeout` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(409) // want `"409" can be replaced by http\.StatusConflict` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(410) // want `"410" can be replaced by http\.StatusGone` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(411) // want `"411" can be replaced by http\.StatusLengthRequired` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(412) // want `"412" can be replaced by http\.StatusPreconditionFailed` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(413) // want `"413" can be replaced by http\.StatusRequestEntityTooLarge` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(414) // want `"414" can be replaced by http\.StatusRequestURITooLong` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(415) // want `"415" can be replaced by http\.StatusUnsupportedMediaType` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(416) // want `"416" can be replaced by http\.StatusRequestedRangeNotSatisfiable` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(417) // want `"417" can be replaced by http\.StatusExpectationFailed` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(418) // want `"418" can be replaced by http\.StatusTeapot` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(421) // want `"421" can be replaced by http\.StatusMisdirectedRequest` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(422) // want `"422" can be replaced by http\.StatusUnprocessableEntity` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(423) // want `"423" can be replaced by http\.StatusLocked` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(424) // want `"424" can be replaced by http\.StatusFailedDependency` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(425) // want `"425" can be replaced by http\.StatusTooEarly` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(426) // want `"426" can be replaced by http\.StatusUpgradeRequired` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(428) // want `"428" can be replaced by http\.StatusPreconditionRequired` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(429) // want `"429" can be replaced by http\.StatusTooManyRequests` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(431) // want `"431" can be replaced by http\.StatusRequestHeaderFieldsTooLarge` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(451) // want `"451" can be replaced by http\.StatusUnavailableForLegalReasons` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(500) // want `"500" can be replaced by http\.StatusInternalServerError` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(501) // want `"501" can be replaced by http\.StatusNotImplemented` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(502) // want `"502" can be replaced by http\.StatusBadGateway` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(503) // want `"503" can be replaced by http\.StatusServiceUnavailable` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(504) // want `"504" can be replaced by http\.StatusGatewayTimeout` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(505) // want `"505" can be replaced by http\.StatusHTTPVersionNotSupported` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(506) // want `"506" can be replaced by http\.StatusVariantAlsoNegotiates` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(507) // want `"507" can be replaced by http\.StatusInsufficientStorage` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(508) // want `"508" can be replaced by http\.StatusLoopDetected` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(510) // want `"510" can be replaced by http\.StatusNotExtended` +} + +func _() { + var w http.ResponseWriter + w.WriteHeader(511) // want `"511" can be replaced by http\.StatusNetworkAuthenticationRequired` +} + +func _() { + _ = &http.Response{ + StatusCode: 100, // want `"100" can be replaced by http\.StatusContinue` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 101, // want `"101" can be replaced by http\.StatusSwitchingProtocols` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 102, // want `"102" can be replaced by http\.StatusProcessing` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 103, // want `"103" can be replaced by http\.StatusEarlyHints` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 200, // want `"200" can be replaced by http\.StatusOK` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 201, // want `"201" can be replaced by http\.StatusCreated` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 202, // want `"202" can be replaced by http\.StatusAccepted` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 203, // want `"203" can be replaced by http\.StatusNonAuthoritativeInfo` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 204, // want `"204" can be replaced by http\.StatusNoContent` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 205, // want `"205" can be replaced by http\.StatusResetContent` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 206, // want `"206" can be replaced by http\.StatusPartialContent` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 207, // want `"207" can be replaced by http\.StatusMultiStatus` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 208, // want `"208" can be replaced by http\.StatusAlreadyReported` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 226, // want `"226" can be replaced by http\.StatusIMUsed` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 300, // want `"300" can be replaced by http\.StatusMultipleChoices` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 301, // want `"301" can be replaced by http\.StatusMovedPermanently` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 302, // want `"302" can be replaced by http\.StatusFound` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 303, // want `"303" can be replaced by http\.StatusSeeOther` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 304, // want `"304" can be replaced by http\.StatusNotModified` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 305, // want `"305" can be replaced by http\.StatusUseProxy` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 307, // want `"307" can be replaced by http\.StatusTemporaryRedirect` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 308, // want `"308" can be replaced by http\.StatusPermanentRedirect` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 400, // want `"400" can be replaced by http\.StatusBadRequest` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 401, // want `"401" can be replaced by http\.StatusUnauthorized` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 402, // want `"402" can be replaced by http\.StatusPaymentRequired` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 403, // want `"403" can be replaced by http\.StatusForbidden` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 404, // want `"404" can be replaced by http\.StatusNotFound` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 405, // want `"405" can be replaced by http\.StatusMethodNotAllowed` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 406, // want `"406" can be replaced by http\.StatusNotAcceptable` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 407, // want `"407" can be replaced by http\.StatusProxyAuthRequired` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 408, // want `"408" can be replaced by http\.StatusRequestTimeout` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 409, // want `"409" can be replaced by http\.StatusConflict` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 410, // want `"410" can be replaced by http\.StatusGone` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 411, // want `"411" can be replaced by http\.StatusLengthRequired` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 412, // want `"412" can be replaced by http\.StatusPreconditionFailed` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 413, // want `"413" can be replaced by http\.StatusRequestEntityTooLarge` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 414, // want `"414" can be replaced by http\.StatusRequestURITooLong` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 415, // want `"415" can be replaced by http\.StatusUnsupportedMediaType` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 416, // want `"416" can be replaced by http\.StatusRequestedRangeNotSatisfiable` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 417, // want `"417" can be replaced by http\.StatusExpectationFailed` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 418, // want `"418" can be replaced by http\.StatusTeapot` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 421, // want `"421" can be replaced by http\.StatusMisdirectedRequest` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 422, // want `"422" can be replaced by http\.StatusUnprocessableEntity` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 423, // want `"423" can be replaced by http\.StatusLocked` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 424, // want `"424" can be replaced by http\.StatusFailedDependency` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 425, // want `"425" can be replaced by http\.StatusTooEarly` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 426, // want `"426" can be replaced by http\.StatusUpgradeRequired` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 428, // want `"428" can be replaced by http\.StatusPreconditionRequired` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 429, // want `"429" can be replaced by http\.StatusTooManyRequests` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 431, // want `"431" can be replaced by http\.StatusRequestHeaderFieldsTooLarge` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 451, // want `"451" can be replaced by http\.StatusUnavailableForLegalReasons` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 500, // want `"500" can be replaced by http\.StatusInternalServerError` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 501, // want `"501" can be replaced by http\.StatusNotImplemented` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 502, // want `"502" can be replaced by http\.StatusBadGateway` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 503, // want `"503" can be replaced by http\.StatusServiceUnavailable` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 504, // want `"504" can be replaced by http\.StatusGatewayTimeout` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 505, // want `"505" can be replaced by http\.StatusHTTPVersionNotSupported` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 506, // want `"506" can be replaced by http\.StatusVariantAlsoNegotiates` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 507, // want `"507" can be replaced by http\.StatusInsufficientStorage` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 508, // want `"508" can be replaced by http\.StatusLoopDetected` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 510, // want `"510" can be replaced by http\.StatusNotExtended` + } +} + +func _() { + _ = &http.Response{ + StatusCode: 511, // want `"511" can be replaced by http\.StatusNetworkAuthenticationRequired` + } +} diff --git a/pkg/analyzer/testdata/src/a/rpc/rpc.go b/pkg/analyzer/testdata/src/a/rpc/rpc.go index 37d355f..8e381e0 100644 --- a/pkg/analyzer/testdata/src/a/rpc/rpc.go +++ b/pkg/analyzer/testdata/src/a/rpc/rpc.go @@ -1,7 +1,33 @@ -package rpc +// Code generated by usestdlibvars, DO NOT EDIT. -var _ = "/_goRPC_" // want `"/_goRPC_" can be replaced by rpc.DefaultRPCPath` +package rpc_test + +import "fmt" + +var ( + _ = "/_goRPC_" // want `"/_goRPC_" can be replaced by rpc\.DefaultRPCPath` + _ = "/debug/rpc" // want `"/debug/rpc" can be replaced by rpc\.DefaultDebugPath` +) + +const ( + _ = "/_goRPC_" // want `"/_goRPC_" can be replaced by rpc\.DefaultRPCPath` + _ = "/debug/rpc" // want `"/debug/rpc" can be replaced by rpc\.DefaultDebugPath` +) + +func _() { + _ = func(s string) string { return s }("/_goRPC_") // want `"/_goRPC_" can be replaced by rpc\.DefaultRPCPath` + _ = func(s string) string { return s }("text before key /_goRPC_") + _ = func(s string) string { return s }("/_goRPC_ text after key") + _ = func(s string) string { return s }("/debug/rpc") // want `"/debug/rpc" can be replaced by rpc\.DefaultDebugPath` + _ = func(s string) string { return s }("text before key /debug/rpc") + _ = func(s string) string { return s }("/debug/rpc text after key") +} func _() { - _ = "/debug/rpc" // want `"/debug/rpc" can be replaced by rpc.DefaultDebugPath` + _ = fmt.Sprint("/_goRPC_") // want `"/_goRPC_" can be replaced by rpc\.DefaultRPCPath` + _ = fmt.Sprint("text before key /_goRPC_") + _ = fmt.Sprint("/_goRPC_ text after key") + _ = fmt.Sprint("/debug/rpc") // want `"/debug/rpc" can be replaced by rpc\.DefaultDebugPath` + _ = fmt.Sprint("text before key /debug/rpc") + _ = fmt.Sprint("/debug/rpc text after key") } diff --git a/pkg/analyzer/testdata/src/a/time/layout.go b/pkg/analyzer/testdata/src/a/time/layout.go new file mode 100644 index 0000000..469cd07 --- /dev/null +++ b/pkg/analyzer/testdata/src/a/time/layout.go @@ -0,0 +1,145 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package time_test + +import "fmt" + +var ( + _ = "01/02 03:04:05PM '06 -0700" // want `"01/02 03:04:05PM '06 -0700" can be replaced by time\.Layout` + _ = "02 Jan 06 15:04 -0700" // want `"02 Jan 06 15:04 -0700" can be replaced by time\.RFC822Z` + _ = "02 Jan 06 15:04 MST" // want `"02 Jan 06 15:04 MST" can be replaced by time\.RFC822` + _ = "2006-01-02T15:04:05.999999999Z07:00" // want `"2006-01-02T15:04:05\.999999999Z07:00" can be replaced by time\.RFC3339Nano` + _ = "2006-01-02T15:04:05Z07:00" // want `"2006-01-02T15:04:05Z07:00" can be replaced by time\.RFC3339` + _ = "3:04PM" // want `"3:04PM" can be replaced by time\.Kitchen` + _ = "Jan _2 15:04:05" // want `"Jan _2 15:04:05" can be replaced by time\.Stamp` + _ = "Jan _2 15:04:05.000" // want `"Jan _2 15:04:05\.000" can be replaced by time\.StampMilli` + _ = "Jan _2 15:04:05.000000" // want `"Jan _2 15:04:05\.000000" can be replaced by time\.StampMicro` + _ = "Jan _2 15:04:05.000000000" // want `"Jan _2 15:04:05\.000000000" can be replaced by time\.StampNano` + _ = "Mon Jan 02 15:04:05 -0700 2006" // want `"Mon Jan 02 15:04:05 -0700 2006" can be replaced by time\.RubyDate` + _ = "Mon Jan _2 15:04:05 2006" // want `"Mon Jan _2 15:04:05 2006" can be replaced by time\.ANSIC` + _ = "Mon Jan _2 15:04:05 MST 2006" // want `"Mon Jan _2 15:04:05 MST 2006" can be replaced by time\.UnixDate` + _ = "Mon, 02 Jan 2006 15:04:05 -0700" // want `"Mon, 02 Jan 2006 15:04:05 -0700" can be replaced by time\.RFC1123Z` + _ = "Mon, 02 Jan 2006 15:04:05 MST" // want `"Mon, 02 Jan 2006 15:04:05 MST" can be replaced by time\.RFC1123` + _ = "Monday, 02-Jan-06 15:04:05 MST" // want `"Monday, 02-Jan-06 15:04:05 MST" can be replaced by time\.RFC850` +) + +const ( + _ = "01/02 03:04:05PM '06 -0700" // want `"01/02 03:04:05PM '06 -0700" can be replaced by time\.Layout` + _ = "02 Jan 06 15:04 -0700" // want `"02 Jan 06 15:04 -0700" can be replaced by time\.RFC822Z` + _ = "02 Jan 06 15:04 MST" // want `"02 Jan 06 15:04 MST" can be replaced by time\.RFC822` + _ = "2006-01-02T15:04:05.999999999Z07:00" // want `"2006-01-02T15:04:05\.999999999Z07:00" can be replaced by time\.RFC3339Nano` + _ = "2006-01-02T15:04:05Z07:00" // want `"2006-01-02T15:04:05Z07:00" can be replaced by time\.RFC3339` + _ = "3:04PM" // want `"3:04PM" can be replaced by time\.Kitchen` + _ = "Jan _2 15:04:05" // want `"Jan _2 15:04:05" can be replaced by time\.Stamp` + _ = "Jan _2 15:04:05.000" // want `"Jan _2 15:04:05\.000" can be replaced by time\.StampMilli` + _ = "Jan _2 15:04:05.000000" // want `"Jan _2 15:04:05\.000000" can be replaced by time\.StampMicro` + _ = "Jan _2 15:04:05.000000000" // want `"Jan _2 15:04:05\.000000000" can be replaced by time\.StampNano` + _ = "Mon Jan 02 15:04:05 -0700 2006" // want `"Mon Jan 02 15:04:05 -0700 2006" can be replaced by time\.RubyDate` + _ = "Mon Jan _2 15:04:05 2006" // want `"Mon Jan _2 15:04:05 2006" can be replaced by time\.ANSIC` + _ = "Mon Jan _2 15:04:05 MST 2006" // want `"Mon Jan _2 15:04:05 MST 2006" can be replaced by time\.UnixDate` + _ = "Mon, 02 Jan 2006 15:04:05 -0700" // want `"Mon, 02 Jan 2006 15:04:05 -0700" can be replaced by time\.RFC1123Z` + _ = "Mon, 02 Jan 2006 15:04:05 MST" // want `"Mon, 02 Jan 2006 15:04:05 MST" can be replaced by time\.RFC1123` + _ = "Monday, 02-Jan-06 15:04:05 MST" // want `"Monday, 02-Jan-06 15:04:05 MST" can be replaced by time\.RFC850` +) + +func _() { + _ = func(s string) string { return s }("01/02 03:04:05PM '06 -0700") // want `"01/02 03:04:05PM '06 -0700" can be replaced by time\.Layout` + _ = func(s string) string { return s }("text before key 01/02 03:04:05PM '06 -0700") + _ = func(s string) string { return s }("01/02 03:04:05PM '06 -0700 text after key") + _ = func(s string) string { return s }("02 Jan 06 15:04 -0700") // want `"02 Jan 06 15:04 -0700" can be replaced by time\.RFC822Z` + _ = func(s string) string { return s }("text before key 02 Jan 06 15:04 -0700") + _ = func(s string) string { return s }("02 Jan 06 15:04 -0700 text after key") + _ = func(s string) string { return s }("02 Jan 06 15:04 MST") // want `"02 Jan 06 15:04 MST" can be replaced by time\.RFC822` + _ = func(s string) string { return s }("text before key 02 Jan 06 15:04 MST") + _ = func(s string) string { return s }("02 Jan 06 15:04 MST text after key") + _ = func(s string) string { return s }("2006-01-02T15:04:05.999999999Z07:00") // want `"2006-01-02T15:04:05\.999999999Z07:00" can be replaced by time\.RFC3339Nano` + _ = func(s string) string { return s }("text before key 2006-01-02T15:04:05.999999999Z07:00") + _ = func(s string) string { return s }("2006-01-02T15:04:05.999999999Z07:00 text after key") + _ = func(s string) string { return s }("2006-01-02T15:04:05Z07:00") // want `"2006-01-02T15:04:05Z07:00" can be replaced by time\.RFC3339` + _ = func(s string) string { return s }("text before key 2006-01-02T15:04:05Z07:00") + _ = func(s string) string { return s }("2006-01-02T15:04:05Z07:00 text after key") + _ = func(s string) string { return s }("3:04PM") // want `"3:04PM" can be replaced by time\.Kitchen` + _ = func(s string) string { return s }("text before key 3:04PM") + _ = func(s string) string { return s }("3:04PM text after key") + _ = func(s string) string { return s }("Jan _2 15:04:05") // want `"Jan _2 15:04:05" can be replaced by time\.Stamp` + _ = func(s string) string { return s }("text before key Jan _2 15:04:05") + _ = func(s string) string { return s }("Jan _2 15:04:05 text after key") + _ = func(s string) string { return s }("Jan _2 15:04:05.000") // want `"Jan _2 15:04:05\.000" can be replaced by time\.StampMilli` + _ = func(s string) string { return s }("text before key Jan _2 15:04:05.000") + _ = func(s string) string { return s }("Jan _2 15:04:05.000 text after key") + _ = func(s string) string { return s }("Jan _2 15:04:05.000000") // want `"Jan _2 15:04:05\.000000" can be replaced by time\.StampMicro` + _ = func(s string) string { return s }("text before key Jan _2 15:04:05.000000") + _ = func(s string) string { return s }("Jan _2 15:04:05.000000 text after key") + _ = func(s string) string { return s }("Jan _2 15:04:05.000000000") // want `"Jan _2 15:04:05\.000000000" can be replaced by time\.StampNano` + _ = func(s string) string { return s }("text before key Jan _2 15:04:05.000000000") + _ = func(s string) string { return s }("Jan _2 15:04:05.000000000 text after key") + _ = func(s string) string { return s }("Mon Jan 02 15:04:05 -0700 2006") // want `"Mon Jan 02 15:04:05 -0700 2006" can be replaced by time\.RubyDate` + _ = func(s string) string { return s }("text before key Mon Jan 02 15:04:05 -0700 2006") + _ = func(s string) string { return s }("Mon Jan 02 15:04:05 -0700 2006 text after key") + _ = func(s string) string { return s }("Mon Jan _2 15:04:05 2006") // want `"Mon Jan _2 15:04:05 2006" can be replaced by time\.ANSIC` + _ = func(s string) string { return s }("text before key Mon Jan _2 15:04:05 2006") + _ = func(s string) string { return s }("Mon Jan _2 15:04:05 2006 text after key") + _ = func(s string) string { return s }("Mon Jan _2 15:04:05 MST 2006") // want `"Mon Jan _2 15:04:05 MST 2006" can be replaced by time\.UnixDate` + _ = func(s string) string { return s }("text before key Mon Jan _2 15:04:05 MST 2006") + _ = func(s string) string { return s }("Mon Jan _2 15:04:05 MST 2006 text after key") + _ = func(s string) string { return s }("Mon, 02 Jan 2006 15:04:05 -0700") // want `"Mon, 02 Jan 2006 15:04:05 -0700" can be replaced by time\.RFC1123Z` + _ = func(s string) string { return s }("text before key Mon, 02 Jan 2006 15:04:05 -0700") + _ = func(s string) string { return s }("Mon, 02 Jan 2006 15:04:05 -0700 text after key") + _ = func(s string) string { return s }("Mon, 02 Jan 2006 15:04:05 MST") // want `"Mon, 02 Jan 2006 15:04:05 MST" can be replaced by time\.RFC1123` + _ = func(s string) string { return s }("text before key Mon, 02 Jan 2006 15:04:05 MST") + _ = func(s string) string { return s }("Mon, 02 Jan 2006 15:04:05 MST text after key") + _ = func(s string) string { return s }("Monday, 02-Jan-06 15:04:05 MST") // want `"Monday, 02-Jan-06 15:04:05 MST" can be replaced by time\.RFC850` + _ = func(s string) string { return s }("text before key Monday, 02-Jan-06 15:04:05 MST") + _ = func(s string) string { return s }("Monday, 02-Jan-06 15:04:05 MST text after key") +} + +func _() { + _ = fmt.Sprint("01/02 03:04:05PM '06 -0700") // want `"01/02 03:04:05PM '06 -0700" can be replaced by time\.Layout` + _ = fmt.Sprint("text before key 01/02 03:04:05PM '06 -0700") + _ = fmt.Sprint("01/02 03:04:05PM '06 -0700 text after key") + _ = fmt.Sprint("02 Jan 06 15:04 -0700") // want `"02 Jan 06 15:04 -0700" can be replaced by time\.RFC822Z` + _ = fmt.Sprint("text before key 02 Jan 06 15:04 -0700") + _ = fmt.Sprint("02 Jan 06 15:04 -0700 text after key") + _ = fmt.Sprint("02 Jan 06 15:04 MST") // want `"02 Jan 06 15:04 MST" can be replaced by time\.RFC822` + _ = fmt.Sprint("text before key 02 Jan 06 15:04 MST") + _ = fmt.Sprint("02 Jan 06 15:04 MST text after key") + _ = fmt.Sprint("2006-01-02T15:04:05.999999999Z07:00") // want `"2006-01-02T15:04:05\.999999999Z07:00" can be replaced by time\.RFC3339Nano` + _ = fmt.Sprint("text before key 2006-01-02T15:04:05.999999999Z07:00") + _ = fmt.Sprint("2006-01-02T15:04:05.999999999Z07:00 text after key") + _ = fmt.Sprint("2006-01-02T15:04:05Z07:00") // want `"2006-01-02T15:04:05Z07:00" can be replaced by time\.RFC3339` + _ = fmt.Sprint("text before key 2006-01-02T15:04:05Z07:00") + _ = fmt.Sprint("2006-01-02T15:04:05Z07:00 text after key") + _ = fmt.Sprint("3:04PM") // want `"3:04PM" can be replaced by time\.Kitchen` + _ = fmt.Sprint("text before key 3:04PM") + _ = fmt.Sprint("3:04PM text after key") + _ = fmt.Sprint("Jan _2 15:04:05") // want `"Jan _2 15:04:05" can be replaced by time\.Stamp` + _ = fmt.Sprint("text before key Jan _2 15:04:05") + _ = fmt.Sprint("Jan _2 15:04:05 text after key") + _ = fmt.Sprint("Jan _2 15:04:05.000") // want `"Jan _2 15:04:05\.000" can be replaced by time\.StampMilli` + _ = fmt.Sprint("text before key Jan _2 15:04:05.000") + _ = fmt.Sprint("Jan _2 15:04:05.000 text after key") + _ = fmt.Sprint("Jan _2 15:04:05.000000") // want `"Jan _2 15:04:05\.000000" can be replaced by time\.StampMicro` + _ = fmt.Sprint("text before key Jan _2 15:04:05.000000") + _ = fmt.Sprint("Jan _2 15:04:05.000000 text after key") + _ = fmt.Sprint("Jan _2 15:04:05.000000000") // want `"Jan _2 15:04:05\.000000000" can be replaced by time\.StampNano` + _ = fmt.Sprint("text before key Jan _2 15:04:05.000000000") + _ = fmt.Sprint("Jan _2 15:04:05.000000000 text after key") + _ = fmt.Sprint("Mon Jan 02 15:04:05 -0700 2006") // want `"Mon Jan 02 15:04:05 -0700 2006" can be replaced by time\.RubyDate` + _ = fmt.Sprint("text before key Mon Jan 02 15:04:05 -0700 2006") + _ = fmt.Sprint("Mon Jan 02 15:04:05 -0700 2006 text after key") + _ = fmt.Sprint("Mon Jan _2 15:04:05 2006") // want `"Mon Jan _2 15:04:05 2006" can be replaced by time\.ANSIC` + _ = fmt.Sprint("text before key Mon Jan _2 15:04:05 2006") + _ = fmt.Sprint("Mon Jan _2 15:04:05 2006 text after key") + _ = fmt.Sprint("Mon Jan _2 15:04:05 MST 2006") // want `"Mon Jan _2 15:04:05 MST 2006" can be replaced by time\.UnixDate` + _ = fmt.Sprint("text before key Mon Jan _2 15:04:05 MST 2006") + _ = fmt.Sprint("Mon Jan _2 15:04:05 MST 2006 text after key") + _ = fmt.Sprint("Mon, 02 Jan 2006 15:04:05 -0700") // want `"Mon, 02 Jan 2006 15:04:05 -0700" can be replaced by time\.RFC1123Z` + _ = fmt.Sprint("text before key Mon, 02 Jan 2006 15:04:05 -0700") + _ = fmt.Sprint("Mon, 02 Jan 2006 15:04:05 -0700 text after key") + _ = fmt.Sprint("Mon, 02 Jan 2006 15:04:05 MST") // want `"Mon, 02 Jan 2006 15:04:05 MST" can be replaced by time\.RFC1123` + _ = fmt.Sprint("text before key Mon, 02 Jan 2006 15:04:05 MST") + _ = fmt.Sprint("Mon, 02 Jan 2006 15:04:05 MST text after key") + _ = fmt.Sprint("Monday, 02-Jan-06 15:04:05 MST") // want `"Monday, 02-Jan-06 15:04:05 MST" can be replaced by time\.RFC850` + _ = fmt.Sprint("text before key Monday, 02-Jan-06 15:04:05 MST") + _ = fmt.Sprint("Monday, 02-Jan-06 15:04:05 MST text after key") +} diff --git a/pkg/analyzer/testdata/src/a/time/month.go b/pkg/analyzer/testdata/src/a/time/month.go new file mode 100644 index 0000000..cbf0b42 --- /dev/null +++ b/pkg/analyzer/testdata/src/a/time/month.go @@ -0,0 +1,113 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package time_test + +import "fmt" + +var ( + _ = "April" // want `"April" can be replaced by time\.April\.String\(\)` + _ = "August" // want `"August" can be replaced by time\.August\.String\(\)` + _ = "December" // want `"December" can be replaced by time\.December\.String\(\)` + _ = "February" // want `"February" can be replaced by time\.February\.String\(\)` + _ = "January" // want `"January" can be replaced by time\.January\.String\(\)` + _ = "July" // want `"July" can be replaced by time\.July\.String\(\)` + _ = "June" // want `"June" can be replaced by time\.June\.String\(\)` + _ = "March" // want `"March" can be replaced by time\.March\.String\(\)` + _ = "May" // want `"May" can be replaced by time\.May\.String\(\)` + _ = "November" // want `"November" can be replaced by time\.November\.String\(\)` + _ = "October" // want `"October" can be replaced by time\.October\.String\(\)` + _ = "September" // want `"September" can be replaced by time\.September\.String\(\)` +) + +const ( + _ = "April" // want `"April" can be replaced by time\.April\.String\(\)` + _ = "August" // want `"August" can be replaced by time\.August\.String\(\)` + _ = "December" // want `"December" can be replaced by time\.December\.String\(\)` + _ = "February" // want `"February" can be replaced by time\.February\.String\(\)` + _ = "January" // want `"January" can be replaced by time\.January\.String\(\)` + _ = "July" // want `"July" can be replaced by time\.July\.String\(\)` + _ = "June" // want `"June" can be replaced by time\.June\.String\(\)` + _ = "March" // want `"March" can be replaced by time\.March\.String\(\)` + _ = "May" // want `"May" can be replaced by time\.May\.String\(\)` + _ = "November" // want `"November" can be replaced by time\.November\.String\(\)` + _ = "October" // want `"October" can be replaced by time\.October\.String\(\)` + _ = "September" // want `"September" can be replaced by time\.September\.String\(\)` +) + +func _() { + _ = func(s string) string { return s }("April") // want `"April" can be replaced by time\.April\.String\(\)` + _ = func(s string) string { return s }("text before key April") + _ = func(s string) string { return s }("April text after key") + _ = func(s string) string { return s }("August") // want `"August" can be replaced by time\.August\.String\(\)` + _ = func(s string) string { return s }("text before key August") + _ = func(s string) string { return s }("August text after key") + _ = func(s string) string { return s }("December") // want `"December" can be replaced by time\.December\.String\(\)` + _ = func(s string) string { return s }("text before key December") + _ = func(s string) string { return s }("December text after key") + _ = func(s string) string { return s }("February") // want `"February" can be replaced by time\.February\.String\(\)` + _ = func(s string) string { return s }("text before key February") + _ = func(s string) string { return s }("February text after key") + _ = func(s string) string { return s }("January") // want `"January" can be replaced by time\.January\.String\(\)` + _ = func(s string) string { return s }("text before key January") + _ = func(s string) string { return s }("January text after key") + _ = func(s string) string { return s }("July") // want `"July" can be replaced by time\.July\.String\(\)` + _ = func(s string) string { return s }("text before key July") + _ = func(s string) string { return s }("July text after key") + _ = func(s string) string { return s }("June") // want `"June" can be replaced by time\.June\.String\(\)` + _ = func(s string) string { return s }("text before key June") + _ = func(s string) string { return s }("June text after key") + _ = func(s string) string { return s }("March") // want `"March" can be replaced by time\.March\.String\(\)` + _ = func(s string) string { return s }("text before key March") + _ = func(s string) string { return s }("March text after key") + _ = func(s string) string { return s }("May") // want `"May" can be replaced by time\.May\.String\(\)` + _ = func(s string) string { return s }("text before key May") + _ = func(s string) string { return s }("May text after key") + _ = func(s string) string { return s }("November") // want `"November" can be replaced by time\.November\.String\(\)` + _ = func(s string) string { return s }("text before key November") + _ = func(s string) string { return s }("November text after key") + _ = func(s string) string { return s }("October") // want `"October" can be replaced by time\.October\.String\(\)` + _ = func(s string) string { return s }("text before key October") + _ = func(s string) string { return s }("October text after key") + _ = func(s string) string { return s }("September") // want `"September" can be replaced by time\.September\.String\(\)` + _ = func(s string) string { return s }("text before key September") + _ = func(s string) string { return s }("September text after key") +} + +func _() { + _ = fmt.Sprint("April") // want `"April" can be replaced by time\.April\.String\(\)` + _ = fmt.Sprint("text before key April") + _ = fmt.Sprint("April text after key") + _ = fmt.Sprint("August") // want `"August" can be replaced by time\.August\.String\(\)` + _ = fmt.Sprint("text before key August") + _ = fmt.Sprint("August text after key") + _ = fmt.Sprint("December") // want `"December" can be replaced by time\.December\.String\(\)` + _ = fmt.Sprint("text before key December") + _ = fmt.Sprint("December text after key") + _ = fmt.Sprint("February") // want `"February" can be replaced by time\.February\.String\(\)` + _ = fmt.Sprint("text before key February") + _ = fmt.Sprint("February text after key") + _ = fmt.Sprint("January") // want `"January" can be replaced by time\.January\.String\(\)` + _ = fmt.Sprint("text before key January") + _ = fmt.Sprint("January text after key") + _ = fmt.Sprint("July") // want `"July" can be replaced by time\.July\.String\(\)` + _ = fmt.Sprint("text before key July") + _ = fmt.Sprint("July text after key") + _ = fmt.Sprint("June") // want `"June" can be replaced by time\.June\.String\(\)` + _ = fmt.Sprint("text before key June") + _ = fmt.Sprint("June text after key") + _ = fmt.Sprint("March") // want `"March" can be replaced by time\.March\.String\(\)` + _ = fmt.Sprint("text before key March") + _ = fmt.Sprint("March text after key") + _ = fmt.Sprint("May") // want `"May" can be replaced by time\.May\.String\(\)` + _ = fmt.Sprint("text before key May") + _ = fmt.Sprint("May text after key") + _ = fmt.Sprint("November") // want `"November" can be replaced by time\.November\.String\(\)` + _ = fmt.Sprint("text before key November") + _ = fmt.Sprint("November text after key") + _ = fmt.Sprint("October") // want `"October" can be replaced by time\.October\.String\(\)` + _ = fmt.Sprint("text before key October") + _ = fmt.Sprint("October text after key") + _ = fmt.Sprint("September") // want `"September" can be replaced by time\.September\.String\(\)` + _ = fmt.Sprint("text before key September") + _ = fmt.Sprint("September text after key") +} diff --git a/pkg/analyzer/testdata/src/a/time/time.go b/pkg/analyzer/testdata/src/a/time/time.go deleted file mode 100644 index 55b397d..0000000 --- a/pkg/analyzer/testdata/src/a/time/time.go +++ /dev/null @@ -1,147 +0,0 @@ -package time - -// DAY - -func sunday() { - _ = "Sunday" // want `"Sunday" can be replaced by time.Sunday.String\(\)` -} - -func monday() { - _ = "Monday" // want `"Monday" can be replaced by time.Monday.String\(\)` -} - -func tuesday() { - _ = "Tuesday" // want `"Tuesday" can be replaced by time.Tuesday.String\(\)` -} - -func wednesday() { - _ = "Wednesday" // want `"Wednesday" can be replaced by time.Wednesday.String\(\)` -} - -func thursday() { - _ = "Thursday" // want `"Thursday" can be replaced by time.Thursday.String\(\)` -} - -func friday() { - _ = "Friday" // want `"Friday" can be replaced by time.Friday.String\(\)` -} - -func saturday() { - _ = "Saturday" // want `"Saturday" can be replaced by time.Saturday.String\(\)` -} - -// MONTH - -func january() { - _ = "January" // want `"January" can be replaced by time.January.String\(\)` -} - -func february() { - _ = "February" // want `"February" can be replaced by time.February.String\(\)` -} - -func march() { - _ = "March" // want `"March" can be replaced by time.March.String\(\)` -} - -func april() { - _ = "April" // want `"April" can be replaced by time.April.String\(\)` -} - -func may() { - _ = "May" // want `"May" can be replaced by time.May.String\(\)` -} - -func june() { - _ = "June" // want `"June" can be replaced by time.June.String\(\)` -} - -func july() { - _ = "July" // want `"July" can be replaced by time.July.String\(\)` -} - -func august() { - _ = "August" // want `"August" can be replaced by time.August.String\(\)` -} - -func september() { - _ = "September" // want `"September" can be replaced by time.September.String\(\)` -} - -func october() { - _ = "October" // want `"October" can be replaced by time.October.String\(\)` -} - -func november() { - _ = "November" // want `"November" can be replaced by time.November.String\(\)` -} - -func december() { - _ = "December" // want `"December" can be replaced by time.December.String\(\)` -} - -// LAYOUT - -func layout() { - _ = "01/02 03:04:05PM '06 -0700" // want `"01/02 03:04:05PM '06 -0700" can be replaced by time.Layout` -} - -func ansic() { - _ = "Mon Jan _2 15:04:05 2006" // want `"Mon Jan _2 15:04:05 2006" can be replaced by time.ANSIC` -} - -func unixDate() { - _ = "Mon Jan _2 15:04:05 MST 2006" // want `"Mon Jan _2 15:04:05 MST 2006" can be replaced by time.UnixDate` -} - -func rubyDate() { - _ = "Mon Jan 02 15:04:05 -0700 2006" // want `"Mon Jan 02 15:04:05 -0700 2006" can be replaced by time.RubyDate` -} - -func rfc822() { - _ = "02 Jan 06 15:04 MST" // want `"02 Jan 06 15:04 MST" can be replaced by time.RFC822` -} - -func rfc822Z() { - _ = "02 Jan 06 15:04 -0700" // want `"02 Jan 06 15:04 -0700" can be replaced by time.RFC822Z` -} - -func rfc850() { - _ = "Monday, 02-Jan-06 15:04:05 MST" // want `"Monday, 02-Jan-06 15:04:05 MST" can be replaced by time.RFC850` -} - -func rfc1123() { - _ = "Mon, 02 Jan 2006 15:04:05 MST" // want `"Mon, 02 Jan 2006 15:04:05 MST" can be replaced by time.RFC1123` -} - -func rfc1123Z() { - _ = "Mon, 02 Jan 2006 15:04:05 -0700" // want `"Mon, 02 Jan 2006 15:04:05 -0700" can be replaced by time.RFC1123Z` -} - -func rfc3339() { - _ = "2006-01-02T15:04:05Z07:00" // want `"2006-01-02T15:04:05Z07:00" can be replaced by time.RFC3339` -} - -func rfc3339Nano() { - _ = "2006-01-02T15:04:05.999999999Z07:00" // want `"2006-01-02T15:04:05.999999999Z07:00" can be replaced by time.RFC3339Nano` -} - -func kitchen() { - _ = "3:04PM" // want `"3:04PM" can be replaced by time.Kitchen` -} - -func stamp() { - _ = "Jan _2 15:04:05" // want `"Jan _2 15:04:05" can be replaced by time.Stamp` -} - -func stampMilli() { - _ = "Jan _2 15:04:05.000" // want `"Jan _2 15:04:05.000" can be replaced by time.StampMilli` -} - -func stampMicro() { - _ = "Jan _2 15:04:05.000000" // want `"Jan _2 15:04:05.000000" can be replaced by time.StampMicro` -} - -func stampNano() { - _ = "Jan _2 15:04:05.000000000" // want `"Jan _2 15:04:05.000000000" can be replaced by time.StampNano` -} diff --git a/pkg/analyzer/testdata/src/a/time/weekday.go b/pkg/analyzer/testdata/src/a/time/weekday.go new file mode 100644 index 0000000..9132ec4 --- /dev/null +++ b/pkg/analyzer/testdata/src/a/time/weekday.go @@ -0,0 +1,73 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package time_test + +import "fmt" + +var ( + _ = "Friday" // want `"Friday" can be replaced by time\.Friday\.String\(\)` + _ = "Monday" // want `"Monday" can be replaced by time\.Monday\.String\(\)` + _ = "Saturday" // want `"Saturday" can be replaced by time\.Saturday\.String\(\)` + _ = "Sunday" // want `"Sunday" can be replaced by time\.Sunday\.String\(\)` + _ = "Thursday" // want `"Thursday" can be replaced by time\.Thursday\.String\(\)` + _ = "Tuesday" // want `"Tuesday" can be replaced by time\.Tuesday\.String\(\)` + _ = "Wednesday" // want `"Wednesday" can be replaced by time\.Wednesday\.String\(\)` +) + +const ( + _ = "Friday" // want `"Friday" can be replaced by time\.Friday\.String\(\)` + _ = "Monday" // want `"Monday" can be replaced by time\.Monday\.String\(\)` + _ = "Saturday" // want `"Saturday" can be replaced by time\.Saturday\.String\(\)` + _ = "Sunday" // want `"Sunday" can be replaced by time\.Sunday\.String\(\)` + _ = "Thursday" // want `"Thursday" can be replaced by time\.Thursday\.String\(\)` + _ = "Tuesday" // want `"Tuesday" can be replaced by time\.Tuesday\.String\(\)` + _ = "Wednesday" // want `"Wednesday" can be replaced by time\.Wednesday\.String\(\)` +) + +func _() { + _ = func(s string) string { return s }("Friday") // want `"Friday" can be replaced by time\.Friday\.String\(\)` + _ = func(s string) string { return s }("text before key Friday") + _ = func(s string) string { return s }("Friday text after key") + _ = func(s string) string { return s }("Monday") // want `"Monday" can be replaced by time\.Monday\.String\(\)` + _ = func(s string) string { return s }("text before key Monday") + _ = func(s string) string { return s }("Monday text after key") + _ = func(s string) string { return s }("Saturday") // want `"Saturday" can be replaced by time\.Saturday\.String\(\)` + _ = func(s string) string { return s }("text before key Saturday") + _ = func(s string) string { return s }("Saturday text after key") + _ = func(s string) string { return s }("Sunday") // want `"Sunday" can be replaced by time\.Sunday\.String\(\)` + _ = func(s string) string { return s }("text before key Sunday") + _ = func(s string) string { return s }("Sunday text after key") + _ = func(s string) string { return s }("Thursday") // want `"Thursday" can be replaced by time\.Thursday\.String\(\)` + _ = func(s string) string { return s }("text before key Thursday") + _ = func(s string) string { return s }("Thursday text after key") + _ = func(s string) string { return s }("Tuesday") // want `"Tuesday" can be replaced by time\.Tuesday\.String\(\)` + _ = func(s string) string { return s }("text before key Tuesday") + _ = func(s string) string { return s }("Tuesday text after key") + _ = func(s string) string { return s }("Wednesday") // want `"Wednesday" can be replaced by time\.Wednesday\.String\(\)` + _ = func(s string) string { return s }("text before key Wednesday") + _ = func(s string) string { return s }("Wednesday text after key") +} + +func _() { + _ = fmt.Sprint("Friday") // want `"Friday" can be replaced by time\.Friday\.String\(\)` + _ = fmt.Sprint("text before key Friday") + _ = fmt.Sprint("Friday text after key") + _ = fmt.Sprint("Monday") // want `"Monday" can be replaced by time\.Monday\.String\(\)` + _ = fmt.Sprint("text before key Monday") + _ = fmt.Sprint("Monday text after key") + _ = fmt.Sprint("Saturday") // want `"Saturday" can be replaced by time\.Saturday\.String\(\)` + _ = fmt.Sprint("text before key Saturday") + _ = fmt.Sprint("Saturday text after key") + _ = fmt.Sprint("Sunday") // want `"Sunday" can be replaced by time\.Sunday\.String\(\)` + _ = fmt.Sprint("text before key Sunday") + _ = fmt.Sprint("Sunday text after key") + _ = fmt.Sprint("Thursday") // want `"Thursday" can be replaced by time\.Thursday\.String\(\)` + _ = fmt.Sprint("text before key Thursday") + _ = fmt.Sprint("Thursday text after key") + _ = fmt.Sprint("Tuesday") // want `"Tuesday" can be replaced by time\.Tuesday\.String\(\)` + _ = fmt.Sprint("text before key Tuesday") + _ = fmt.Sprint("Tuesday text after key") + _ = fmt.Sprint("Wednesday") // want `"Wednesday" can be replaced by time\.Wednesday\.String\(\)` + _ = fmt.Sprint("text before key Wednesday") + _ = fmt.Sprint("Wednesday text after key") +}