@@ -3,7 +3,6 @@ package checkers
3
3
import (
4
4
"go/ast"
5
5
"go/token"
6
- "go/types"
7
6
8
7
"golang.org/x/tools/go/analysis"
9
8
@@ -204,101 +203,10 @@ func (checker BoolCompare) Check(pass *analysis.Pass, call *CallMeta) *analysis.
204
203
return nil
205
204
}
206
205
207
- func isEmptyInterface (pass * analysis.Pass , expr ast.Expr ) bool {
208
- t , ok := pass .TypesInfo .Types [expr ]
209
- if ! ok {
210
- return false
211
- }
212
-
213
- iface , ok := t .Type .Underlying ().(* types.Interface )
214
- return ok && iface .NumMethods () == 0
215
- }
216
-
217
- func isBuiltinBool (pass * analysis.Pass , e ast.Expr ) bool {
218
- basicType , ok := pass .TypesInfo .TypeOf (e ).(* types.Basic )
219
- return ok && basicType .Kind () == types .Bool
220
- }
221
-
222
- func isBoolOverride (pass * analysis.Pass , e ast.Expr ) bool {
223
- namedType , ok := pass .TypesInfo .TypeOf (e ).(* types.Named )
224
- return ok && namedType .Obj ().Name () == "bool"
225
- }
226
-
227
- var (
228
- falseObj = types .Universe .Lookup ("false" )
229
- trueObj = types .Universe .Lookup ("true" )
230
- )
231
-
232
- func isUntypedTrue (pass * analysis.Pass , e ast.Expr ) bool {
233
- return analysisutil .IsObj (pass .TypesInfo , e , trueObj )
234
- }
235
-
236
- func isUntypedFalse (pass * analysis.Pass , e ast.Expr ) bool {
237
- return analysisutil .IsObj (pass .TypesInfo , e , falseObj )
238
- }
239
-
240
- func isComparisonWithTrue (pass * analysis.Pass , e ast.Expr , op token.Token ) (ast.Expr , bool ) {
241
- return isComparisonWith (pass , e , isUntypedTrue , op )
242
- }
243
-
244
- func isComparisonWithFalse (pass * analysis.Pass , e ast.Expr , op token.Token ) (ast.Expr , bool ) {
245
- return isComparisonWith (pass , e , isUntypedFalse , op )
246
- }
247
-
248
- type predicate func (pass * analysis.Pass , e ast.Expr ) bool
249
-
250
- func isComparisonWith (pass * analysis.Pass , e ast.Expr , predicate predicate , op token.Token ) (ast.Expr , bool ) {
251
- be , ok := e .(* ast.BinaryExpr )
252
- if ! ok {
253
- return nil , false
254
- }
255
- if be .Op != op {
256
- return nil , false
257
- }
258
-
259
- t1 , t2 := predicate (pass , be .X ), predicate (pass , be .Y )
260
- if xor (t1 , t2 ) {
261
- if t1 {
262
- return be .Y , true
263
- }
264
- return be .X , true
265
- }
266
- return nil , false
267
- }
268
-
269
206
func isNegation (e ast.Expr ) (ast.Expr , bool ) {
270
207
ue , ok := e .(* ast.UnaryExpr )
271
208
if ! ok {
272
209
return nil , false
273
210
}
274
211
return ue .X , ue .Op == token .NOT
275
212
}
276
-
277
- func xor (a , b bool ) bool {
278
- return a != b
279
- }
280
-
281
- // anyVal returns the first value[i] for which bools[i] is true.
282
- func anyVal [T any ](bools []bool , vals ... T ) (T , bool ) {
283
- if len (bools ) != len (vals ) {
284
- panic ("inconsistent usage of valOr" ) //nolint:forbidigo // Does not depend on the code being analyzed.
285
- }
286
-
287
- for i , b := range bools {
288
- if b {
289
- return vals [i ], true
290
- }
291
- }
292
-
293
- var _default T
294
- return _default , false
295
- }
296
-
297
- func anyCondSatisfaction (pass * analysis.Pass , p predicate , vals ... ast.Expr ) bool {
298
- for _ , v := range vals {
299
- if p (pass , v ) {
300
- return true
301
- }
302
- }
303
- return false
304
- }
0 commit comments