| 1 |
package pkg |
| 2 |
|
| 3 |
func fn() bool { return true } |
| 4 |
func fn1() bool { |
| 5 |
x := true |
| 6 |
if x { //@ diag(`should use 'return x'`) |
| 7 |
return true |
| 8 |
} |
| 9 |
return false |
| 10 |
} |
| 11 |
|
| 12 |
func fn2() bool { |
| 13 |
x := true |
| 14 |
if !x { |
| 15 |
return true |
| 16 |
} |
| 17 |
if x { |
| 18 |
return true |
| 19 |
} |
| 20 |
return false |
| 21 |
} |
| 22 |
|
| 23 |
func fn3() int { |
| 24 |
var x bool |
| 25 |
if x { |
| 26 |
return 1 |
| 27 |
} |
| 28 |
return 2 |
| 29 |
} |
| 30 |
|
| 31 |
func fn4() bool { return true } |
| 32 |
|
| 33 |
func fn5() bool { |
| 34 |
if fn() { //@ diag(`should use 'return !fn()'`) |
| 35 |
return false |
| 36 |
} |
| 37 |
return true |
| 38 |
} |
| 39 |
|
| 40 |
func fn6() bool { |
| 41 |
if fn3() != fn3() { //@ diag(`should use 'return fn3() != fn3()'`) |
| 42 |
return true |
| 43 |
} |
| 44 |
return false |
| 45 |
} |
| 46 |
|
| 47 |
func fn7() bool { |
| 48 |
if 1 > 2 { //@ diag(`should use 'return 1 > 2'`) |
| 49 |
return true |
| 50 |
} |
| 51 |
return false |
| 52 |
} |
| 53 |
|
| 54 |
func fn8() bool { |
| 55 |
if fn() || fn() { |
| 56 |
return true |
| 57 |
} |
| 58 |
return false |
| 59 |
} |
| 60 |
|
| 61 |
func fn9(x int) bool { |
| 62 |
if x > 0 { |
| 63 |
return true |
| 64 |
} |
| 65 |
return true |
| 66 |
} |
| 67 |
|
| 68 |
func fn10(x int) bool { |
| 69 |
if x > 0 { //@ diag(`should use 'return x <= 0'`) |
| 70 |
return false |
| 71 |
} |
| 72 |
return true |
| 73 |
} |
| 74 |
|
| 75 |
func fn11(x bool) bool { |
| 76 |
if x { //@ diag(`should use 'return !x'`) |
| 77 |
return false |
| 78 |
} |
| 79 |
return true |
| 80 |
} |
| 81 |
|
| 82 |
func fn12() bool { |
| 83 |
var x []bool |
| 84 |
if x[0] { //@ diag(`should use 'return !x[0]'`) |
| 85 |
return false |
| 86 |
} |
| 87 |
return true |
| 88 |
} |
| 89 |
|
| 90 |
func fn13(a, b int) bool { |
| 91 |
if a != b { //@ diag(`should use 'return a == b' instead of 'if a != b`) |
| 92 |
return false |
| 93 |
} |
| 94 |
return true |
| 95 |
} |
| 96 |
|
| 97 |
func fn14(a, b int) bool { |
| 98 |
if a >= b { //@ diag(`should use 'return a < b' instead of 'if a >= b`) |
| 99 |
return false |
| 100 |
} |
| 101 |
return true |
| 102 |
} |
| 103 |
|
| 104 |
func fn15() bool { |
| 105 |
if !fn() { //@ diag(`should use 'return fn()'`) |
| 106 |
return false |
| 107 |
} |
| 108 |
return true |
| 109 |
} |
| 110 |
|
| 111 |
func fn16() <-chan bool { |
| 112 |
x := make(chan bool, 1) |
| 113 |
x <- true |
| 114 |
return x |
| 115 |
} |
| 116 |
|
| 117 |
func fn17() bool { |
| 118 |
if <-fn16() { //@ diag(`should use 'return !<-fn16()'`) |
| 119 |
return false |
| 120 |
} |
| 121 |
return true |
| 122 |
} |
| 123 |
|
| 124 |
func fn18() *bool { |
| 125 |
x := true |
| 126 |
return &x |
| 127 |
} |
| 128 |
|
| 129 |
func fn19() bool { |
| 130 |
if *fn18() { //@ diag(`should use 'return !*fn18()'`) |
| 131 |
return false |
| 132 |
} |
| 133 |
return true |
| 134 |
} |
| 135 |
|
| 136 |
const a = true |
| 137 |
const b = false |
| 138 |
|
| 139 |
func fn20(x bool) bool { |
| 140 |
// Don't match on constants other than the predeclared true and false. This protects us both from build tag woes, |
| 141 |
// and from code that breaks when the constant values change. |
| 142 |
if x { |
| 143 |
return a |
| 144 |
} |
| 145 |
return b |
| 146 |
} |
| 147 |
|
| 148 |
func fn21(x bool) bool { |
| 149 |
// Don't flag, 'true' isn't the predeclared identifier. |
| 150 |
const true = false |
| 151 |
if x { |
| 152 |
return true |
| 153 |
} |
| 154 |
return false |
| 155 |
} |
| 156 |
|
| 157 |
func fn22(x string) bool { |
| 158 |
if len(x) > 0 { //@ diag(`should use 'return len(x) == 0'`) |
| 159 |
return false |
| 160 |
} |
| 161 |
return true |
| 162 |
} |