diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 44267a4..db63cb8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,9 +25,6 @@ jobs: version: latest args: --timeout 5m - - name: Go Format - run: gofmt -s -w . && git diff --exit-code - - name: Go Tidy run: go mod tidy && git diff --exit-code diff --git a/internal/gen.go b/internal/gen.go new file mode 100644 index 0000000..52d50a2 --- /dev/null +++ b/internal/gen.go @@ -0,0 +1,242 @@ +//go:build ignore +// +build ignore + +package main + +import ( + "crypto" + "embed" + "log" + "net/http" + "net/rpc" + "os" + "regexp" + "strconv" + "text/template" + "time" +) + +type tmpl struct { + PackageName string + Dict dict +} + +type ( + dict struct { + Name string + Data []data + } + data struct { + Key string + Value string + } +) + +var cryptoHash = dict{ + Name: "cryptoHash", + Data: []data{ + {Key: crypto.MD4.String(), Value: "crypto.MD4.String()"}, + {Key: crypto.MD5.String(), Value: "crypto.MD5.String()"}, + {Key: crypto.SHA1.String(), Value: "crypto.SHA1.String()"}, + {Key: crypto.SHA224.String(), Value: "crypto.SHA224.String()"}, + {Key: crypto.SHA256.String(), Value: "crypto.SHA256.String()"}, + {Key: crypto.SHA384.String(), Value: "crypto.SHA384.String()"}, + {Key: crypto.SHA512.String(), Value: "crypto.SHA512.String()"}, + {Key: crypto.MD5SHA1.String(), Value: "crypto.MD5SHA1.String()"}, + {Key: crypto.RIPEMD160.String(), Value: "crypto.RIPEMD160.String()"}, + {Key: crypto.SHA3_224.String(), Value: "crypto.SHA3_224.String()"}, + {Key: crypto.SHA3_256.String(), Value: "crypto.SHA3_256.String()"}, + {Key: crypto.SHA3_384.String(), Value: "crypto.SHA3_384.String()"}, + {Key: crypto.SHA3_512.String(), Value: "crypto.SHA3_512.String()"}, + {Key: crypto.SHA512_224.String(), Value: "crypto.SHA512_224.String()"}, + {Key: crypto.SHA512_256.String(), Value: "crypto.SHA512_256.String()"}, + {Key: crypto.BLAKE2s_256.String(), Value: "crypto.BLAKE2s_256.String()"}, + {Key: crypto.BLAKE2b_256.String(), Value: "crypto.BLAKE2b_256.String()"}, + {Key: crypto.BLAKE2b_384.String(), Value: "crypto.BLAKE2b_384.String()"}, + {Key: crypto.BLAKE2b_512.String(), Value: "crypto.BLAKE2b_512.String()"}, + }, +} + +var httpMethod = dict{ + Name: "httpMethod", + Data: []data{ + {Key: http.MethodGet, Value: "http.MethodGet"}, + {Key: http.MethodHead, Value: "http.MethodHead"}, + {Key: http.MethodPost, Value: "http.MethodPost"}, + {Key: http.MethodPut, Value: "http.MethodPut"}, + {Key: http.MethodPatch, Value: "http.MethodPatch"}, + {Key: http.MethodDelete, Value: "http.MethodDelete"}, + {Key: http.MethodConnect, Value: "http.MethodConnect"}, + {Key: http.MethodOptions, Value: "http.MethodOptions"}, + {Key: http.MethodTrace, Value: "http.MethodTrace"}, + }, +} + +var httpStatusCode = dict{ + Name: "httpStatusCode", + Data: []data{ + {Key: strconv.Itoa(http.StatusContinue), Value: "http.StatusContinue"}, + {Key: strconv.Itoa(http.StatusSwitchingProtocols), Value: "http.StatusSwitchingProtocols"}, + {Key: strconv.Itoa(http.StatusProcessing), Value: "http.StatusProcessing"}, + {Key: strconv.Itoa(http.StatusEarlyHints), Value: "http.StatusEarlyHints"}, + + {Key: strconv.Itoa(http.StatusOK), Value: "http.StatusOK"}, + {Key: strconv.Itoa(http.StatusCreated), Value: "http.StatusCreated"}, + {Key: strconv.Itoa(http.StatusAccepted), Value: "http.StatusAccepted"}, + {Key: strconv.Itoa(http.StatusNonAuthoritativeInfo), Value: "http.StatusNonAuthoritativeInfo"}, + {Key: strconv.Itoa(http.StatusNoContent), Value: "http.StatusNoContent"}, + {Key: strconv.Itoa(http.StatusResetContent), Value: "http.StatusResetContent"}, + {Key: strconv.Itoa(http.StatusPartialContent), Value: "http.StatusPartialContent"}, + {Key: strconv.Itoa(http.StatusMultiStatus), Value: "http.StatusMultiStatus"}, + {Key: strconv.Itoa(http.StatusAlreadyReported), Value: "http.StatusAlreadyReported"}, + {Key: strconv.Itoa(http.StatusIMUsed), Value: "http.StatusIMUsed"}, + + {Key: strconv.Itoa(http.StatusMultipleChoices), Value: "http.StatusMultipleChoices"}, + {Key: strconv.Itoa(http.StatusMovedPermanently), Value: "http.StatusMovedPermanently"}, + {Key: strconv.Itoa(http.StatusFound), Value: "http.StatusFound"}, + {Key: strconv.Itoa(http.StatusSeeOther), Value: "http.StatusSeeOther"}, + {Key: strconv.Itoa(http.StatusNotModified), Value: "http.StatusNotModified"}, + {Key: strconv.Itoa(http.StatusUseProxy), Value: "http.StatusUseProxy"}, + {Key: strconv.Itoa(http.StatusTemporaryRedirect), Value: "http.StatusTemporaryRedirect"}, + {Key: strconv.Itoa(http.StatusPermanentRedirect), Value: "http.StatusPermanentRedirect"}, + + {Key: strconv.Itoa(http.StatusBadRequest), Value: "http.StatusBadRequest"}, + {Key: strconv.Itoa(http.StatusUnauthorized), Value: "http.StatusUnauthorized"}, + {Key: strconv.Itoa(http.StatusPaymentRequired), Value: "http.StatusPaymentRequired"}, + {Key: strconv.Itoa(http.StatusForbidden), Value: "http.StatusForbidden"}, + {Key: strconv.Itoa(http.StatusNotFound), Value: "http.StatusNotFound"}, + {Key: strconv.Itoa(http.StatusMethodNotAllowed), Value: "http.StatusMethodNotAllowed"}, + {Key: strconv.Itoa(http.StatusNotAcceptable), Value: "http.StatusNotAcceptable"}, + {Key: strconv.Itoa(http.StatusProxyAuthRequired), Value: "http.StatusProxyAuthRequired"}, + {Key: strconv.Itoa(http.StatusRequestTimeout), Value: "http.StatusRequestTimeout"}, + {Key: strconv.Itoa(http.StatusConflict), Value: "http.StatusConflict"}, + {Key: strconv.Itoa(http.StatusGone), Value: "http.StatusGone"}, + {Key: strconv.Itoa(http.StatusLengthRequired), Value: "http.StatusLengthRequired"}, + {Key: strconv.Itoa(http.StatusPreconditionFailed), Value: "http.StatusPreconditionFailed"}, + {Key: strconv.Itoa(http.StatusRequestEntityTooLarge), Value: "http.StatusRequestEntityTooLarge"}, + {Key: strconv.Itoa(http.StatusRequestURITooLong), Value: "http.StatusRequestURITooLong"}, + {Key: strconv.Itoa(http.StatusUnsupportedMediaType), Value: "http.StatusUnsupportedMediaType"}, + {Key: strconv.Itoa(http.StatusRequestedRangeNotSatisfiable), Value: "http.StatusRequestedRangeNotSatisfiable"}, + {Key: strconv.Itoa(http.StatusExpectationFailed), Value: "http.StatusExpectationFailed"}, + {Key: strconv.Itoa(http.StatusTeapot), Value: "http.StatusTeapot"}, + {Key: strconv.Itoa(http.StatusMisdirectedRequest), Value: "http.StatusMisdirectedRequest"}, + {Key: strconv.Itoa(http.StatusUnprocessableEntity), Value: "http.StatusUnprocessableEntity"}, + {Key: strconv.Itoa(http.StatusLocked), Value: "http.StatusLocked"}, + {Key: strconv.Itoa(http.StatusFailedDependency), Value: "http.StatusFailedDependency"}, + {Key: strconv.Itoa(http.StatusTooEarly), Value: "http.StatusTooEarly"}, + {Key: strconv.Itoa(http.StatusUpgradeRequired), Value: "http.StatusUpgradeRequired"}, + {Key: strconv.Itoa(http.StatusPreconditionRequired), Value: "http.StatusPreconditionRequired"}, + {Key: strconv.Itoa(http.StatusTooManyRequests), Value: "http.StatusTooManyRequests"}, + {Key: strconv.Itoa(http.StatusRequestHeaderFieldsTooLarge), Value: "http.StatusRequestHeaderFieldsTooLarge"}, + {Key: strconv.Itoa(http.StatusUnavailableForLegalReasons), Value: "http.StatusUnavailableForLegalReasons"}, + + {Key: strconv.Itoa(http.StatusInternalServerError), Value: "http.StatusInternalServerError"}, + {Key: strconv.Itoa(http.StatusNotImplemented), Value: "http.StatusNotImplemented"}, + {Key: strconv.Itoa(http.StatusBadGateway), Value: "http.StatusBadGateway"}, + {Key: strconv.Itoa(http.StatusServiceUnavailable), Value: "http.StatusServiceUnavailable"}, + {Key: strconv.Itoa(http.StatusGatewayTimeout), Value: "http.StatusGatewayTimeout"}, + {Key: strconv.Itoa(http.StatusHTTPVersionNotSupported), Value: "http.StatusHTTPVersionNotSupported"}, + {Key: strconv.Itoa(http.StatusVariantAlsoNegotiates), Value: "http.StatusVariantAlsoNegotiates"}, + {Key: strconv.Itoa(http.StatusInsufficientStorage), Value: "http.StatusInsufficientStorage"}, + {Key: strconv.Itoa(http.StatusLoopDetected), Value: "http.StatusLoopDetected"}, + {Key: strconv.Itoa(http.StatusNotExtended), Value: "http.StatusNotExtended"}, + {Key: strconv.Itoa(http.StatusNetworkAuthenticationRequired), Value: "http.StatusNetworkAuthenticationRequired"}, + }, +} + +var defaultRPCPath = dict{ + Name: "defaultRPCPath", + Data: []data{ + {Key: rpc.DefaultRPCPath, Value: "rpc.DefaultRPCPath"}, + {Key: rpc.DefaultDebugPath, Value: "rpc.DefaultDebugPath"}, + }, +} + +var timeWeekday = dict{ + Name: "timeWeekday", + Data: []data{ + {Key: time.Sunday.String(), Value: "time.Sunday.String()"}, + {Key: time.Monday.String(), Value: "time.Monday.String()"}, + {Key: time.Tuesday.String(), Value: "time.Tuesday.String()"}, + {Key: time.Wednesday.String(), Value: "time.Wednesday.String()"}, + {Key: time.Thursday.String(), Value: "time.Thursday.String()"}, + {Key: time.Friday.String(), Value: "time.Friday.String()"}, + {Key: time.Saturday.String(), Value: "time.Saturday.String()"}, + }, +} + +var timeMonth = dict{ + Name: "timeMonth", + Data: []data{ + {Key: time.January.String(), Value: "time.January.String()"}, + {Key: time.February.String(), Value: "time.February.String()"}, + {Key: time.March.String(), Value: "time.March.String()"}, + {Key: time.April.String(), Value: "time.April.String()"}, + {Key: time.May.String(), Value: "time.May.String()"}, + {Key: time.June.String(), Value: "time.June.String()"}, + {Key: time.July.String(), Value: "time.July.String()"}, + {Key: time.August.String(), Value: "time.August.String()"}, + {Key: time.September.String(), Value: "time.September.String()"}, + {Key: time.October.String(), Value: "time.October.String()"}, + {Key: time.November.String(), Value: "time.November.String()"}, + {Key: time.December.String(), Value: "time.December.String()"}, + }, +} + +var timeLayout = dict{ + Name: "timeLayout", + Data: []data{ + {Key: time.Layout, Value: "time.Layout"}, + {Key: time.ANSIC, Value: "time.ANSIC"}, + {Key: time.UnixDate, Value: "time.UnixDate"}, + {Key: time.RubyDate, Value: "time.RubyDate"}, + {Key: time.RFC822, Value: "time.RFC822"}, + {Key: time.RFC822Z, Value: "time.RFC822Z"}, + {Key: time.RFC850, Value: "time.RFC850"}, + {Key: time.RFC1123, Value: "time.RFC1123"}, + {Key: time.RFC1123Z, Value: "time.RFC1123Z"}, + {Key: time.RFC3339, Value: "time.RFC3339"}, + {Key: time.RFC3339Nano, Value: "time.RFC3339Nano"}, + {Key: time.Kitchen, Value: "time.Kitchen"}, + {Key: time.Stamp, Value: "time.Stamp"}, + {Key: time.StampMilli, Value: "time.StampMilli"}, + {Key: time.StampMicro, Value: "time.StampMicro"}, + {Key: time.StampNano, Value: "time.StampNano"}, + }, +} + +//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"), + ) + execute("pkg/analyzer/mapping.go", t, "mapping.tmpl", []dict{cryptoHash, httpMethod, httpStatusCode, defaultRPCPath, timeWeekday, timeMonth, timeLayout}) + execute("pkg/analyzer/testdata/src/a/crypto/crypto.go", t, "template.tmpl", tmpl{PackageName: "crypto", Dict: cryptoHash}) + execute("pkg/analyzer/testdata/src/a/http/method.go", t, "httpmethod.tmpl", httpMethod) + execute("pkg/analyzer/testdata/src/a/http/statuscode.go", t, "httpstatuscode.tmpl", httpStatusCode) + execute("pkg/analyzer/testdata/src/a/rpc/rpc.go", t, "template.tmpl", tmpl{PackageName: "rpc", Dict: defaultRPCPath}) + execute("pkg/analyzer/testdata/src/a/time/weekday.go", t, "template.tmpl", tmpl{PackageName: "time", Dict: timeWeekday}) + execute("pkg/analyzer/testdata/src/a/time/month.go", t, "template.tmpl", tmpl{PackageName: "time", Dict: timeMonth}) + execute("pkg/analyzer/testdata/src/a/time/layout.go", t, "template.tmpl", tmpl{PackageName: "time", Dict: timeLayout}) +} + +func execute(fileName string, t *template.Template, templateName string, data any) { + f, err := os.Create(fileName) + mustNil(err) + defer f.Close() + t.ExecuteTemplate( + f, + templateName, + data, + ) +} + +func mustNil(err error) { + if err != nil { + log.Panic(err) + } +} diff --git a/internal/template/httpmethod.tmpl b/internal/template/httpmethod.tmpl new file mode 100644 index 0000000..f62c498 --- /dev/null +++ b/internal/template/httpmethod.tmpl @@ -0,0 +1,37 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package http + +import "net/http" + +var ( +{{- range $key, $data := .Data }} + _ = "{{ $data.Key }}" +{{- end }} +) + +const ( +{{- range $key, $data := .Data }} + _ = "{{ $data.Key }}" +{{- end }} +) + +func _() { +{{- range $key, $data := .Data }} + _, _ = http.NewRequest("{{ $data.Key }}", "", nil) // want `"{{ quoteMeta $data.Key }}" can be replaced by {{ quoteMeta $data.Value }}` +{{- end }} +} + +func _() { +{{- range $key, $data := .Data }} + _, _ = http.NewRequestWithContext(nil, "{{ $data.Key }}", "", nil) // want `"{{ quoteMeta $data.Key }}" can be replaced by {{ quoteMeta $data.Value }}` +{{- end }} +} + +func _() { +{{- range $key, $data := .Data }} + _ = &http.Request{ + Method: "{{ $data.Key }}", // want `"{{ quoteMeta $data.Key }}" can be replaced by {{ quoteMeta $data.Value }}` + } +{{- end }} +} diff --git a/internal/template/httpstatuscode.tmpl b/internal/template/httpstatuscode.tmpl new file mode 100644 index 0000000..fb56890 --- /dev/null +++ b/internal/template/httpstatuscode.tmpl @@ -0,0 +1,31 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package http + +import "net/http" + +var ( +{{- range $key, $data := .Data }} + _ = {{ $data.Key }} +{{- end }} +) + +const ( +{{- range $key, $data := .Data }} + _ = {{ $data.Key }} +{{- end }} +) +{{ range $key, $data := .Data }} +func _() { + var w http.ResponseWriter + w.WriteHeader({{ $data.Key }}) // want `"{{ quoteMeta $data.Key }}" can be replaced by {{ quoteMeta $data.Value }}` +} +{{ end -}} + +{{ range $key, $data := .Data }} +func _() { + _ = &http.Response{ + StatusCode: {{ $data.Key }}, // want `"{{ quoteMeta $data.Key }}" can be replaced by {{ quoteMeta $data.Value }}` + } +} +{{ end -}} diff --git a/internal/template/mapping.tmpl b/internal/template/mapping.tmpl new file mode 100644 index 0000000..5ee1e6d --- /dev/null +++ b/internal/template/mapping.tmpl @@ -0,0 +1,10 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package analyzer +{{ range $key, $value := . }} +var {{ $value.Name }} = map[string]string{ + {{- range $key, $data := $value.Data }} + "{{ $data.Key }}":"{{ $data.Value }}", + {{- end }} +} +{{ end -}} diff --git a/internal/template/template.tmpl b/internal/template/template.tmpl new file mode 100644 index 0000000..9310d28 --- /dev/null +++ b/internal/template/template.tmpl @@ -0,0 +1,33 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package {{ .PackageName }} + +import "fmt" + +var ( +{{- range $key, $data := .Dict.Data }} + _ = "{{ $data.Key }}" // want `"{{ quoteMeta $data.Key }}" can be replaced by {{ quoteMeta $data.Value }}` +{{- end }} +) + +const ( +{{- range $key, $data := .Dict.Data }} + _ = "{{ $data.Key }}" // want `"{{ quoteMeta $data.Key }}" can be replaced by {{ quoteMeta $data.Value }}` +{{- end }} +) + +func _() { +{{- range $key, $data := .Dict.Data }} + _ = func(s string)string{return s}("{{ $data.Key }}") // want `"{{ quoteMeta $data.Key }}" can be replaced by {{ quoteMeta $data.Value }}` + _ = func(s string)string{return s}("text before key {{ $data.Key }}") + _ = func(s string)string{return s}("{{ $data.Key }} text after key") +{{- end }} +} + +func _() { +{{- range $key, $data := .Dict.Data }} + _ = fmt.Sprint("{{ $data.Key }}") // want `"{{ quoteMeta $data.Key }}" can be replaced by {{ quoteMeta $data.Value }}` + _ = fmt.Sprint("text before key {{ $data.Key }}") + _ = fmt.Sprint("{{ $data.Key }} text after key") +{{- end }} +} diff --git a/main.go b/main.go index 30fe81c..b0460a3 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,9 @@ import ( "github.com/sashamelentyev/usestdlibvars/pkg/analyzer" ) +//go:generate go run internal/gen.go +//go:generate gofmt -s -w . + func main() { singlechecker.Main(analyzer.New()) } diff --git a/pkg/analyzer/mapping.go b/pkg/analyzer/mapping.go index f32bf61..cbb3e15 100644 --- a/pkg/analyzer/mapping.go +++ b/pkg/analyzer/mapping.go @@ -1,161 +1,151 @@ -package analyzer +// Code generated by usestdlibvars, DO NOT EDIT. -import ( - "crypto" - "net/http" - "net/rpc" - "strconv" - "time" -) +package analyzer var cryptoHash = map[string]string{ - crypto.MD4.String(): "crypto.MD4.String()", - crypto.MD5.String(): "crypto.MD5.String()", - crypto.SHA1.String(): "crypto.SHA1.String()", - crypto.SHA224.String(): "crypto.SHA224.String()", - crypto.SHA256.String(): "crypto.SHA256.String()", - crypto.SHA384.String(): "crypto.SHA384.String()", - crypto.SHA512.String(): "crypto.SHA512.String()", - crypto.MD5SHA1.String(): "crypto.MD5SHA1.String()", - crypto.RIPEMD160.String(): "crypto.RIPEMD160.String()", - crypto.SHA3_224.String(): "crypto.SHA3_224.String()", - crypto.SHA3_256.String(): "crypto.SHA3_256.String()", - crypto.SHA3_384.String(): "crypto.SHA3_384.String()", - crypto.SHA3_512.String(): "crypto.SHA3_512.String()", - crypto.SHA512_224.String(): "crypto.SHA512_224.String()", - crypto.SHA512_256.String(): "crypto.SHA512_256.String()", - crypto.BLAKE2s_256.String(): "crypto.BLAKE2s_256.String()", - crypto.BLAKE2b_256.String(): "crypto.BLAKE2b_256.String()", - crypto.BLAKE2b_384.String(): "crypto.BLAKE2b_384.String()", - crypto.BLAKE2b_512.String(): "crypto.BLAKE2b_512.String()", + "MD4": "crypto.MD4.String()", + "MD5": "crypto.MD5.String()", + "SHA-1": "crypto.SHA1.String()", + "SHA-224": "crypto.SHA224.String()", + "SHA-256": "crypto.SHA256.String()", + "SHA-384": "crypto.SHA384.String()", + "SHA-512": "crypto.SHA512.String()", + "MD5+SHA1": "crypto.MD5SHA1.String()", + "RIPEMD-160": "crypto.RIPEMD160.String()", + "SHA3-224": "crypto.SHA3_224.String()", + "SHA3-256": "crypto.SHA3_256.String()", + "SHA3-384": "crypto.SHA3_384.String()", + "SHA3-512": "crypto.SHA3_512.String()", + "SHA-512/224": "crypto.SHA512_224.String()", + "SHA-512/256": "crypto.SHA512_256.String()", + "BLAKE2s-256": "crypto.BLAKE2s_256.String()", + "BLAKE2b-256": "crypto.BLAKE2b_256.String()", + "BLAKE2b-384": "crypto.BLAKE2b_384.String()", + "BLAKE2b-512": "crypto.BLAKE2b_512.String()", } var httpMethod = map[string]string{ - http.MethodGet: "http.MethodGet", - http.MethodHead: "http.MethodHead", - http.MethodPost: "http.MethodPost", - http.MethodPut: "http.MethodPut", - http.MethodPatch: "http.MethodPatch", - http.MethodDelete: "http.MethodDelete", - http.MethodConnect: "http.MethodConnect", - http.MethodOptions: "http.MethodOptions", - http.MethodTrace: "http.MethodTrace", + "GET": "http.MethodGet", + "HEAD": "http.MethodHead", + "POST": "http.MethodPost", + "PUT": "http.MethodPut", + "PATCH": "http.MethodPatch", + "DELETE": "http.MethodDelete", + "CONNECT": "http.MethodConnect", + "OPTIONS": "http.MethodOptions", + "TRACE": "http.MethodTrace", } var httpStatusCode = map[string]string{ - strconv.Itoa(http.StatusContinue): "http.StatusContinue", - strconv.Itoa(http.StatusSwitchingProtocols): "http.StatusSwitchingProtocols", - strconv.Itoa(http.StatusProcessing): "http.StatusProcessing", - strconv.Itoa(http.StatusEarlyHints): "http.StatusEarlyHints", - - strconv.Itoa(http.StatusOK): "http.StatusOK", - strconv.Itoa(http.StatusCreated): "http.StatusCreated", - strconv.Itoa(http.StatusAccepted): "http.StatusAccepted", - strconv.Itoa(http.StatusNonAuthoritativeInfo): "http.StatusNonAuthoritativeInfo", - strconv.Itoa(http.StatusNoContent): "http.StatusNoContent", - strconv.Itoa(http.StatusResetContent): "http.StatusResetContent", - strconv.Itoa(http.StatusPartialContent): "http.StatusPartialContent", - strconv.Itoa(http.StatusMultiStatus): "http.StatusMultiStatus", - strconv.Itoa(http.StatusAlreadyReported): "http.StatusAlreadyReported", - strconv.Itoa(http.StatusIMUsed): "http.StatusIMUsed", - - strconv.Itoa(http.StatusMultipleChoices): "http.StatusMultipleChoices", - strconv.Itoa(http.StatusMovedPermanently): "http.StatusMovedPermanently", - strconv.Itoa(http.StatusFound): "http.StatusFound", - strconv.Itoa(http.StatusSeeOther): "http.StatusSeeOther", - strconv.Itoa(http.StatusNotModified): "http.StatusNotModified", - strconv.Itoa(http.StatusUseProxy): "http.StatusUseProxy", - strconv.Itoa(http.StatusTemporaryRedirect): "http.StatusTemporaryRedirect", - strconv.Itoa(http.StatusPermanentRedirect): "http.StatusPermanentRedirect", - - strconv.Itoa(http.StatusBadRequest): "http.StatusBadRequest", - strconv.Itoa(http.StatusUnauthorized): "http.StatusUnauthorized", - strconv.Itoa(http.StatusPaymentRequired): "http.StatusPaymentRequired", - strconv.Itoa(http.StatusForbidden): "http.StatusForbidden", - strconv.Itoa(http.StatusNotFound): "http.StatusNotFound", - strconv.Itoa(http.StatusMethodNotAllowed): "http.StatusMethodNotAllowed", - strconv.Itoa(http.StatusNotAcceptable): "http.StatusNotAcceptable", - strconv.Itoa(http.StatusProxyAuthRequired): "http.StatusProxyAuthRequired", - strconv.Itoa(http.StatusRequestTimeout): "http.StatusRequestTimeout", - strconv.Itoa(http.StatusConflict): "http.StatusConflict", - strconv.Itoa(http.StatusGone): "http.StatusGone", - strconv.Itoa(http.StatusLengthRequired): "http.StatusLengthRequired", - strconv.Itoa(http.StatusPreconditionFailed): "http.StatusPreconditionFailed", - strconv.Itoa(http.StatusRequestEntityTooLarge): "http.StatusRequestEntityTooLarge", - strconv.Itoa(http.StatusRequestURITooLong): "http.StatusRequestURITooLong", - strconv.Itoa(http.StatusUnsupportedMediaType): "http.StatusUnsupportedMediaType", - strconv.Itoa(http.StatusRequestedRangeNotSatisfiable): "http.StatusRequestedRangeNotSatisfiable", - strconv.Itoa(http.StatusExpectationFailed): "http.StatusExpectationFailed", - strconv.Itoa(http.StatusTeapot): "http.StatusTeapot", - strconv.Itoa(http.StatusMisdirectedRequest): "http.StatusMisdirectedRequest", - strconv.Itoa(http.StatusUnprocessableEntity): "http.StatusUnprocessableEntity", - strconv.Itoa(http.StatusLocked): "http.StatusLocked", - strconv.Itoa(http.StatusFailedDependency): "http.StatusFailedDependency", - strconv.Itoa(http.StatusTooEarly): "http.StatusTooEarly", - strconv.Itoa(http.StatusUpgradeRequired): "http.StatusUpgradeRequired", - strconv.Itoa(http.StatusPreconditionRequired): "http.StatusPreconditionRequired", - strconv.Itoa(http.StatusTooManyRequests): "http.StatusTooManyRequests", - strconv.Itoa(http.StatusRequestHeaderFieldsTooLarge): "http.StatusRequestHeaderFieldsTooLarge", - strconv.Itoa(http.StatusUnavailableForLegalReasons): "http.StatusUnavailableForLegalReasons", - - strconv.Itoa(http.StatusInternalServerError): "http.StatusInternalServerError", - strconv.Itoa(http.StatusNotImplemented): "http.StatusNotImplemented", - strconv.Itoa(http.StatusBadGateway): "http.StatusBadGateway", - strconv.Itoa(http.StatusServiceUnavailable): "http.StatusServiceUnavailable", - strconv.Itoa(http.StatusGatewayTimeout): "http.StatusGatewayTimeout", - strconv.Itoa(http.StatusHTTPVersionNotSupported): "http.StatusHTTPVersionNotSupported", - strconv.Itoa(http.StatusVariantAlsoNegotiates): "http.StatusVariantAlsoNegotiates", - strconv.Itoa(http.StatusInsufficientStorage): "http.StatusInsufficientStorage", - strconv.Itoa(http.StatusLoopDetected): "http.StatusLoopDetected", - strconv.Itoa(http.StatusNotExtended): "http.StatusNotExtended", - strconv.Itoa(http.StatusNetworkAuthenticationRequired): "http.StatusNetworkAuthenticationRequired", + "100": "http.StatusContinue", + "101": "http.StatusSwitchingProtocols", + "102": "http.StatusProcessing", + "103": "http.StatusEarlyHints", + "200": "http.StatusOK", + "201": "http.StatusCreated", + "202": "http.StatusAccepted", + "203": "http.StatusNonAuthoritativeInfo", + "204": "http.StatusNoContent", + "205": "http.StatusResetContent", + "206": "http.StatusPartialContent", + "207": "http.StatusMultiStatus", + "208": "http.StatusAlreadyReported", + "226": "http.StatusIMUsed", + "300": "http.StatusMultipleChoices", + "301": "http.StatusMovedPermanently", + "302": "http.StatusFound", + "303": "http.StatusSeeOther", + "304": "http.StatusNotModified", + "305": "http.StatusUseProxy", + "307": "http.StatusTemporaryRedirect", + "308": "http.StatusPermanentRedirect", + "400": "http.StatusBadRequest", + "401": "http.StatusUnauthorized", + "402": "http.StatusPaymentRequired", + "403": "http.StatusForbidden", + "404": "http.StatusNotFound", + "405": "http.StatusMethodNotAllowed", + "406": "http.StatusNotAcceptable", + "407": "http.StatusProxyAuthRequired", + "408": "http.StatusRequestTimeout", + "409": "http.StatusConflict", + "410": "http.StatusGone", + "411": "http.StatusLengthRequired", + "412": "http.StatusPreconditionFailed", + "413": "http.StatusRequestEntityTooLarge", + "414": "http.StatusRequestURITooLong", + "415": "http.StatusUnsupportedMediaType", + "416": "http.StatusRequestedRangeNotSatisfiable", + "417": "http.StatusExpectationFailed", + "418": "http.StatusTeapot", + "421": "http.StatusMisdirectedRequest", + "422": "http.StatusUnprocessableEntity", + "423": "http.StatusLocked", + "424": "http.StatusFailedDependency", + "425": "http.StatusTooEarly", + "426": "http.StatusUpgradeRequired", + "428": "http.StatusPreconditionRequired", + "429": "http.StatusTooManyRequests", + "431": "http.StatusRequestHeaderFieldsTooLarge", + "451": "http.StatusUnavailableForLegalReasons", + "500": "http.StatusInternalServerError", + "501": "http.StatusNotImplemented", + "502": "http.StatusBadGateway", + "503": "http.StatusServiceUnavailable", + "504": "http.StatusGatewayTimeout", + "505": "http.StatusHTTPVersionNotSupported", + "506": "http.StatusVariantAlsoNegotiates", + "507": "http.StatusInsufficientStorage", + "508": "http.StatusLoopDetected", + "510": "http.StatusNotExtended", + "511": "http.StatusNetworkAuthenticationRequired", } var defaultRPCPath = map[string]string{ - rpc.DefaultRPCPath: "rpc.DefaultRPCPath", - rpc.DefaultDebugPath: "rpc.DefaultDebugPath", + "/_goRPC_": "rpc.DefaultRPCPath", + "/debug/rpc": "rpc.DefaultDebugPath", } var timeWeekday = map[string]string{ - time.Sunday.String(): "time.Sunday.String()", - time.Monday.String(): "time.Monday.String()", - time.Tuesday.String(): "time.Tuesday.String()", - time.Wednesday.String(): "time.Wednesday.String()", - time.Thursday.String(): "time.Thursday.String()", - time.Friday.String(): "time.Friday.String()", - time.Saturday.String(): "time.Saturday.String()", + "Sunday": "time.Sunday.String()", + "Monday": "time.Monday.String()", + "Tuesday": "time.Tuesday.String()", + "Wednesday": "time.Wednesday.String()", + "Thursday": "time.Thursday.String()", + "Friday": "time.Friday.String()", + "Saturday": "time.Saturday.String()", } var timeMonth = map[string]string{ - time.January.String(): "time.January.String()", - time.February.String(): "time.February.String()", - time.March.String(): "time.March.String()", - time.April.String(): "time.April.String()", - time.May.String(): "time.May.String()", - time.June.String(): "time.June.String()", - time.July.String(): "time.July.String()", - time.August.String(): "time.August.String()", - time.September.String(): "time.September.String()", - time.October.String(): "time.October.String()", - time.November.String(): "time.November.String()", - time.December.String(): "time.December.String()", + "January": "time.January.String()", + "February": "time.February.String()", + "March": "time.March.String()", + "April": "time.April.String()", + "May": "time.May.String()", + "June": "time.June.String()", + "July": "time.July.String()", + "August": "time.August.String()", + "September": "time.September.String()", + "October": "time.October.String()", + "November": "time.November.String()", + "December": "time.December.String()", } var timeLayout = map[string]string{ - time.Layout: "time.Layout", - time.ANSIC: "time.ANSIC", - time.UnixDate: "time.UnixDate", - time.RubyDate: "time.RubyDate", - time.RFC822: "time.RFC822", - time.RFC822Z: "time.RFC822Z", - time.RFC850: "time.RFC850", - time.RFC1123: "time.RFC1123", - time.RFC1123Z: "time.RFC1123Z", - time.RFC3339: "time.RFC3339", - time.RFC3339Nano: "time.RFC3339Nano", - time.Kitchen: "time.Kitchen", - time.Stamp: "time.Stamp", - time.StampMilli: "time.StampMilli", - time.StampMicro: "time.StampMicro", - time.StampNano: "time.StampNano", + "01/02 03:04:05PM '06 -0700": "time.Layout", + "Mon Jan _2 15:04:05 2006": "time.ANSIC", + "Mon Jan _2 15:04:05 MST 2006": "time.UnixDate", + "Mon Jan 02 15:04:05 -0700 2006": "time.RubyDate", + "02 Jan 06 15:04 MST": "time.RFC822", + "02 Jan 06 15:04 -0700": "time.RFC822Z", + "Monday, 02-Jan-06 15:04:05 MST": "time.RFC850", + "Mon, 02 Jan 2006 15:04:05 MST": "time.RFC1123", + "Mon, 02 Jan 2006 15:04:05 -0700": "time.RFC1123Z", + "2006-01-02T15:04:05Z07:00": "time.RFC3339", + "2006-01-02T15:04:05.999999999Z07:00": "time.RFC3339Nano", + "3:04PM": "time.Kitchen", + "Jan _2 15:04:05": "time.Stamp", + "Jan _2 15:04:05.000": "time.StampMilli", + "Jan _2 15:04:05.000000": "time.StampMicro", + "Jan _2 15:04:05.000000000": "time.StampNano", } diff --git a/pkg/analyzer/testdata/src/a/crypto/crypto.go b/pkg/analyzer/testdata/src/a/crypto/crypto.go index d36add6..ce45f0a 100644 --- a/pkg/analyzer/testdata/src/a/crypto/crypto.go +++ b/pkg/analyzer/testdata/src/a/crypto/crypto.go @@ -1,52 +1,169 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + package crypto 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\(\)` + _ = "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\(\)` ) 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\(\)` + _ = "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\(\)` ) 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 }("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 }("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 }("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 }("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(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 }("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 }("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 _() { + _ = 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("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("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("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") + _ = 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("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("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") } 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..e876c41 --- /dev/null +++ b/pkg/analyzer/testdata/src/a/http/method.go @@ -0,0 +1,83 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package http + +import "net/http" + +var ( + _ = "GET" + _ = "HEAD" + _ = "POST" + _ = "PUT" + _ = "PATCH" + _ = "DELETE" + _ = "CONNECT" + _ = "OPTIONS" + _ = "TRACE" +) + +const ( + _ = "GET" + _ = "HEAD" + _ = "POST" + _ = "PUT" + _ = "PATCH" + _ = "DELETE" + _ = "CONNECT" + _ = "OPTIONS" + _ = "TRACE" +) + +func _() { + _, _ = 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("POST", "", nil) // want `"POST" can be replaced by http\.MethodPost` + _, _ = http.NewRequest("PUT", "", nil) // want `"PUT" can be replaced by http\.MethodPut` + _, _ = http.NewRequest("PATCH", "", nil) // want `"PATCH" can be replaced by http\.MethodPatch` + _, _ = http.NewRequest("DELETE", "", nil) // want `"DELETE" can be replaced by http\.MethodDelete` + _, _ = http.NewRequest("CONNECT", "", nil) // want `"CONNECT" can be replaced by http\.MethodConnect` + _, _ = http.NewRequest("OPTIONS", "", nil) // want `"OPTIONS" can be replaced by http\.MethodOptions` + _, _ = http.NewRequest("TRACE", "", nil) // want `"TRACE" can be replaced by http\.MethodTrace` +} + +func _() { + _, _ = 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, "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, "PATCH", "", nil) // want `"PATCH" can be replaced by http\.MethodPatch` + _, _ = http.NewRequestWithContext(nil, "DELETE", "", nil) // want `"DELETE" can be replaced by http\.MethodDelete` + _, _ = http.NewRequestWithContext(nil, "CONNECT", "", nil) // want `"CONNECT" can be replaced by http\.MethodConnect` + _, _ = http.NewRequestWithContext(nil, "OPTIONS", "", nil) // want `"OPTIONS" can be replaced by http\.MethodOptions` + _, _ = http.NewRequestWithContext(nil, "TRACE", "", nil) // want `"TRACE" can be replaced by http\.MethodTrace` +} + +func _() { + _ = &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: "POST", // want `"POST" can be replaced by http\.MethodPost` + } + _ = &http.Request{ + Method: "PUT", // want `"PUT" can be replaced by http\.MethodPut` + } + _ = &http.Request{ + Method: "PATCH", // want `"PATCH" can be replaced by http\.MethodPatch` + } + _ = &http.Request{ + Method: "DELETE", // want `"DELETE" can be replaced by http\.MethodDelete` + } + _ = &http.Request{ + Method: "CONNECT", // want `"CONNECT" can be replaced by http\.MethodConnect` + } + _ = &http.Request{ + Method: "OPTIONS", // want `"OPTIONS" can be replaced by http\.MethodOptions` + } + _ = &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..74d4f4c --- /dev/null +++ b/pkg/analyzer/testdata/src/a/http/statuscode.go @@ -0,0 +1,817 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package http + +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..9586248 100644 --- a/pkg/analyzer/testdata/src/a/rpc/rpc.go +++ b/pkg/analyzer/testdata/src/a/rpc/rpc.go @@ -1,7 +1,33 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + package rpc -var _ = "/_goRPC_" // want `"/_goRPC_" can be replaced by rpc.DefaultRPCPath` +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..18e90c5 --- /dev/null +++ b/pkg/analyzer/testdata/src/a/time/layout.go @@ -0,0 +1,145 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package time + +import "fmt" + +var ( + _ = "01/02 03:04:05PM '06 -0700" // want `"01/02 03:04:05PM '06 -0700" can be replaced by time\.Layout` + _ = "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 Jan 02 15:04:05 -0700 2006" // want `"Mon Jan 02 15:04:05 -0700 2006" can be replaced by time\.RubyDate` + _ = "02 Jan 06 15:04 MST" // want `"02 Jan 06 15:04 MST" can be replaced by time\.RFC822` + _ = "02 Jan 06 15:04 -0700" // want `"02 Jan 06 15:04 -0700" can be replaced by time\.RFC822Z` + _ = "Monday, 02-Jan-06 15:04:05 MST" // want `"Monday, 02-Jan-06 15:04:05 MST" can be replaced by time\.RFC850` + _ = "Mon, 02 Jan 2006 15:04:05 MST" // want `"Mon, 02 Jan 2006 15:04:05 MST" can be replaced by time\.RFC1123` + _ = "Mon, 02 Jan 2006 15:04:05 -0700" // want `"Mon, 02 Jan 2006 15:04:05 -0700" can be replaced by time\.RFC1123Z` + _ = "2006-01-02T15:04:05Z07:00" // want `"2006-01-02T15:04:05Z07:00" can be replaced by time\.RFC3339` + _ = "2006-01-02T15:04:05.999999999Z07:00" // want `"2006-01-02T15:04:05\.999999999Z07:00" can be replaced by time\.RFC3339Nano` + _ = "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` +) + +const ( + _ = "01/02 03:04:05PM '06 -0700" // want `"01/02 03:04:05PM '06 -0700" can be replaced by time\.Layout` + _ = "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 Jan 02 15:04:05 -0700 2006" // want `"Mon Jan 02 15:04:05 -0700 2006" can be replaced by time\.RubyDate` + _ = "02 Jan 06 15:04 MST" // want `"02 Jan 06 15:04 MST" can be replaced by time\.RFC822` + _ = "02 Jan 06 15:04 -0700" // want `"02 Jan 06 15:04 -0700" can be replaced by time\.RFC822Z` + _ = "Monday, 02-Jan-06 15:04:05 MST" // want `"Monday, 02-Jan-06 15:04:05 MST" can be replaced by time\.RFC850` + _ = "Mon, 02 Jan 2006 15:04:05 MST" // want `"Mon, 02 Jan 2006 15:04:05 MST" can be replaced by time\.RFC1123` + _ = "Mon, 02 Jan 2006 15:04:05 -0700" // want `"Mon, 02 Jan 2006 15:04:05 -0700" can be replaced by time\.RFC1123Z` + _ = "2006-01-02T15:04:05Z07:00" // want `"2006-01-02T15:04:05Z07:00" can be replaced by time\.RFC3339` + _ = "2006-01-02T15:04:05.999999999Z07:00" // want `"2006-01-02T15:04:05\.999999999Z07:00" can be replaced by time\.RFC3339Nano` + _ = "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` +) + +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 }("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 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 }("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 }("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 }("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(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 }("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 }("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 }("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 }("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 _() { + _ = 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("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 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("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("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("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") + _ = 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("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("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("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("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") +} 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..19a7a12 --- /dev/null +++ b/pkg/analyzer/testdata/src/a/time/month.go @@ -0,0 +1,113 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package time + +import "fmt" + +var ( + _ = "January" // want `"January" can be replaced by time\.January\.String\(\)` + _ = "February" // want `"February" can be replaced by time\.February\.String\(\)` + _ = "March" // want `"March" can be replaced by time\.March\.String\(\)` + _ = "April" // want `"April" can be replaced by time\.April\.String\(\)` + _ = "May" // want `"May" can be replaced by time\.May\.String\(\)` + _ = "June" // want `"June" can be replaced by time\.June\.String\(\)` + _ = "July" // want `"July" can be replaced by time\.July\.String\(\)` + _ = "August" // want `"August" can be replaced by time\.August\.String\(\)` + _ = "September" // want `"September" can be replaced by time\.September\.String\(\)` + _ = "October" // want `"October" can be replaced by time\.October\.String\(\)` + _ = "November" // want `"November" can be replaced by time\.November\.String\(\)` + _ = "December" // want `"December" can be replaced by time\.December\.String\(\)` +) + +const ( + _ = "January" // want `"January" can be replaced by time\.January\.String\(\)` + _ = "February" // want `"February" can be replaced by time\.February\.String\(\)` + _ = "March" // want `"March" can be replaced by time\.March\.String\(\)` + _ = "April" // want `"April" can be replaced by time\.April\.String\(\)` + _ = "May" // want `"May" can be replaced by time\.May\.String\(\)` + _ = "June" // want `"June" can be replaced by time\.June\.String\(\)` + _ = "July" // want `"July" can be replaced by time\.July\.String\(\)` + _ = "August" // want `"August" can be replaced by time\.August\.String\(\)` + _ = "September" // want `"September" can be replaced by time\.September\.String\(\)` + _ = "October" // want `"October" can be replaced by time\.October\.String\(\)` + _ = "November" // want `"November" can be replaced by time\.November\.String\(\)` + _ = "December" // want `"December" can be replaced by time\.December\.String\(\)` +) + +func _() { + _ = 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 }("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 }("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 }("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 }("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 }("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 }("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 }("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 }("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(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 }("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 }("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 _() { + _ = 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("February") // want `"February" can be replaced by time\.February\.String\(\)` + _ = fmt.Sprint("text before key February") + _ = fmt.Sprint("February 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("April") // want `"April" can be replaced by time\.April\.String\(\)` + _ = fmt.Sprint("text before key April") + _ = fmt.Sprint("April 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("June") // want `"June" can be replaced by time\.June\.String\(\)` + _ = fmt.Sprint("text before key June") + _ = fmt.Sprint("June 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("August") // want `"August" can be replaced by time\.August\.String\(\)` + _ = fmt.Sprint("text before key August") + _ = fmt.Sprint("August 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") + _ = 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("November") // want `"November" can be replaced by time\.November\.String\(\)` + _ = fmt.Sprint("text before key November") + _ = fmt.Sprint("November 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") +} 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..1c28dba --- /dev/null +++ b/pkg/analyzer/testdata/src/a/time/weekday.go @@ -0,0 +1,73 @@ +// Code generated by usestdlibvars, DO NOT EDIT. + +package time + +import "fmt" + +var ( + _ = "Sunday" // want `"Sunday" can be replaced by time\.Sunday\.String\(\)` + _ = "Monday" // want `"Monday" can be replaced by time\.Monday\.String\(\)` + _ = "Tuesday" // want `"Tuesday" can be replaced by time\.Tuesday\.String\(\)` + _ = "Wednesday" // want `"Wednesday" can be replaced by time\.Wednesday\.String\(\)` + _ = "Thursday" // want `"Thursday" can be replaced by time\.Thursday\.String\(\)` + _ = "Friday" // want `"Friday" can be replaced by time\.Friday\.String\(\)` + _ = "Saturday" // want `"Saturday" can be replaced by time\.Saturday\.String\(\)` +) + +const ( + _ = "Sunday" // want `"Sunday" can be replaced by time\.Sunday\.String\(\)` + _ = "Monday" // want `"Monday" can be replaced by time\.Monday\.String\(\)` + _ = "Tuesday" // want `"Tuesday" can be replaced by time\.Tuesday\.String\(\)` + _ = "Wednesday" // want `"Wednesday" can be replaced by time\.Wednesday\.String\(\)` + _ = "Thursday" // want `"Thursday" can be replaced by time\.Thursday\.String\(\)` + _ = "Friday" // want `"Friday" can be replaced by time\.Friday\.String\(\)` + _ = "Saturday" // want `"Saturday" can be replaced by time\.Saturday\.String\(\)` +) + +func _() { + _ = 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 }("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 }("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(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 }("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 }("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 _() { + _ = 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("Monday") // want `"Monday" can be replaced by time\.Monday\.String\(\)` + _ = fmt.Sprint("text before key Monday") + _ = fmt.Sprint("Monday 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") + _ = 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("Friday") // want `"Friday" can be replaced by time\.Friday\.String\(\)` + _ = fmt.Sprint("text before key Friday") + _ = fmt.Sprint("Friday 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") +}