├── .github
└── workflows
│ └── ci.yaml
├── .gitignore
├── LICENSE
├── README.md
├── assets
└── uslv_logo.svg
├── go.mod
├── go.sum
├── main.go
└── pkg
└── analyzer
├── analyzer.go
├── analyzer_test.go
├── internal
├── gen.go
├── mapping
│ └── mapping.go
└── template
│ ├── test-httpmethod.go.golden.tmpl
│ ├── test-httpmethod.go.tmpl
│ ├── test-httpstatus.go.golden.tmpl
│ ├── test-httpstatus.go.tmpl
│ ├── test-issue103.go.golden.tmpl
│ ├── test-issue103.go.tmpl
│ ├── test-issue32.go.golden.tmpl
│ ├── test-issue32.go.tmpl
│ ├── test-issue89.go.golden.tmpl
│ ├── test-issue89.go.tmpl
│ ├── test-syslog.go.tmpl
│ ├── test-template.go.golden.tmpl
│ └── test-template.go.tmpl
└── testdata
└── src
└── a
├── constant
├── kind.go
└── kind.go.golden
├── crypto
├── crypto.go
└── crypto.go.golden
├── http
├── issue32.go
├── issue32.go.golden
├── issue89.go
├── issue89.go.golden
├── issue96.go
├── method.go
├── method.go.golden
├── status.go
└── status.go.golden
├── rpc
├── rpc.go
└── rpc.go.golden
├── sql
├── isolationlevel.go
└── isolationlevel.go.golden
├── time
├── issue103.go
├── issue103.go.golden
├── layout.go
├── layout.go.golden
├── month.go
├── month.go.golden
├── weekday.go
└── weekday.go.golden
└── tls
├── signaturescheme.go
└── signaturescheme.go.golden
/.github/workflows/ci.yaml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | branches: [ main ]
6 | pull_request:
7 | branches: [ main ]
8 |
9 | env:
10 | GO_VERSION: stable
11 |
12 | jobs:
13 | run:
14 | runs-on: ubuntu-latest
15 | strategy:
16 | matrix:
17 | go: [ stable, oldstable ]
18 |
19 | steps:
20 | - name: Checkout code
21 | uses: actions/checkout@v4
22 |
23 | - name: Install Go
24 | uses: actions/setup-go@v5
25 | with:
26 | go-version: ${{ matrix.go }}
27 |
28 | - name: Go Tidy
29 | run: go mod tidy && git diff --exit-code
30 |
31 | - name: Lint
32 | uses: golangci/golangci-lint-action@v8
33 | with:
34 | version: latest
35 | args: --timeout 5m
36 |
37 | - name: run
38 | run: go run . ./...
39 |
40 | tests:
41 | strategy:
42 | matrix:
43 | os: [ubuntu-latest, macos-latest, windows-latest]
44 | needs: run
45 | runs-on: ${{ matrix.os }}
46 | steps:
47 | - uses: actions/checkout@v4
48 |
49 | - name: Install Go
50 | uses: actions/setup-go@v5
51 | with:
52 | go-version: ${{ env.GO_VERSION }}
53 |
54 | - name: Go Test
55 | run: go test -v -race ./...
56 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Binaries for programs and plugins
2 | *.exe
3 | *.exe~
4 | *.dll
5 | *.so
6 | *.dylib
7 |
8 | # Test binary, built with `go test -c`
9 | *.test
10 |
11 | # Output of the go coverage tool, specifically when used with LiteIDE
12 | *.out
13 |
14 | # Dependency directories (remove the comment below to include it)
15 | # vendor/
16 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Sasha Melentyev
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # usestdlibvars
4 |
5 | A linter that detect the possibility to use variables/constants from the Go standard library.
6 |
7 | ## Install
8 |
9 | ### `go install`
10 |
11 | ```bash
12 | go install github.com/sashamelentyev/usestdlibvars@latest
13 | ```
14 |
15 | ### `golangci-lint`
16 |
17 | `usestdlibvars` is already integrated with
18 | [golangci-lint](https://github.com/golangci/golangci-lint).
19 |
20 | ## Usage
21 |
22 | ### Binary
23 |
24 | ```console
25 | $ usestdlibvars -h
26 | usestdlibvars: A linter that detect the possibility to use variables/constants from the Go standard library.
27 |
28 | Usage: usestdlibvars [-flag] [package]
29 |
30 |
31 | Flags:
32 | -V print version and exit
33 | -all
34 | no effect (deprecated)
35 | -c int
36 | display offending line with this many lines of context (default -1)
37 | -constant-kind
38 | suggest the use of constant.Kind.String()
39 | -cpuprofile string
40 | write CPU profile to this file
41 | -crypto-hash
42 | suggest the use of crypto.Hash.String()
43 | -debug string
44 | debug flags, any subset of "fpstv"
45 | -fix
46 | apply all suggested fixes
47 | -flags
48 | print analyzer flags in JSON
49 | -http-method
50 | suggest the use of http.MethodXX (default true)
51 | -http-status-code
52 | suggest the use of http.StatusXX (default true)
53 | -json
54 | emit JSON output
55 | -memprofile string
56 | write memory profile to this file
57 | -os-dev-null
58 | suggest the use of os.DevNull
59 | -rpc-default-path
60 | suggest the use of rpc.DefaultXXPath
61 | -source
62 | no effect (deprecated)
63 | -sql-isolation-level
64 | suggest the use of sql.LevelXX.String()
65 | -tags string
66 | no effect (deprecated)
67 | -test
68 | indicates whether test files should be analyzed, too (default true)
69 | -time-layout
70 | suggest the use of time.Layout
71 | -time-month
72 | suggest the use of time.Month.String()
73 | -time-weekday
74 | suggest the use of time.Weekday.String()
75 | -tls-signature-scheme
76 | suggest the use of tls.SignatureScheme.String()
77 | -trace string
78 | write trace log to this file
79 | -v no effect (deprecated)
80 | ```
81 |
82 | ### `golangci-lint`
83 |
84 | ```console
85 | golangci-lint run --disable-all --enable usestdlibvars
86 | ```
87 |
88 | ## Examples
89 |
90 | ```go
91 | package response
92 |
93 | import (
94 | "bytes"
95 | "encoding/json"
96 | "net/http"
97 | )
98 |
99 | // JSON marshals v to JSON, automatically escaping HTML,
100 | // setting the Content-Type header as "application/json; charset=utf-8",
101 | // sends an HTTP response header with the provided statusCode and
102 | // writes the marshaled v as bytes to the connection as part of an HTTP reply.
103 | func JSON(w http.ResponseWriter, statusCode int, v any) {
104 | var buf bytes.Buffer
105 | enc := json.NewEncoder(&buf)
106 | enc.SetEscapeHTML(true)
107 | if err := enc.Encode(v); err != nil {
108 | http.Error(w, err.Error(), 500)
109 | return
110 | }
111 | w.Header().Set("Content-Type", "application/json; charset=utf-8")
112 | w.WriteHeader(statusCode)
113 | if _, err := w.Write(buf.Bytes()); err != nil {
114 | http.Error(w, err.Error(), 500)
115 | return
116 | }
117 | }
118 | ```
119 |
120 | ```bash
121 | usestdlibvars ./...
122 | ```
123 |
124 | ```console
125 | response.go:18:30: "500" can be replaced by http.StatusInternalServerError
126 | response.go:24:30: "500" can be replaced by http.StatusInternalServerError
127 | ```
128 |
129 | ## Sponsors
130 |
131 | [
](https://evrone.com/?utm_source=usestdlibvars)
132 |
--------------------------------------------------------------------------------
/assets/uslv_logo.svg:
--------------------------------------------------------------------------------
1 |
33 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/sashamelentyev/usestdlibvars
2 |
3 | go 1.23.0
4 |
5 | require golang.org/x/tools v0.33.0
6 |
7 | require (
8 | golang.org/x/mod v0.24.0 // indirect
9 | golang.org/x/sync v0.14.0 // indirect
10 | )
11 |
--------------------------------------------------------------------------------
/go.sum:
--------------------------------------------------------------------------------
1 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
2 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
3 | golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
4 | golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
5 | golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
6 | golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
7 | golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
8 | golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
9 |
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "golang.org/x/tools/go/analysis/singlechecker"
5 |
6 | "github.com/sashamelentyev/usestdlibvars/pkg/analyzer"
7 | )
8 |
9 | //go:generate go run pkg/analyzer/internal/gen.go
10 |
11 | func main() {
12 | singlechecker.Main(analyzer.New())
13 | }
14 |
--------------------------------------------------------------------------------
/pkg/analyzer/analyzer.go:
--------------------------------------------------------------------------------
1 | package analyzer
2 |
3 | import (
4 | "flag"
5 | "fmt"
6 | "go/ast"
7 | "go/token"
8 | "strings"
9 |
10 | "golang.org/x/tools/go/analysis"
11 | "golang.org/x/tools/go/analysis/passes/inspect"
12 | "golang.org/x/tools/go/ast/inspector"
13 |
14 | "github.com/sashamelentyev/usestdlibvars/pkg/analyzer/internal/mapping"
15 | )
16 |
17 | const (
18 | TimeWeekdayFlag = "time-weekday"
19 | TimeMonthFlag = "time-month"
20 | TimeLayoutFlag = "time-layout"
21 | CryptoHashFlag = "crypto-hash"
22 | HTTPMethodFlag = "http-method"
23 | HTTPStatusCodeFlag = "http-status-code"
24 | RPCDefaultPathFlag = "rpc-default-path"
25 | OSDevNullFlag = "os-dev-null"
26 | SQLIsolationLevelFlag = "sql-isolation-level"
27 | TLSSignatureSchemeFlag = "tls-signature-scheme"
28 | ConstantKindFlag = "constant-kind"
29 | SyslogPriorityFlag = "syslog-priority"
30 | TimeDateMonthFlag = "time-date-month"
31 | )
32 |
33 | // New returns new usestdlibvars analyzer.
34 | func New() *analysis.Analyzer {
35 | return &analysis.Analyzer{
36 | Name: "usestdlibvars",
37 | Doc: "A linter that detect the possibility to use variables/constants from the Go standard library.",
38 | Run: run,
39 | Flags: flags(),
40 | Requires: []*analysis.Analyzer{inspect.Analyzer},
41 | }
42 | }
43 |
44 | func flags() flag.FlagSet {
45 | flags := flag.NewFlagSet("", flag.ExitOnError)
46 | flags.Bool(HTTPMethodFlag, true, "suggest the use of http.MethodXX")
47 | flags.Bool(HTTPStatusCodeFlag, true, "suggest the use of http.StatusXX")
48 | flags.Bool(TimeWeekdayFlag, false, "suggest the use of time.Weekday.String()")
49 | flags.Bool(TimeMonthFlag, false, "suggest the use of time.Month.String()")
50 | flags.Bool(TimeLayoutFlag, false, "suggest the use of time.Layout")
51 | flags.Bool(CryptoHashFlag, false, "suggest the use of crypto.Hash.String()")
52 | flags.Bool(RPCDefaultPathFlag, false, "suggest the use of rpc.DefaultXXPath")
53 | flags.Bool(OSDevNullFlag, false, "[DEPRECATED] suggest the use of os.DevNull")
54 | flags.Bool(SQLIsolationLevelFlag, false, "suggest the use of sql.LevelXX.String()")
55 | flags.Bool(TLSSignatureSchemeFlag, false, "suggest the use of tls.SignatureScheme.String()")
56 | flags.Bool(ConstantKindFlag, false, "suggest the use of constant.Kind.String()")
57 | flags.Bool(SyslogPriorityFlag, false, "[DEPRECATED] suggest the use of syslog.Priority")
58 | flags.Bool(TimeDateMonthFlag, false, "suggest the use of time.Month in time.Date")
59 | return *flags
60 | }
61 |
62 | func run(pass *analysis.Pass) (interface{}, error) {
63 | insp := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
64 |
65 | types := []ast.Node{
66 | (*ast.CallExpr)(nil),
67 | (*ast.BasicLit)(nil),
68 | (*ast.CompositeLit)(nil),
69 | (*ast.BinaryExpr)(nil),
70 | (*ast.SwitchStmt)(nil),
71 | }
72 |
73 | insp.Preorder(types, func(node ast.Node) {
74 | switch n := node.(type) {
75 | case *ast.CallExpr:
76 | fun, ok := n.Fun.(*ast.SelectorExpr)
77 | if !ok {
78 | return
79 | }
80 |
81 | x, ok := fun.X.(*ast.Ident)
82 | if !ok {
83 | return
84 | }
85 |
86 | funArgs(pass, x, fun, n.Args)
87 |
88 | case *ast.BasicLit:
89 | for _, c := range []struct {
90 | flag string
91 | checkFunc func(pass *analysis.Pass, basicLit *ast.BasicLit)
92 | }{
93 | {flag: TimeWeekdayFlag, checkFunc: checkTimeWeekday},
94 | {flag: TimeMonthFlag, checkFunc: checkTimeMonth},
95 | {flag: TimeLayoutFlag, checkFunc: checkTimeLayout},
96 | {flag: CryptoHashFlag, checkFunc: checkCryptoHash},
97 | {flag: RPCDefaultPathFlag, checkFunc: checkRPCDefaultPath},
98 | {flag: OSDevNullFlag, checkFunc: checkOSDevNull},
99 | {flag: SQLIsolationLevelFlag, checkFunc: checkSQLIsolationLevel},
100 | {flag: TLSSignatureSchemeFlag, checkFunc: checkTLSSignatureScheme},
101 | {flag: ConstantKindFlag, checkFunc: checkConstantKind},
102 | } {
103 | if lookupFlag(pass, c.flag) {
104 | c.checkFunc(pass, n)
105 | }
106 | }
107 |
108 | case *ast.CompositeLit:
109 | typ, ok := n.Type.(*ast.SelectorExpr)
110 | if !ok {
111 | return
112 | }
113 |
114 | x, ok := typ.X.(*ast.Ident)
115 | if !ok {
116 | return
117 | }
118 |
119 | typeElts(pass, x, typ, n.Elts)
120 |
121 | case *ast.BinaryExpr:
122 | switch n.Op {
123 | case token.LSS, token.GTR, token.LEQ, token.GEQ, token.QUO, token.ADD, token.SUB, token.MUL:
124 | return
125 | default:
126 | }
127 |
128 | x, ok := n.X.(*ast.SelectorExpr)
129 | if !ok {
130 | return
131 | }
132 |
133 | y, ok := n.Y.(*ast.BasicLit)
134 | if !ok {
135 | return
136 | }
137 |
138 | binaryExpr(pass, x, y)
139 |
140 | case *ast.SwitchStmt:
141 | x, ok := n.Tag.(*ast.SelectorExpr)
142 | if ok {
143 | switchStmt(pass, x, n.Body.List)
144 | }
145 | }
146 | })
147 |
148 | return nil, nil
149 | }
150 |
151 | // funArgs checks arguments of function or method.
152 | func funArgs(pass *analysis.Pass, x *ast.Ident, fun *ast.SelectorExpr, args []ast.Expr) {
153 | switch x.Name {
154 | case "http":
155 | switch fun.Sel.Name {
156 | // http.NewRequest(http.MethodGet, "localhost", http.NoBody)
157 | case "NewRequest":
158 | if !lookupFlag(pass, HTTPMethodFlag) {
159 | return
160 | }
161 |
162 | if basicLit := getBasicLitFromArgs(args, 3, 0, token.STRING); basicLit != nil {
163 | checkHTTPMethod(pass, basicLit)
164 | }
165 |
166 | // http.NewRequestWithContext(context.Background(), http.MethodGet, "localhost", http.NoBody)
167 | case "NewRequestWithContext":
168 | if !lookupFlag(pass, HTTPMethodFlag) {
169 | return
170 | }
171 |
172 | if basicLit := getBasicLitFromArgs(args, 4, 1, token.STRING); basicLit != nil {
173 | checkHTTPMethod(pass, basicLit)
174 | }
175 |
176 | // http.Error(w, err, http.StatusInternalServerError)
177 | case "Error":
178 | if !lookupFlag(pass, HTTPStatusCodeFlag) {
179 | return
180 | }
181 |
182 | if basicLit := getBasicLitFromArgs(args, 3, 2, token.INT); basicLit != nil {
183 | checkHTTPStatusCode(pass, basicLit)
184 | }
185 |
186 | // http.StatusText(http.StatusOK)
187 | case "StatusText":
188 | if !lookupFlag(pass, HTTPStatusCodeFlag) {
189 | return
190 | }
191 |
192 | if basicLit := getBasicLitFromArgs(args, 1, 0, token.INT); basicLit != nil {
193 | checkHTTPStatusCode(pass, basicLit)
194 | }
195 |
196 | // http.Redirect(w, r, "localhost", http.StatusMovedPermanently)
197 | case "Redirect":
198 | if !lookupFlag(pass, HTTPStatusCodeFlag) {
199 | return
200 | }
201 |
202 | if basicLit := getBasicLitFromArgs(args, 4, 3, token.INT); basicLit != nil {
203 | checkHTTPStatusCode(pass, basicLit)
204 | }
205 |
206 | // http.RedirectHandler("localhost", http.StatusMovedPermanently)
207 | case "RedirectHandler":
208 | if !lookupFlag(pass, HTTPStatusCodeFlag) {
209 | return
210 | }
211 |
212 | if basicLit := getBasicLitFromArgs(args, 2, 1, token.INT); basicLit != nil {
213 | checkHTTPStatusCode(pass, basicLit)
214 | }
215 | }
216 | case "httptest":
217 | if fun.Sel.Name == "NewRequest" {
218 | if !lookupFlag(pass, HTTPMethodFlag) {
219 | return
220 | }
221 |
222 | if basicLit := getBasicLitFromArgs(args, 3, 0, token.STRING); basicLit != nil {
223 | checkHTTPMethod(pass, basicLit)
224 | }
225 | }
226 | case "syslog":
227 | if !lookupFlag(pass, SyslogPriorityFlag) {
228 | return
229 | }
230 |
231 | switch fun.Sel.Name {
232 | case "New":
233 | if basicLit := getBasicLitFromArgs(args, 2, 0, token.INT); basicLit != nil {
234 | checkSyslogPriority(pass, basicLit)
235 | }
236 |
237 | case "Dial":
238 | if basicLit := getBasicLitFromArgs(args, 4, 2, token.INT); basicLit != nil {
239 | checkSyslogPriority(pass, basicLit)
240 | }
241 |
242 | case "NewLogger":
243 | if basicLit := getBasicLitFromArgs(args, 2, 0, token.INT); basicLit != nil {
244 | checkSyslogPriority(pass, basicLit)
245 | }
246 | }
247 | case "time":
248 | if !lookupFlag(pass, TimeDateMonthFlag) {
249 | return
250 | }
251 |
252 | // time.Date(2023, time.January, 2, 3, 4, 5, 0, time.UTC)
253 | if fun.Sel.Name == "Date" {
254 | if basicLit := getBasicLitFromArgs(args, 8, 1, token.INT); basicLit != nil {
255 | checkTimeDateMonth(pass, basicLit)
256 | }
257 | }
258 |
259 | default:
260 | // w.WriteHeader(http.StatusOk)
261 | if fun.Sel.Name == "WriteHeader" {
262 | if !lookupFlag(pass, HTTPStatusCodeFlag) {
263 | return
264 | }
265 |
266 | if basicLit := getBasicLitFromArgs(args, 1, 0, token.INT); basicLit != nil {
267 | checkHTTPStatusCode(pass, basicLit)
268 | }
269 | }
270 | }
271 | }
272 |
273 | // typeElts checks elements of type.
274 | func typeElts(pass *analysis.Pass, x *ast.Ident, typ *ast.SelectorExpr, elts []ast.Expr) {
275 | switch x.Name {
276 | case "http":
277 | switch typ.Sel.Name {
278 | // http.Request{Method: http.MethodGet}
279 | case "Request":
280 | if !lookupFlag(pass, HTTPMethodFlag) {
281 | return
282 | }
283 |
284 | if basicLit := getBasicLitFromElts(elts, "Method"); basicLit != nil {
285 | checkHTTPMethod(pass, basicLit)
286 | }
287 |
288 | // http.Response{StatusCode: http.StatusOK}
289 | case "Response":
290 | if !lookupFlag(pass, HTTPStatusCodeFlag) {
291 | return
292 | }
293 |
294 | if basicLit := getBasicLitFromElts(elts, "StatusCode"); basicLit != nil {
295 | checkHTTPStatusCode(pass, basicLit)
296 | }
297 | }
298 | case "httptest":
299 | if typ.Sel.Name == "ResponseRecorder" {
300 | if !lookupFlag(pass, HTTPStatusCodeFlag) {
301 | return
302 | }
303 |
304 | if basicLit := getBasicLitFromElts(elts, "Code"); basicLit != nil {
305 | checkHTTPStatusCode(pass, basicLit)
306 | }
307 | }
308 | }
309 | }
310 |
311 | // binaryExpr checks X and Y in binary expressions, including:
312 | // - if-else-statement
313 | // - for loops conditions
314 | // - switch cases without a tag expression
315 | func binaryExpr(pass *analysis.Pass, x *ast.SelectorExpr, y *ast.BasicLit) {
316 | switch x.Sel.Name {
317 | case "StatusCode":
318 | if !lookupFlag(pass, HTTPStatusCodeFlag) {
319 | return
320 | }
321 |
322 | checkHTTPStatusCode(pass, y)
323 |
324 | case "Method":
325 | if !lookupFlag(pass, HTTPMethodFlag) {
326 | return
327 | }
328 |
329 | checkHTTPMethod(pass, y)
330 | }
331 | }
332 |
333 | func switchStmt(pass *analysis.Pass, x *ast.SelectorExpr, cases []ast.Stmt) {
334 | var checkFunc func(pass *analysis.Pass, basicLit *ast.BasicLit)
335 |
336 | switch x.Sel.Name {
337 | case "StatusCode":
338 | if !lookupFlag(pass, HTTPStatusCodeFlag) {
339 | return
340 | }
341 |
342 | checkFunc = checkHTTPStatusCode
343 |
344 | case "Method":
345 | if !lookupFlag(pass, HTTPMethodFlag) {
346 | return
347 | }
348 |
349 | checkFunc = checkHTTPMethod
350 |
351 | default:
352 | return
353 | }
354 |
355 | for _, c := range cases {
356 | caseClause, ok := c.(*ast.CaseClause)
357 | if !ok {
358 | continue
359 | }
360 |
361 | for _, expr := range caseClause.List {
362 | basicLit, ok := expr.(*ast.BasicLit)
363 | if !ok {
364 | continue
365 | }
366 |
367 | checkFunc(pass, basicLit)
368 | }
369 | }
370 | }
371 |
372 | func lookupFlag(pass *analysis.Pass, name string) bool {
373 | return pass.Analyzer.Flags.Lookup(name).Value.(flag.Getter).Get().(bool)
374 | }
375 |
376 | func checkHTTPMethod(pass *analysis.Pass, basicLit *ast.BasicLit) {
377 | currentVal := getBasicLitValue(basicLit)
378 |
379 | key := strings.ToUpper(currentVal)
380 |
381 | if newVal, ok := mapping.HTTPMethod[key]; ok {
382 | report(pass, basicLit, currentVal, newVal)
383 | }
384 | }
385 |
386 | func checkHTTPStatusCode(pass *analysis.Pass, basicLit *ast.BasicLit) {
387 | currentVal := getBasicLitValue(basicLit)
388 |
389 | if newVal, ok := mapping.HTTPStatusCode[currentVal]; ok {
390 | report(pass, basicLit, currentVal, newVal)
391 | }
392 | }
393 |
394 | func checkTimeWeekday(pass *analysis.Pass, basicLit *ast.BasicLit) {
395 | currentVal := getBasicLitValue(basicLit)
396 |
397 | if newVal, ok := mapping.TimeWeekday[currentVal]; ok {
398 | report(pass, basicLit, currentVal, newVal)
399 | }
400 | }
401 |
402 | func checkTimeMonth(pass *analysis.Pass, basicLit *ast.BasicLit) {
403 | currentVal := getBasicLitValue(basicLit)
404 |
405 | if newVal, ok := mapping.TimeMonth[currentVal]; ok {
406 | report(pass, basicLit, currentVal, newVal)
407 | }
408 | }
409 |
410 | func checkTimeLayout(pass *analysis.Pass, basicLit *ast.BasicLit) {
411 | currentVal := getBasicLitValue(basicLit)
412 |
413 | if newVal, ok := mapping.TimeLayout[currentVal]; ok {
414 | report(pass, basicLit, currentVal, newVal)
415 | }
416 | }
417 |
418 | func checkCryptoHash(pass *analysis.Pass, basicLit *ast.BasicLit) {
419 | currentVal := getBasicLitValue(basicLit)
420 |
421 | if newVal, ok := mapping.CryptoHash[currentVal]; ok {
422 | report(pass, basicLit, currentVal, newVal)
423 | }
424 | }
425 |
426 | func checkRPCDefaultPath(pass *analysis.Pass, basicLit *ast.BasicLit) {
427 | currentVal := getBasicLitValue(basicLit)
428 |
429 | if newVal, ok := mapping.RPCDefaultPath[currentVal]; ok {
430 | report(pass, basicLit, currentVal, newVal)
431 | }
432 | }
433 |
434 | func checkOSDevNull(pass *analysis.Pass, basicLit *ast.BasicLit) {}
435 |
436 | func checkSQLIsolationLevel(pass *analysis.Pass, basicLit *ast.BasicLit) {
437 | currentVal := getBasicLitValue(basicLit)
438 |
439 | if newVal, ok := mapping.SQLIsolationLevel[currentVal]; ok {
440 | report(pass, basicLit, currentVal, newVal)
441 | }
442 | }
443 |
444 | func checkTLSSignatureScheme(pass *analysis.Pass, basicLit *ast.BasicLit) {
445 | currentVal := getBasicLitValue(basicLit)
446 |
447 | if newVal, ok := mapping.TLSSignatureScheme[currentVal]; ok {
448 | report(pass, basicLit, currentVal, newVal)
449 | }
450 | }
451 |
452 | func checkConstantKind(pass *analysis.Pass, basicLit *ast.BasicLit) {
453 | currentVal := getBasicLitValue(basicLit)
454 |
455 | if newVal, ok := mapping.ConstantKind[currentVal]; ok {
456 | report(pass, basicLit, currentVal, newVal)
457 | }
458 | }
459 |
460 | func checkSyslogPriority(pass *analysis.Pass, basicLit *ast.BasicLit) {}
461 |
462 | func checkTimeDateMonth(pass *analysis.Pass, basicLit *ast.BasicLit) {
463 | currentVal := getBasicLitValue(basicLit)
464 |
465 | if newVal, ok := mapping.TimeDateMonth[currentVal]; ok {
466 | report(pass, basicLit, currentVal, newVal)
467 | }
468 | }
469 |
470 | // getBasicLitFromArgs gets the *ast.BasicLit of a function argument.
471 | //
472 | // Arguments:
473 | // - args - slice of function arguments
474 | // - count - expected number of argument in function
475 | // - idx - index of the argument to get the *ast.BasicLit
476 | // - typ - argument type
477 | func getBasicLitFromArgs(args []ast.Expr, count, idx int, typ token.Token) *ast.BasicLit {
478 | if len(args) != count {
479 | return nil
480 | }
481 |
482 | if idx > count-1 {
483 | return nil
484 | }
485 |
486 | basicLit, ok := args[idx].(*ast.BasicLit)
487 | if !ok {
488 | return nil
489 | }
490 |
491 | if basicLit.Kind != typ {
492 | return nil
493 | }
494 |
495 | return basicLit
496 | }
497 |
498 | // getBasicLitFromElts gets the *ast.BasicLit of a struct elements.
499 | //
500 | // Arguments:
501 | // - elts - slice of a struct elements
502 | // - key - name of key in struct
503 | func getBasicLitFromElts(elts []ast.Expr, key string) *ast.BasicLit {
504 | for _, e := range elts {
505 | keyValueExpr, ok := e.(*ast.KeyValueExpr)
506 | if !ok {
507 | continue
508 | }
509 |
510 | ident, ok := keyValueExpr.Key.(*ast.Ident)
511 | if !ok {
512 | continue
513 | }
514 |
515 | if ident.Name != key {
516 | continue
517 | }
518 |
519 | if basicLit, ok := keyValueExpr.Value.(*ast.BasicLit); ok {
520 | return basicLit
521 | }
522 | }
523 |
524 | return nil
525 | }
526 |
527 | // getBasicLitValue returns BasicLit value as string without quotes.
528 | func getBasicLitValue(basicLit *ast.BasicLit) string {
529 | var val strings.Builder
530 | for _, r := range basicLit.Value {
531 | if r == '"' {
532 | continue
533 | } else {
534 | val.WriteRune(r)
535 | }
536 | }
537 | return val.String()
538 | }
539 |
540 | func report(pass *analysis.Pass, rg analysis.Range, currentVal, newVal string) {
541 | pass.Report(analysis.Diagnostic{
542 | Pos: rg.Pos(),
543 | Message: fmt.Sprintf("%q can be replaced by %s", currentVal, newVal),
544 | SuggestedFixes: []analysis.SuggestedFix{{
545 | TextEdits: []analysis.TextEdit{{
546 | Pos: rg.Pos(),
547 | End: rg.End(),
548 | NewText: []byte(newVal),
549 | }},
550 | }},
551 | })
552 | }
553 |
--------------------------------------------------------------------------------
/pkg/analyzer/analyzer_test.go:
--------------------------------------------------------------------------------
1 | package analyzer_test
2 |
3 | import (
4 | "testing"
5 |
6 | "golang.org/x/tools/go/analysis/analysistest"
7 |
8 | "github.com/sashamelentyev/usestdlibvars/pkg/analyzer"
9 | )
10 |
11 | var flags = []string{
12 | analyzer.TimeWeekdayFlag,
13 | analyzer.TimeMonthFlag,
14 | analyzer.TimeLayoutFlag,
15 | analyzer.CryptoHashFlag,
16 | analyzer.RPCDefaultPathFlag,
17 | analyzer.SQLIsolationLevelFlag,
18 | analyzer.TLSSignatureSchemeFlag,
19 | analyzer.ConstantKindFlag,
20 | analyzer.TimeDateMonthFlag,
21 | }
22 |
23 | func TestUseStdlibVars(t *testing.T) {
24 | a := analyzer.New()
25 |
26 | for _, flag := range flags {
27 | if err := a.Flags.Set(flag, "true"); err != nil {
28 | t.Fatal(err)
29 | }
30 | }
31 |
32 | testCases := []struct {
33 | dir string
34 | }{
35 | {dir: "a/crypto"},
36 | {dir: "a/http"},
37 | {dir: "a/rpc"},
38 | {dir: "a/time"},
39 | {dir: "a/sql"},
40 | {dir: "a/tls"},
41 | {dir: "a/constant"},
42 | }
43 |
44 | for _, test := range testCases {
45 | t.Run(test.dir, func(t *testing.T) {
46 | analysistest.RunWithSuggestedFixes(t, analysistest.TestData(), a, test.dir)
47 | })
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/pkg/analyzer/internal/gen.go:
--------------------------------------------------------------------------------
1 | //go:build ignore
2 | // +build ignore
3 |
4 | package main
5 |
6 | import (
7 | "bytes"
8 | "embed"
9 | "go/format"
10 | "log"
11 | "os"
12 | "path/filepath"
13 | "regexp"
14 | "strings"
15 | "text/template"
16 |
17 | "github.com/sashamelentyev/usestdlibvars/pkg/analyzer/internal/mapping"
18 | )
19 |
20 | //go:embed template/*
21 | var templateDir embed.FS
22 |
23 | func main() {
24 | t := template.Must(
25 | template.New("template").
26 | Funcs(map[string]any{
27 | "quoteMeta": regexp.QuoteMeta,
28 | "toLower": strings.ToLower,
29 | }).
30 | ParseFS(templateDir, "template/*.tmpl"),
31 | )
32 |
33 | operations := []struct {
34 | mapping map[string]string
35 | packageName string
36 | templateName string
37 | goldenTemplateName string
38 | fileName string
39 | }{
40 | {
41 | mapping: mapping.CryptoHash,
42 | packageName: "crypto_test",
43 | templateName: "test-template.go.tmpl",
44 | goldenTemplateName: "test-template.go.golden.tmpl",
45 | fileName: "pkg/analyzer/testdata/src/a/crypto/crypto.go",
46 | },
47 | {
48 | mapping: mapping.RPCDefaultPath,
49 | packageName: "rpc_test",
50 | templateName: "test-template.go.tmpl",
51 | goldenTemplateName: "test-template.go.golden.tmpl",
52 | fileName: "pkg/analyzer/testdata/src/a/rpc/rpc.go",
53 | },
54 | {
55 | mapping: mapping.TimeWeekday,
56 | packageName: "time_test",
57 | templateName: "test-template.go.tmpl",
58 | goldenTemplateName: "test-template.go.golden.tmpl",
59 | fileName: "pkg/analyzer/testdata/src/a/time/weekday.go",
60 | },
61 | {
62 | mapping: mapping.TimeMonth,
63 | packageName: "time_test",
64 | templateName: "test-template.go.tmpl",
65 | goldenTemplateName: "test-template.go.golden.tmpl",
66 | fileName: "pkg/analyzer/testdata/src/a/time/month.go",
67 | },
68 | {
69 | mapping: mapping.TimeLayout,
70 | packageName: "time_test",
71 | templateName: "test-template.go.tmpl",
72 | goldenTemplateName: "test-template.go.golden.tmpl",
73 | fileName: "pkg/analyzer/testdata/src/a/time/layout.go",
74 | },
75 | {
76 | mapping: mapping.SQLIsolationLevel,
77 | packageName: "sql_test",
78 | templateName: "test-template.go.tmpl",
79 | goldenTemplateName: "test-template.go.golden.tmpl",
80 | fileName: "pkg/analyzer/testdata/src/a/sql/isolationlevel.go",
81 | },
82 | {
83 | mapping: mapping.TLSSignatureScheme,
84 | packageName: "tls_test",
85 | templateName: "test-template.go.tmpl",
86 | goldenTemplateName: "test-template.go.golden.tmpl",
87 | fileName: "pkg/analyzer/testdata/src/a/tls/signaturescheme.go",
88 | },
89 | {
90 | mapping: mapping.ConstantKind,
91 | packageName: "constant_test",
92 | templateName: "test-template.go.tmpl",
93 | goldenTemplateName: "test-template.go.golden.tmpl",
94 | fileName: "pkg/analyzer/testdata/src/a/constant/kind.go",
95 | },
96 | {
97 | mapping: mapping.HTTPMethod,
98 | packageName: "http_test",
99 | templateName: "test-httpmethod.go.tmpl",
100 | goldenTemplateName: "test-httpmethod.go.golden.tmpl",
101 | fileName: "pkg/analyzer/testdata/src/a/http/method.go",
102 | },
103 | {
104 | mapping: mapping.HTTPStatusCode,
105 | packageName: "http_test",
106 | templateName: "test-httpstatus.go.tmpl",
107 | goldenTemplateName: "test-httpstatus.go.golden.tmpl",
108 | fileName: "pkg/analyzer/testdata/src/a/http/status.go",
109 | },
110 | {
111 | mapping: mapping.HTTPMethod,
112 | packageName: "http_test",
113 | templateName: "test-issue32.go.tmpl",
114 | goldenTemplateName: "test-issue32.go.golden.tmpl",
115 | fileName: "pkg/analyzer/testdata/src/a/http/issue32.go",
116 | },
117 | {
118 | mapping: mapping.HTTPStatusCode,
119 | packageName: "http_test",
120 | templateName: "test-issue89.go.tmpl",
121 | goldenTemplateName: "test-issue89.go.golden.tmpl",
122 | fileName: "pkg/analyzer/testdata/src/a/http/issue89.go",
123 | },
124 | {
125 | mapping: mapping.TimeDateMonth,
126 | packageName: "time_test",
127 | templateName: "test-issue103.go.tmpl",
128 | goldenTemplateName: "test-issue103.go.golden.tmpl",
129 | fileName: "pkg/analyzer/testdata/src/a/time/issue103.go",
130 | },
131 | }
132 |
133 | for _, operation := range operations {
134 | data := map[string]any{
135 | "PackageName": operation.packageName,
136 | "Mapping": operation.mapping,
137 | }
138 |
139 | if err := execute(t, operation.templateName, data, operation.fileName); err != nil {
140 | log.Fatal(err)
141 | }
142 |
143 | if operation.goldenTemplateName != "" {
144 | if err := execute(t, operation.goldenTemplateName, data, operation.fileName+".golden"); err != nil {
145 | log.Fatal(err)
146 | }
147 | }
148 | }
149 | }
150 |
151 | func execute(t *template.Template, templateName string, data any, fileName string) error {
152 | var builder bytes.Buffer
153 |
154 | if err := t.ExecuteTemplate(&builder, templateName, data); err != nil {
155 | return err
156 | }
157 |
158 | if filepath.Ext(fileName) == ".go" {
159 | sourceData, err := format.Source(builder.Bytes())
160 | if err != nil {
161 | return err
162 | }
163 |
164 | return os.WriteFile(fileName, sourceData, os.ModePerm)
165 | }
166 |
167 | return os.WriteFile(fileName, builder.Bytes(), os.ModePerm)
168 | }
169 |
--------------------------------------------------------------------------------
/pkg/analyzer/internal/mapping/mapping.go:
--------------------------------------------------------------------------------
1 | package mapping
2 |
3 | import (
4 | "crypto"
5 | "crypto/tls"
6 | "database/sql"
7 | "go/constant"
8 | "net/http"
9 | "net/rpc"
10 | "strconv"
11 | "time"
12 | )
13 |
14 | var CryptoHash = map[string]string{
15 | crypto.MD4.String(): "crypto.MD4.String()",
16 | crypto.MD5.String(): "crypto.MD5.String()",
17 | crypto.SHA1.String(): "crypto.SHA1.String()",
18 | crypto.SHA224.String(): "crypto.SHA224.String()",
19 | crypto.SHA256.String(): "crypto.SHA256.String()",
20 | crypto.SHA384.String(): "crypto.SHA384.String()",
21 | crypto.SHA512.String(): "crypto.SHA512.String()",
22 | crypto.MD5SHA1.String(): "crypto.MD5SHA1.String()",
23 | crypto.RIPEMD160.String(): "crypto.RIPEMD160.String()",
24 | crypto.SHA3_224.String(): "crypto.SHA3_224.String()",
25 | crypto.SHA3_256.String(): "crypto.SHA3_256.String()",
26 | crypto.SHA3_384.String(): "crypto.SHA3_384.String()",
27 | crypto.SHA3_512.String(): "crypto.SHA3_512.String()",
28 | crypto.SHA512_224.String(): "crypto.SHA512_224.String()",
29 | crypto.SHA512_256.String(): "crypto.SHA512_256.String()",
30 | crypto.BLAKE2s_256.String(): "crypto.BLAKE2s_256.String()",
31 | crypto.BLAKE2b_256.String(): "crypto.BLAKE2b_256.String()",
32 | crypto.BLAKE2b_384.String(): "crypto.BLAKE2b_384.String()",
33 | crypto.BLAKE2b_512.String(): "crypto.BLAKE2b_512.String()",
34 | }
35 |
36 | var HTTPMethod = map[string]string{
37 | http.MethodGet: "http.MethodGet",
38 | http.MethodHead: "http.MethodHead",
39 | http.MethodPost: "http.MethodPost",
40 | http.MethodPut: "http.MethodPut",
41 | http.MethodPatch: "http.MethodPatch",
42 | http.MethodDelete: "http.MethodDelete",
43 | http.MethodConnect: "http.MethodConnect",
44 | http.MethodOptions: "http.MethodOptions",
45 | http.MethodTrace: "http.MethodTrace",
46 | }
47 |
48 | var HTTPStatusCode = map[string]string{
49 | strconv.Itoa(http.StatusContinue): "http.StatusContinue",
50 | strconv.Itoa(http.StatusSwitchingProtocols): "http.StatusSwitchingProtocols",
51 | strconv.Itoa(http.StatusProcessing): "http.StatusProcessing",
52 | strconv.Itoa(http.StatusEarlyHints): "http.StatusEarlyHints",
53 |
54 | strconv.Itoa(http.StatusOK): "http.StatusOK",
55 | strconv.Itoa(http.StatusCreated): "http.StatusCreated",
56 | strconv.Itoa(http.StatusAccepted): "http.StatusAccepted",
57 | strconv.Itoa(http.StatusNonAuthoritativeInfo): "http.StatusNonAuthoritativeInfo",
58 | strconv.Itoa(http.StatusNoContent): "http.StatusNoContent",
59 | strconv.Itoa(http.StatusResetContent): "http.StatusResetContent",
60 | strconv.Itoa(http.StatusPartialContent): "http.StatusPartialContent",
61 | strconv.Itoa(http.StatusMultiStatus): "http.StatusMultiStatus",
62 | strconv.Itoa(http.StatusAlreadyReported): "http.StatusAlreadyReported",
63 | strconv.Itoa(http.StatusIMUsed): "http.StatusIMUsed",
64 |
65 | strconv.Itoa(http.StatusMultipleChoices): "http.StatusMultipleChoices",
66 | strconv.Itoa(http.StatusMovedPermanently): "http.StatusMovedPermanently",
67 | strconv.Itoa(http.StatusFound): "http.StatusFound",
68 | strconv.Itoa(http.StatusSeeOther): "http.StatusSeeOther",
69 | strconv.Itoa(http.StatusNotModified): "http.StatusNotModified",
70 | strconv.Itoa(http.StatusUseProxy): "http.StatusUseProxy",
71 | strconv.Itoa(http.StatusTemporaryRedirect): "http.StatusTemporaryRedirect",
72 | strconv.Itoa(http.StatusPermanentRedirect): "http.StatusPermanentRedirect",
73 |
74 | strconv.Itoa(http.StatusBadRequest): "http.StatusBadRequest",
75 | strconv.Itoa(http.StatusUnauthorized): "http.StatusUnauthorized",
76 | strconv.Itoa(http.StatusPaymentRequired): "http.StatusPaymentRequired",
77 | strconv.Itoa(http.StatusForbidden): "http.StatusForbidden",
78 | strconv.Itoa(http.StatusNotFound): "http.StatusNotFound",
79 | strconv.Itoa(http.StatusMethodNotAllowed): "http.StatusMethodNotAllowed",
80 | strconv.Itoa(http.StatusNotAcceptable): "http.StatusNotAcceptable",
81 | strconv.Itoa(http.StatusProxyAuthRequired): "http.StatusProxyAuthRequired",
82 | strconv.Itoa(http.StatusRequestTimeout): "http.StatusRequestTimeout",
83 | strconv.Itoa(http.StatusConflict): "http.StatusConflict",
84 | strconv.Itoa(http.StatusGone): "http.StatusGone",
85 | strconv.Itoa(http.StatusLengthRequired): "http.StatusLengthRequired",
86 | strconv.Itoa(http.StatusPreconditionFailed): "http.StatusPreconditionFailed",
87 | strconv.Itoa(http.StatusRequestEntityTooLarge): "http.StatusRequestEntityTooLarge",
88 | strconv.Itoa(http.StatusRequestURITooLong): "http.StatusRequestURITooLong",
89 | strconv.Itoa(http.StatusUnsupportedMediaType): "http.StatusUnsupportedMediaType",
90 | strconv.Itoa(http.StatusRequestedRangeNotSatisfiable): "http.StatusRequestedRangeNotSatisfiable",
91 | strconv.Itoa(http.StatusExpectationFailed): "http.StatusExpectationFailed",
92 | strconv.Itoa(http.StatusTeapot): "http.StatusTeapot",
93 | strconv.Itoa(http.StatusMisdirectedRequest): "http.StatusMisdirectedRequest",
94 | strconv.Itoa(http.StatusUnprocessableEntity): "http.StatusUnprocessableEntity",
95 | strconv.Itoa(http.StatusLocked): "http.StatusLocked",
96 | strconv.Itoa(http.StatusFailedDependency): "http.StatusFailedDependency",
97 | strconv.Itoa(http.StatusTooEarly): "http.StatusTooEarly",
98 | strconv.Itoa(http.StatusUpgradeRequired): "http.StatusUpgradeRequired",
99 | strconv.Itoa(http.StatusPreconditionRequired): "http.StatusPreconditionRequired",
100 | strconv.Itoa(http.StatusTooManyRequests): "http.StatusTooManyRequests",
101 | strconv.Itoa(http.StatusRequestHeaderFieldsTooLarge): "http.StatusRequestHeaderFieldsTooLarge",
102 | strconv.Itoa(http.StatusUnavailableForLegalReasons): "http.StatusUnavailableForLegalReasons",
103 |
104 | strconv.Itoa(http.StatusInternalServerError): "http.StatusInternalServerError",
105 | strconv.Itoa(http.StatusNotImplemented): "http.StatusNotImplemented",
106 | strconv.Itoa(http.StatusBadGateway): "http.StatusBadGateway",
107 | strconv.Itoa(http.StatusServiceUnavailable): "http.StatusServiceUnavailable",
108 | strconv.Itoa(http.StatusGatewayTimeout): "http.StatusGatewayTimeout",
109 | strconv.Itoa(http.StatusHTTPVersionNotSupported): "http.StatusHTTPVersionNotSupported",
110 | strconv.Itoa(http.StatusVariantAlsoNegotiates): "http.StatusVariantAlsoNegotiates",
111 | strconv.Itoa(http.StatusInsufficientStorage): "http.StatusInsufficientStorage",
112 | strconv.Itoa(http.StatusLoopDetected): "http.StatusLoopDetected",
113 | strconv.Itoa(http.StatusNotExtended): "http.StatusNotExtended",
114 | strconv.Itoa(http.StatusNetworkAuthenticationRequired): "http.StatusNetworkAuthenticationRequired",
115 | }
116 |
117 | var RPCDefaultPath = map[string]string{
118 | rpc.DefaultRPCPath: "rpc.DefaultRPCPath",
119 | rpc.DefaultDebugPath: "rpc.DefaultDebugPath",
120 | }
121 |
122 | var TimeWeekday = map[string]string{
123 | time.Sunday.String(): "time.Sunday.String()",
124 | time.Monday.String(): "time.Monday.String()",
125 | time.Tuesday.String(): "time.Tuesday.String()",
126 | time.Wednesday.String(): "time.Wednesday.String()",
127 | time.Thursday.String(): "time.Thursday.String()",
128 | time.Friday.String(): "time.Friday.String()",
129 | time.Saturday.String(): "time.Saturday.String()",
130 | }
131 |
132 | var TimeMonth = map[string]string{
133 | time.January.String(): "time.January.String()",
134 | time.February.String(): "time.February.String()",
135 | time.March.String(): "time.March.String()",
136 | time.April.String(): "time.April.String()",
137 | time.May.String(): "time.May.String()",
138 | time.June.String(): "time.June.String()",
139 | time.July.String(): "time.July.String()",
140 | time.August.String(): "time.August.String()",
141 | time.September.String(): "time.September.String()",
142 | time.October.String(): "time.October.String()",
143 | time.November.String(): "time.November.String()",
144 | time.December.String(): "time.December.String()",
145 | }
146 |
147 | var TimeLayout = map[string]string{
148 | time.Layout: "time.Layout",
149 | time.ANSIC: "time.ANSIC",
150 | time.UnixDate: "time.UnixDate",
151 | time.RubyDate: "time.RubyDate",
152 | time.RFC822: "time.RFC822",
153 | time.RFC822Z: "time.RFC822Z",
154 | time.RFC850: "time.RFC850",
155 | time.RFC1123: "time.RFC1123",
156 | time.RFC1123Z: "time.RFC1123Z",
157 | time.RFC3339: "time.RFC3339",
158 | time.RFC3339Nano: "time.RFC3339Nano",
159 | time.Kitchen: "time.Kitchen",
160 | time.Stamp: "time.Stamp",
161 | time.StampMilli: "time.StampMilli",
162 | time.StampMicro: "time.StampMicro",
163 | time.StampNano: "time.StampNano",
164 | time.DateTime: "time.DateTime",
165 | time.DateOnly: "time.DateOnly",
166 | time.TimeOnly: "time.TimeOnly",
167 | }
168 |
169 | var SQLIsolationLevel = map[string]string{
170 | // sql.LevelDefault.String(): "sql.LevelDefault.String()",
171 | sql.LevelReadUncommitted.String(): "sql.LevelReadUncommitted.String()",
172 | sql.LevelReadCommitted.String(): "sql.LevelReadCommitted.String()",
173 | sql.LevelWriteCommitted.String(): "sql.LevelWriteCommitted.String()",
174 | sql.LevelRepeatableRead.String(): "sql.LevelRepeatableRead.String()",
175 | // sql.LevelSnapshot.String(): "sql.LevelSnapshot.String()",
176 | // sql.LevelSerializable.String(): "sql.LevelSerializable.String()",
177 | // sql.LevelLinearizable.String(): "sql.LevelLinearizable.String()",
178 | }
179 |
180 | var TLSSignatureScheme = map[string]string{
181 | tls.PSSWithSHA256.String(): "tls.PSSWithSHA256.String()",
182 | tls.ECDSAWithP256AndSHA256.String(): "tls.ECDSAWithP256AndSHA256.String()",
183 | tls.Ed25519.String(): "tls.Ed25519.String()",
184 | tls.PSSWithSHA384.String(): "tls.PSSWithSHA384.String()",
185 | tls.PSSWithSHA512.String(): "tls.PSSWithSHA512.String()",
186 | tls.PKCS1WithSHA256.String(): "tls.PKCS1WithSHA256.String()",
187 | tls.PKCS1WithSHA384.String(): "tls.PKCS1WithSHA384.String()",
188 | tls.PKCS1WithSHA512.String(): "tls.PKCS1WithSHA512.String()",
189 | tls.ECDSAWithP384AndSHA384.String(): "tls.ECDSAWithP384AndSHA384.String()",
190 | tls.ECDSAWithP521AndSHA512.String(): "tls.ECDSAWithP521AndSHA512.String()",
191 | tls.PKCS1WithSHA1.String(): "tls.PKCS1WithSHA1.String()",
192 | tls.ECDSAWithSHA1.String(): "tls.ECDSAWithSHA1.String()",
193 | }
194 |
195 | var ConstantKind = map[string]string{
196 | // constant.Unknown.String(): "constant.Unknown.String()",
197 | constant.Bool.String(): "constant.Bool.String()",
198 | constant.String.String(): "constant.String.String()",
199 | constant.Int.String(): "constant.Int.String()",
200 | constant.Float.String(): "constant.Float.String()",
201 | constant.Complex.String(): "constant.Complex.String()",
202 | }
203 |
204 | var TimeDateMonth = map[string]string{
205 | "1": "time.January",
206 | "2": "time.February",
207 | "3": "time.March",
208 | "4": "time.April",
209 | "5": "time.May",
210 | "6": "time.June",
211 | "7": "time.July",
212 | "8": "time.August",
213 | "9": "time.September",
214 | "10": "time.October",
215 | "11": "time.November",
216 | "12": "time.December",
217 | }
218 |
--------------------------------------------------------------------------------
/pkg/analyzer/internal/template/test-httpmethod.go.golden.tmpl:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package {{ .PackageName }}
4 |
5 | import (
6 | "net/http"
7 | "net/http/httptest"
8 | )
9 |
10 | var (
11 | {{- range $key, $value := .Mapping }}
12 | _ = "{{ $key }}"
13 | {{- end }}
14 | )
15 |
16 | const (
17 | {{- range $key, $value := .Mapping }}
18 | _ = "{{ $key }}"
19 | {{- end }}
20 | )
21 |
22 | var (
23 | {{- range $key, $value := .Mapping }}
24 | _, _ = http.NewRequest({{ $value }}, "", http.NoBody) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
25 | {{- end }}
26 | )
27 |
28 | var (
29 | {{- range $key, $value := .Mapping }}
30 | _, _ = http.NewRequestWithContext(nil, {{ $value }}, "", http.NoBody) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
31 | {{- end }}
32 | )
33 |
34 | var (
35 | {{- range $key, $value := .Mapping }}
36 | _ = http.Request{Method: {{ $value }}} // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
37 | {{- end }}
38 | )
39 |
40 | var (
41 | {{- range $key, $value := .Mapping }}
42 | _ = &http.Request{Method: {{ $value }}} // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
43 | {{- end }}
44 | )
45 |
46 | func _() error {
47 | resp, err := http.DefaultClient.Do(&http.Request{})
48 | if err != nil {
49 | return err
50 | }
51 | defer func() { _ = resp.Body.Close() }()
52 | {{- range $key, $value := .Mapping }}
53 | if resp.Request.Method == {{ $value }} { // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
54 | return nil
55 | }
56 | {{- end }}
57 | {{- range $key, $value := .Mapping }}
58 | for resp.Request.Method == {{ $value }} { // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
59 | return nil
60 | }
61 | {{- end }}
62 | return nil
63 | }
64 |
65 | func _() error {
66 | resp, err := http.DefaultClient.Do(&http.Request{})
67 | if err != nil {
68 | return err
69 | }
70 | defer func() { _ = resp.Body.Close() }()
71 | {{- range $key, $value := .Mapping }}
72 | if resp.Request.Method == {{ $value }} {
73 | return nil
74 | }
75 | {{- end }}
76 | {{- range $key, $value := .Mapping }}
77 | for resp.Request.Method == {{ $value }} {
78 | return nil
79 | }
80 | {{- end }}
81 | return nil
82 | }
83 |
84 | func _() {
85 | var r http.Request
86 | switch r.Method {
87 | {{- range $key, $value := .Mapping }}
88 | case {{ $value }}: // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
89 | return
90 | {{- end }}
91 | }
92 | }
93 |
94 | func _() {
95 | var r http.Request
96 | switch r.Method {
97 | {{- range $key, $value := .Mapping }}
98 | case {{ $value }}:
99 | return
100 | {{- end }}
101 | }
102 | }
103 |
104 | func _() {
105 | var r http.Request
106 | switch {
107 | {{- range $key, $value := .Mapping }}
108 | case r.Method == {{ $value }}: // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
109 | return
110 | {{- end }}
111 | }
112 | }
113 |
114 | func _() {
115 | var r http.Request
116 | switch {
117 | {{- range $key, $value := .Mapping }}
118 | case r.Method == {{ $value }}:
119 | return
120 | {{- end }}
121 | }
122 | }
123 |
124 | var (
125 | {{- range $key, $value := .Mapping }}
126 | _ = httptest.NewRequest({{ $value }}, "", http.NoBody) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
127 | {{- end }}
128 | )
129 |
--------------------------------------------------------------------------------
/pkg/analyzer/internal/template/test-httpmethod.go.tmpl:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package {{ .PackageName }}
4 |
5 | import (
6 | "net/http"
7 | "net/http/httptest"
8 | )
9 |
10 | var (
11 | {{- range $key, $value := .Mapping }}
12 | _ = "{{ $key }}"
13 | {{- end }}
14 | )
15 |
16 | const (
17 | {{- range $key, $value := .Mapping }}
18 | _ = "{{ $key }}"
19 | {{- end }}
20 | )
21 |
22 | var (
23 | {{- range $key, $value := .Mapping }}
24 | _, _ = http.NewRequest("{{ $key }}", "", http.NoBody) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
25 | {{- end }}
26 | )
27 |
28 | var (
29 | {{- range $key, $value := .Mapping }}
30 | _, _ = http.NewRequestWithContext(nil, "{{ $key }}", "", http.NoBody) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
31 | {{- end }}
32 | )
33 |
34 | var (
35 | {{- range $key, $value := .Mapping }}
36 | _ = http.Request{Method: "{{ $key }}"} // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
37 | {{- end }}
38 | )
39 |
40 | var (
41 | {{- range $key, $value := .Mapping }}
42 | _ = &http.Request{Method: "{{ $key }}"} // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
43 | {{- end }}
44 | )
45 |
46 | func _() error {
47 | resp, err := http.DefaultClient.Do(&http.Request{})
48 | if err != nil {
49 | return err
50 | }
51 | defer func() { _ = resp.Body.Close() }()
52 | {{- range $key, $value := .Mapping }}
53 | if resp.Request.Method == "{{ $key }}" { // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
54 | return nil
55 | }
56 | {{- end }}
57 | {{- range $key, $value := .Mapping }}
58 | for resp.Request.Method == "{{ $key }}" { // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
59 | return nil
60 | }
61 | {{- end }}
62 | return nil
63 | }
64 |
65 | func _() error {
66 | resp, err := http.DefaultClient.Do(&http.Request{})
67 | if err != nil {
68 | return err
69 | }
70 | defer func() { _ = resp.Body.Close() }()
71 | {{- range $key, $value := .Mapping }}
72 | if resp.Request.Method == {{ $value }} {
73 | return nil
74 | }
75 | {{- end }}
76 | {{- range $key, $value := .Mapping }}
77 | for resp.Request.Method == {{ $value }} {
78 | return nil
79 | }
80 | {{- end }}
81 | return nil
82 | }
83 |
84 | func _() {
85 | var r http.Request
86 | switch r.Method {
87 | {{- range $key, $value := .Mapping }}
88 | case "{{ $key }}": // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
89 | return
90 | {{- end }}
91 | }
92 | }
93 |
94 | func _() {
95 | var r http.Request
96 | switch r.Method {
97 | {{- range $key, $value := .Mapping }}
98 | case {{ $value }}:
99 | return
100 | {{- end }}
101 | }
102 | }
103 |
104 | func _() {
105 | var r http.Request
106 | switch {
107 | {{- range $key, $value := .Mapping }}
108 | case r.Method == "{{ $key }}": // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
109 | return
110 | {{- end }}
111 | }
112 | }
113 |
114 | func _() {
115 | var r http.Request
116 | switch {
117 | {{- range $key, $value := .Mapping }}
118 | case r.Method == {{ $value }}:
119 | return
120 | {{- end }}
121 | }
122 | }
123 |
124 | var (
125 | {{- range $key, $value := .Mapping }}
126 | _ = httptest.NewRequest("{{ $key }}", "", http.NoBody) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
127 | {{- end }}
128 | )
129 |
--------------------------------------------------------------------------------
/pkg/analyzer/internal/template/test-httpstatus.go.golden.tmpl:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package {{ .PackageName }}
4 |
5 | import (
6 | "net/http"
7 | "net/http/httptest"
8 | )
9 |
10 | var (
11 | {{- range $key, $value := .Mapping }}
12 | _ = {{ $key }}
13 | {{- end }}
14 | )
15 |
16 | const (
17 | {{- range $key, $value := .Mapping }}
18 | _ = {{ $key }}
19 | {{- end }}
20 | )
21 |
22 | func _() {
23 | var w http.ResponseWriter
24 | {{- range $key, $value := .Mapping }}
25 | w.WriteHeader({{ $value }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
26 | {{- end }}
27 | }
28 |
29 | func _() {
30 | var w http.ResponseWriter
31 | {{- range $key, $value := .Mapping }}
32 | w.WriteHeader({{ $value }})
33 | {{- end }}
34 | }
35 |
36 | var (
37 | {{- range $key, $value := .Mapping }}
38 | _ = http.Response{StatusCode: {{ $value }}} // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
39 | {{- end }}
40 | )
41 |
42 | var (
43 | {{- range $key, $value := .Mapping }}
44 | _ = http.Response{StatusCode: {{ $value }}}
45 | {{- end }}
46 | )
47 |
48 | var (
49 | {{- range $key, $value := .Mapping }}
50 | _ = &http.Response{StatusCode: {{ $value }}} // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
51 | {{- end }}
52 | )
53 |
54 | var (
55 | {{- range $key, $value := .Mapping }}
56 | _ = &http.Response{StatusCode: {{ $value }}}
57 | {{- end }}
58 | )
59 |
60 | func _() error {
61 | resp, err := http.DefaultClient.Do(&http.Request{})
62 | if err != nil {
63 | return err
64 | }
65 | defer func() { _ = resp.Body.Close() }()
66 | {{- range $key, $value := .Mapping }}
67 | if resp.StatusCode == {{ $value }} { // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
68 | return nil
69 | } else if resp.StatusCode == {{ $value }} { // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
70 | return nil
71 | } else if false || resp.StatusCode == {{ $value }} { // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
72 | return nil
73 | }
74 | {{- end }}
75 | {{- range $key, $value := .Mapping }}
76 | for resp.StatusCode == {{ $value }} { // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
77 | return nil
78 | }
79 | {{- end }}
80 | return nil
81 | }
82 |
83 | func _() error {
84 | resp, err := http.DefaultClient.Do(&http.Request{})
85 | if err != nil {
86 | return err
87 | }
88 | defer func() { _ = resp.Body.Close() }()
89 | {{- range $key, $value := .Mapping }}
90 | if resp.StatusCode == {{ $value }} {
91 | return nil
92 | } else if resp.StatusCode == {{ $value }} {
93 | return nil
94 | } else if false || resp.StatusCode == {{ $value }} {
95 | return nil
96 | }
97 | {{- end }}
98 | {{- range $key, $value := .Mapping }}
99 | for resp.StatusCode == {{ $value }} {
100 | return nil
101 | }
102 | {{- end }}
103 | return nil
104 | }
105 |
106 | func _() {
107 | var w http.ResponseWriter
108 | {{- range $key, $value := .Mapping }}
109 | http.Error(w, "", {{ $value }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
110 | {{- end }}
111 | }
112 |
113 | func _() {
114 | var w http.ResponseWriter
115 | {{- range $key, $value := .Mapping }}
116 | http.Error(w, "", {{ $value }})
117 | {{- end }}
118 | }
119 |
120 | var (
121 | {{- range $key, $value := .Mapping }}
122 | _ = http.StatusText({{ $value }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
123 | {{- end }}
124 | )
125 |
126 | var (
127 | {{- range $key, $value := .Mapping }}
128 | _ = http.StatusText({{ $value }})
129 | {{- end }}
130 | )
131 |
132 | func _() {
133 | var w http.ResponseWriter
134 | var r *http.Request
135 | {{- range $key, $value := .Mapping }}
136 | http.Redirect(w, r, "", {{ $value }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
137 | {{- end }}
138 | }
139 |
140 | func _() {
141 | var w http.ResponseWriter
142 | var r *http.Request
143 | {{- range $key, $value := .Mapping }}
144 | http.Redirect(w, r, "", {{ $value }})
145 | {{- end }}
146 | }
147 |
148 | var (
149 | {{- range $key, $value := .Mapping }}
150 | _ = http.RedirectHandler("", {{ $value }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
151 | {{- end }}
152 | )
153 |
154 | var (
155 | {{- range $key, $value := .Mapping }}
156 | _ = http.RedirectHandler("", {{ $value }})
157 | {{- end }}
158 | )
159 |
160 | func _() {
161 | var resp http.Response
162 | switch resp.StatusCode {
163 | {{- range $key, $value := .Mapping }}
164 | case {{ $value }}: // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
165 | return
166 | {{- end }}
167 | }
168 | }
169 |
170 | func _() {
171 | var resp http.Response
172 | switch resp.StatusCode {
173 | {{- range $key, $value := .Mapping }}
174 | case {{ $value }}:
175 | return
176 | {{- end }}
177 | }
178 | }
179 |
180 | func _() {
181 | var resp http.Response
182 | switch {
183 | {{- range $key, $value := .Mapping }}
184 | case resp.StatusCode == {{ $value }}: // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
185 | return
186 | {{- end }}
187 | }
188 | }
189 |
190 | func _() {
191 | var resp http.Response
192 | switch {
193 | {{- range $key, $value := .Mapping }}
194 | case resp.StatusCode == {{ $value }}:
195 | return
196 | {{- end }}
197 | }
198 | }
199 |
200 | var (
201 | {{- range $key, $value := .Mapping }}
202 | _ = httptest.ResponseRecorder{Code: {{ $value }}} // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
203 | {{- end }}
204 | )
205 |
206 | var (
207 | {{- range $key, $value := .Mapping }}
208 | _ = httptest.ResponseRecorder{Code: {{ $value }}}
209 | {{- end }}
210 | )
211 |
--------------------------------------------------------------------------------
/pkg/analyzer/internal/template/test-httpstatus.go.tmpl:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package {{ .PackageName }}
4 |
5 | import (
6 | "net/http"
7 | "net/http/httptest"
8 | )
9 |
10 | var (
11 | {{- range $key, $value := .Mapping }}
12 | _ = {{ $key }}
13 | {{- end }}
14 | )
15 |
16 | const (
17 | {{- range $key, $value := .Mapping }}
18 | _ = {{ $key }}
19 | {{- end }}
20 | )
21 |
22 | func _() {
23 | var w http.ResponseWriter
24 | {{- range $key, $value := .Mapping }}
25 | w.WriteHeader({{ $key }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
26 | {{- end }}
27 | }
28 |
29 | func _() {
30 | var w http.ResponseWriter
31 | {{- range $key, $value := .Mapping }}
32 | w.WriteHeader({{ $value }})
33 | {{- end }}
34 | }
35 |
36 | var (
37 | {{- range $key, $value := .Mapping }}
38 | _ = http.Response{StatusCode: {{ $key }}} // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
39 | {{- end }}
40 | )
41 |
42 | var (
43 | {{- range $key, $value := .Mapping }}
44 | _ = http.Response{StatusCode: {{ $value }}}
45 | {{- end }}
46 | )
47 |
48 | var (
49 | {{- range $key, $value := .Mapping }}
50 | _ = &http.Response{StatusCode: {{ $key }}} // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
51 | {{- end }}
52 | )
53 |
54 | var (
55 | {{- range $key, $value := .Mapping }}
56 | _ = &http.Response{StatusCode: {{ $value }}}
57 | {{- end }}
58 | )
59 |
60 | func _() error {
61 | resp, err := http.DefaultClient.Do(&http.Request{})
62 | if err != nil {
63 | return err
64 | }
65 | defer func() { _ = resp.Body.Close() }()
66 | {{- range $key, $value := .Mapping }}
67 | if resp.StatusCode == {{ $key }} { // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
68 | return nil
69 | } else if resp.StatusCode == {{ $key }} { // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
70 | return nil
71 | } else if false || resp.StatusCode == {{ $key }} { // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
72 | return nil
73 | }
74 | {{- end }}
75 | {{- range $key, $value := .Mapping }}
76 | for resp.StatusCode == {{ $key }} { // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
77 | return nil
78 | }
79 | {{- end }}
80 | return nil
81 | }
82 |
83 | func _() error {
84 | resp, err := http.DefaultClient.Do(&http.Request{})
85 | if err != nil {
86 | return err
87 | }
88 | defer func() { _ = resp.Body.Close() }()
89 | {{- range $key, $value := .Mapping }}
90 | if resp.StatusCode == {{ $value }} {
91 | return nil
92 | } else if resp.StatusCode == {{ $value }} {
93 | return nil
94 | } else if false || resp.StatusCode == {{ $value }} {
95 | return nil
96 | }
97 | {{- end }}
98 | {{- range $key, $value := .Mapping }}
99 | for resp.StatusCode == {{ $value }} {
100 | return nil
101 | }
102 | {{- end }}
103 | return nil
104 | }
105 |
106 | func _() {
107 | var w http.ResponseWriter
108 | {{- range $key, $value := .Mapping }}
109 | http.Error(w, "", {{ $key }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
110 | {{- end }}
111 | }
112 |
113 | func _() {
114 | var w http.ResponseWriter
115 | {{- range $key, $value := .Mapping }}
116 | http.Error(w, "", {{ $value }})
117 | {{- end }}
118 | }
119 |
120 | var (
121 | {{- range $key, $value := .Mapping }}
122 | _ = http.StatusText({{ $key }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
123 | {{- end }}
124 | )
125 |
126 | var (
127 | {{- range $key, $value := .Mapping }}
128 | _ = http.StatusText({{ $value }})
129 | {{- end }}
130 | )
131 |
132 | func _() {
133 | var w http.ResponseWriter
134 | var r *http.Request
135 | {{- range $key, $value := .Mapping }}
136 | http.Redirect(w, r, "", {{ $key }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
137 | {{- end }}
138 | }
139 |
140 | func _() {
141 | var w http.ResponseWriter
142 | var r *http.Request
143 | {{- range $key, $value := .Mapping }}
144 | http.Redirect(w, r, "", {{ $value }})
145 | {{- end }}
146 | }
147 |
148 | var (
149 | {{- range $key, $value := .Mapping }}
150 | _ = http.RedirectHandler("", {{ $key }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
151 | {{- end }}
152 | )
153 |
154 | var (
155 | {{- range $key, $value := .Mapping }}
156 | _ = http.RedirectHandler("", {{ $value }})
157 | {{- end }}
158 | )
159 |
160 | func _() {
161 | var resp http.Response
162 | switch resp.StatusCode {
163 | {{- range $key, $value := .Mapping }}
164 | case {{ $key }}: // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
165 | return
166 | {{- end }}
167 | }
168 | }
169 |
170 | func _() {
171 | var resp http.Response
172 | switch resp.StatusCode {
173 | {{- range $key, $value := .Mapping }}
174 | case {{ $value }}:
175 | return
176 | {{- end }}
177 | }
178 | }
179 |
180 | func _() {
181 | var resp http.Response
182 | switch {
183 | {{- range $key, $value := .Mapping }}
184 | case resp.StatusCode == {{ $key }}: // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
185 | return
186 | {{- end }}
187 | }
188 | }
189 |
190 | func _() {
191 | var resp http.Response
192 | switch {
193 | {{- range $key, $value := .Mapping }}
194 | case resp.StatusCode == {{ $value }}:
195 | return
196 | {{- end }}
197 | }
198 | }
199 |
200 | var (
201 | {{- range $key, $value := .Mapping }}
202 | _ = httptest.ResponseRecorder{Code: {{ $key }}} // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
203 | {{- end }}
204 | )
205 |
206 | var (
207 | {{- range $key, $value := .Mapping }}
208 | _ = httptest.ResponseRecorder{Code: {{ $value }}}
209 | {{- end }}
210 | )
211 |
--------------------------------------------------------------------------------
/pkg/analyzer/internal/template/test-issue103.go.golden.tmpl:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package {{ .PackageName }}
4 |
5 | import "time"
6 |
7 | func _() {
8 | {{- range $key, $value := .Mapping }}
9 | var _ = time.Date(2023, {{ $value }}, 2, 3, 4, 5, 0, time.UTC) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
10 | {{- end }}
11 |
12 | {{ range $key, $value := .Mapping }}
13 | var _ = time.Date(2023, {{ $value }}, 2, 3, 4, 5, 0, time.UTC)
14 | {{- end }}
15 | }
16 |
17 | var _ = time.Date(2023, 13, 2, 3, 4, 5, 0, time.UTC)
18 |
--------------------------------------------------------------------------------
/pkg/analyzer/internal/template/test-issue103.go.tmpl:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package {{ .PackageName }}
4 |
5 | import "time"
6 |
7 | func _() {
8 | {{- range $key, $value := .Mapping }}
9 | var _ = time.Date(2023, {{ $key }}, 2, 3, 4, 5, 0, time.UTC) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
10 | {{- end }}
11 |
12 | {{ range $key, $value := .Mapping }}
13 | var _ = time.Date(2023, {{ $value }}, 2, 3, 4, 5, 0, time.UTC)
14 | {{- end }}
15 | }
16 |
17 | var _ = time.Date(2023, 13, 2, 3, 4, 5, 0, time.UTC)
18 |
--------------------------------------------------------------------------------
/pkg/analyzer/internal/template/test-issue32.go.golden.tmpl:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package {{ .PackageName }}
4 |
5 | import "net/http"
6 |
7 | var (
8 | {{- range $key, $value := .Mapping }}
9 | _ = "{{ toLower $key }}"
10 | {{- end }}
11 | )
12 |
13 | const (
14 | {{- range $key, $value := .Mapping }}
15 | _ = "{{ toLower $key }}"
16 | {{- end }}
17 | )
18 |
19 | var (
20 | {{- range $key, $value := .Mapping }}
21 | _ = http.Request{Method: {{ $value }}} // want `"{{ quoteMeta (toLower $key) }}" can be replaced by {{ quoteMeta $value }}`
22 | {{- end }}
23 | )
24 |
25 | var (
26 | {{- range $key, $value := .Mapping }}
27 | _ = &http.Request{Method: {{ $value }}} // want `"{{ quoteMeta (toLower $key) }}" can be replaced by {{ quoteMeta $value }}`
28 | {{- end }}
29 | )
30 |
31 | var (
32 | {{- range $key, $value := .Mapping }}
33 | _, _ = http.NewRequest({{ $value }}, "", http.NoBody) // want `"{{ quoteMeta (toLower $key) }}" can be replaced by {{ quoteMeta $value }}`
34 | {{- end }}
35 | )
36 |
37 | var (
38 | {{- range $key, $value := .Mapping }}
39 | _, _ = http.NewRequestWithContext(nil, {{ $value }}, "", http.NoBody) // want `"{{ quoteMeta (toLower $key) }}" can be replaced by {{ quoteMeta $value }}`
40 | {{- end }}
41 | )
42 |
--------------------------------------------------------------------------------
/pkg/analyzer/internal/template/test-issue32.go.tmpl:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package {{ .PackageName }}
4 |
5 | import "net/http"
6 |
7 | var (
8 | {{- range $key, $value := .Mapping }}
9 | _ = "{{ toLower $key }}"
10 | {{- end }}
11 | )
12 |
13 | const (
14 | {{- range $key, $value := .Mapping }}
15 | _ = "{{ toLower $key }}"
16 | {{- end }}
17 | )
18 |
19 | var (
20 | {{- range $key, $value := .Mapping }}
21 | _ = http.Request{Method: "{{ toLower $key }}"} // want `"{{ quoteMeta (toLower $key) }}" can be replaced by {{ quoteMeta $value }}`
22 | {{- end }}
23 | )
24 |
25 | var (
26 | {{- range $key, $value := .Mapping }}
27 | _ = &http.Request{Method: "{{ toLower $key }}"} // want `"{{ quoteMeta (toLower $key) }}" can be replaced by {{ quoteMeta $value }}`
28 | {{- end }}
29 | )
30 |
31 | var (
32 | {{- range $key, $value := .Mapping }}
33 | _, _ = http.NewRequest("{{ toLower $key }}", "", http.NoBody) // want `"{{ quoteMeta (toLower $key) }}" can be replaced by {{ quoteMeta $value }}`
34 | {{- end }}
35 | )
36 |
37 | var (
38 | {{- range $key, $value := .Mapping }}
39 | _, _ = http.NewRequestWithContext(nil, "{{ toLower $key }}", "", http.NoBody) // want `"{{ quoteMeta (toLower $key) }}" can be replaced by {{ quoteMeta $value }}`
40 | {{- end }}
41 | )
42 |
--------------------------------------------------------------------------------
/pkg/analyzer/internal/template/test-issue89.go.golden.tmpl:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package {{ .PackageName }}
4 |
5 | import "net/http"
6 |
7 | func _() error {
8 | resp, err := http.DefaultClient.Do(&http.Request{})
9 | if err != nil {
10 | return err
11 | }
12 | defer func() { _ = resp.Body.Close() }()
13 | {{- range $key, $value := .Mapping }}
14 | if resp.StatusCode < {{ $key }} {
15 | return nil
16 | } else if resp.StatusCode < {{ $key }} {
17 | return nil
18 | }
19 | {{- end }}
20 | {{- range $key, $value := .Mapping }}
21 | if resp.StatusCode > {{ $key }} {
22 | return nil
23 | } else if resp.StatusCode > {{ $key }} {
24 | return nil
25 | }
26 | {{- end }}
27 | {{- range $key, $value := .Mapping }}
28 | if resp.StatusCode <= {{ $key }} {
29 | return nil
30 | } else if resp.StatusCode < {{ $key }} {
31 | return nil
32 | }
33 | {{- end }}
34 | {{- range $key, $value := .Mapping }}
35 | if resp.StatusCode >= {{ $key }} {
36 | return nil
37 | } else if resp.StatusCode > {{ $key }} {
38 | return nil
39 | }
40 | {{- end }}
41 | return nil
42 | }
--------------------------------------------------------------------------------
/pkg/analyzer/internal/template/test-issue89.go.tmpl:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package {{ .PackageName }}
4 |
5 | import "net/http"
6 |
7 | func _() error {
8 | resp, err := http.DefaultClient.Do(&http.Request{})
9 | if err != nil {
10 | return err
11 | }
12 | defer func() { _ = resp.Body.Close() }()
13 | {{- range $key, $value := .Mapping }}
14 | if resp.StatusCode < {{ $key }} {
15 | return nil
16 | } else if resp.StatusCode < {{ $key }} {
17 | return nil
18 | }
19 | {{- end }}
20 | {{- range $key, $value := .Mapping }}
21 | if resp.StatusCode > {{ $key }} {
22 | return nil
23 | } else if resp.StatusCode > {{ $key }} {
24 | return nil
25 | }
26 | {{- end }}
27 | {{- range $key, $value := .Mapping }}
28 | if resp.StatusCode <= {{ $key }} {
29 | return nil
30 | } else if resp.StatusCode < {{ $key }} {
31 | return nil
32 | }
33 | {{- end }}
34 | {{- range $key, $value := .Mapping }}
35 | if resp.StatusCode >= {{ $key }} {
36 | return nil
37 | } else if resp.StatusCode > {{ $key }} {
38 | return nil
39 | }
40 | {{- end }}
41 | return nil
42 | }
--------------------------------------------------------------------------------
/pkg/analyzer/internal/template/test-syslog.go.tmpl:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package {{ .PackageName }}
4 |
5 | import "log/syslog"
6 |
7 | var (
8 | {{- range $key, $value := .Mapping }}
9 | _ = {{ $key }}
10 | {{- end }}
11 | )
12 |
13 | var (
14 | {{- range $key, $value := .Mapping }}
15 | _, _ = syslog.New({{ $key }}, "") // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
16 | {{- end }}
17 | )
18 |
19 | var (
20 | {{- range $key, $value := .Mapping }}
21 | _, _ = syslog.Dial("", "", {{ $key }}, "") // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
22 | {{- end }}
23 | )
24 |
25 | var (
26 | {{- range $key, $value := .Mapping }}
27 | _, _ = syslog.NewLogger({{ $key }}, 0) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
28 | {{- end }}
29 | )
--------------------------------------------------------------------------------
/pkg/analyzer/internal/template/test-template.go.golden.tmpl:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package {{ .PackageName }}
4 |
5 | var (
6 | {{- range $key, $value := .Mapping }}
7 | _ = {{ $value }} // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
8 | {{- end }}
9 | )
10 |
11 | const (
12 | {{- range $key, $value := .Mapping }}
13 | _ = {{ $value }} // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
14 | {{- end }}
15 | )
16 |
17 | var (
18 | {{- range $key, $value := .Mapping }}
19 | _ = func(s string)string{return s}({{ $value }}) // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
20 | {{- end }}
21 | )
22 |
--------------------------------------------------------------------------------
/pkg/analyzer/internal/template/test-template.go.tmpl:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package {{ .PackageName }}
4 |
5 | var (
6 | {{- range $key, $value := .Mapping }}
7 | _ = "{{ $key }}" // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
8 | {{- end }}
9 | )
10 |
11 | const (
12 | {{- range $key, $value := .Mapping }}
13 | _ = "{{ $key }}" // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
14 | {{- end }}
15 | )
16 |
17 | var (
18 | {{- range $key, $value := .Mapping }}
19 | _ = func(s string)string{return s}("{{ $key }}") // want `"{{ quoteMeta $key }}" can be replaced by {{ quoteMeta $value }}`
20 | {{- end }}
21 | )
22 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/constant/kind.go:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package constant_test
4 |
5 | var (
6 | _ = "Bool" // want `"Bool" can be replaced by constant\.Bool\.String\(\)`
7 | _ = "Complex" // want `"Complex" can be replaced by constant\.Complex\.String\(\)`
8 | _ = "Float" // want `"Float" can be replaced by constant\.Float\.String\(\)`
9 | _ = "Int" // want `"Int" can be replaced by constant\.Int\.String\(\)`
10 | _ = "String" // want `"String" can be replaced by constant\.String\.String\(\)`
11 | )
12 |
13 | const (
14 | _ = "Bool" // want `"Bool" can be replaced by constant\.Bool\.String\(\)`
15 | _ = "Complex" // want `"Complex" can be replaced by constant\.Complex\.String\(\)`
16 | _ = "Float" // want `"Float" can be replaced by constant\.Float\.String\(\)`
17 | _ = "Int" // want `"Int" can be replaced by constant\.Int\.String\(\)`
18 | _ = "String" // want `"String" can be replaced by constant\.String\.String\(\)`
19 | )
20 |
21 | var (
22 | _ = func(s string) string { return s }("Bool") // want `"Bool" can be replaced by constant\.Bool\.String\(\)`
23 | _ = func(s string) string { return s }("Complex") // want `"Complex" can be replaced by constant\.Complex\.String\(\)`
24 | _ = func(s string) string { return s }("Float") // want `"Float" can be replaced by constant\.Float\.String\(\)`
25 | _ = func(s string) string { return s }("Int") // want `"Int" can be replaced by constant\.Int\.String\(\)`
26 | _ = func(s string) string { return s }("String") // want `"String" can be replaced by constant\.String\.String\(\)`
27 | )
28 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/constant/kind.go.golden:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package constant_test
4 |
5 | var (
6 | _ = constant.Bool.String() // want `"Bool" can be replaced by constant\.Bool\.String\(\)`
7 | _ = constant.Complex.String() // want `"Complex" can be replaced by constant\.Complex\.String\(\)`
8 | _ = constant.Float.String() // want `"Float" can be replaced by constant\.Float\.String\(\)`
9 | _ = constant.Int.String() // want `"Int" can be replaced by constant\.Int\.String\(\)`
10 | _ = constant.String.String() // want `"String" can be replaced by constant\.String\.String\(\)`
11 | )
12 |
13 | const (
14 | _ = constant.Bool.String() // want `"Bool" can be replaced by constant\.Bool\.String\(\)`
15 | _ = constant.Complex.String() // want `"Complex" can be replaced by constant\.Complex\.String\(\)`
16 | _ = constant.Float.String() // want `"Float" can be replaced by constant\.Float\.String\(\)`
17 | _ = constant.Int.String() // want `"Int" can be replaced by constant\.Int\.String\(\)`
18 | _ = constant.String.String() // want `"String" can be replaced by constant\.String\.String\(\)`
19 | )
20 |
21 | var (
22 | _ = func(s string)string{return s}(constant.Bool.String()) // want `"Bool" can be replaced by constant\.Bool\.String\(\)`
23 | _ = func(s string)string{return s}(constant.Complex.String()) // want `"Complex" can be replaced by constant\.Complex\.String\(\)`
24 | _ = func(s string)string{return s}(constant.Float.String()) // want `"Float" can be replaced by constant\.Float\.String\(\)`
25 | _ = func(s string)string{return s}(constant.Int.String()) // want `"Int" can be replaced by constant\.Int\.String\(\)`
26 | _ = func(s string)string{return s}(constant.String.String()) // want `"String" can be replaced by constant\.String\.String\(\)`
27 | )
28 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/crypto/crypto.go:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package crypto_test
4 |
5 | var (
6 | _ = "BLAKE2b-256" // want `"BLAKE2b-256" can be replaced by crypto\.BLAKE2b_256\.String\(\)`
7 | _ = "BLAKE2b-384" // want `"BLAKE2b-384" can be replaced by crypto\.BLAKE2b_384\.String\(\)`
8 | _ = "BLAKE2b-512" // want `"BLAKE2b-512" can be replaced by crypto\.BLAKE2b_512\.String\(\)`
9 | _ = "BLAKE2s-256" // want `"BLAKE2s-256" can be replaced by crypto\.BLAKE2s_256\.String\(\)`
10 | _ = "MD4" // want `"MD4" can be replaced by crypto\.MD4\.String\(\)`
11 | _ = "MD5" // want `"MD5" can be replaced by crypto\.MD5\.String\(\)`
12 | _ = "MD5+SHA1" // want `"MD5\+SHA1" can be replaced by crypto\.MD5SHA1\.String\(\)`
13 | _ = "RIPEMD-160" // want `"RIPEMD-160" can be replaced by crypto\.RIPEMD160\.String\(\)`
14 | _ = "SHA-1" // want `"SHA-1" can be replaced by crypto\.SHA1\.String\(\)`
15 | _ = "SHA-224" // want `"SHA-224" can be replaced by crypto\.SHA224\.String\(\)`
16 | _ = "SHA-256" // want `"SHA-256" can be replaced by crypto\.SHA256\.String\(\)`
17 | _ = "SHA-384" // want `"SHA-384" can be replaced by crypto\.SHA384\.String\(\)`
18 | _ = "SHA-512" // want `"SHA-512" can be replaced by crypto\.SHA512\.String\(\)`
19 | _ = "SHA-512/224" // want `"SHA-512/224" can be replaced by crypto\.SHA512_224\.String\(\)`
20 | _ = "SHA-512/256" // want `"SHA-512/256" can be replaced by crypto\.SHA512_256\.String\(\)`
21 | _ = "SHA3-224" // want `"SHA3-224" can be replaced by crypto\.SHA3_224\.String\(\)`
22 | _ = "SHA3-256" // want `"SHA3-256" can be replaced by crypto\.SHA3_256\.String\(\)`
23 | _ = "SHA3-384" // want `"SHA3-384" can be replaced by crypto\.SHA3_384\.String\(\)`
24 | _ = "SHA3-512" // want `"SHA3-512" can be replaced by crypto\.SHA3_512\.String\(\)`
25 | )
26 |
27 | const (
28 | _ = "BLAKE2b-256" // want `"BLAKE2b-256" can be replaced by crypto\.BLAKE2b_256\.String\(\)`
29 | _ = "BLAKE2b-384" // want `"BLAKE2b-384" can be replaced by crypto\.BLAKE2b_384\.String\(\)`
30 | _ = "BLAKE2b-512" // want `"BLAKE2b-512" can be replaced by crypto\.BLAKE2b_512\.String\(\)`
31 | _ = "BLAKE2s-256" // want `"BLAKE2s-256" can be replaced by crypto\.BLAKE2s_256\.String\(\)`
32 | _ = "MD4" // want `"MD4" can be replaced by crypto\.MD4\.String\(\)`
33 | _ = "MD5" // want `"MD5" can be replaced by crypto\.MD5\.String\(\)`
34 | _ = "MD5+SHA1" // want `"MD5\+SHA1" can be replaced by crypto\.MD5SHA1\.String\(\)`
35 | _ = "RIPEMD-160" // want `"RIPEMD-160" can be replaced by crypto\.RIPEMD160\.String\(\)`
36 | _ = "SHA-1" // want `"SHA-1" can be replaced by crypto\.SHA1\.String\(\)`
37 | _ = "SHA-224" // want `"SHA-224" can be replaced by crypto\.SHA224\.String\(\)`
38 | _ = "SHA-256" // want `"SHA-256" can be replaced by crypto\.SHA256\.String\(\)`
39 | _ = "SHA-384" // want `"SHA-384" can be replaced by crypto\.SHA384\.String\(\)`
40 | _ = "SHA-512" // want `"SHA-512" can be replaced by crypto\.SHA512\.String\(\)`
41 | _ = "SHA-512/224" // want `"SHA-512/224" can be replaced by crypto\.SHA512_224\.String\(\)`
42 | _ = "SHA-512/256" // want `"SHA-512/256" can be replaced by crypto\.SHA512_256\.String\(\)`
43 | _ = "SHA3-224" // want `"SHA3-224" can be replaced by crypto\.SHA3_224\.String\(\)`
44 | _ = "SHA3-256" // want `"SHA3-256" can be replaced by crypto\.SHA3_256\.String\(\)`
45 | _ = "SHA3-384" // want `"SHA3-384" can be replaced by crypto\.SHA3_384\.String\(\)`
46 | _ = "SHA3-512" // want `"SHA3-512" can be replaced by crypto\.SHA3_512\.String\(\)`
47 | )
48 |
49 | var (
50 | _ = func(s string) string { return s }("BLAKE2b-256") // want `"BLAKE2b-256" can be replaced by crypto\.BLAKE2b_256\.String\(\)`
51 | _ = func(s string) string { return s }("BLAKE2b-384") // want `"BLAKE2b-384" can be replaced by crypto\.BLAKE2b_384\.String\(\)`
52 | _ = func(s string) string { return s }("BLAKE2b-512") // want `"BLAKE2b-512" can be replaced by crypto\.BLAKE2b_512\.String\(\)`
53 | _ = func(s string) string { return s }("BLAKE2s-256") // want `"BLAKE2s-256" can be replaced by crypto\.BLAKE2s_256\.String\(\)`
54 | _ = func(s string) string { return s }("MD4") // want `"MD4" can be replaced by crypto\.MD4\.String\(\)`
55 | _ = func(s string) string { return s }("MD5") // want `"MD5" can be replaced by crypto\.MD5\.String\(\)`
56 | _ = func(s string) string { return s }("MD5+SHA1") // want `"MD5\+SHA1" can be replaced by crypto\.MD5SHA1\.String\(\)`
57 | _ = func(s string) string { return s }("RIPEMD-160") // want `"RIPEMD-160" can be replaced by crypto\.RIPEMD160\.String\(\)`
58 | _ = func(s string) string { return s }("SHA-1") // want `"SHA-1" can be replaced by crypto\.SHA1\.String\(\)`
59 | _ = func(s string) string { return s }("SHA-224") // want `"SHA-224" can be replaced by crypto\.SHA224\.String\(\)`
60 | _ = func(s string) string { return s }("SHA-256") // want `"SHA-256" can be replaced by crypto\.SHA256\.String\(\)`
61 | _ = func(s string) string { return s }("SHA-384") // want `"SHA-384" can be replaced by crypto\.SHA384\.String\(\)`
62 | _ = func(s string) string { return s }("SHA-512") // want `"SHA-512" can be replaced by crypto\.SHA512\.String\(\)`
63 | _ = func(s string) string { return s }("SHA-512/224") // want `"SHA-512/224" can be replaced by crypto\.SHA512_224\.String\(\)`
64 | _ = func(s string) string { return s }("SHA-512/256") // want `"SHA-512/256" can be replaced by crypto\.SHA512_256\.String\(\)`
65 | _ = func(s string) string { return s }("SHA3-224") // want `"SHA3-224" can be replaced by crypto\.SHA3_224\.String\(\)`
66 | _ = func(s string) string { return s }("SHA3-256") // want `"SHA3-256" can be replaced by crypto\.SHA3_256\.String\(\)`
67 | _ = func(s string) string { return s }("SHA3-384") // want `"SHA3-384" can be replaced by crypto\.SHA3_384\.String\(\)`
68 | _ = func(s string) string { return s }("SHA3-512") // want `"SHA3-512" can be replaced by crypto\.SHA3_512\.String\(\)`
69 | )
70 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/crypto/crypto.go.golden:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package crypto_test
4 |
5 | var (
6 | _ = crypto.BLAKE2b_256.String() // want `"BLAKE2b-256" can be replaced by crypto\.BLAKE2b_256\.String\(\)`
7 | _ = crypto.BLAKE2b_384.String() // want `"BLAKE2b-384" can be replaced by crypto\.BLAKE2b_384\.String\(\)`
8 | _ = crypto.BLAKE2b_512.String() // want `"BLAKE2b-512" can be replaced by crypto\.BLAKE2b_512\.String\(\)`
9 | _ = crypto.BLAKE2s_256.String() // want `"BLAKE2s-256" can be replaced by crypto\.BLAKE2s_256\.String\(\)`
10 | _ = crypto.MD4.String() // want `"MD4" can be replaced by crypto\.MD4\.String\(\)`
11 | _ = crypto.MD5.String() // want `"MD5" can be replaced by crypto\.MD5\.String\(\)`
12 | _ = crypto.MD5SHA1.String() // want `"MD5\+SHA1" can be replaced by crypto\.MD5SHA1\.String\(\)`
13 | _ = crypto.RIPEMD160.String() // want `"RIPEMD-160" can be replaced by crypto\.RIPEMD160\.String\(\)`
14 | _ = crypto.SHA1.String() // want `"SHA-1" can be replaced by crypto\.SHA1\.String\(\)`
15 | _ = crypto.SHA224.String() // want `"SHA-224" can be replaced by crypto\.SHA224\.String\(\)`
16 | _ = crypto.SHA256.String() // want `"SHA-256" can be replaced by crypto\.SHA256\.String\(\)`
17 | _ = crypto.SHA384.String() // want `"SHA-384" can be replaced by crypto\.SHA384\.String\(\)`
18 | _ = crypto.SHA512.String() // want `"SHA-512" can be replaced by crypto\.SHA512\.String\(\)`
19 | _ = crypto.SHA512_224.String() // want `"SHA-512/224" can be replaced by crypto\.SHA512_224\.String\(\)`
20 | _ = crypto.SHA512_256.String() // want `"SHA-512/256" can be replaced by crypto\.SHA512_256\.String\(\)`
21 | _ = crypto.SHA3_224.String() // want `"SHA3-224" can be replaced by crypto\.SHA3_224\.String\(\)`
22 | _ = crypto.SHA3_256.String() // want `"SHA3-256" can be replaced by crypto\.SHA3_256\.String\(\)`
23 | _ = crypto.SHA3_384.String() // want `"SHA3-384" can be replaced by crypto\.SHA3_384\.String\(\)`
24 | _ = crypto.SHA3_512.String() // want `"SHA3-512" can be replaced by crypto\.SHA3_512\.String\(\)`
25 | )
26 |
27 | const (
28 | _ = crypto.BLAKE2b_256.String() // want `"BLAKE2b-256" can be replaced by crypto\.BLAKE2b_256\.String\(\)`
29 | _ = crypto.BLAKE2b_384.String() // want `"BLAKE2b-384" can be replaced by crypto\.BLAKE2b_384\.String\(\)`
30 | _ = crypto.BLAKE2b_512.String() // want `"BLAKE2b-512" can be replaced by crypto\.BLAKE2b_512\.String\(\)`
31 | _ = crypto.BLAKE2s_256.String() // want `"BLAKE2s-256" can be replaced by crypto\.BLAKE2s_256\.String\(\)`
32 | _ = crypto.MD4.String() // want `"MD4" can be replaced by crypto\.MD4\.String\(\)`
33 | _ = crypto.MD5.String() // want `"MD5" can be replaced by crypto\.MD5\.String\(\)`
34 | _ = crypto.MD5SHA1.String() // want `"MD5\+SHA1" can be replaced by crypto\.MD5SHA1\.String\(\)`
35 | _ = crypto.RIPEMD160.String() // want `"RIPEMD-160" can be replaced by crypto\.RIPEMD160\.String\(\)`
36 | _ = crypto.SHA1.String() // want `"SHA-1" can be replaced by crypto\.SHA1\.String\(\)`
37 | _ = crypto.SHA224.String() // want `"SHA-224" can be replaced by crypto\.SHA224\.String\(\)`
38 | _ = crypto.SHA256.String() // want `"SHA-256" can be replaced by crypto\.SHA256\.String\(\)`
39 | _ = crypto.SHA384.String() // want `"SHA-384" can be replaced by crypto\.SHA384\.String\(\)`
40 | _ = crypto.SHA512.String() // want `"SHA-512" can be replaced by crypto\.SHA512\.String\(\)`
41 | _ = crypto.SHA512_224.String() // want `"SHA-512/224" can be replaced by crypto\.SHA512_224\.String\(\)`
42 | _ = crypto.SHA512_256.String() // want `"SHA-512/256" can be replaced by crypto\.SHA512_256\.String\(\)`
43 | _ = crypto.SHA3_224.String() // want `"SHA3-224" can be replaced by crypto\.SHA3_224\.String\(\)`
44 | _ = crypto.SHA3_256.String() // want `"SHA3-256" can be replaced by crypto\.SHA3_256\.String\(\)`
45 | _ = crypto.SHA3_384.String() // want `"SHA3-384" can be replaced by crypto\.SHA3_384\.String\(\)`
46 | _ = crypto.SHA3_512.String() // want `"SHA3-512" can be replaced by crypto\.SHA3_512\.String\(\)`
47 | )
48 |
49 | var (
50 | _ = func(s string)string{return s}(crypto.BLAKE2b_256.String()) // want `"BLAKE2b-256" can be replaced by crypto\.BLAKE2b_256\.String\(\)`
51 | _ = func(s string)string{return s}(crypto.BLAKE2b_384.String()) // want `"BLAKE2b-384" can be replaced by crypto\.BLAKE2b_384\.String\(\)`
52 | _ = func(s string)string{return s}(crypto.BLAKE2b_512.String()) // want `"BLAKE2b-512" can be replaced by crypto\.BLAKE2b_512\.String\(\)`
53 | _ = func(s string)string{return s}(crypto.BLAKE2s_256.String()) // want `"BLAKE2s-256" can be replaced by crypto\.BLAKE2s_256\.String\(\)`
54 | _ = func(s string)string{return s}(crypto.MD4.String()) // want `"MD4" can be replaced by crypto\.MD4\.String\(\)`
55 | _ = func(s string)string{return s}(crypto.MD5.String()) // want `"MD5" can be replaced by crypto\.MD5\.String\(\)`
56 | _ = func(s string)string{return s}(crypto.MD5SHA1.String()) // want `"MD5\+SHA1" can be replaced by crypto\.MD5SHA1\.String\(\)`
57 | _ = func(s string)string{return s}(crypto.RIPEMD160.String()) // want `"RIPEMD-160" can be replaced by crypto\.RIPEMD160\.String\(\)`
58 | _ = func(s string)string{return s}(crypto.SHA1.String()) // want `"SHA-1" can be replaced by crypto\.SHA1\.String\(\)`
59 | _ = func(s string)string{return s}(crypto.SHA224.String()) // want `"SHA-224" can be replaced by crypto\.SHA224\.String\(\)`
60 | _ = func(s string)string{return s}(crypto.SHA256.String()) // want `"SHA-256" can be replaced by crypto\.SHA256\.String\(\)`
61 | _ = func(s string)string{return s}(crypto.SHA384.String()) // want `"SHA-384" can be replaced by crypto\.SHA384\.String\(\)`
62 | _ = func(s string)string{return s}(crypto.SHA512.String()) // want `"SHA-512" can be replaced by crypto\.SHA512\.String\(\)`
63 | _ = func(s string)string{return s}(crypto.SHA512_224.String()) // want `"SHA-512/224" can be replaced by crypto\.SHA512_224\.String\(\)`
64 | _ = func(s string)string{return s}(crypto.SHA512_256.String()) // want `"SHA-512/256" can be replaced by crypto\.SHA512_256\.String\(\)`
65 | _ = func(s string)string{return s}(crypto.SHA3_224.String()) // want `"SHA3-224" can be replaced by crypto\.SHA3_224\.String\(\)`
66 | _ = func(s string)string{return s}(crypto.SHA3_256.String()) // want `"SHA3-256" can be replaced by crypto\.SHA3_256\.String\(\)`
67 | _ = func(s string)string{return s}(crypto.SHA3_384.String()) // want `"SHA3-384" can be replaced by crypto\.SHA3_384\.String\(\)`
68 | _ = func(s string)string{return s}(crypto.SHA3_512.String()) // want `"SHA3-512" can be replaced by crypto\.SHA3_512\.String\(\)`
69 | )
70 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/http/issue32.go:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package http_test
4 |
5 | import "net/http"
6 |
7 | var (
8 | _ = "connect"
9 | _ = "delete"
10 | _ = "get"
11 | _ = "head"
12 | _ = "options"
13 | _ = "patch"
14 | _ = "post"
15 | _ = "put"
16 | _ = "trace"
17 | )
18 |
19 | const (
20 | _ = "connect"
21 | _ = "delete"
22 | _ = "get"
23 | _ = "head"
24 | _ = "options"
25 | _ = "patch"
26 | _ = "post"
27 | _ = "put"
28 | _ = "trace"
29 | )
30 |
31 | var (
32 | _ = http.Request{Method: "connect"} // want `"connect" can be replaced by http\.MethodConnect`
33 | _ = http.Request{Method: "delete"} // want `"delete" can be replaced by http\.MethodDelete`
34 | _ = http.Request{Method: "get"} // want `"get" can be replaced by http\.MethodGet`
35 | _ = http.Request{Method: "head"} // want `"head" can be replaced by http\.MethodHead`
36 | _ = http.Request{Method: "options"} // want `"options" can be replaced by http\.MethodOptions`
37 | _ = http.Request{Method: "patch"} // want `"patch" can be replaced by http\.MethodPatch`
38 | _ = http.Request{Method: "post"} // want `"post" can be replaced by http\.MethodPost`
39 | _ = http.Request{Method: "put"} // want `"put" can be replaced by http\.MethodPut`
40 | _ = http.Request{Method: "trace"} // want `"trace" can be replaced by http\.MethodTrace`
41 | )
42 |
43 | var (
44 | _ = &http.Request{Method: "connect"} // want `"connect" can be replaced by http\.MethodConnect`
45 | _ = &http.Request{Method: "delete"} // want `"delete" can be replaced by http\.MethodDelete`
46 | _ = &http.Request{Method: "get"} // want `"get" can be replaced by http\.MethodGet`
47 | _ = &http.Request{Method: "head"} // want `"head" can be replaced by http\.MethodHead`
48 | _ = &http.Request{Method: "options"} // want `"options" can be replaced by http\.MethodOptions`
49 | _ = &http.Request{Method: "patch"} // want `"patch" can be replaced by http\.MethodPatch`
50 | _ = &http.Request{Method: "post"} // want `"post" can be replaced by http\.MethodPost`
51 | _ = &http.Request{Method: "put"} // want `"put" can be replaced by http\.MethodPut`
52 | _ = &http.Request{Method: "trace"} // want `"trace" can be replaced by http\.MethodTrace`
53 | )
54 |
55 | var (
56 | _, _ = http.NewRequest("connect", "", http.NoBody) // want `"connect" can be replaced by http\.MethodConnect`
57 | _, _ = http.NewRequest("delete", "", http.NoBody) // want `"delete" can be replaced by http\.MethodDelete`
58 | _, _ = http.NewRequest("get", "", http.NoBody) // want `"get" can be replaced by http\.MethodGet`
59 | _, _ = http.NewRequest("head", "", http.NoBody) // want `"head" can be replaced by http\.MethodHead`
60 | _, _ = http.NewRequest("options", "", http.NoBody) // want `"options" can be replaced by http\.MethodOptions`
61 | _, _ = http.NewRequest("patch", "", http.NoBody) // want `"patch" can be replaced by http\.MethodPatch`
62 | _, _ = http.NewRequest("post", "", http.NoBody) // want `"post" can be replaced by http\.MethodPost`
63 | _, _ = http.NewRequest("put", "", http.NoBody) // want `"put" can be replaced by http\.MethodPut`
64 | _, _ = http.NewRequest("trace", "", http.NoBody) // want `"trace" can be replaced by http\.MethodTrace`
65 | )
66 |
67 | var (
68 | _, _ = http.NewRequestWithContext(nil, "connect", "", http.NoBody) // want `"connect" can be replaced by http\.MethodConnect`
69 | _, _ = http.NewRequestWithContext(nil, "delete", "", http.NoBody) // want `"delete" can be replaced by http\.MethodDelete`
70 | _, _ = http.NewRequestWithContext(nil, "get", "", http.NoBody) // want `"get" can be replaced by http\.MethodGet`
71 | _, _ = http.NewRequestWithContext(nil, "head", "", http.NoBody) // want `"head" can be replaced by http\.MethodHead`
72 | _, _ = http.NewRequestWithContext(nil, "options", "", http.NoBody) // want `"options" can be replaced by http\.MethodOptions`
73 | _, _ = http.NewRequestWithContext(nil, "patch", "", http.NoBody) // want `"patch" can be replaced by http\.MethodPatch`
74 | _, _ = http.NewRequestWithContext(nil, "post", "", http.NoBody) // want `"post" can be replaced by http\.MethodPost`
75 | _, _ = http.NewRequestWithContext(nil, "put", "", http.NoBody) // want `"put" can be replaced by http\.MethodPut`
76 | _, _ = http.NewRequestWithContext(nil, "trace", "", http.NoBody) // want `"trace" can be replaced by http\.MethodTrace`
77 | )
78 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/http/issue32.go.golden:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package http_test
4 |
5 | import "net/http"
6 |
7 | var (
8 | _ = "connect"
9 | _ = "delete"
10 | _ = "get"
11 | _ = "head"
12 | _ = "options"
13 | _ = "patch"
14 | _ = "post"
15 | _ = "put"
16 | _ = "trace"
17 | )
18 |
19 | const (
20 | _ = "connect"
21 | _ = "delete"
22 | _ = "get"
23 | _ = "head"
24 | _ = "options"
25 | _ = "patch"
26 | _ = "post"
27 | _ = "put"
28 | _ = "trace"
29 | )
30 |
31 | var (
32 | _ = http.Request{Method: http.MethodConnect} // want `"connect" can be replaced by http\.MethodConnect`
33 | _ = http.Request{Method: http.MethodDelete} // want `"delete" can be replaced by http\.MethodDelete`
34 | _ = http.Request{Method: http.MethodGet} // want `"get" can be replaced by http\.MethodGet`
35 | _ = http.Request{Method: http.MethodHead} // want `"head" can be replaced by http\.MethodHead`
36 | _ = http.Request{Method: http.MethodOptions} // want `"options" can be replaced by http\.MethodOptions`
37 | _ = http.Request{Method: http.MethodPatch} // want `"patch" can be replaced by http\.MethodPatch`
38 | _ = http.Request{Method: http.MethodPost} // want `"post" can be replaced by http\.MethodPost`
39 | _ = http.Request{Method: http.MethodPut} // want `"put" can be replaced by http\.MethodPut`
40 | _ = http.Request{Method: http.MethodTrace} // want `"trace" can be replaced by http\.MethodTrace`
41 | )
42 |
43 | var (
44 | _ = &http.Request{Method: http.MethodConnect} // want `"connect" can be replaced by http\.MethodConnect`
45 | _ = &http.Request{Method: http.MethodDelete} // want `"delete" can be replaced by http\.MethodDelete`
46 | _ = &http.Request{Method: http.MethodGet} // want `"get" can be replaced by http\.MethodGet`
47 | _ = &http.Request{Method: http.MethodHead} // want `"head" can be replaced by http\.MethodHead`
48 | _ = &http.Request{Method: http.MethodOptions} // want `"options" can be replaced by http\.MethodOptions`
49 | _ = &http.Request{Method: http.MethodPatch} // want `"patch" can be replaced by http\.MethodPatch`
50 | _ = &http.Request{Method: http.MethodPost} // want `"post" can be replaced by http\.MethodPost`
51 | _ = &http.Request{Method: http.MethodPut} // want `"put" can be replaced by http\.MethodPut`
52 | _ = &http.Request{Method: http.MethodTrace} // want `"trace" can be replaced by http\.MethodTrace`
53 | )
54 |
55 | var (
56 | _, _ = http.NewRequest(http.MethodConnect, "", http.NoBody) // want `"connect" can be replaced by http\.MethodConnect`
57 | _, _ = http.NewRequest(http.MethodDelete, "", http.NoBody) // want `"delete" can be replaced by http\.MethodDelete`
58 | _, _ = http.NewRequest(http.MethodGet, "", http.NoBody) // want `"get" can be replaced by http\.MethodGet`
59 | _, _ = http.NewRequest(http.MethodHead, "", http.NoBody) // want `"head" can be replaced by http\.MethodHead`
60 | _, _ = http.NewRequest(http.MethodOptions, "", http.NoBody) // want `"options" can be replaced by http\.MethodOptions`
61 | _, _ = http.NewRequest(http.MethodPatch, "", http.NoBody) // want `"patch" can be replaced by http\.MethodPatch`
62 | _, _ = http.NewRequest(http.MethodPost, "", http.NoBody) // want `"post" can be replaced by http\.MethodPost`
63 | _, _ = http.NewRequest(http.MethodPut, "", http.NoBody) // want `"put" can be replaced by http\.MethodPut`
64 | _, _ = http.NewRequest(http.MethodTrace, "", http.NoBody) // want `"trace" can be replaced by http\.MethodTrace`
65 | )
66 |
67 | var (
68 | _, _ = http.NewRequestWithContext(nil, http.MethodConnect, "", http.NoBody) // want `"connect" can be replaced by http\.MethodConnect`
69 | _, _ = http.NewRequestWithContext(nil, http.MethodDelete, "", http.NoBody) // want `"delete" can be replaced by http\.MethodDelete`
70 | _, _ = http.NewRequestWithContext(nil, http.MethodGet, "", http.NoBody) // want `"get" can be replaced by http\.MethodGet`
71 | _, _ = http.NewRequestWithContext(nil, http.MethodHead, "", http.NoBody) // want `"head" can be replaced by http\.MethodHead`
72 | _, _ = http.NewRequestWithContext(nil, http.MethodOptions, "", http.NoBody) // want `"options" can be replaced by http\.MethodOptions`
73 | _, _ = http.NewRequestWithContext(nil, http.MethodPatch, "", http.NoBody) // want `"patch" can be replaced by http\.MethodPatch`
74 | _, _ = http.NewRequestWithContext(nil, http.MethodPost, "", http.NoBody) // want `"post" can be replaced by http\.MethodPost`
75 | _, _ = http.NewRequestWithContext(nil, http.MethodPut, "", http.NoBody) // want `"put" can be replaced by http\.MethodPut`
76 | _, _ = http.NewRequestWithContext(nil, http.MethodTrace, "", http.NoBody) // want `"trace" can be replaced by http\.MethodTrace`
77 | )
78 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/http/issue89.go:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package http_test
4 |
5 | import "net/http"
6 |
7 | func _() error {
8 | resp, err := http.DefaultClient.Do(&http.Request{})
9 | if err != nil {
10 | return err
11 | }
12 | defer func() { _ = resp.Body.Close() }()
13 | if resp.StatusCode < 100 {
14 | return nil
15 | } else if resp.StatusCode < 100 {
16 | return nil
17 | }
18 | if resp.StatusCode < 101 {
19 | return nil
20 | } else if resp.StatusCode < 101 {
21 | return nil
22 | }
23 | if resp.StatusCode < 102 {
24 | return nil
25 | } else if resp.StatusCode < 102 {
26 | return nil
27 | }
28 | if resp.StatusCode < 103 {
29 | return nil
30 | } else if resp.StatusCode < 103 {
31 | return nil
32 | }
33 | if resp.StatusCode < 200 {
34 | return nil
35 | } else if resp.StatusCode < 200 {
36 | return nil
37 | }
38 | if resp.StatusCode < 201 {
39 | return nil
40 | } else if resp.StatusCode < 201 {
41 | return nil
42 | }
43 | if resp.StatusCode < 202 {
44 | return nil
45 | } else if resp.StatusCode < 202 {
46 | return nil
47 | }
48 | if resp.StatusCode < 203 {
49 | return nil
50 | } else if resp.StatusCode < 203 {
51 | return nil
52 | }
53 | if resp.StatusCode < 204 {
54 | return nil
55 | } else if resp.StatusCode < 204 {
56 | return nil
57 | }
58 | if resp.StatusCode < 205 {
59 | return nil
60 | } else if resp.StatusCode < 205 {
61 | return nil
62 | }
63 | if resp.StatusCode < 206 {
64 | return nil
65 | } else if resp.StatusCode < 206 {
66 | return nil
67 | }
68 | if resp.StatusCode < 207 {
69 | return nil
70 | } else if resp.StatusCode < 207 {
71 | return nil
72 | }
73 | if resp.StatusCode < 208 {
74 | return nil
75 | } else if resp.StatusCode < 208 {
76 | return nil
77 | }
78 | if resp.StatusCode < 226 {
79 | return nil
80 | } else if resp.StatusCode < 226 {
81 | return nil
82 | }
83 | if resp.StatusCode < 300 {
84 | return nil
85 | } else if resp.StatusCode < 300 {
86 | return nil
87 | }
88 | if resp.StatusCode < 301 {
89 | return nil
90 | } else if resp.StatusCode < 301 {
91 | return nil
92 | }
93 | if resp.StatusCode < 302 {
94 | return nil
95 | } else if resp.StatusCode < 302 {
96 | return nil
97 | }
98 | if resp.StatusCode < 303 {
99 | return nil
100 | } else if resp.StatusCode < 303 {
101 | return nil
102 | }
103 | if resp.StatusCode < 304 {
104 | return nil
105 | } else if resp.StatusCode < 304 {
106 | return nil
107 | }
108 | if resp.StatusCode < 305 {
109 | return nil
110 | } else if resp.StatusCode < 305 {
111 | return nil
112 | }
113 | if resp.StatusCode < 307 {
114 | return nil
115 | } else if resp.StatusCode < 307 {
116 | return nil
117 | }
118 | if resp.StatusCode < 308 {
119 | return nil
120 | } else if resp.StatusCode < 308 {
121 | return nil
122 | }
123 | if resp.StatusCode < 400 {
124 | return nil
125 | } else if resp.StatusCode < 400 {
126 | return nil
127 | }
128 | if resp.StatusCode < 401 {
129 | return nil
130 | } else if resp.StatusCode < 401 {
131 | return nil
132 | }
133 | if resp.StatusCode < 402 {
134 | return nil
135 | } else if resp.StatusCode < 402 {
136 | return nil
137 | }
138 | if resp.StatusCode < 403 {
139 | return nil
140 | } else if resp.StatusCode < 403 {
141 | return nil
142 | }
143 | if resp.StatusCode < 404 {
144 | return nil
145 | } else if resp.StatusCode < 404 {
146 | return nil
147 | }
148 | if resp.StatusCode < 405 {
149 | return nil
150 | } else if resp.StatusCode < 405 {
151 | return nil
152 | }
153 | if resp.StatusCode < 406 {
154 | return nil
155 | } else if resp.StatusCode < 406 {
156 | return nil
157 | }
158 | if resp.StatusCode < 407 {
159 | return nil
160 | } else if resp.StatusCode < 407 {
161 | return nil
162 | }
163 | if resp.StatusCode < 408 {
164 | return nil
165 | } else if resp.StatusCode < 408 {
166 | return nil
167 | }
168 | if resp.StatusCode < 409 {
169 | return nil
170 | } else if resp.StatusCode < 409 {
171 | return nil
172 | }
173 | if resp.StatusCode < 410 {
174 | return nil
175 | } else if resp.StatusCode < 410 {
176 | return nil
177 | }
178 | if resp.StatusCode < 411 {
179 | return nil
180 | } else if resp.StatusCode < 411 {
181 | return nil
182 | }
183 | if resp.StatusCode < 412 {
184 | return nil
185 | } else if resp.StatusCode < 412 {
186 | return nil
187 | }
188 | if resp.StatusCode < 413 {
189 | return nil
190 | } else if resp.StatusCode < 413 {
191 | return nil
192 | }
193 | if resp.StatusCode < 414 {
194 | return nil
195 | } else if resp.StatusCode < 414 {
196 | return nil
197 | }
198 | if resp.StatusCode < 415 {
199 | return nil
200 | } else if resp.StatusCode < 415 {
201 | return nil
202 | }
203 | if resp.StatusCode < 416 {
204 | return nil
205 | } else if resp.StatusCode < 416 {
206 | return nil
207 | }
208 | if resp.StatusCode < 417 {
209 | return nil
210 | } else if resp.StatusCode < 417 {
211 | return nil
212 | }
213 | if resp.StatusCode < 418 {
214 | return nil
215 | } else if resp.StatusCode < 418 {
216 | return nil
217 | }
218 | if resp.StatusCode < 421 {
219 | return nil
220 | } else if resp.StatusCode < 421 {
221 | return nil
222 | }
223 | if resp.StatusCode < 422 {
224 | return nil
225 | } else if resp.StatusCode < 422 {
226 | return nil
227 | }
228 | if resp.StatusCode < 423 {
229 | return nil
230 | } else if resp.StatusCode < 423 {
231 | return nil
232 | }
233 | if resp.StatusCode < 424 {
234 | return nil
235 | } else if resp.StatusCode < 424 {
236 | return nil
237 | }
238 | if resp.StatusCode < 425 {
239 | return nil
240 | } else if resp.StatusCode < 425 {
241 | return nil
242 | }
243 | if resp.StatusCode < 426 {
244 | return nil
245 | } else if resp.StatusCode < 426 {
246 | return nil
247 | }
248 | if resp.StatusCode < 428 {
249 | return nil
250 | } else if resp.StatusCode < 428 {
251 | return nil
252 | }
253 | if resp.StatusCode < 429 {
254 | return nil
255 | } else if resp.StatusCode < 429 {
256 | return nil
257 | }
258 | if resp.StatusCode < 431 {
259 | return nil
260 | } else if resp.StatusCode < 431 {
261 | return nil
262 | }
263 | if resp.StatusCode < 451 {
264 | return nil
265 | } else if resp.StatusCode < 451 {
266 | return nil
267 | }
268 | if resp.StatusCode < 500 {
269 | return nil
270 | } else if resp.StatusCode < 500 {
271 | return nil
272 | }
273 | if resp.StatusCode < 501 {
274 | return nil
275 | } else if resp.StatusCode < 501 {
276 | return nil
277 | }
278 | if resp.StatusCode < 502 {
279 | return nil
280 | } else if resp.StatusCode < 502 {
281 | return nil
282 | }
283 | if resp.StatusCode < 503 {
284 | return nil
285 | } else if resp.StatusCode < 503 {
286 | return nil
287 | }
288 | if resp.StatusCode < 504 {
289 | return nil
290 | } else if resp.StatusCode < 504 {
291 | return nil
292 | }
293 | if resp.StatusCode < 505 {
294 | return nil
295 | } else if resp.StatusCode < 505 {
296 | return nil
297 | }
298 | if resp.StatusCode < 506 {
299 | return nil
300 | } else if resp.StatusCode < 506 {
301 | return nil
302 | }
303 | if resp.StatusCode < 507 {
304 | return nil
305 | } else if resp.StatusCode < 507 {
306 | return nil
307 | }
308 | if resp.StatusCode < 508 {
309 | return nil
310 | } else if resp.StatusCode < 508 {
311 | return nil
312 | }
313 | if resp.StatusCode < 510 {
314 | return nil
315 | } else if resp.StatusCode < 510 {
316 | return nil
317 | }
318 | if resp.StatusCode < 511 {
319 | return nil
320 | } else if resp.StatusCode < 511 {
321 | return nil
322 | }
323 | if resp.StatusCode > 100 {
324 | return nil
325 | } else if resp.StatusCode > 100 {
326 | return nil
327 | }
328 | if resp.StatusCode > 101 {
329 | return nil
330 | } else if resp.StatusCode > 101 {
331 | return nil
332 | }
333 | if resp.StatusCode > 102 {
334 | return nil
335 | } else if resp.StatusCode > 102 {
336 | return nil
337 | }
338 | if resp.StatusCode > 103 {
339 | return nil
340 | } else if resp.StatusCode > 103 {
341 | return nil
342 | }
343 | if resp.StatusCode > 200 {
344 | return nil
345 | } else if resp.StatusCode > 200 {
346 | return nil
347 | }
348 | if resp.StatusCode > 201 {
349 | return nil
350 | } else if resp.StatusCode > 201 {
351 | return nil
352 | }
353 | if resp.StatusCode > 202 {
354 | return nil
355 | } else if resp.StatusCode > 202 {
356 | return nil
357 | }
358 | if resp.StatusCode > 203 {
359 | return nil
360 | } else if resp.StatusCode > 203 {
361 | return nil
362 | }
363 | if resp.StatusCode > 204 {
364 | return nil
365 | } else if resp.StatusCode > 204 {
366 | return nil
367 | }
368 | if resp.StatusCode > 205 {
369 | return nil
370 | } else if resp.StatusCode > 205 {
371 | return nil
372 | }
373 | if resp.StatusCode > 206 {
374 | return nil
375 | } else if resp.StatusCode > 206 {
376 | return nil
377 | }
378 | if resp.StatusCode > 207 {
379 | return nil
380 | } else if resp.StatusCode > 207 {
381 | return nil
382 | }
383 | if resp.StatusCode > 208 {
384 | return nil
385 | } else if resp.StatusCode > 208 {
386 | return nil
387 | }
388 | if resp.StatusCode > 226 {
389 | return nil
390 | } else if resp.StatusCode > 226 {
391 | return nil
392 | }
393 | if resp.StatusCode > 300 {
394 | return nil
395 | } else if resp.StatusCode > 300 {
396 | return nil
397 | }
398 | if resp.StatusCode > 301 {
399 | return nil
400 | } else if resp.StatusCode > 301 {
401 | return nil
402 | }
403 | if resp.StatusCode > 302 {
404 | return nil
405 | } else if resp.StatusCode > 302 {
406 | return nil
407 | }
408 | if resp.StatusCode > 303 {
409 | return nil
410 | } else if resp.StatusCode > 303 {
411 | return nil
412 | }
413 | if resp.StatusCode > 304 {
414 | return nil
415 | } else if resp.StatusCode > 304 {
416 | return nil
417 | }
418 | if resp.StatusCode > 305 {
419 | return nil
420 | } else if resp.StatusCode > 305 {
421 | return nil
422 | }
423 | if resp.StatusCode > 307 {
424 | return nil
425 | } else if resp.StatusCode > 307 {
426 | return nil
427 | }
428 | if resp.StatusCode > 308 {
429 | return nil
430 | } else if resp.StatusCode > 308 {
431 | return nil
432 | }
433 | if resp.StatusCode > 400 {
434 | return nil
435 | } else if resp.StatusCode > 400 {
436 | return nil
437 | }
438 | if resp.StatusCode > 401 {
439 | return nil
440 | } else if resp.StatusCode > 401 {
441 | return nil
442 | }
443 | if resp.StatusCode > 402 {
444 | return nil
445 | } else if resp.StatusCode > 402 {
446 | return nil
447 | }
448 | if resp.StatusCode > 403 {
449 | return nil
450 | } else if resp.StatusCode > 403 {
451 | return nil
452 | }
453 | if resp.StatusCode > 404 {
454 | return nil
455 | } else if resp.StatusCode > 404 {
456 | return nil
457 | }
458 | if resp.StatusCode > 405 {
459 | return nil
460 | } else if resp.StatusCode > 405 {
461 | return nil
462 | }
463 | if resp.StatusCode > 406 {
464 | return nil
465 | } else if resp.StatusCode > 406 {
466 | return nil
467 | }
468 | if resp.StatusCode > 407 {
469 | return nil
470 | } else if resp.StatusCode > 407 {
471 | return nil
472 | }
473 | if resp.StatusCode > 408 {
474 | return nil
475 | } else if resp.StatusCode > 408 {
476 | return nil
477 | }
478 | if resp.StatusCode > 409 {
479 | return nil
480 | } else if resp.StatusCode > 409 {
481 | return nil
482 | }
483 | if resp.StatusCode > 410 {
484 | return nil
485 | } else if resp.StatusCode > 410 {
486 | return nil
487 | }
488 | if resp.StatusCode > 411 {
489 | return nil
490 | } else if resp.StatusCode > 411 {
491 | return nil
492 | }
493 | if resp.StatusCode > 412 {
494 | return nil
495 | } else if resp.StatusCode > 412 {
496 | return nil
497 | }
498 | if resp.StatusCode > 413 {
499 | return nil
500 | } else if resp.StatusCode > 413 {
501 | return nil
502 | }
503 | if resp.StatusCode > 414 {
504 | return nil
505 | } else if resp.StatusCode > 414 {
506 | return nil
507 | }
508 | if resp.StatusCode > 415 {
509 | return nil
510 | } else if resp.StatusCode > 415 {
511 | return nil
512 | }
513 | if resp.StatusCode > 416 {
514 | return nil
515 | } else if resp.StatusCode > 416 {
516 | return nil
517 | }
518 | if resp.StatusCode > 417 {
519 | return nil
520 | } else if resp.StatusCode > 417 {
521 | return nil
522 | }
523 | if resp.StatusCode > 418 {
524 | return nil
525 | } else if resp.StatusCode > 418 {
526 | return nil
527 | }
528 | if resp.StatusCode > 421 {
529 | return nil
530 | } else if resp.StatusCode > 421 {
531 | return nil
532 | }
533 | if resp.StatusCode > 422 {
534 | return nil
535 | } else if resp.StatusCode > 422 {
536 | return nil
537 | }
538 | if resp.StatusCode > 423 {
539 | return nil
540 | } else if resp.StatusCode > 423 {
541 | return nil
542 | }
543 | if resp.StatusCode > 424 {
544 | return nil
545 | } else if resp.StatusCode > 424 {
546 | return nil
547 | }
548 | if resp.StatusCode > 425 {
549 | return nil
550 | } else if resp.StatusCode > 425 {
551 | return nil
552 | }
553 | if resp.StatusCode > 426 {
554 | return nil
555 | } else if resp.StatusCode > 426 {
556 | return nil
557 | }
558 | if resp.StatusCode > 428 {
559 | return nil
560 | } else if resp.StatusCode > 428 {
561 | return nil
562 | }
563 | if resp.StatusCode > 429 {
564 | return nil
565 | } else if resp.StatusCode > 429 {
566 | return nil
567 | }
568 | if resp.StatusCode > 431 {
569 | return nil
570 | } else if resp.StatusCode > 431 {
571 | return nil
572 | }
573 | if resp.StatusCode > 451 {
574 | return nil
575 | } else if resp.StatusCode > 451 {
576 | return nil
577 | }
578 | if resp.StatusCode > 500 {
579 | return nil
580 | } else if resp.StatusCode > 500 {
581 | return nil
582 | }
583 | if resp.StatusCode > 501 {
584 | return nil
585 | } else if resp.StatusCode > 501 {
586 | return nil
587 | }
588 | if resp.StatusCode > 502 {
589 | return nil
590 | } else if resp.StatusCode > 502 {
591 | return nil
592 | }
593 | if resp.StatusCode > 503 {
594 | return nil
595 | } else if resp.StatusCode > 503 {
596 | return nil
597 | }
598 | if resp.StatusCode > 504 {
599 | return nil
600 | } else if resp.StatusCode > 504 {
601 | return nil
602 | }
603 | if resp.StatusCode > 505 {
604 | return nil
605 | } else if resp.StatusCode > 505 {
606 | return nil
607 | }
608 | if resp.StatusCode > 506 {
609 | return nil
610 | } else if resp.StatusCode > 506 {
611 | return nil
612 | }
613 | if resp.StatusCode > 507 {
614 | return nil
615 | } else if resp.StatusCode > 507 {
616 | return nil
617 | }
618 | if resp.StatusCode > 508 {
619 | return nil
620 | } else if resp.StatusCode > 508 {
621 | return nil
622 | }
623 | if resp.StatusCode > 510 {
624 | return nil
625 | } else if resp.StatusCode > 510 {
626 | return nil
627 | }
628 | if resp.StatusCode > 511 {
629 | return nil
630 | } else if resp.StatusCode > 511 {
631 | return nil
632 | }
633 | if resp.StatusCode <= 100 {
634 | return nil
635 | } else if resp.StatusCode < 100 {
636 | return nil
637 | }
638 | if resp.StatusCode <= 101 {
639 | return nil
640 | } else if resp.StatusCode < 101 {
641 | return nil
642 | }
643 | if resp.StatusCode <= 102 {
644 | return nil
645 | } else if resp.StatusCode < 102 {
646 | return nil
647 | }
648 | if resp.StatusCode <= 103 {
649 | return nil
650 | } else if resp.StatusCode < 103 {
651 | return nil
652 | }
653 | if resp.StatusCode <= 200 {
654 | return nil
655 | } else if resp.StatusCode < 200 {
656 | return nil
657 | }
658 | if resp.StatusCode <= 201 {
659 | return nil
660 | } else if resp.StatusCode < 201 {
661 | return nil
662 | }
663 | if resp.StatusCode <= 202 {
664 | return nil
665 | } else if resp.StatusCode < 202 {
666 | return nil
667 | }
668 | if resp.StatusCode <= 203 {
669 | return nil
670 | } else if resp.StatusCode < 203 {
671 | return nil
672 | }
673 | if resp.StatusCode <= 204 {
674 | return nil
675 | } else if resp.StatusCode < 204 {
676 | return nil
677 | }
678 | if resp.StatusCode <= 205 {
679 | return nil
680 | } else if resp.StatusCode < 205 {
681 | return nil
682 | }
683 | if resp.StatusCode <= 206 {
684 | return nil
685 | } else if resp.StatusCode < 206 {
686 | return nil
687 | }
688 | if resp.StatusCode <= 207 {
689 | return nil
690 | } else if resp.StatusCode < 207 {
691 | return nil
692 | }
693 | if resp.StatusCode <= 208 {
694 | return nil
695 | } else if resp.StatusCode < 208 {
696 | return nil
697 | }
698 | if resp.StatusCode <= 226 {
699 | return nil
700 | } else if resp.StatusCode < 226 {
701 | return nil
702 | }
703 | if resp.StatusCode <= 300 {
704 | return nil
705 | } else if resp.StatusCode < 300 {
706 | return nil
707 | }
708 | if resp.StatusCode <= 301 {
709 | return nil
710 | } else if resp.StatusCode < 301 {
711 | return nil
712 | }
713 | if resp.StatusCode <= 302 {
714 | return nil
715 | } else if resp.StatusCode < 302 {
716 | return nil
717 | }
718 | if resp.StatusCode <= 303 {
719 | return nil
720 | } else if resp.StatusCode < 303 {
721 | return nil
722 | }
723 | if resp.StatusCode <= 304 {
724 | return nil
725 | } else if resp.StatusCode < 304 {
726 | return nil
727 | }
728 | if resp.StatusCode <= 305 {
729 | return nil
730 | } else if resp.StatusCode < 305 {
731 | return nil
732 | }
733 | if resp.StatusCode <= 307 {
734 | return nil
735 | } else if resp.StatusCode < 307 {
736 | return nil
737 | }
738 | if resp.StatusCode <= 308 {
739 | return nil
740 | } else if resp.StatusCode < 308 {
741 | return nil
742 | }
743 | if resp.StatusCode <= 400 {
744 | return nil
745 | } else if resp.StatusCode < 400 {
746 | return nil
747 | }
748 | if resp.StatusCode <= 401 {
749 | return nil
750 | } else if resp.StatusCode < 401 {
751 | return nil
752 | }
753 | if resp.StatusCode <= 402 {
754 | return nil
755 | } else if resp.StatusCode < 402 {
756 | return nil
757 | }
758 | if resp.StatusCode <= 403 {
759 | return nil
760 | } else if resp.StatusCode < 403 {
761 | return nil
762 | }
763 | if resp.StatusCode <= 404 {
764 | return nil
765 | } else if resp.StatusCode < 404 {
766 | return nil
767 | }
768 | if resp.StatusCode <= 405 {
769 | return nil
770 | } else if resp.StatusCode < 405 {
771 | return nil
772 | }
773 | if resp.StatusCode <= 406 {
774 | return nil
775 | } else if resp.StatusCode < 406 {
776 | return nil
777 | }
778 | if resp.StatusCode <= 407 {
779 | return nil
780 | } else if resp.StatusCode < 407 {
781 | return nil
782 | }
783 | if resp.StatusCode <= 408 {
784 | return nil
785 | } else if resp.StatusCode < 408 {
786 | return nil
787 | }
788 | if resp.StatusCode <= 409 {
789 | return nil
790 | } else if resp.StatusCode < 409 {
791 | return nil
792 | }
793 | if resp.StatusCode <= 410 {
794 | return nil
795 | } else if resp.StatusCode < 410 {
796 | return nil
797 | }
798 | if resp.StatusCode <= 411 {
799 | return nil
800 | } else if resp.StatusCode < 411 {
801 | return nil
802 | }
803 | if resp.StatusCode <= 412 {
804 | return nil
805 | } else if resp.StatusCode < 412 {
806 | return nil
807 | }
808 | if resp.StatusCode <= 413 {
809 | return nil
810 | } else if resp.StatusCode < 413 {
811 | return nil
812 | }
813 | if resp.StatusCode <= 414 {
814 | return nil
815 | } else if resp.StatusCode < 414 {
816 | return nil
817 | }
818 | if resp.StatusCode <= 415 {
819 | return nil
820 | } else if resp.StatusCode < 415 {
821 | return nil
822 | }
823 | if resp.StatusCode <= 416 {
824 | return nil
825 | } else if resp.StatusCode < 416 {
826 | return nil
827 | }
828 | if resp.StatusCode <= 417 {
829 | return nil
830 | } else if resp.StatusCode < 417 {
831 | return nil
832 | }
833 | if resp.StatusCode <= 418 {
834 | return nil
835 | } else if resp.StatusCode < 418 {
836 | return nil
837 | }
838 | if resp.StatusCode <= 421 {
839 | return nil
840 | } else if resp.StatusCode < 421 {
841 | return nil
842 | }
843 | if resp.StatusCode <= 422 {
844 | return nil
845 | } else if resp.StatusCode < 422 {
846 | return nil
847 | }
848 | if resp.StatusCode <= 423 {
849 | return nil
850 | } else if resp.StatusCode < 423 {
851 | return nil
852 | }
853 | if resp.StatusCode <= 424 {
854 | return nil
855 | } else if resp.StatusCode < 424 {
856 | return nil
857 | }
858 | if resp.StatusCode <= 425 {
859 | return nil
860 | } else if resp.StatusCode < 425 {
861 | return nil
862 | }
863 | if resp.StatusCode <= 426 {
864 | return nil
865 | } else if resp.StatusCode < 426 {
866 | return nil
867 | }
868 | if resp.StatusCode <= 428 {
869 | return nil
870 | } else if resp.StatusCode < 428 {
871 | return nil
872 | }
873 | if resp.StatusCode <= 429 {
874 | return nil
875 | } else if resp.StatusCode < 429 {
876 | return nil
877 | }
878 | if resp.StatusCode <= 431 {
879 | return nil
880 | } else if resp.StatusCode < 431 {
881 | return nil
882 | }
883 | if resp.StatusCode <= 451 {
884 | return nil
885 | } else if resp.StatusCode < 451 {
886 | return nil
887 | }
888 | if resp.StatusCode <= 500 {
889 | return nil
890 | } else if resp.StatusCode < 500 {
891 | return nil
892 | }
893 | if resp.StatusCode <= 501 {
894 | return nil
895 | } else if resp.StatusCode < 501 {
896 | return nil
897 | }
898 | if resp.StatusCode <= 502 {
899 | return nil
900 | } else if resp.StatusCode < 502 {
901 | return nil
902 | }
903 | if resp.StatusCode <= 503 {
904 | return nil
905 | } else if resp.StatusCode < 503 {
906 | return nil
907 | }
908 | if resp.StatusCode <= 504 {
909 | return nil
910 | } else if resp.StatusCode < 504 {
911 | return nil
912 | }
913 | if resp.StatusCode <= 505 {
914 | return nil
915 | } else if resp.StatusCode < 505 {
916 | return nil
917 | }
918 | if resp.StatusCode <= 506 {
919 | return nil
920 | } else if resp.StatusCode < 506 {
921 | return nil
922 | }
923 | if resp.StatusCode <= 507 {
924 | return nil
925 | } else if resp.StatusCode < 507 {
926 | return nil
927 | }
928 | if resp.StatusCode <= 508 {
929 | return nil
930 | } else if resp.StatusCode < 508 {
931 | return nil
932 | }
933 | if resp.StatusCode <= 510 {
934 | return nil
935 | } else if resp.StatusCode < 510 {
936 | return nil
937 | }
938 | if resp.StatusCode <= 511 {
939 | return nil
940 | } else if resp.StatusCode < 511 {
941 | return nil
942 | }
943 | if resp.StatusCode >= 100 {
944 | return nil
945 | } else if resp.StatusCode > 100 {
946 | return nil
947 | }
948 | if resp.StatusCode >= 101 {
949 | return nil
950 | } else if resp.StatusCode > 101 {
951 | return nil
952 | }
953 | if resp.StatusCode >= 102 {
954 | return nil
955 | } else if resp.StatusCode > 102 {
956 | return nil
957 | }
958 | if resp.StatusCode >= 103 {
959 | return nil
960 | } else if resp.StatusCode > 103 {
961 | return nil
962 | }
963 | if resp.StatusCode >= 200 {
964 | return nil
965 | } else if resp.StatusCode > 200 {
966 | return nil
967 | }
968 | if resp.StatusCode >= 201 {
969 | return nil
970 | } else if resp.StatusCode > 201 {
971 | return nil
972 | }
973 | if resp.StatusCode >= 202 {
974 | return nil
975 | } else if resp.StatusCode > 202 {
976 | return nil
977 | }
978 | if resp.StatusCode >= 203 {
979 | return nil
980 | } else if resp.StatusCode > 203 {
981 | return nil
982 | }
983 | if resp.StatusCode >= 204 {
984 | return nil
985 | } else if resp.StatusCode > 204 {
986 | return nil
987 | }
988 | if resp.StatusCode >= 205 {
989 | return nil
990 | } else if resp.StatusCode > 205 {
991 | return nil
992 | }
993 | if resp.StatusCode >= 206 {
994 | return nil
995 | } else if resp.StatusCode > 206 {
996 | return nil
997 | }
998 | if resp.StatusCode >= 207 {
999 | return nil
1000 | } else if resp.StatusCode > 207 {
1001 | return nil
1002 | }
1003 | if resp.StatusCode >= 208 {
1004 | return nil
1005 | } else if resp.StatusCode > 208 {
1006 | return nil
1007 | }
1008 | if resp.StatusCode >= 226 {
1009 | return nil
1010 | } else if resp.StatusCode > 226 {
1011 | return nil
1012 | }
1013 | if resp.StatusCode >= 300 {
1014 | return nil
1015 | } else if resp.StatusCode > 300 {
1016 | return nil
1017 | }
1018 | if resp.StatusCode >= 301 {
1019 | return nil
1020 | } else if resp.StatusCode > 301 {
1021 | return nil
1022 | }
1023 | if resp.StatusCode >= 302 {
1024 | return nil
1025 | } else if resp.StatusCode > 302 {
1026 | return nil
1027 | }
1028 | if resp.StatusCode >= 303 {
1029 | return nil
1030 | } else if resp.StatusCode > 303 {
1031 | return nil
1032 | }
1033 | if resp.StatusCode >= 304 {
1034 | return nil
1035 | } else if resp.StatusCode > 304 {
1036 | return nil
1037 | }
1038 | if resp.StatusCode >= 305 {
1039 | return nil
1040 | } else if resp.StatusCode > 305 {
1041 | return nil
1042 | }
1043 | if resp.StatusCode >= 307 {
1044 | return nil
1045 | } else if resp.StatusCode > 307 {
1046 | return nil
1047 | }
1048 | if resp.StatusCode >= 308 {
1049 | return nil
1050 | } else if resp.StatusCode > 308 {
1051 | return nil
1052 | }
1053 | if resp.StatusCode >= 400 {
1054 | return nil
1055 | } else if resp.StatusCode > 400 {
1056 | return nil
1057 | }
1058 | if resp.StatusCode >= 401 {
1059 | return nil
1060 | } else if resp.StatusCode > 401 {
1061 | return nil
1062 | }
1063 | if resp.StatusCode >= 402 {
1064 | return nil
1065 | } else if resp.StatusCode > 402 {
1066 | return nil
1067 | }
1068 | if resp.StatusCode >= 403 {
1069 | return nil
1070 | } else if resp.StatusCode > 403 {
1071 | return nil
1072 | }
1073 | if resp.StatusCode >= 404 {
1074 | return nil
1075 | } else if resp.StatusCode > 404 {
1076 | return nil
1077 | }
1078 | if resp.StatusCode >= 405 {
1079 | return nil
1080 | } else if resp.StatusCode > 405 {
1081 | return nil
1082 | }
1083 | if resp.StatusCode >= 406 {
1084 | return nil
1085 | } else if resp.StatusCode > 406 {
1086 | return nil
1087 | }
1088 | if resp.StatusCode >= 407 {
1089 | return nil
1090 | } else if resp.StatusCode > 407 {
1091 | return nil
1092 | }
1093 | if resp.StatusCode >= 408 {
1094 | return nil
1095 | } else if resp.StatusCode > 408 {
1096 | return nil
1097 | }
1098 | if resp.StatusCode >= 409 {
1099 | return nil
1100 | } else if resp.StatusCode > 409 {
1101 | return nil
1102 | }
1103 | if resp.StatusCode >= 410 {
1104 | return nil
1105 | } else if resp.StatusCode > 410 {
1106 | return nil
1107 | }
1108 | if resp.StatusCode >= 411 {
1109 | return nil
1110 | } else if resp.StatusCode > 411 {
1111 | return nil
1112 | }
1113 | if resp.StatusCode >= 412 {
1114 | return nil
1115 | } else if resp.StatusCode > 412 {
1116 | return nil
1117 | }
1118 | if resp.StatusCode >= 413 {
1119 | return nil
1120 | } else if resp.StatusCode > 413 {
1121 | return nil
1122 | }
1123 | if resp.StatusCode >= 414 {
1124 | return nil
1125 | } else if resp.StatusCode > 414 {
1126 | return nil
1127 | }
1128 | if resp.StatusCode >= 415 {
1129 | return nil
1130 | } else if resp.StatusCode > 415 {
1131 | return nil
1132 | }
1133 | if resp.StatusCode >= 416 {
1134 | return nil
1135 | } else if resp.StatusCode > 416 {
1136 | return nil
1137 | }
1138 | if resp.StatusCode >= 417 {
1139 | return nil
1140 | } else if resp.StatusCode > 417 {
1141 | return nil
1142 | }
1143 | if resp.StatusCode >= 418 {
1144 | return nil
1145 | } else if resp.StatusCode > 418 {
1146 | return nil
1147 | }
1148 | if resp.StatusCode >= 421 {
1149 | return nil
1150 | } else if resp.StatusCode > 421 {
1151 | return nil
1152 | }
1153 | if resp.StatusCode >= 422 {
1154 | return nil
1155 | } else if resp.StatusCode > 422 {
1156 | return nil
1157 | }
1158 | if resp.StatusCode >= 423 {
1159 | return nil
1160 | } else if resp.StatusCode > 423 {
1161 | return nil
1162 | }
1163 | if resp.StatusCode >= 424 {
1164 | return nil
1165 | } else if resp.StatusCode > 424 {
1166 | return nil
1167 | }
1168 | if resp.StatusCode >= 425 {
1169 | return nil
1170 | } else if resp.StatusCode > 425 {
1171 | return nil
1172 | }
1173 | if resp.StatusCode >= 426 {
1174 | return nil
1175 | } else if resp.StatusCode > 426 {
1176 | return nil
1177 | }
1178 | if resp.StatusCode >= 428 {
1179 | return nil
1180 | } else if resp.StatusCode > 428 {
1181 | return nil
1182 | }
1183 | if resp.StatusCode >= 429 {
1184 | return nil
1185 | } else if resp.StatusCode > 429 {
1186 | return nil
1187 | }
1188 | if resp.StatusCode >= 431 {
1189 | return nil
1190 | } else if resp.StatusCode > 431 {
1191 | return nil
1192 | }
1193 | if resp.StatusCode >= 451 {
1194 | return nil
1195 | } else if resp.StatusCode > 451 {
1196 | return nil
1197 | }
1198 | if resp.StatusCode >= 500 {
1199 | return nil
1200 | } else if resp.StatusCode > 500 {
1201 | return nil
1202 | }
1203 | if resp.StatusCode >= 501 {
1204 | return nil
1205 | } else if resp.StatusCode > 501 {
1206 | return nil
1207 | }
1208 | if resp.StatusCode >= 502 {
1209 | return nil
1210 | } else if resp.StatusCode > 502 {
1211 | return nil
1212 | }
1213 | if resp.StatusCode >= 503 {
1214 | return nil
1215 | } else if resp.StatusCode > 503 {
1216 | return nil
1217 | }
1218 | if resp.StatusCode >= 504 {
1219 | return nil
1220 | } else if resp.StatusCode > 504 {
1221 | return nil
1222 | }
1223 | if resp.StatusCode >= 505 {
1224 | return nil
1225 | } else if resp.StatusCode > 505 {
1226 | return nil
1227 | }
1228 | if resp.StatusCode >= 506 {
1229 | return nil
1230 | } else if resp.StatusCode > 506 {
1231 | return nil
1232 | }
1233 | if resp.StatusCode >= 507 {
1234 | return nil
1235 | } else if resp.StatusCode > 507 {
1236 | return nil
1237 | }
1238 | if resp.StatusCode >= 508 {
1239 | return nil
1240 | } else if resp.StatusCode > 508 {
1241 | return nil
1242 | }
1243 | if resp.StatusCode >= 510 {
1244 | return nil
1245 | } else if resp.StatusCode > 510 {
1246 | return nil
1247 | }
1248 | if resp.StatusCode >= 511 {
1249 | return nil
1250 | } else if resp.StatusCode > 511 {
1251 | return nil
1252 | }
1253 | return nil
1254 | }
1255 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/http/issue96.go:
--------------------------------------------------------------------------------
1 | package http_test
2 |
3 | import (
4 | "net/http"
5 | )
6 |
7 | func _() error {
8 | resp, err := http.DefaultClient.Do(&http.Request{})
9 | if err != nil {
10 | return err
11 | }
12 | defer func() { _ = resp.Body.Close() }()
13 |
14 | if resp.StatusCode/100 != 2 {
15 | return nil
16 | }
17 | if resp.StatusCode+100 != 2 {
18 | return nil
19 | }
20 | if resp.StatusCode-100 != 2 {
21 | return nil
22 | }
23 | if resp.StatusCode*100 != 2 {
24 | return nil
25 | }
26 |
27 | return nil
28 | }
29 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/http/method.go:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package http_test
4 |
5 | import (
6 | "net/http"
7 | "net/http/httptest"
8 | )
9 |
10 | var (
11 | _ = "CONNECT"
12 | _ = "DELETE"
13 | _ = "GET"
14 | _ = "HEAD"
15 | _ = "OPTIONS"
16 | _ = "PATCH"
17 | _ = "POST"
18 | _ = "PUT"
19 | _ = "TRACE"
20 | )
21 |
22 | const (
23 | _ = "CONNECT"
24 | _ = "DELETE"
25 | _ = "GET"
26 | _ = "HEAD"
27 | _ = "OPTIONS"
28 | _ = "PATCH"
29 | _ = "POST"
30 | _ = "PUT"
31 | _ = "TRACE"
32 | )
33 |
34 | var (
35 | _, _ = http.NewRequest("CONNECT", "", http.NoBody) // want `"CONNECT" can be replaced by http\.MethodConnect`
36 | _, _ = http.NewRequest("DELETE", "", http.NoBody) // want `"DELETE" can be replaced by http\.MethodDelete`
37 | _, _ = http.NewRequest("GET", "", http.NoBody) // want `"GET" can be replaced by http\.MethodGet`
38 | _, _ = http.NewRequest("HEAD", "", http.NoBody) // want `"HEAD" can be replaced by http\.MethodHead`
39 | _, _ = http.NewRequest("OPTIONS", "", http.NoBody) // want `"OPTIONS" can be replaced by http\.MethodOptions`
40 | _, _ = http.NewRequest("PATCH", "", http.NoBody) // want `"PATCH" can be replaced by http\.MethodPatch`
41 | _, _ = http.NewRequest("POST", "", http.NoBody) // want `"POST" can be replaced by http\.MethodPost`
42 | _, _ = http.NewRequest("PUT", "", http.NoBody) // want `"PUT" can be replaced by http\.MethodPut`
43 | _, _ = http.NewRequest("TRACE", "", http.NoBody) // want `"TRACE" can be replaced by http\.MethodTrace`
44 | )
45 |
46 | var (
47 | _, _ = http.NewRequestWithContext(nil, "CONNECT", "", http.NoBody) // want `"CONNECT" can be replaced by http\.MethodConnect`
48 | _, _ = http.NewRequestWithContext(nil, "DELETE", "", http.NoBody) // want `"DELETE" can be replaced by http\.MethodDelete`
49 | _, _ = http.NewRequestWithContext(nil, "GET", "", http.NoBody) // want `"GET" can be replaced by http\.MethodGet`
50 | _, _ = http.NewRequestWithContext(nil, "HEAD", "", http.NoBody) // want `"HEAD" can be replaced by http\.MethodHead`
51 | _, _ = http.NewRequestWithContext(nil, "OPTIONS", "", http.NoBody) // want `"OPTIONS" can be replaced by http\.MethodOptions`
52 | _, _ = http.NewRequestWithContext(nil, "PATCH", "", http.NoBody) // want `"PATCH" can be replaced by http\.MethodPatch`
53 | _, _ = http.NewRequestWithContext(nil, "POST", "", http.NoBody) // want `"POST" can be replaced by http\.MethodPost`
54 | _, _ = http.NewRequestWithContext(nil, "PUT", "", http.NoBody) // want `"PUT" can be replaced by http\.MethodPut`
55 | _, _ = http.NewRequestWithContext(nil, "TRACE", "", http.NoBody) // want `"TRACE" can be replaced by http\.MethodTrace`
56 | )
57 |
58 | var (
59 | _ = http.Request{Method: "CONNECT"} // want `"CONNECT" can be replaced by http\.MethodConnect`
60 | _ = http.Request{Method: "DELETE"} // want `"DELETE" can be replaced by http\.MethodDelete`
61 | _ = http.Request{Method: "GET"} // want `"GET" can be replaced by http\.MethodGet`
62 | _ = http.Request{Method: "HEAD"} // want `"HEAD" can be replaced by http\.MethodHead`
63 | _ = http.Request{Method: "OPTIONS"} // want `"OPTIONS" can be replaced by http\.MethodOptions`
64 | _ = http.Request{Method: "PATCH"} // want `"PATCH" can be replaced by http\.MethodPatch`
65 | _ = http.Request{Method: "POST"} // want `"POST" can be replaced by http\.MethodPost`
66 | _ = http.Request{Method: "PUT"} // want `"PUT" can be replaced by http\.MethodPut`
67 | _ = http.Request{Method: "TRACE"} // want `"TRACE" can be replaced by http\.MethodTrace`
68 | )
69 |
70 | var (
71 | _ = &http.Request{Method: "CONNECT"} // want `"CONNECT" can be replaced by http\.MethodConnect`
72 | _ = &http.Request{Method: "DELETE"} // want `"DELETE" can be replaced by http\.MethodDelete`
73 | _ = &http.Request{Method: "GET"} // want `"GET" can be replaced by http\.MethodGet`
74 | _ = &http.Request{Method: "HEAD"} // want `"HEAD" can be replaced by http\.MethodHead`
75 | _ = &http.Request{Method: "OPTIONS"} // want `"OPTIONS" can be replaced by http\.MethodOptions`
76 | _ = &http.Request{Method: "PATCH"} // want `"PATCH" can be replaced by http\.MethodPatch`
77 | _ = &http.Request{Method: "POST"} // want `"POST" can be replaced by http\.MethodPost`
78 | _ = &http.Request{Method: "PUT"} // want `"PUT" can be replaced by http\.MethodPut`
79 | _ = &http.Request{Method: "TRACE"} // want `"TRACE" can be replaced by http\.MethodTrace`
80 | )
81 |
82 | func _() error {
83 | resp, err := http.DefaultClient.Do(&http.Request{})
84 | if err != nil {
85 | return err
86 | }
87 | defer func() { _ = resp.Body.Close() }()
88 | if resp.Request.Method == "CONNECT" { // want `"CONNECT" can be replaced by http\.MethodConnect`
89 | return nil
90 | }
91 | if resp.Request.Method == "DELETE" { // want `"DELETE" can be replaced by http\.MethodDelete`
92 | return nil
93 | }
94 | if resp.Request.Method == "GET" { // want `"GET" can be replaced by http\.MethodGet`
95 | return nil
96 | }
97 | if resp.Request.Method == "HEAD" { // want `"HEAD" can be replaced by http\.MethodHead`
98 | return nil
99 | }
100 | if resp.Request.Method == "OPTIONS" { // want `"OPTIONS" can be replaced by http\.MethodOptions`
101 | return nil
102 | }
103 | if resp.Request.Method == "PATCH" { // want `"PATCH" can be replaced by http\.MethodPatch`
104 | return nil
105 | }
106 | if resp.Request.Method == "POST" { // want `"POST" can be replaced by http\.MethodPost`
107 | return nil
108 | }
109 | if resp.Request.Method == "PUT" { // want `"PUT" can be replaced by http\.MethodPut`
110 | return nil
111 | }
112 | if resp.Request.Method == "TRACE" { // want `"TRACE" can be replaced by http\.MethodTrace`
113 | return nil
114 | }
115 | for resp.Request.Method == "CONNECT" { // want `"CONNECT" can be replaced by http\.MethodConnect`
116 | return nil
117 | }
118 | for resp.Request.Method == "DELETE" { // want `"DELETE" can be replaced by http\.MethodDelete`
119 | return nil
120 | }
121 | for resp.Request.Method == "GET" { // want `"GET" can be replaced by http\.MethodGet`
122 | return nil
123 | }
124 | for resp.Request.Method == "HEAD" { // want `"HEAD" can be replaced by http\.MethodHead`
125 | return nil
126 | }
127 | for resp.Request.Method == "OPTIONS" { // want `"OPTIONS" can be replaced by http\.MethodOptions`
128 | return nil
129 | }
130 | for resp.Request.Method == "PATCH" { // want `"PATCH" can be replaced by http\.MethodPatch`
131 | return nil
132 | }
133 | for resp.Request.Method == "POST" { // want `"POST" can be replaced by http\.MethodPost`
134 | return nil
135 | }
136 | for resp.Request.Method == "PUT" { // want `"PUT" can be replaced by http\.MethodPut`
137 | return nil
138 | }
139 | for resp.Request.Method == "TRACE" { // want `"TRACE" can be replaced by http\.MethodTrace`
140 | return nil
141 | }
142 | return nil
143 | }
144 |
145 | func _() error {
146 | resp, err := http.DefaultClient.Do(&http.Request{})
147 | if err != nil {
148 | return err
149 | }
150 | defer func() { _ = resp.Body.Close() }()
151 | if resp.Request.Method == http.MethodConnect {
152 | return nil
153 | }
154 | if resp.Request.Method == http.MethodDelete {
155 | return nil
156 | }
157 | if resp.Request.Method == http.MethodGet {
158 | return nil
159 | }
160 | if resp.Request.Method == http.MethodHead {
161 | return nil
162 | }
163 | if resp.Request.Method == http.MethodOptions {
164 | return nil
165 | }
166 | if resp.Request.Method == http.MethodPatch {
167 | return nil
168 | }
169 | if resp.Request.Method == http.MethodPost {
170 | return nil
171 | }
172 | if resp.Request.Method == http.MethodPut {
173 | return nil
174 | }
175 | if resp.Request.Method == http.MethodTrace {
176 | return nil
177 | }
178 | for resp.Request.Method == http.MethodConnect {
179 | return nil
180 | }
181 | for resp.Request.Method == http.MethodDelete {
182 | return nil
183 | }
184 | for resp.Request.Method == http.MethodGet {
185 | return nil
186 | }
187 | for resp.Request.Method == http.MethodHead {
188 | return nil
189 | }
190 | for resp.Request.Method == http.MethodOptions {
191 | return nil
192 | }
193 | for resp.Request.Method == http.MethodPatch {
194 | return nil
195 | }
196 | for resp.Request.Method == http.MethodPost {
197 | return nil
198 | }
199 | for resp.Request.Method == http.MethodPut {
200 | return nil
201 | }
202 | for resp.Request.Method == http.MethodTrace {
203 | return nil
204 | }
205 | return nil
206 | }
207 |
208 | func _() {
209 | var r http.Request
210 | switch r.Method {
211 | case "CONNECT": // want `"CONNECT" can be replaced by http\.MethodConnect`
212 | return
213 | case "DELETE": // want `"DELETE" can be replaced by http\.MethodDelete`
214 | return
215 | case "GET": // want `"GET" can be replaced by http\.MethodGet`
216 | return
217 | case "HEAD": // want `"HEAD" can be replaced by http\.MethodHead`
218 | return
219 | case "OPTIONS": // want `"OPTIONS" can be replaced by http\.MethodOptions`
220 | return
221 | case "PATCH": // want `"PATCH" can be replaced by http\.MethodPatch`
222 | return
223 | case "POST": // want `"POST" can be replaced by http\.MethodPost`
224 | return
225 | case "PUT": // want `"PUT" can be replaced by http\.MethodPut`
226 | return
227 | case "TRACE": // want `"TRACE" can be replaced by http\.MethodTrace`
228 | return
229 | }
230 | }
231 |
232 | func _() {
233 | var r http.Request
234 | switch r.Method {
235 | case http.MethodConnect:
236 | return
237 | case http.MethodDelete:
238 | return
239 | case http.MethodGet:
240 | return
241 | case http.MethodHead:
242 | return
243 | case http.MethodOptions:
244 | return
245 | case http.MethodPatch:
246 | return
247 | case http.MethodPost:
248 | return
249 | case http.MethodPut:
250 | return
251 | case http.MethodTrace:
252 | return
253 | }
254 | }
255 |
256 | func _() {
257 | var r http.Request
258 | switch {
259 | case r.Method == "CONNECT": // want `"CONNECT" can be replaced by http\.MethodConnect`
260 | return
261 | case r.Method == "DELETE": // want `"DELETE" can be replaced by http\.MethodDelete`
262 | return
263 | case r.Method == "GET": // want `"GET" can be replaced by http\.MethodGet`
264 | return
265 | case r.Method == "HEAD": // want `"HEAD" can be replaced by http\.MethodHead`
266 | return
267 | case r.Method == "OPTIONS": // want `"OPTIONS" can be replaced by http\.MethodOptions`
268 | return
269 | case r.Method == "PATCH": // want `"PATCH" can be replaced by http\.MethodPatch`
270 | return
271 | case r.Method == "POST": // want `"POST" can be replaced by http\.MethodPost`
272 | return
273 | case r.Method == "PUT": // want `"PUT" can be replaced by http\.MethodPut`
274 | return
275 | case r.Method == "TRACE": // want `"TRACE" can be replaced by http\.MethodTrace`
276 | return
277 | }
278 | }
279 |
280 | func _() {
281 | var r http.Request
282 | switch {
283 | case r.Method == http.MethodConnect:
284 | return
285 | case r.Method == http.MethodDelete:
286 | return
287 | case r.Method == http.MethodGet:
288 | return
289 | case r.Method == http.MethodHead:
290 | return
291 | case r.Method == http.MethodOptions:
292 | return
293 | case r.Method == http.MethodPatch:
294 | return
295 | case r.Method == http.MethodPost:
296 | return
297 | case r.Method == http.MethodPut:
298 | return
299 | case r.Method == http.MethodTrace:
300 | return
301 | }
302 | }
303 |
304 | var (
305 | _ = httptest.NewRequest("CONNECT", "", http.NoBody) // want `"CONNECT" can be replaced by http\.MethodConnect`
306 | _ = httptest.NewRequest("DELETE", "", http.NoBody) // want `"DELETE" can be replaced by http\.MethodDelete`
307 | _ = httptest.NewRequest("GET", "", http.NoBody) // want `"GET" can be replaced by http\.MethodGet`
308 | _ = httptest.NewRequest("HEAD", "", http.NoBody) // want `"HEAD" can be replaced by http\.MethodHead`
309 | _ = httptest.NewRequest("OPTIONS", "", http.NoBody) // want `"OPTIONS" can be replaced by http\.MethodOptions`
310 | _ = httptest.NewRequest("PATCH", "", http.NoBody) // want `"PATCH" can be replaced by http\.MethodPatch`
311 | _ = httptest.NewRequest("POST", "", http.NoBody) // want `"POST" can be replaced by http\.MethodPost`
312 | _ = httptest.NewRequest("PUT", "", http.NoBody) // want `"PUT" can be replaced by http\.MethodPut`
313 | _ = httptest.NewRequest("TRACE", "", http.NoBody) // want `"TRACE" can be replaced by http\.MethodTrace`
314 | )
315 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/http/method.go.golden:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package http_test
4 |
5 | import (
6 | "net/http"
7 | "net/http/httptest"
8 | )
9 |
10 | var (
11 | _ = "CONNECT"
12 | _ = "DELETE"
13 | _ = "GET"
14 | _ = "HEAD"
15 | _ = "OPTIONS"
16 | _ = "PATCH"
17 | _ = "POST"
18 | _ = "PUT"
19 | _ = "TRACE"
20 | )
21 |
22 | const (
23 | _ = "CONNECT"
24 | _ = "DELETE"
25 | _ = "GET"
26 | _ = "HEAD"
27 | _ = "OPTIONS"
28 | _ = "PATCH"
29 | _ = "POST"
30 | _ = "PUT"
31 | _ = "TRACE"
32 | )
33 |
34 | var (
35 | _, _ = http.NewRequest(http.MethodConnect, "", http.NoBody) // want `"CONNECT" can be replaced by http\.MethodConnect`
36 | _, _ = http.NewRequest(http.MethodDelete, "", http.NoBody) // want `"DELETE" can be replaced by http\.MethodDelete`
37 | _, _ = http.NewRequest(http.MethodGet, "", http.NoBody) // want `"GET" can be replaced by http\.MethodGet`
38 | _, _ = http.NewRequest(http.MethodHead, "", http.NoBody) // want `"HEAD" can be replaced by http\.MethodHead`
39 | _, _ = http.NewRequest(http.MethodOptions, "", http.NoBody) // want `"OPTIONS" can be replaced by http\.MethodOptions`
40 | _, _ = http.NewRequest(http.MethodPatch, "", http.NoBody) // want `"PATCH" can be replaced by http\.MethodPatch`
41 | _, _ = http.NewRequest(http.MethodPost, "", http.NoBody) // want `"POST" can be replaced by http\.MethodPost`
42 | _, _ = http.NewRequest(http.MethodPut, "", http.NoBody) // want `"PUT" can be replaced by http\.MethodPut`
43 | _, _ = http.NewRequest(http.MethodTrace, "", http.NoBody) // want `"TRACE" can be replaced by http\.MethodTrace`
44 | )
45 |
46 | var (
47 | _, _ = http.NewRequestWithContext(nil, http.MethodConnect, "", http.NoBody) // want `"CONNECT" can be replaced by http\.MethodConnect`
48 | _, _ = http.NewRequestWithContext(nil, http.MethodDelete, "", http.NoBody) // want `"DELETE" can be replaced by http\.MethodDelete`
49 | _, _ = http.NewRequestWithContext(nil, http.MethodGet, "", http.NoBody) // want `"GET" can be replaced by http\.MethodGet`
50 | _, _ = http.NewRequestWithContext(nil, http.MethodHead, "", http.NoBody) // want `"HEAD" can be replaced by http\.MethodHead`
51 | _, _ = http.NewRequestWithContext(nil, http.MethodOptions, "", http.NoBody) // want `"OPTIONS" can be replaced by http\.MethodOptions`
52 | _, _ = http.NewRequestWithContext(nil, http.MethodPatch, "", http.NoBody) // want `"PATCH" can be replaced by http\.MethodPatch`
53 | _, _ = http.NewRequestWithContext(nil, http.MethodPost, "", http.NoBody) // want `"POST" can be replaced by http\.MethodPost`
54 | _, _ = http.NewRequestWithContext(nil, http.MethodPut, "", http.NoBody) // want `"PUT" can be replaced by http\.MethodPut`
55 | _, _ = http.NewRequestWithContext(nil, http.MethodTrace, "", http.NoBody) // want `"TRACE" can be replaced by http\.MethodTrace`
56 | )
57 |
58 | var (
59 | _ = http.Request{Method: http.MethodConnect} // want `"CONNECT" can be replaced by http\.MethodConnect`
60 | _ = http.Request{Method: http.MethodDelete} // want `"DELETE" can be replaced by http\.MethodDelete`
61 | _ = http.Request{Method: http.MethodGet} // want `"GET" can be replaced by http\.MethodGet`
62 | _ = http.Request{Method: http.MethodHead} // want `"HEAD" can be replaced by http\.MethodHead`
63 | _ = http.Request{Method: http.MethodOptions} // want `"OPTIONS" can be replaced by http\.MethodOptions`
64 | _ = http.Request{Method: http.MethodPatch} // want `"PATCH" can be replaced by http\.MethodPatch`
65 | _ = http.Request{Method: http.MethodPost} // want `"POST" can be replaced by http\.MethodPost`
66 | _ = http.Request{Method: http.MethodPut} // want `"PUT" can be replaced by http\.MethodPut`
67 | _ = http.Request{Method: http.MethodTrace} // want `"TRACE" can be replaced by http\.MethodTrace`
68 | )
69 |
70 | var (
71 | _ = &http.Request{Method: http.MethodConnect} // want `"CONNECT" can be replaced by http\.MethodConnect`
72 | _ = &http.Request{Method: http.MethodDelete} // want `"DELETE" can be replaced by http\.MethodDelete`
73 | _ = &http.Request{Method: http.MethodGet} // want `"GET" can be replaced by http\.MethodGet`
74 | _ = &http.Request{Method: http.MethodHead} // want `"HEAD" can be replaced by http\.MethodHead`
75 | _ = &http.Request{Method: http.MethodOptions} // want `"OPTIONS" can be replaced by http\.MethodOptions`
76 | _ = &http.Request{Method: http.MethodPatch} // want `"PATCH" can be replaced by http\.MethodPatch`
77 | _ = &http.Request{Method: http.MethodPost} // want `"POST" can be replaced by http\.MethodPost`
78 | _ = &http.Request{Method: http.MethodPut} // want `"PUT" can be replaced by http\.MethodPut`
79 | _ = &http.Request{Method: http.MethodTrace} // want `"TRACE" can be replaced by http\.MethodTrace`
80 | )
81 |
82 | func _() error {
83 | resp, err := http.DefaultClient.Do(&http.Request{})
84 | if err != nil {
85 | return err
86 | }
87 | defer func() { _ = resp.Body.Close() }()
88 | if resp.Request.Method == http.MethodConnect { // want `"CONNECT" can be replaced by http\.MethodConnect`
89 | return nil
90 | }
91 | if resp.Request.Method == http.MethodDelete { // want `"DELETE" can be replaced by http\.MethodDelete`
92 | return nil
93 | }
94 | if resp.Request.Method == http.MethodGet { // want `"GET" can be replaced by http\.MethodGet`
95 | return nil
96 | }
97 | if resp.Request.Method == http.MethodHead { // want `"HEAD" can be replaced by http\.MethodHead`
98 | return nil
99 | }
100 | if resp.Request.Method == http.MethodOptions { // want `"OPTIONS" can be replaced by http\.MethodOptions`
101 | return nil
102 | }
103 | if resp.Request.Method == http.MethodPatch { // want `"PATCH" can be replaced by http\.MethodPatch`
104 | return nil
105 | }
106 | if resp.Request.Method == http.MethodPost { // want `"POST" can be replaced by http\.MethodPost`
107 | return nil
108 | }
109 | if resp.Request.Method == http.MethodPut { // want `"PUT" can be replaced by http\.MethodPut`
110 | return nil
111 | }
112 | if resp.Request.Method == http.MethodTrace { // want `"TRACE" can be replaced by http\.MethodTrace`
113 | return nil
114 | }
115 | for resp.Request.Method == http.MethodConnect { // want `"CONNECT" can be replaced by http\.MethodConnect`
116 | return nil
117 | }
118 | for resp.Request.Method == http.MethodDelete { // want `"DELETE" can be replaced by http\.MethodDelete`
119 | return nil
120 | }
121 | for resp.Request.Method == http.MethodGet { // want `"GET" can be replaced by http\.MethodGet`
122 | return nil
123 | }
124 | for resp.Request.Method == http.MethodHead { // want `"HEAD" can be replaced by http\.MethodHead`
125 | return nil
126 | }
127 | for resp.Request.Method == http.MethodOptions { // want `"OPTIONS" can be replaced by http\.MethodOptions`
128 | return nil
129 | }
130 | for resp.Request.Method == http.MethodPatch { // want `"PATCH" can be replaced by http\.MethodPatch`
131 | return nil
132 | }
133 | for resp.Request.Method == http.MethodPost { // want `"POST" can be replaced by http\.MethodPost`
134 | return nil
135 | }
136 | for resp.Request.Method == http.MethodPut { // want `"PUT" can be replaced by http\.MethodPut`
137 | return nil
138 | }
139 | for resp.Request.Method == http.MethodTrace { // want `"TRACE" can be replaced by http\.MethodTrace`
140 | return nil
141 | }
142 | return nil
143 | }
144 |
145 | func _() error {
146 | resp, err := http.DefaultClient.Do(&http.Request{})
147 | if err != nil {
148 | return err
149 | }
150 | defer func() { _ = resp.Body.Close() }()
151 | if resp.Request.Method == http.MethodConnect {
152 | return nil
153 | }
154 | if resp.Request.Method == http.MethodDelete {
155 | return nil
156 | }
157 | if resp.Request.Method == http.MethodGet {
158 | return nil
159 | }
160 | if resp.Request.Method == http.MethodHead {
161 | return nil
162 | }
163 | if resp.Request.Method == http.MethodOptions {
164 | return nil
165 | }
166 | if resp.Request.Method == http.MethodPatch {
167 | return nil
168 | }
169 | if resp.Request.Method == http.MethodPost {
170 | return nil
171 | }
172 | if resp.Request.Method == http.MethodPut {
173 | return nil
174 | }
175 | if resp.Request.Method == http.MethodTrace {
176 | return nil
177 | }
178 | for resp.Request.Method == http.MethodConnect {
179 | return nil
180 | }
181 | for resp.Request.Method == http.MethodDelete {
182 | return nil
183 | }
184 | for resp.Request.Method == http.MethodGet {
185 | return nil
186 | }
187 | for resp.Request.Method == http.MethodHead {
188 | return nil
189 | }
190 | for resp.Request.Method == http.MethodOptions {
191 | return nil
192 | }
193 | for resp.Request.Method == http.MethodPatch {
194 | return nil
195 | }
196 | for resp.Request.Method == http.MethodPost {
197 | return nil
198 | }
199 | for resp.Request.Method == http.MethodPut {
200 | return nil
201 | }
202 | for resp.Request.Method == http.MethodTrace {
203 | return nil
204 | }
205 | return nil
206 | }
207 |
208 | func _() {
209 | var r http.Request
210 | switch r.Method {
211 | case http.MethodConnect: // want `"CONNECT" can be replaced by http\.MethodConnect`
212 | return
213 | case http.MethodDelete: // want `"DELETE" can be replaced by http\.MethodDelete`
214 | return
215 | case http.MethodGet: // want `"GET" can be replaced by http\.MethodGet`
216 | return
217 | case http.MethodHead: // want `"HEAD" can be replaced by http\.MethodHead`
218 | return
219 | case http.MethodOptions: // want `"OPTIONS" can be replaced by http\.MethodOptions`
220 | return
221 | case http.MethodPatch: // want `"PATCH" can be replaced by http\.MethodPatch`
222 | return
223 | case http.MethodPost: // want `"POST" can be replaced by http\.MethodPost`
224 | return
225 | case http.MethodPut: // want `"PUT" can be replaced by http\.MethodPut`
226 | return
227 | case http.MethodTrace: // want `"TRACE" can be replaced by http\.MethodTrace`
228 | return
229 | }
230 | }
231 |
232 | func _() {
233 | var r http.Request
234 | switch r.Method {
235 | case http.MethodConnect:
236 | return
237 | case http.MethodDelete:
238 | return
239 | case http.MethodGet:
240 | return
241 | case http.MethodHead:
242 | return
243 | case http.MethodOptions:
244 | return
245 | case http.MethodPatch:
246 | return
247 | case http.MethodPost:
248 | return
249 | case http.MethodPut:
250 | return
251 | case http.MethodTrace:
252 | return
253 | }
254 | }
255 |
256 | func _() {
257 | var r http.Request
258 | switch {
259 | case r.Method == http.MethodConnect: // want `"CONNECT" can be replaced by http\.MethodConnect`
260 | return
261 | case r.Method == http.MethodDelete: // want `"DELETE" can be replaced by http\.MethodDelete`
262 | return
263 | case r.Method == http.MethodGet: // want `"GET" can be replaced by http\.MethodGet`
264 | return
265 | case r.Method == http.MethodHead: // want `"HEAD" can be replaced by http\.MethodHead`
266 | return
267 | case r.Method == http.MethodOptions: // want `"OPTIONS" can be replaced by http\.MethodOptions`
268 | return
269 | case r.Method == http.MethodPatch: // want `"PATCH" can be replaced by http\.MethodPatch`
270 | return
271 | case r.Method == http.MethodPost: // want `"POST" can be replaced by http\.MethodPost`
272 | return
273 | case r.Method == http.MethodPut: // want `"PUT" can be replaced by http\.MethodPut`
274 | return
275 | case r.Method == http.MethodTrace: // want `"TRACE" can be replaced by http\.MethodTrace`
276 | return
277 | }
278 | }
279 |
280 | func _() {
281 | var r http.Request
282 | switch {
283 | case r.Method == http.MethodConnect:
284 | return
285 | case r.Method == http.MethodDelete:
286 | return
287 | case r.Method == http.MethodGet:
288 | return
289 | case r.Method == http.MethodHead:
290 | return
291 | case r.Method == http.MethodOptions:
292 | return
293 | case r.Method == http.MethodPatch:
294 | return
295 | case r.Method == http.MethodPost:
296 | return
297 | case r.Method == http.MethodPut:
298 | return
299 | case r.Method == http.MethodTrace:
300 | return
301 | }
302 | }
303 |
304 | var (
305 | _ = httptest.NewRequest(http.MethodConnect, "", http.NoBody) // want `"CONNECT" can be replaced by http\.MethodConnect`
306 | _ = httptest.NewRequest(http.MethodDelete, "", http.NoBody) // want `"DELETE" can be replaced by http\.MethodDelete`
307 | _ = httptest.NewRequest(http.MethodGet, "", http.NoBody) // want `"GET" can be replaced by http\.MethodGet`
308 | _ = httptest.NewRequest(http.MethodHead, "", http.NoBody) // want `"HEAD" can be replaced by http\.MethodHead`
309 | _ = httptest.NewRequest(http.MethodOptions, "", http.NoBody) // want `"OPTIONS" can be replaced by http\.MethodOptions`
310 | _ = httptest.NewRequest(http.MethodPatch, "", http.NoBody) // want `"PATCH" can be replaced by http\.MethodPatch`
311 | _ = httptest.NewRequest(http.MethodPost, "", http.NoBody) // want `"POST" can be replaced by http\.MethodPost`
312 | _ = httptest.NewRequest(http.MethodPut, "", http.NoBody) // want `"PUT" can be replaced by http\.MethodPut`
313 | _ = httptest.NewRequest(http.MethodTrace, "", http.NoBody) // want `"TRACE" can be replaced by http\.MethodTrace`
314 | )
315 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/rpc/rpc.go:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package rpc_test
4 |
5 | var (
6 | _ = "/_goRPC_" // want `"/_goRPC_" can be replaced by rpc\.DefaultRPCPath`
7 | _ = "/debug/rpc" // want `"/debug/rpc" can be replaced by rpc\.DefaultDebugPath`
8 | )
9 |
10 | const (
11 | _ = "/_goRPC_" // want `"/_goRPC_" can be replaced by rpc\.DefaultRPCPath`
12 | _ = "/debug/rpc" // want `"/debug/rpc" can be replaced by rpc\.DefaultDebugPath`
13 | )
14 |
15 | var (
16 | _ = func(s string) string { return s }("/_goRPC_") // want `"/_goRPC_" can be replaced by rpc\.DefaultRPCPath`
17 | _ = func(s string) string { return s }("/debug/rpc") // want `"/debug/rpc" can be replaced by rpc\.DefaultDebugPath`
18 | )
19 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/rpc/rpc.go.golden:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package rpc_test
4 |
5 | var (
6 | _ = rpc.DefaultRPCPath // want `"/_goRPC_" can be replaced by rpc\.DefaultRPCPath`
7 | _ = rpc.DefaultDebugPath // want `"/debug/rpc" can be replaced by rpc\.DefaultDebugPath`
8 | )
9 |
10 | const (
11 | _ = rpc.DefaultRPCPath // want `"/_goRPC_" can be replaced by rpc\.DefaultRPCPath`
12 | _ = rpc.DefaultDebugPath // want `"/debug/rpc" can be replaced by rpc\.DefaultDebugPath`
13 | )
14 |
15 | var (
16 | _ = func(s string)string{return s}(rpc.DefaultRPCPath) // want `"/_goRPC_" can be replaced by rpc\.DefaultRPCPath`
17 | _ = func(s string)string{return s}(rpc.DefaultDebugPath) // want `"/debug/rpc" can be replaced by rpc\.DefaultDebugPath`
18 | )
19 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/sql/isolationlevel.go:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package sql_test
4 |
5 | var (
6 | _ = "Read Committed" // want `"Read Committed" can be replaced by sql\.LevelReadCommitted\.String\(\)`
7 | _ = "Read Uncommitted" // want `"Read Uncommitted" can be replaced by sql\.LevelReadUncommitted\.String\(\)`
8 | _ = "Repeatable Read" // want `"Repeatable Read" can be replaced by sql\.LevelRepeatableRead\.String\(\)`
9 | _ = "Write Committed" // want `"Write Committed" can be replaced by sql\.LevelWriteCommitted\.String\(\)`
10 | )
11 |
12 | const (
13 | _ = "Read Committed" // want `"Read Committed" can be replaced by sql\.LevelReadCommitted\.String\(\)`
14 | _ = "Read Uncommitted" // want `"Read Uncommitted" can be replaced by sql\.LevelReadUncommitted\.String\(\)`
15 | _ = "Repeatable Read" // want `"Repeatable Read" can be replaced by sql\.LevelRepeatableRead\.String\(\)`
16 | _ = "Write Committed" // want `"Write Committed" can be replaced by sql\.LevelWriteCommitted\.String\(\)`
17 | )
18 |
19 | var (
20 | _ = func(s string) string { return s }("Read Committed") // want `"Read Committed" can be replaced by sql\.LevelReadCommitted\.String\(\)`
21 | _ = func(s string) string { return s }("Read Uncommitted") // want `"Read Uncommitted" can be replaced by sql\.LevelReadUncommitted\.String\(\)`
22 | _ = func(s string) string { return s }("Repeatable Read") // want `"Repeatable Read" can be replaced by sql\.LevelRepeatableRead\.String\(\)`
23 | _ = func(s string) string { return s }("Write Committed") // want `"Write Committed" can be replaced by sql\.LevelWriteCommitted\.String\(\)`
24 | )
25 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/sql/isolationlevel.go.golden:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package sql_test
4 |
5 | var (
6 | _ = sql.LevelReadCommitted.String() // want `"Read Committed" can be replaced by sql\.LevelReadCommitted\.String\(\)`
7 | _ = sql.LevelReadUncommitted.String() // want `"Read Uncommitted" can be replaced by sql\.LevelReadUncommitted\.String\(\)`
8 | _ = sql.LevelRepeatableRead.String() // want `"Repeatable Read" can be replaced by sql\.LevelRepeatableRead\.String\(\)`
9 | _ = sql.LevelWriteCommitted.String() // want `"Write Committed" can be replaced by sql\.LevelWriteCommitted\.String\(\)`
10 | )
11 |
12 | const (
13 | _ = sql.LevelReadCommitted.String() // want `"Read Committed" can be replaced by sql\.LevelReadCommitted\.String\(\)`
14 | _ = sql.LevelReadUncommitted.String() // want `"Read Uncommitted" can be replaced by sql\.LevelReadUncommitted\.String\(\)`
15 | _ = sql.LevelRepeatableRead.String() // want `"Repeatable Read" can be replaced by sql\.LevelRepeatableRead\.String\(\)`
16 | _ = sql.LevelWriteCommitted.String() // want `"Write Committed" can be replaced by sql\.LevelWriteCommitted\.String\(\)`
17 | )
18 |
19 | var (
20 | _ = func(s string)string{return s}(sql.LevelReadCommitted.String()) // want `"Read Committed" can be replaced by sql\.LevelReadCommitted\.String\(\)`
21 | _ = func(s string)string{return s}(sql.LevelReadUncommitted.String()) // want `"Read Uncommitted" can be replaced by sql\.LevelReadUncommitted\.String\(\)`
22 | _ = func(s string)string{return s}(sql.LevelRepeatableRead.String()) // want `"Repeatable Read" can be replaced by sql\.LevelRepeatableRead\.String\(\)`
23 | _ = func(s string)string{return s}(sql.LevelWriteCommitted.String()) // want `"Write Committed" can be replaced by sql\.LevelWriteCommitted\.String\(\)`
24 | )
25 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/time/issue103.go:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package time_test
4 |
5 | import "time"
6 |
7 | func _() {
8 | var _ = time.Date(2023, 1, 2, 3, 4, 5, 0, time.UTC) // want `"1" can be replaced by time\.January`
9 | var _ = time.Date(2023, 10, 2, 3, 4, 5, 0, time.UTC) // want `"10" can be replaced by time\.October`
10 | var _ = time.Date(2023, 11, 2, 3, 4, 5, 0, time.UTC) // want `"11" can be replaced by time\.November`
11 | var _ = time.Date(2023, 12, 2, 3, 4, 5, 0, time.UTC) // want `"12" can be replaced by time\.December`
12 | var _ = time.Date(2023, 2, 2, 3, 4, 5, 0, time.UTC) // want `"2" can be replaced by time\.February`
13 | var _ = time.Date(2023, 3, 2, 3, 4, 5, 0, time.UTC) // want `"3" can be replaced by time\.March`
14 | var _ = time.Date(2023, 4, 2, 3, 4, 5, 0, time.UTC) // want `"4" can be replaced by time\.April`
15 | var _ = time.Date(2023, 5, 2, 3, 4, 5, 0, time.UTC) // want `"5" can be replaced by time\.May`
16 | var _ = time.Date(2023, 6, 2, 3, 4, 5, 0, time.UTC) // want `"6" can be replaced by time\.June`
17 | var _ = time.Date(2023, 7, 2, 3, 4, 5, 0, time.UTC) // want `"7" can be replaced by time\.July`
18 | var _ = time.Date(2023, 8, 2, 3, 4, 5, 0, time.UTC) // want `"8" can be replaced by time\.August`
19 | var _ = time.Date(2023, 9, 2, 3, 4, 5, 0, time.UTC) // want `"9" can be replaced by time\.September`
20 |
21 | var _ = time.Date(2023, time.January, 2, 3, 4, 5, 0, time.UTC)
22 | var _ = time.Date(2023, time.October, 2, 3, 4, 5, 0, time.UTC)
23 | var _ = time.Date(2023, time.November, 2, 3, 4, 5, 0, time.UTC)
24 | var _ = time.Date(2023, time.December, 2, 3, 4, 5, 0, time.UTC)
25 | var _ = time.Date(2023, time.February, 2, 3, 4, 5, 0, time.UTC)
26 | var _ = time.Date(2023, time.March, 2, 3, 4, 5, 0, time.UTC)
27 | var _ = time.Date(2023, time.April, 2, 3, 4, 5, 0, time.UTC)
28 | var _ = time.Date(2023, time.May, 2, 3, 4, 5, 0, time.UTC)
29 | var _ = time.Date(2023, time.June, 2, 3, 4, 5, 0, time.UTC)
30 | var _ = time.Date(2023, time.July, 2, 3, 4, 5, 0, time.UTC)
31 | var _ = time.Date(2023, time.August, 2, 3, 4, 5, 0, time.UTC)
32 | var _ = time.Date(2023, time.September, 2, 3, 4, 5, 0, time.UTC)
33 | }
34 |
35 | var _ = time.Date(2023, 13, 2, 3, 4, 5, 0, time.UTC)
36 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/time/issue103.go.golden:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package time_test
4 |
5 | import "time"
6 |
7 | func _() {
8 | var _ = time.Date(2023, time.January, 2, 3, 4, 5, 0, time.UTC) // want `"1" can be replaced by time\.January`
9 | var _ = time.Date(2023, time.October, 2, 3, 4, 5, 0, time.UTC) // want `"10" can be replaced by time\.October`
10 | var _ = time.Date(2023, time.November, 2, 3, 4, 5, 0, time.UTC) // want `"11" can be replaced by time\.November`
11 | var _ = time.Date(2023, time.December, 2, 3, 4, 5, 0, time.UTC) // want `"12" can be replaced by time\.December`
12 | var _ = time.Date(2023, time.February, 2, 3, 4, 5, 0, time.UTC) // want `"2" can be replaced by time\.February`
13 | var _ = time.Date(2023, time.March, 2, 3, 4, 5, 0, time.UTC) // want `"3" can be replaced by time\.March`
14 | var _ = time.Date(2023, time.April, 2, 3, 4, 5, 0, time.UTC) // want `"4" can be replaced by time\.April`
15 | var _ = time.Date(2023, time.May, 2, 3, 4, 5, 0, time.UTC) // want `"5" can be replaced by time\.May`
16 | var _ = time.Date(2023, time.June, 2, 3, 4, 5, 0, time.UTC) // want `"6" can be replaced by time\.June`
17 | var _ = time.Date(2023, time.July, 2, 3, 4, 5, 0, time.UTC) // want `"7" can be replaced by time\.July`
18 | var _ = time.Date(2023, time.August, 2, 3, 4, 5, 0, time.UTC) // want `"8" can be replaced by time\.August`
19 | var _ = time.Date(2023, time.September, 2, 3, 4, 5, 0, time.UTC) // want `"9" can be replaced by time\.September`
20 |
21 |
22 | var _ = time.Date(2023, time.January, 2, 3, 4, 5, 0, time.UTC)
23 | var _ = time.Date(2023, time.October, 2, 3, 4, 5, 0, time.UTC)
24 | var _ = time.Date(2023, time.November, 2, 3, 4, 5, 0, time.UTC)
25 | var _ = time.Date(2023, time.December, 2, 3, 4, 5, 0, time.UTC)
26 | var _ = time.Date(2023, time.February, 2, 3, 4, 5, 0, time.UTC)
27 | var _ = time.Date(2023, time.March, 2, 3, 4, 5, 0, time.UTC)
28 | var _ = time.Date(2023, time.April, 2, 3, 4, 5, 0, time.UTC)
29 | var _ = time.Date(2023, time.May, 2, 3, 4, 5, 0, time.UTC)
30 | var _ = time.Date(2023, time.June, 2, 3, 4, 5, 0, time.UTC)
31 | var _ = time.Date(2023, time.July, 2, 3, 4, 5, 0, time.UTC)
32 | var _ = time.Date(2023, time.August, 2, 3, 4, 5, 0, time.UTC)
33 | var _ = time.Date(2023, time.September, 2, 3, 4, 5, 0, time.UTC)
34 | }
35 |
36 | var _ = time.Date(2023, 13, 2, 3, 4, 5, 0, time.UTC)
37 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/time/layout.go:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package time_test
4 |
5 | var (
6 | _ = "01/02 03:04:05PM '06 -0700" // want `"01/02 03:04:05PM '06 -0700" can be replaced by time\.Layout`
7 | _ = "02 Jan 06 15:04 -0700" // want `"02 Jan 06 15:04 -0700" can be replaced by time\.RFC822Z`
8 | _ = "02 Jan 06 15:04 MST" // want `"02 Jan 06 15:04 MST" can be replaced by time\.RFC822`
9 | _ = "15:04:05" // want `"15:04:05" can be replaced by time\.TimeOnly`
10 | _ = "2006-01-02" // want `"2006-01-02" can be replaced by time\.DateOnly`
11 | _ = "2006-01-02 15:04:05" // want `"2006-01-02 15:04:05" can be replaced by time\.DateTime`
12 | _ = "2006-01-02T15:04:05.999999999Z07:00" // want `"2006-01-02T15:04:05\.999999999Z07:00" can be replaced by time\.RFC3339Nano`
13 | _ = "2006-01-02T15:04:05Z07:00" // want `"2006-01-02T15:04:05Z07:00" can be replaced by time\.RFC3339`
14 | _ = "3:04PM" // want `"3:04PM" can be replaced by time\.Kitchen`
15 | _ = "Jan _2 15:04:05" // want `"Jan _2 15:04:05" can be replaced by time\.Stamp`
16 | _ = "Jan _2 15:04:05.000" // want `"Jan _2 15:04:05\.000" can be replaced by time\.StampMilli`
17 | _ = "Jan _2 15:04:05.000000" // want `"Jan _2 15:04:05\.000000" can be replaced by time\.StampMicro`
18 | _ = "Jan _2 15:04:05.000000000" // want `"Jan _2 15:04:05\.000000000" can be replaced by time\.StampNano`
19 | _ = "Mon Jan 02 15:04:05 -0700 2006" // want `"Mon Jan 02 15:04:05 -0700 2006" can be replaced by time\.RubyDate`
20 | _ = "Mon Jan _2 15:04:05 2006" // want `"Mon Jan _2 15:04:05 2006" can be replaced by time\.ANSIC`
21 | _ = "Mon Jan _2 15:04:05 MST 2006" // want `"Mon Jan _2 15:04:05 MST 2006" can be replaced by time\.UnixDate`
22 | _ = "Mon, 02 Jan 2006 15:04:05 -0700" // want `"Mon, 02 Jan 2006 15:04:05 -0700" can be replaced by time\.RFC1123Z`
23 | _ = "Mon, 02 Jan 2006 15:04:05 MST" // want `"Mon, 02 Jan 2006 15:04:05 MST" can be replaced by time\.RFC1123`
24 | _ = "Monday, 02-Jan-06 15:04:05 MST" // want `"Monday, 02-Jan-06 15:04:05 MST" can be replaced by time\.RFC850`
25 | )
26 |
27 | const (
28 | _ = "01/02 03:04:05PM '06 -0700" // want `"01/02 03:04:05PM '06 -0700" can be replaced by time\.Layout`
29 | _ = "02 Jan 06 15:04 -0700" // want `"02 Jan 06 15:04 -0700" can be replaced by time\.RFC822Z`
30 | _ = "02 Jan 06 15:04 MST" // want `"02 Jan 06 15:04 MST" can be replaced by time\.RFC822`
31 | _ = "15:04:05" // want `"15:04:05" can be replaced by time\.TimeOnly`
32 | _ = "2006-01-02" // want `"2006-01-02" can be replaced by time\.DateOnly`
33 | _ = "2006-01-02 15:04:05" // want `"2006-01-02 15:04:05" can be replaced by time\.DateTime`
34 | _ = "2006-01-02T15:04:05.999999999Z07:00" // want `"2006-01-02T15:04:05\.999999999Z07:00" can be replaced by time\.RFC3339Nano`
35 | _ = "2006-01-02T15:04:05Z07:00" // want `"2006-01-02T15:04:05Z07:00" can be replaced by time\.RFC3339`
36 | _ = "3:04PM" // want `"3:04PM" can be replaced by time\.Kitchen`
37 | _ = "Jan _2 15:04:05" // want `"Jan _2 15:04:05" can be replaced by time\.Stamp`
38 | _ = "Jan _2 15:04:05.000" // want `"Jan _2 15:04:05\.000" can be replaced by time\.StampMilli`
39 | _ = "Jan _2 15:04:05.000000" // want `"Jan _2 15:04:05\.000000" can be replaced by time\.StampMicro`
40 | _ = "Jan _2 15:04:05.000000000" // want `"Jan _2 15:04:05\.000000000" can be replaced by time\.StampNano`
41 | _ = "Mon Jan 02 15:04:05 -0700 2006" // want `"Mon Jan 02 15:04:05 -0700 2006" can be replaced by time\.RubyDate`
42 | _ = "Mon Jan _2 15:04:05 2006" // want `"Mon Jan _2 15:04:05 2006" can be replaced by time\.ANSIC`
43 | _ = "Mon Jan _2 15:04:05 MST 2006" // want `"Mon Jan _2 15:04:05 MST 2006" can be replaced by time\.UnixDate`
44 | _ = "Mon, 02 Jan 2006 15:04:05 -0700" // want `"Mon, 02 Jan 2006 15:04:05 -0700" can be replaced by time\.RFC1123Z`
45 | _ = "Mon, 02 Jan 2006 15:04:05 MST" // want `"Mon, 02 Jan 2006 15:04:05 MST" can be replaced by time\.RFC1123`
46 | _ = "Monday, 02-Jan-06 15:04:05 MST" // want `"Monday, 02-Jan-06 15:04:05 MST" can be replaced by time\.RFC850`
47 | )
48 |
49 | var (
50 | _ = 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`
51 | _ = 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`
52 | _ = 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`
53 | _ = func(s string) string { return s }("15:04:05") // want `"15:04:05" can be replaced by time\.TimeOnly`
54 | _ = func(s string) string { return s }("2006-01-02") // want `"2006-01-02" can be replaced by time\.DateOnly`
55 | _ = func(s string) string { return s }("2006-01-02 15:04:05") // want `"2006-01-02 15:04:05" can be replaced by time\.DateTime`
56 | _ = 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`
57 | _ = 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`
58 | _ = func(s string) string { return s }("3:04PM") // want `"3:04PM" can be replaced by time\.Kitchen`
59 | _ = func(s string) string { return s }("Jan _2 15:04:05") // want `"Jan _2 15:04:05" can be replaced by time\.Stamp`
60 | _ = 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`
61 | _ = 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`
62 | _ = 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`
63 | _ = 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`
64 | _ = 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`
65 | _ = 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`
66 | _ = 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`
67 | _ = 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`
68 | _ = 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`
69 | )
70 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/time/layout.go.golden:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package time_test
4 |
5 | var (
6 | _ = time.Layout // want `"01/02 03:04:05PM '06 -0700" can be replaced by time\.Layout`
7 | _ = time.RFC822Z // want `"02 Jan 06 15:04 -0700" can be replaced by time\.RFC822Z`
8 | _ = time.RFC822 // want `"02 Jan 06 15:04 MST" can be replaced by time\.RFC822`
9 | _ = time.TimeOnly // want `"15:04:05" can be replaced by time\.TimeOnly`
10 | _ = time.DateOnly // want `"2006-01-02" can be replaced by time\.DateOnly`
11 | _ = time.DateTime // want `"2006-01-02 15:04:05" can be replaced by time\.DateTime`
12 | _ = time.RFC3339Nano // want `"2006-01-02T15:04:05\.999999999Z07:00" can be replaced by time\.RFC3339Nano`
13 | _ = time.RFC3339 // want `"2006-01-02T15:04:05Z07:00" can be replaced by time\.RFC3339`
14 | _ = time.Kitchen // want `"3:04PM" can be replaced by time\.Kitchen`
15 | _ = time.Stamp // want `"Jan _2 15:04:05" can be replaced by time\.Stamp`
16 | _ = time.StampMilli // want `"Jan _2 15:04:05\.000" can be replaced by time\.StampMilli`
17 | _ = time.StampMicro // want `"Jan _2 15:04:05\.000000" can be replaced by time\.StampMicro`
18 | _ = time.StampNano // want `"Jan _2 15:04:05\.000000000" can be replaced by time\.StampNano`
19 | _ = time.RubyDate // want `"Mon Jan 02 15:04:05 -0700 2006" can be replaced by time\.RubyDate`
20 | _ = time.ANSIC // want `"Mon Jan _2 15:04:05 2006" can be replaced by time\.ANSIC`
21 | _ = time.UnixDate // want `"Mon Jan _2 15:04:05 MST 2006" can be replaced by time\.UnixDate`
22 | _ = time.RFC1123Z // want `"Mon, 02 Jan 2006 15:04:05 -0700" can be replaced by time\.RFC1123Z`
23 | _ = time.RFC1123 // want `"Mon, 02 Jan 2006 15:04:05 MST" can be replaced by time\.RFC1123`
24 | _ = time.RFC850 // want `"Monday, 02-Jan-06 15:04:05 MST" can be replaced by time\.RFC850`
25 | )
26 |
27 | const (
28 | _ = time.Layout // want `"01/02 03:04:05PM '06 -0700" can be replaced by time\.Layout`
29 | _ = time.RFC822Z // want `"02 Jan 06 15:04 -0700" can be replaced by time\.RFC822Z`
30 | _ = time.RFC822 // want `"02 Jan 06 15:04 MST" can be replaced by time\.RFC822`
31 | _ = time.TimeOnly // want `"15:04:05" can be replaced by time\.TimeOnly`
32 | _ = time.DateOnly // want `"2006-01-02" can be replaced by time\.DateOnly`
33 | _ = time.DateTime // want `"2006-01-02 15:04:05" can be replaced by time\.DateTime`
34 | _ = time.RFC3339Nano // want `"2006-01-02T15:04:05\.999999999Z07:00" can be replaced by time\.RFC3339Nano`
35 | _ = time.RFC3339 // want `"2006-01-02T15:04:05Z07:00" can be replaced by time\.RFC3339`
36 | _ = time.Kitchen // want `"3:04PM" can be replaced by time\.Kitchen`
37 | _ = time.Stamp // want `"Jan _2 15:04:05" can be replaced by time\.Stamp`
38 | _ = time.StampMilli // want `"Jan _2 15:04:05\.000" can be replaced by time\.StampMilli`
39 | _ = time.StampMicro // want `"Jan _2 15:04:05\.000000" can be replaced by time\.StampMicro`
40 | _ = time.StampNano // want `"Jan _2 15:04:05\.000000000" can be replaced by time\.StampNano`
41 | _ = time.RubyDate // want `"Mon Jan 02 15:04:05 -0700 2006" can be replaced by time\.RubyDate`
42 | _ = time.ANSIC // want `"Mon Jan _2 15:04:05 2006" can be replaced by time\.ANSIC`
43 | _ = time.UnixDate // want `"Mon Jan _2 15:04:05 MST 2006" can be replaced by time\.UnixDate`
44 | _ = time.RFC1123Z // want `"Mon, 02 Jan 2006 15:04:05 -0700" can be replaced by time\.RFC1123Z`
45 | _ = time.RFC1123 // want `"Mon, 02 Jan 2006 15:04:05 MST" can be replaced by time\.RFC1123`
46 | _ = time.RFC850 // want `"Monday, 02-Jan-06 15:04:05 MST" can be replaced by time\.RFC850`
47 | )
48 |
49 | var (
50 | _ = func(s string)string{return s}(time.Layout) // want `"01/02 03:04:05PM '06 -0700" can be replaced by time\.Layout`
51 | _ = func(s string)string{return s}(time.RFC822Z) // want `"02 Jan 06 15:04 -0700" can be replaced by time\.RFC822Z`
52 | _ = func(s string)string{return s}(time.RFC822) // want `"02 Jan 06 15:04 MST" can be replaced by time\.RFC822`
53 | _ = func(s string)string{return s}(time.TimeOnly) // want `"15:04:05" can be replaced by time\.TimeOnly`
54 | _ = func(s string)string{return s}(time.DateOnly) // want `"2006-01-02" can be replaced by time\.DateOnly`
55 | _ = func(s string)string{return s}(time.DateTime) // want `"2006-01-02 15:04:05" can be replaced by time\.DateTime`
56 | _ = func(s string)string{return s}(time.RFC3339Nano) // want `"2006-01-02T15:04:05\.999999999Z07:00" can be replaced by time\.RFC3339Nano`
57 | _ = func(s string)string{return s}(time.RFC3339) // want `"2006-01-02T15:04:05Z07:00" can be replaced by time\.RFC3339`
58 | _ = func(s string)string{return s}(time.Kitchen) // want `"3:04PM" can be replaced by time\.Kitchen`
59 | _ = func(s string)string{return s}(time.Stamp) // want `"Jan _2 15:04:05" can be replaced by time\.Stamp`
60 | _ = func(s string)string{return s}(time.StampMilli) // want `"Jan _2 15:04:05\.000" can be replaced by time\.StampMilli`
61 | _ = func(s string)string{return s}(time.StampMicro) // want `"Jan _2 15:04:05\.000000" can be replaced by time\.StampMicro`
62 | _ = func(s string)string{return s}(time.StampNano) // want `"Jan _2 15:04:05\.000000000" can be replaced by time\.StampNano`
63 | _ = func(s string)string{return s}(time.RubyDate) // want `"Mon Jan 02 15:04:05 -0700 2006" can be replaced by time\.RubyDate`
64 | _ = func(s string)string{return s}(time.ANSIC) // want `"Mon Jan _2 15:04:05 2006" can be replaced by time\.ANSIC`
65 | _ = func(s string)string{return s}(time.UnixDate) // want `"Mon Jan _2 15:04:05 MST 2006" can be replaced by time\.UnixDate`
66 | _ = func(s string)string{return s}(time.RFC1123Z) // want `"Mon, 02 Jan 2006 15:04:05 -0700" can be replaced by time\.RFC1123Z`
67 | _ = func(s string)string{return s}(time.RFC1123) // want `"Mon, 02 Jan 2006 15:04:05 MST" can be replaced by time\.RFC1123`
68 | _ = func(s string)string{return s}(time.RFC850) // want `"Monday, 02-Jan-06 15:04:05 MST" can be replaced by time\.RFC850`
69 | )
70 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/time/month.go:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package time_test
4 |
5 | var (
6 | _ = "April" // want `"April" can be replaced by time\.April\.String\(\)`
7 | _ = "August" // want `"August" can be replaced by time\.August\.String\(\)`
8 | _ = "December" // want `"December" can be replaced by time\.December\.String\(\)`
9 | _ = "February" // want `"February" can be replaced by time\.February\.String\(\)`
10 | _ = "January" // want `"January" can be replaced by time\.January\.String\(\)`
11 | _ = "July" // want `"July" can be replaced by time\.July\.String\(\)`
12 | _ = "June" // want `"June" can be replaced by time\.June\.String\(\)`
13 | _ = "March" // want `"March" can be replaced by time\.March\.String\(\)`
14 | _ = "May" // want `"May" can be replaced by time\.May\.String\(\)`
15 | _ = "November" // want `"November" can be replaced by time\.November\.String\(\)`
16 | _ = "October" // want `"October" can be replaced by time\.October\.String\(\)`
17 | _ = "September" // want `"September" can be replaced by time\.September\.String\(\)`
18 | )
19 |
20 | const (
21 | _ = "April" // want `"April" can be replaced by time\.April\.String\(\)`
22 | _ = "August" // want `"August" can be replaced by time\.August\.String\(\)`
23 | _ = "December" // want `"December" can be replaced by time\.December\.String\(\)`
24 | _ = "February" // want `"February" can be replaced by time\.February\.String\(\)`
25 | _ = "January" // want `"January" can be replaced by time\.January\.String\(\)`
26 | _ = "July" // want `"July" can be replaced by time\.July\.String\(\)`
27 | _ = "June" // want `"June" can be replaced by time\.June\.String\(\)`
28 | _ = "March" // want `"March" can be replaced by time\.March\.String\(\)`
29 | _ = "May" // want `"May" can be replaced by time\.May\.String\(\)`
30 | _ = "November" // want `"November" can be replaced by time\.November\.String\(\)`
31 | _ = "October" // want `"October" can be replaced by time\.October\.String\(\)`
32 | _ = "September" // want `"September" can be replaced by time\.September\.String\(\)`
33 | )
34 |
35 | var (
36 | _ = func(s string) string { return s }("April") // want `"April" can be replaced by time\.April\.String\(\)`
37 | _ = func(s string) string { return s }("August") // want `"August" can be replaced by time\.August\.String\(\)`
38 | _ = func(s string) string { return s }("December") // want `"December" can be replaced by time\.December\.String\(\)`
39 | _ = func(s string) string { return s }("February") // want `"February" can be replaced by time\.February\.String\(\)`
40 | _ = func(s string) string { return s }("January") // want `"January" can be replaced by time\.January\.String\(\)`
41 | _ = func(s string) string { return s }("July") // want `"July" can be replaced by time\.July\.String\(\)`
42 | _ = func(s string) string { return s }("June") // want `"June" can be replaced by time\.June\.String\(\)`
43 | _ = func(s string) string { return s }("March") // want `"March" can be replaced by time\.March\.String\(\)`
44 | _ = func(s string) string { return s }("May") // want `"May" can be replaced by time\.May\.String\(\)`
45 | _ = func(s string) string { return s }("November") // want `"November" can be replaced by time\.November\.String\(\)`
46 | _ = func(s string) string { return s }("October") // want `"October" can be replaced by time\.October\.String\(\)`
47 | _ = func(s string) string { return s }("September") // want `"September" can be replaced by time\.September\.String\(\)`
48 | )
49 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/time/month.go.golden:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package time_test
4 |
5 | var (
6 | _ = time.April.String() // want `"April" can be replaced by time\.April\.String\(\)`
7 | _ = time.August.String() // want `"August" can be replaced by time\.August\.String\(\)`
8 | _ = time.December.String() // want `"December" can be replaced by time\.December\.String\(\)`
9 | _ = time.February.String() // want `"February" can be replaced by time\.February\.String\(\)`
10 | _ = time.January.String() // want `"January" can be replaced by time\.January\.String\(\)`
11 | _ = time.July.String() // want `"July" can be replaced by time\.July\.String\(\)`
12 | _ = time.June.String() // want `"June" can be replaced by time\.June\.String\(\)`
13 | _ = time.March.String() // want `"March" can be replaced by time\.March\.String\(\)`
14 | _ = time.May.String() // want `"May" can be replaced by time\.May\.String\(\)`
15 | _ = time.November.String() // want `"November" can be replaced by time\.November\.String\(\)`
16 | _ = time.October.String() // want `"October" can be replaced by time\.October\.String\(\)`
17 | _ = time.September.String() // want `"September" can be replaced by time\.September\.String\(\)`
18 | )
19 |
20 | const (
21 | _ = time.April.String() // want `"April" can be replaced by time\.April\.String\(\)`
22 | _ = time.August.String() // want `"August" can be replaced by time\.August\.String\(\)`
23 | _ = time.December.String() // want `"December" can be replaced by time\.December\.String\(\)`
24 | _ = time.February.String() // want `"February" can be replaced by time\.February\.String\(\)`
25 | _ = time.January.String() // want `"January" can be replaced by time\.January\.String\(\)`
26 | _ = time.July.String() // want `"July" can be replaced by time\.July\.String\(\)`
27 | _ = time.June.String() // want `"June" can be replaced by time\.June\.String\(\)`
28 | _ = time.March.String() // want `"March" can be replaced by time\.March\.String\(\)`
29 | _ = time.May.String() // want `"May" can be replaced by time\.May\.String\(\)`
30 | _ = time.November.String() // want `"November" can be replaced by time\.November\.String\(\)`
31 | _ = time.October.String() // want `"October" can be replaced by time\.October\.String\(\)`
32 | _ = time.September.String() // want `"September" can be replaced by time\.September\.String\(\)`
33 | )
34 |
35 | var (
36 | _ = func(s string)string{return s}(time.April.String()) // want `"April" can be replaced by time\.April\.String\(\)`
37 | _ = func(s string)string{return s}(time.August.String()) // want `"August" can be replaced by time\.August\.String\(\)`
38 | _ = func(s string)string{return s}(time.December.String()) // want `"December" can be replaced by time\.December\.String\(\)`
39 | _ = func(s string)string{return s}(time.February.String()) // want `"February" can be replaced by time\.February\.String\(\)`
40 | _ = func(s string)string{return s}(time.January.String()) // want `"January" can be replaced by time\.January\.String\(\)`
41 | _ = func(s string)string{return s}(time.July.String()) // want `"July" can be replaced by time\.July\.String\(\)`
42 | _ = func(s string)string{return s}(time.June.String()) // want `"June" can be replaced by time\.June\.String\(\)`
43 | _ = func(s string)string{return s}(time.March.String()) // want `"March" can be replaced by time\.March\.String\(\)`
44 | _ = func(s string)string{return s}(time.May.String()) // want `"May" can be replaced by time\.May\.String\(\)`
45 | _ = func(s string)string{return s}(time.November.String()) // want `"November" can be replaced by time\.November\.String\(\)`
46 | _ = func(s string)string{return s}(time.October.String()) // want `"October" can be replaced by time\.October\.String\(\)`
47 | _ = func(s string)string{return s}(time.September.String()) // want `"September" can be replaced by time\.September\.String\(\)`
48 | )
49 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/time/weekday.go:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package time_test
4 |
5 | var (
6 | _ = "Friday" // want `"Friday" can be replaced by time\.Friday\.String\(\)`
7 | _ = "Monday" // want `"Monday" can be replaced by time\.Monday\.String\(\)`
8 | _ = "Saturday" // want `"Saturday" can be replaced by time\.Saturday\.String\(\)`
9 | _ = "Sunday" // want `"Sunday" can be replaced by time\.Sunday\.String\(\)`
10 | _ = "Thursday" // want `"Thursday" can be replaced by time\.Thursday\.String\(\)`
11 | _ = "Tuesday" // want `"Tuesday" can be replaced by time\.Tuesday\.String\(\)`
12 | _ = "Wednesday" // want `"Wednesday" can be replaced by time\.Wednesday\.String\(\)`
13 | )
14 |
15 | const (
16 | _ = "Friday" // want `"Friday" can be replaced by time\.Friday\.String\(\)`
17 | _ = "Monday" // want `"Monday" can be replaced by time\.Monday\.String\(\)`
18 | _ = "Saturday" // want `"Saturday" can be replaced by time\.Saturday\.String\(\)`
19 | _ = "Sunday" // want `"Sunday" can be replaced by time\.Sunday\.String\(\)`
20 | _ = "Thursday" // want `"Thursday" can be replaced by time\.Thursday\.String\(\)`
21 | _ = "Tuesday" // want `"Tuesday" can be replaced by time\.Tuesday\.String\(\)`
22 | _ = "Wednesday" // want `"Wednesday" can be replaced by time\.Wednesday\.String\(\)`
23 | )
24 |
25 | var (
26 | _ = func(s string) string { return s }("Friday") // want `"Friday" can be replaced by time\.Friday\.String\(\)`
27 | _ = func(s string) string { return s }("Monday") // want `"Monday" can be replaced by time\.Monday\.String\(\)`
28 | _ = func(s string) string { return s }("Saturday") // want `"Saturday" can be replaced by time\.Saturday\.String\(\)`
29 | _ = func(s string) string { return s }("Sunday") // want `"Sunday" can be replaced by time\.Sunday\.String\(\)`
30 | _ = func(s string) string { return s }("Thursday") // want `"Thursday" can be replaced by time\.Thursday\.String\(\)`
31 | _ = func(s string) string { return s }("Tuesday") // want `"Tuesday" can be replaced by time\.Tuesday\.String\(\)`
32 | _ = func(s string) string { return s }("Wednesday") // want `"Wednesday" can be replaced by time\.Wednesday\.String\(\)`
33 | )
34 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/time/weekday.go.golden:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package time_test
4 |
5 | var (
6 | _ = time.Friday.String() // want `"Friday" can be replaced by time\.Friday\.String\(\)`
7 | _ = time.Monday.String() // want `"Monday" can be replaced by time\.Monday\.String\(\)`
8 | _ = time.Saturday.String() // want `"Saturday" can be replaced by time\.Saturday\.String\(\)`
9 | _ = time.Sunday.String() // want `"Sunday" can be replaced by time\.Sunday\.String\(\)`
10 | _ = time.Thursday.String() // want `"Thursday" can be replaced by time\.Thursday\.String\(\)`
11 | _ = time.Tuesday.String() // want `"Tuesday" can be replaced by time\.Tuesday\.String\(\)`
12 | _ = time.Wednesday.String() // want `"Wednesday" can be replaced by time\.Wednesday\.String\(\)`
13 | )
14 |
15 | const (
16 | _ = time.Friday.String() // want `"Friday" can be replaced by time\.Friday\.String\(\)`
17 | _ = time.Monday.String() // want `"Monday" can be replaced by time\.Monday\.String\(\)`
18 | _ = time.Saturday.String() // want `"Saturday" can be replaced by time\.Saturday\.String\(\)`
19 | _ = time.Sunday.String() // want `"Sunday" can be replaced by time\.Sunday\.String\(\)`
20 | _ = time.Thursday.String() // want `"Thursday" can be replaced by time\.Thursday\.String\(\)`
21 | _ = time.Tuesday.String() // want `"Tuesday" can be replaced by time\.Tuesday\.String\(\)`
22 | _ = time.Wednesday.String() // want `"Wednesday" can be replaced by time\.Wednesday\.String\(\)`
23 | )
24 |
25 | var (
26 | _ = func(s string)string{return s}(time.Friday.String()) // want `"Friday" can be replaced by time\.Friday\.String\(\)`
27 | _ = func(s string)string{return s}(time.Monday.String()) // want `"Monday" can be replaced by time\.Monday\.String\(\)`
28 | _ = func(s string)string{return s}(time.Saturday.String()) // want `"Saturday" can be replaced by time\.Saturday\.String\(\)`
29 | _ = func(s string)string{return s}(time.Sunday.String()) // want `"Sunday" can be replaced by time\.Sunday\.String\(\)`
30 | _ = func(s string)string{return s}(time.Thursday.String()) // want `"Thursday" can be replaced by time\.Thursday\.String\(\)`
31 | _ = func(s string)string{return s}(time.Tuesday.String()) // want `"Tuesday" can be replaced by time\.Tuesday\.String\(\)`
32 | _ = func(s string)string{return s}(time.Wednesday.String()) // want `"Wednesday" can be replaced by time\.Wednesday\.String\(\)`
33 | )
34 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/tls/signaturescheme.go:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package tls_test
4 |
5 | var (
6 | _ = "ECDSAWithP256AndSHA256" // want `"ECDSAWithP256AndSHA256" can be replaced by tls\.ECDSAWithP256AndSHA256\.String\(\)`
7 | _ = "ECDSAWithP384AndSHA384" // want `"ECDSAWithP384AndSHA384" can be replaced by tls\.ECDSAWithP384AndSHA384\.String\(\)`
8 | _ = "ECDSAWithP521AndSHA512" // want `"ECDSAWithP521AndSHA512" can be replaced by tls\.ECDSAWithP521AndSHA512\.String\(\)`
9 | _ = "ECDSAWithSHA1" // want `"ECDSAWithSHA1" can be replaced by tls\.ECDSAWithSHA1\.String\(\)`
10 | _ = "Ed25519" // want `"Ed25519" can be replaced by tls\.Ed25519\.String\(\)`
11 | _ = "PKCS1WithSHA1" // want `"PKCS1WithSHA1" can be replaced by tls\.PKCS1WithSHA1\.String\(\)`
12 | _ = "PKCS1WithSHA256" // want `"PKCS1WithSHA256" can be replaced by tls\.PKCS1WithSHA256\.String\(\)`
13 | _ = "PKCS1WithSHA384" // want `"PKCS1WithSHA384" can be replaced by tls\.PKCS1WithSHA384\.String\(\)`
14 | _ = "PKCS1WithSHA512" // want `"PKCS1WithSHA512" can be replaced by tls\.PKCS1WithSHA512\.String\(\)`
15 | _ = "PSSWithSHA256" // want `"PSSWithSHA256" can be replaced by tls\.PSSWithSHA256\.String\(\)`
16 | _ = "PSSWithSHA384" // want `"PSSWithSHA384" can be replaced by tls\.PSSWithSHA384\.String\(\)`
17 | _ = "PSSWithSHA512" // want `"PSSWithSHA512" can be replaced by tls\.PSSWithSHA512\.String\(\)`
18 | )
19 |
20 | const (
21 | _ = "ECDSAWithP256AndSHA256" // want `"ECDSAWithP256AndSHA256" can be replaced by tls\.ECDSAWithP256AndSHA256\.String\(\)`
22 | _ = "ECDSAWithP384AndSHA384" // want `"ECDSAWithP384AndSHA384" can be replaced by tls\.ECDSAWithP384AndSHA384\.String\(\)`
23 | _ = "ECDSAWithP521AndSHA512" // want `"ECDSAWithP521AndSHA512" can be replaced by tls\.ECDSAWithP521AndSHA512\.String\(\)`
24 | _ = "ECDSAWithSHA1" // want `"ECDSAWithSHA1" can be replaced by tls\.ECDSAWithSHA1\.String\(\)`
25 | _ = "Ed25519" // want `"Ed25519" can be replaced by tls\.Ed25519\.String\(\)`
26 | _ = "PKCS1WithSHA1" // want `"PKCS1WithSHA1" can be replaced by tls\.PKCS1WithSHA1\.String\(\)`
27 | _ = "PKCS1WithSHA256" // want `"PKCS1WithSHA256" can be replaced by tls\.PKCS1WithSHA256\.String\(\)`
28 | _ = "PKCS1WithSHA384" // want `"PKCS1WithSHA384" can be replaced by tls\.PKCS1WithSHA384\.String\(\)`
29 | _ = "PKCS1WithSHA512" // want `"PKCS1WithSHA512" can be replaced by tls\.PKCS1WithSHA512\.String\(\)`
30 | _ = "PSSWithSHA256" // want `"PSSWithSHA256" can be replaced by tls\.PSSWithSHA256\.String\(\)`
31 | _ = "PSSWithSHA384" // want `"PSSWithSHA384" can be replaced by tls\.PSSWithSHA384\.String\(\)`
32 | _ = "PSSWithSHA512" // want `"PSSWithSHA512" can be replaced by tls\.PSSWithSHA512\.String\(\)`
33 | )
34 |
35 | var (
36 | _ = func(s string) string { return s }("ECDSAWithP256AndSHA256") // want `"ECDSAWithP256AndSHA256" can be replaced by tls\.ECDSAWithP256AndSHA256\.String\(\)`
37 | _ = func(s string) string { return s }("ECDSAWithP384AndSHA384") // want `"ECDSAWithP384AndSHA384" can be replaced by tls\.ECDSAWithP384AndSHA384\.String\(\)`
38 | _ = func(s string) string { return s }("ECDSAWithP521AndSHA512") // want `"ECDSAWithP521AndSHA512" can be replaced by tls\.ECDSAWithP521AndSHA512\.String\(\)`
39 | _ = func(s string) string { return s }("ECDSAWithSHA1") // want `"ECDSAWithSHA1" can be replaced by tls\.ECDSAWithSHA1\.String\(\)`
40 | _ = func(s string) string { return s }("Ed25519") // want `"Ed25519" can be replaced by tls\.Ed25519\.String\(\)`
41 | _ = func(s string) string { return s }("PKCS1WithSHA1") // want `"PKCS1WithSHA1" can be replaced by tls\.PKCS1WithSHA1\.String\(\)`
42 | _ = func(s string) string { return s }("PKCS1WithSHA256") // want `"PKCS1WithSHA256" can be replaced by tls\.PKCS1WithSHA256\.String\(\)`
43 | _ = func(s string) string { return s }("PKCS1WithSHA384") // want `"PKCS1WithSHA384" can be replaced by tls\.PKCS1WithSHA384\.String\(\)`
44 | _ = func(s string) string { return s }("PKCS1WithSHA512") // want `"PKCS1WithSHA512" can be replaced by tls\.PKCS1WithSHA512\.String\(\)`
45 | _ = func(s string) string { return s }("PSSWithSHA256") // want `"PSSWithSHA256" can be replaced by tls\.PSSWithSHA256\.String\(\)`
46 | _ = func(s string) string { return s }("PSSWithSHA384") // want `"PSSWithSHA384" can be replaced by tls\.PSSWithSHA384\.String\(\)`
47 | _ = func(s string) string { return s }("PSSWithSHA512") // want `"PSSWithSHA512" can be replaced by tls\.PSSWithSHA512\.String\(\)`
48 | )
49 |
--------------------------------------------------------------------------------
/pkg/analyzer/testdata/src/a/tls/signaturescheme.go.golden:
--------------------------------------------------------------------------------
1 | // Code generated by usestdlibvars, DO NOT EDIT.
2 |
3 | package tls_test
4 |
5 | var (
6 | _ = tls.ECDSAWithP256AndSHA256.String() // want `"ECDSAWithP256AndSHA256" can be replaced by tls\.ECDSAWithP256AndSHA256\.String\(\)`
7 | _ = tls.ECDSAWithP384AndSHA384.String() // want `"ECDSAWithP384AndSHA384" can be replaced by tls\.ECDSAWithP384AndSHA384\.String\(\)`
8 | _ = tls.ECDSAWithP521AndSHA512.String() // want `"ECDSAWithP521AndSHA512" can be replaced by tls\.ECDSAWithP521AndSHA512\.String\(\)`
9 | _ = tls.ECDSAWithSHA1.String() // want `"ECDSAWithSHA1" can be replaced by tls\.ECDSAWithSHA1\.String\(\)`
10 | _ = tls.Ed25519.String() // want `"Ed25519" can be replaced by tls\.Ed25519\.String\(\)`
11 | _ = tls.PKCS1WithSHA1.String() // want `"PKCS1WithSHA1" can be replaced by tls\.PKCS1WithSHA1\.String\(\)`
12 | _ = tls.PKCS1WithSHA256.String() // want `"PKCS1WithSHA256" can be replaced by tls\.PKCS1WithSHA256\.String\(\)`
13 | _ = tls.PKCS1WithSHA384.String() // want `"PKCS1WithSHA384" can be replaced by tls\.PKCS1WithSHA384\.String\(\)`
14 | _ = tls.PKCS1WithSHA512.String() // want `"PKCS1WithSHA512" can be replaced by tls\.PKCS1WithSHA512\.String\(\)`
15 | _ = tls.PSSWithSHA256.String() // want `"PSSWithSHA256" can be replaced by tls\.PSSWithSHA256\.String\(\)`
16 | _ = tls.PSSWithSHA384.String() // want `"PSSWithSHA384" can be replaced by tls\.PSSWithSHA384\.String\(\)`
17 | _ = tls.PSSWithSHA512.String() // want `"PSSWithSHA512" can be replaced by tls\.PSSWithSHA512\.String\(\)`
18 | )
19 |
20 | const (
21 | _ = tls.ECDSAWithP256AndSHA256.String() // want `"ECDSAWithP256AndSHA256" can be replaced by tls\.ECDSAWithP256AndSHA256\.String\(\)`
22 | _ = tls.ECDSAWithP384AndSHA384.String() // want `"ECDSAWithP384AndSHA384" can be replaced by tls\.ECDSAWithP384AndSHA384\.String\(\)`
23 | _ = tls.ECDSAWithP521AndSHA512.String() // want `"ECDSAWithP521AndSHA512" can be replaced by tls\.ECDSAWithP521AndSHA512\.String\(\)`
24 | _ = tls.ECDSAWithSHA1.String() // want `"ECDSAWithSHA1" can be replaced by tls\.ECDSAWithSHA1\.String\(\)`
25 | _ = tls.Ed25519.String() // want `"Ed25519" can be replaced by tls\.Ed25519\.String\(\)`
26 | _ = tls.PKCS1WithSHA1.String() // want `"PKCS1WithSHA1" can be replaced by tls\.PKCS1WithSHA1\.String\(\)`
27 | _ = tls.PKCS1WithSHA256.String() // want `"PKCS1WithSHA256" can be replaced by tls\.PKCS1WithSHA256\.String\(\)`
28 | _ = tls.PKCS1WithSHA384.String() // want `"PKCS1WithSHA384" can be replaced by tls\.PKCS1WithSHA384\.String\(\)`
29 | _ = tls.PKCS1WithSHA512.String() // want `"PKCS1WithSHA512" can be replaced by tls\.PKCS1WithSHA512\.String\(\)`
30 | _ = tls.PSSWithSHA256.String() // want `"PSSWithSHA256" can be replaced by tls\.PSSWithSHA256\.String\(\)`
31 | _ = tls.PSSWithSHA384.String() // want `"PSSWithSHA384" can be replaced by tls\.PSSWithSHA384\.String\(\)`
32 | _ = tls.PSSWithSHA512.String() // want `"PSSWithSHA512" can be replaced by tls\.PSSWithSHA512\.String\(\)`
33 | )
34 |
35 | var (
36 | _ = func(s string)string{return s}(tls.ECDSAWithP256AndSHA256.String()) // want `"ECDSAWithP256AndSHA256" can be replaced by tls\.ECDSAWithP256AndSHA256\.String\(\)`
37 | _ = func(s string)string{return s}(tls.ECDSAWithP384AndSHA384.String()) // want `"ECDSAWithP384AndSHA384" can be replaced by tls\.ECDSAWithP384AndSHA384\.String\(\)`
38 | _ = func(s string)string{return s}(tls.ECDSAWithP521AndSHA512.String()) // want `"ECDSAWithP521AndSHA512" can be replaced by tls\.ECDSAWithP521AndSHA512\.String\(\)`
39 | _ = func(s string)string{return s}(tls.ECDSAWithSHA1.String()) // want `"ECDSAWithSHA1" can be replaced by tls\.ECDSAWithSHA1\.String\(\)`
40 | _ = func(s string)string{return s}(tls.Ed25519.String()) // want `"Ed25519" can be replaced by tls\.Ed25519\.String\(\)`
41 | _ = func(s string)string{return s}(tls.PKCS1WithSHA1.String()) // want `"PKCS1WithSHA1" can be replaced by tls\.PKCS1WithSHA1\.String\(\)`
42 | _ = func(s string)string{return s}(tls.PKCS1WithSHA256.String()) // want `"PKCS1WithSHA256" can be replaced by tls\.PKCS1WithSHA256\.String\(\)`
43 | _ = func(s string)string{return s}(tls.PKCS1WithSHA384.String()) // want `"PKCS1WithSHA384" can be replaced by tls\.PKCS1WithSHA384\.String\(\)`
44 | _ = func(s string)string{return s}(tls.PKCS1WithSHA512.String()) // want `"PKCS1WithSHA512" can be replaced by tls\.PKCS1WithSHA512\.String\(\)`
45 | _ = func(s string)string{return s}(tls.PSSWithSHA256.String()) // want `"PSSWithSHA256" can be replaced by tls\.PSSWithSHA256\.String\(\)`
46 | _ = func(s string)string{return s}(tls.PSSWithSHA384.String()) // want `"PSSWithSHA384" can be replaced by tls\.PSSWithSHA384\.String\(\)`
47 | _ = func(s string)string{return s}(tls.PSSWithSHA512.String()) // want `"PSSWithSHA512" can be replaced by tls\.PSSWithSHA512\.String\(\)`
48 | )
49 |
--------------------------------------------------------------------------------