Skip to content

Commit

Permalink
Remove range uses case in HTTP status (#90)
Browse files Browse the repository at this point in the history
Remove range uses case in HTTP status
  • Loading branch information
sashamelentyev authored Feb 16, 2023
1 parent c561d44 commit 8b9d590
Show file tree
Hide file tree
Showing 7 changed files with 1,317 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ main ]

env:
GO_VERSION: 1.19.4
GO_VERSION: 1.20.1

jobs:
run:
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module github.com/sashamelentyev/usestdlibvars

go 1.19

require golang.org/x/tools v0.5.0
require golang.org/x/tools v0.6.0

require (
golang.org/x/mod v0.7.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/sys v0.5.0 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.5.0 h1:+bSpV5HIeWkuvgaMfI3UmKRThoTA5ODJTUd8T17NO+4=
golang.org/x/tools v0.5.0/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
5 changes: 5 additions & 0 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ func run(pass *analysis.Pass) (interface{}, error) {
return
}

switch cond.Op {
case token.LSS, token.GTR, token.LEQ, token.GEQ:
return
}

x, ok := cond.X.(*ast.SelectorExpr)
if !ok {
return
Expand Down
6 changes: 6 additions & 0 deletions pkg/analyzer/internal/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ func main() {
templateName: "test-template.go.tmpl",
fileName: "pkg/analyzer/testdata/src/a/constant/kind.go",
},
{
mapping: mapping.HTTPStatusCode,
packageName: "http_test",
templateName: "test-issue89.go.tmpl",
fileName: "pkg/analyzer/testdata/src/a/http/issue89.go",
},
}

for _, operation := range operations {
Expand Down
42 changes: 42 additions & 0 deletions pkg/analyzer/internal/template/test-issue89.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Code generated by usestdlibvars, DO NOT EDIT.

package {{ .PackageName }}

import "net/http"

func _() error {
resp, err := http.DefaultClient.Do(&http.Request{})
if err != nil {
return err
}
defer func() { _ = resp.Body.Close() }()
{{- range $key, $value := .Mapping }}
if resp.StatusCode < {{ $key }} {
return nil
} else if resp.StatusCode < {{ $key }} {
return nil
}
{{- end }}
{{- range $key, $value := .Mapping }}
if resp.StatusCode > {{ $key }} {
return nil
} else if resp.StatusCode > {{ $key }} {
return nil
}
{{- end }}
{{- range $key, $value := .Mapping }}
if resp.StatusCode <= {{ $key }} {
return nil
} else if resp.StatusCode < {{ $key }} {
return nil
}
{{- end }}
{{- range $key, $value := .Mapping }}
if resp.StatusCode >= {{ $key }} {
return nil
} else if resp.StatusCode > {{ $key }} {
return nil
}
{{- end }}
return nil
}
Loading

0 comments on commit 8b9d590

Please sign in to comment.