aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/sashamelentyev
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2024-09-10 12:16:33 +0200
committerTaras Madan <tarasmadan@google.com>2024-09-10 14:05:26 +0000
commitc97c816133b42257d0bcf1ee4bd178bb2a7a2b9e (patch)
tree0bcbc2e540bbf8f62f6c17887cdd53b8c2cee637 /vendor/github.com/sashamelentyev
parent54e657429ab892ad06c90cd7c1a4eb33ba93a3dc (diff)
vendor: update
Diffstat (limited to 'vendor/github.com/sashamelentyev')
-rw-r--r--vendor/github.com/sashamelentyev/usestdlibvars/pkg/analyzer/analyzer.go76
1 files changed, 13 insertions, 63 deletions
diff --git a/vendor/github.com/sashamelentyev/usestdlibvars/pkg/analyzer/analyzer.go b/vendor/github.com/sashamelentyev/usestdlibvars/pkg/analyzer/analyzer.go
index 4d6ab3cca..09f7c8240 100644
--- a/vendor/github.com/sashamelentyev/usestdlibvars/pkg/analyzer/analyzer.go
+++ b/vendor/github.com/sashamelentyev/usestdlibvars/pkg/analyzer/analyzer.go
@@ -63,9 +63,8 @@ func run(pass *analysis.Pass) (interface{}, error) {
(*ast.CallExpr)(nil),
(*ast.BasicLit)(nil),
(*ast.CompositeLit)(nil),
- (*ast.IfStmt)(nil),
+ (*ast.BinaryExpr)(nil),
(*ast.SwitchStmt)(nil),
- (*ast.ForStmt)(nil),
}
insp.Preorder(types, func(node ast.Node) {
@@ -116,54 +115,30 @@ func run(pass *analysis.Pass) (interface{}, error) {
typeElts(pass, x, typ, n.Elts)
- case *ast.IfStmt:
- cond, ok := n.Cond.(*ast.BinaryExpr)
- if !ok {
+ case *ast.BinaryExpr:
+ switch n.Op {
+ case token.LSS, token.GTR, token.LEQ, token.GEQ, token.QUO, token.ADD, token.SUB, token.MUL:
return
+ default:
}
- switch cond.Op {
- case token.LSS, token.GTR, token.LEQ, token.GEQ:
- return
- }
-
- x, ok := cond.X.(*ast.SelectorExpr)
+ x, ok := n.X.(*ast.SelectorExpr)
if !ok {
return
}
- y, ok := cond.Y.(*ast.BasicLit)
+ y, ok := n.Y.(*ast.BasicLit)
if !ok {
return
}
- ifElseStmt(pass, x, y)
+ binaryExpr(pass, x, y)
case *ast.SwitchStmt:
x, ok := n.Tag.(*ast.SelectorExpr)
if ok {
switchStmt(pass, x, n.Body.List)
- } else {
- switchStmtAsIfElseStmt(pass, n.Body.List)
- }
-
- case *ast.ForStmt:
- cond, ok := n.Cond.(*ast.BinaryExpr)
- if !ok {
- return
- }
-
- x, ok := cond.X.(*ast.SelectorExpr)
- if !ok {
- return
- }
-
- y, ok := cond.Y.(*ast.BasicLit)
- if !ok {
- return
}
-
- ifElseStmt(pass, x, y)
}
})
@@ -318,8 +293,11 @@ func typeElts(pass *analysis.Pass, x *ast.Ident, typ *ast.SelectorExpr, elts []a
}
}
-// ifElseStmt checks X and Y in if-else-statement.
-func ifElseStmt(pass *analysis.Pass, x *ast.SelectorExpr, y *ast.BasicLit) {
+// binaryExpr checks X and Y in binary expressions, including:
+// - if-else-statement
+// - for loops conditions
+// - switch cases without a tag expression
+func binaryExpr(pass *analysis.Pass, x *ast.SelectorExpr, y *ast.BasicLit) {
switch x.Sel.Name {
case "StatusCode":
if !lookupFlag(pass, HTTPStatusCodeFlag) {
@@ -376,34 +354,6 @@ func switchStmt(pass *analysis.Pass, x *ast.SelectorExpr, cases []ast.Stmt) {
}
}
-func switchStmtAsIfElseStmt(pass *analysis.Pass, cases []ast.Stmt) {
- for _, c := range cases {
- caseClause, ok := c.(*ast.CaseClause)
- if !ok {
- continue
- }
-
- for _, expr := range caseClause.List {
- binaryExpr, ok := expr.(*ast.BinaryExpr)
- if !ok {
- continue
- }
-
- x, ok := binaryExpr.X.(*ast.SelectorExpr)
- if !ok {
- continue
- }
-
- y, ok := binaryExpr.Y.(*ast.BasicLit)
- if !ok {
- continue
- }
-
- ifElseStmt(pass, x, y)
- }
- }
-}
-
func lookupFlag(pass *analysis.Pass, name string) bool {
return pass.Analyzer.Flags.Lookup(name).Value.(flag.Getter).Get().(bool)
}