Skip to content

Commit 1ea85c7

Browse files
authored
cleanup code (#48)
Signed-off-by: sivchari <[email protected]>
1 parent b69ab3c commit 1ea85c7

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

tenv.go

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package tenv
22

33
import (
4-
"fmt"
54
"go/ast"
65
"go/token"
76
"go/types"
@@ -73,40 +72,33 @@ func checkStmts(pass *analysis.Pass, stmts []ast.Stmt, funcName, argName string)
7372
for _, stmt := range stmts {
7473
switch stmt := stmt.(type) {
7574
case *ast.ExprStmt:
76-
if !checkExprStmt(pass, stmt, funcName, argName) {
77-
continue
78-
}
75+
checkExprStmt(pass, stmt, funcName, argName)
7976
case *ast.IfStmt:
80-
if !checkIfStmt(pass, stmt, funcName, argName) {
81-
continue
82-
}
77+
checkIfStmt(pass, stmt, funcName, argName)
8378
case *ast.AssignStmt:
84-
if !checkAssignStmt(pass, stmt, funcName, argName) {
85-
continue
86-
}
79+
checkAssignStmt(pass, stmt, funcName, argName)
8780
case *ast.ForStmt:
8881
checkForStmt(pass, stmt, funcName, argName)
8982
}
9083
}
9184
}
9285

93-
func checkExprStmt(pass *analysis.Pass, stmt *ast.ExprStmt, funcName, argName string) bool {
86+
func checkExprStmt(pass *analysis.Pass, stmt *ast.ExprStmt, funcName, argName string) {
9487
callExpr, ok := stmt.X.(*ast.CallExpr)
9588
if !ok {
96-
return false
89+
return
9790
}
9891
checkArgs(pass, callExpr.Args, funcName, argName)
9992
ident, ok := callExpr.Fun.(*ast.Ident)
10093
if ok {
10194
obj := pass.TypesInfo.ObjectOf(ident)
102-
return checkObj(pass, obj, stmt.Pos(), funcName, argName)
95+
checkObj(pass, obj, stmt.Pos(), funcName, argName)
10396
}
10497
fun, ok := callExpr.Fun.(*ast.SelectorExpr)
10598
if ok {
10699
obj := pass.TypesInfo.ObjectOf(fun.Sel)
107-
return checkObj(pass, obj, stmt.Pos(), funcName, argName)
100+
checkObj(pass, obj, stmt.Pos(), funcName, argName)
108101
}
109-
return false
110102
}
111103

112104
func checkArgs(pass *analysis.Pass, args []ast.Expr, funcName, argName string) {
@@ -128,47 +120,45 @@ func checkArgs(pass *analysis.Pass, args []ast.Expr, funcName, argName string) {
128120
}
129121
}
130122

131-
func checkIfStmt(pass *analysis.Pass, stmt *ast.IfStmt, funcName, argName string) bool {
123+
func checkIfStmt(pass *analysis.Pass, stmt *ast.IfStmt, funcName, argName string) {
132124
assignStmt, ok := stmt.Init.(*ast.AssignStmt)
133125
if !ok {
134-
return false
126+
return
135127
}
136128
rhs, ok := assignStmt.Rhs[0].(*ast.CallExpr)
137129
if !ok {
138-
return false
130+
return
139131
}
140132
ident, ok := rhs.Fun.(*ast.Ident)
141133
if ok {
142134
obj := pass.TypesInfo.ObjectOf(ident)
143-
return checkObj(pass, obj, stmt.Pos(), funcName, argName)
135+
checkObj(pass, obj, stmt.Pos(), funcName, argName)
144136
}
145137
fun, ok := rhs.Fun.(*ast.SelectorExpr)
146138
if ok {
147139
obj := pass.TypesInfo.ObjectOf(fun.Sel)
148-
return checkObj(pass, obj, stmt.Pos(), funcName, argName)
140+
checkObj(pass, obj, stmt.Pos(), funcName, argName)
149141
}
150-
return false
151142
}
152143

153-
func checkAssignStmt(pass *analysis.Pass, stmt *ast.AssignStmt, funcName, argName string) bool {
144+
func checkAssignStmt(pass *analysis.Pass, stmt *ast.AssignStmt, funcName, argName string) {
154145
rhs, ok := stmt.Rhs[0].(*ast.CallExpr)
155146
if !ok {
156-
return false
147+
return
157148
}
158149
ident, ok := rhs.Fun.(*ast.Ident)
159150
if ok {
160151
obj := pass.TypesInfo.ObjectOf(ident)
161-
return checkObj(pass, obj, stmt.Pos(), funcName, argName)
152+
checkObj(pass, obj, stmt.Pos(), funcName, argName)
162153
}
163154
fun, ok := rhs.Fun.(*ast.SelectorExpr)
164155
if ok {
165156
obj := pass.TypesInfo.ObjectOf(fun.Sel)
166-
return checkObj(pass, obj, stmt.Pos(), funcName, argName)
157+
checkObj(pass, obj, stmt.Pos(), funcName, argName)
167158
}
168-
return false
169159
}
170160

171-
func checkObj(pass *analysis.Pass, obj types.Object, pos token.Pos, funcName, argName string) bool {
161+
func checkObj(pass *analysis.Pass, obj types.Object, pos token.Pos, funcName, argName string) {
172162
// For built-in objects, obj.Pkg() returns nil.
173163
var pkgPrefix string
174164
if pkg := obj.Pkg(); pkg != nil {
@@ -180,10 +170,8 @@ func checkObj(pass *analysis.Pass, obj types.Object, pos token.Pos, funcName, ar
180170
if argName == "" {
181171
argName = "testing"
182172
}
183-
fmt.Println(argName, funcName)
184173
pass.Reportf(pos, "os.Setenv() can be replaced by `%s.Setenv()` in %s", argName, funcName)
185174
}
186-
return true
187175
}
188176

189177
func checkForStmt(pass *analysis.Pass, stmt *ast.ForStmt, funcName, argName string) {

testdata/src/regression/go.sum

Whitespace-only changes.

0 commit comments

Comments
 (0)