OLD | NEW |
1 // Copyright 2014 The Go Authors. All rights reserved. | 1 // Copyright 2014 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // This file contains boolean condition tests. | 5 // This file contains boolean condition tests. |
6 | 6 |
7 package main | 7 package main |
8 | 8 |
9 import ( | 9 import ( |
10 "go/ast" | 10 "go/ast" |
11 "go/token" | 11 "go/token" |
12 ) | 12 ) |
13 | 13 |
14 func init() { | 14 func init() { |
15 register("bool", | 15 register("bool", |
16 "check for mistakes involving boolean operators", | 16 "check for mistakes involving boolean operators", |
| 17 filterBool, |
17 checkBool, | 18 checkBool, |
18 binaryExpr) | 19 binaryExpr) |
19 } | 20 } |
20 | 21 |
| 22 func filterBool(f *File) bool { return true } |
| 23 |
21 func checkBool(f *File, n ast.Node) { | 24 func checkBool(f *File, n ast.Node) { |
22 e := n.(*ast.BinaryExpr) | 25 e := n.(*ast.BinaryExpr) |
23 | 26 |
24 var op boolOp | 27 var op boolOp |
25 switch e.Op { | 28 switch e.Op { |
26 case token.LOR: | 29 case token.LOR: |
27 op = or | 30 op = or |
28 case token.LAND: | 31 case token.LAND: |
29 op = and | 32 op = and |
30 default: | 33 default: |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 179 |
177 func unparen(e ast.Expr) ast.Expr { | 180 func unparen(e ast.Expr) ast.Expr { |
178 for { | 181 for { |
179 p, ok := e.(*ast.ParenExpr) | 182 p, ok := e.(*ast.ParenExpr) |
180 if !ok { | 183 if !ok { |
181 return e | 184 return e |
182 } | 185 } |
183 e = p.X | 186 e = p.X |
184 } | 187 } |
185 } | 188 } |
OLD | NEW |