@@ -43,20 +43,17 @@ var (
43
43
(IfStmt
44
44
nil
45
45
cond
46
- [fret @(ReturnStmt _)]
46
+ [fullret @(ReturnStmt _)]
47
47
nil)
48
48
` )
49
49
checkIfReturnQRet = pattern .MustParse (`
50
- (Binding "fret " (ReturnStmt _))
50
+ (Binding "fullret " (ReturnStmt _))
51
51
` )
52
52
checkReturnValue = pattern .MustParse (`
53
- (Or
54
- (ReturnStmt
55
- (List
56
- ret@(Builtin (Or "true" "false"))
57
- tail@(Any)))
58
- (ReturnStmt
59
- [ret@(Builtin (Or "true" "false"))]))
53
+ (ReturnStmt
54
+ (List
55
+ ret@(Builtin (Or "true" "false"))
56
+ tail@(Any)))
60
57
` )
61
58
)
62
59
@@ -75,31 +72,31 @@ func run(pass *analysis.Pass) (interface{}, error) {
75
72
return
76
73
}
77
74
}
78
- fm1 , ok := code .Match (pass , checkIfReturnQIf , n1 )
75
+ fullm1 , ok := code .Match (pass , checkIfReturnQIf , n1 )
79
76
if ! ok {
80
77
return
81
78
}
82
- fm2 , ok := code .Match (pass , checkIfReturnQRet , n2 )
79
+ fullm2 , ok := code .Match (pass , checkIfReturnQRet , n2 )
83
80
if ! ok {
84
81
return
85
82
}
86
83
87
- if op , ok := fm1 .State ["cond" ].(* ast.BinaryExpr ); ok {
84
+ if op , ok := fullm1 .State ["cond" ].(* ast.BinaryExpr ); ok {
88
85
switch op .Op {
89
86
case token .EQL , token .LSS , token .GTR , token .NEQ , token .LEQ , token .GEQ :
90
87
default :
91
88
return
92
89
}
93
90
}
94
91
95
- fret1 := fm1 .State ["fret " ].(* ast.ReturnStmt )
96
- m1 , ok := code .Match (pass , checkReturnValue , fret1 )
92
+ fullret1 := fullm1 .State ["fullret " ].(* ast.ReturnStmt )
93
+ m1 , ok := code .Match (pass , checkReturnValue , fullret1 )
97
94
if ! ok {
98
95
return
99
96
}
100
97
101
- fret2 := fm2 .State ["fret " ].(* ast.ReturnStmt )
102
- m2 , ok := code .Match (pass , checkReturnValue , fret2 )
98
+ fullret2 := fullm2 .State ["fullret " ].(* ast.ReturnStmt )
99
+ m2 , ok := code .Match (pass , checkReturnValue , fullret2 )
103
100
if ! ok {
104
101
return
105
102
}
@@ -121,7 +118,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
121
118
return
122
119
}
123
120
124
- cond := fm1 .State ["cond" ].(ast.Expr )
121
+ cond := fullm1 .State ["cond" ].(ast.Expr )
125
122
origCond := cond
126
123
if ret1 .Name == "false" {
127
124
cond = negate (pass , cond )
@@ -146,22 +143,22 @@ func run(pass *analysis.Pass) (interface{}, error) {
146
143
return nil , nil
147
144
}
148
145
149
- func getRetAndTail (m1 * pattern.Matcher ) (* ast.Ident , []ast.Expr ) {
150
- ret1 := m1 .State ["ret" ].(* ast.Ident )
151
- var tail1 []ast.Expr
152
- if tail , ok := m1 .State ["tail" ]; ok {
153
- tail1 , _ = tail .([]ast.Expr )
146
+ func getRetAndTail (m * pattern.Matcher ) (* ast.Ident , []ast.Expr ) {
147
+ ret1 := m .State ["ret" ].(* ast.Ident )
148
+ var tail []ast.Expr
149
+ if t , ok := m .State ["tail" ]; ok {
150
+ tail , _ = t .([]ast.Expr )
154
151
}
155
- return ret1 , tail1
152
+ return ret1 , tail
156
153
}
157
154
158
155
func renderTailString (pass * analysis.Pass , tail []ast.Expr ) string {
159
- var tail1StringBuilder strings.Builder
156
+ var tailStringBuilder strings.Builder
160
157
if len (tail ) != 0 {
161
- tail1StringBuilder .WriteString (", " )
162
- tail1StringBuilder .WriteString (report .RenderArgs (pass , tail ))
158
+ tailStringBuilder .WriteString (", " )
159
+ tailStringBuilder .WriteString (report .RenderArgs (pass , tail ))
163
160
}
164
- return tail1StringBuilder .String ()
161
+ return tailStringBuilder .String ()
165
162
}
166
163
167
164
func negate (pass * analysis.Pass , expr ast.Expr ) ast.Expr {
0 commit comments