github.com/songshiyun/revive@v1.1.5-0.20220323112655-f8433a19b3c5/testdata/optimize-operands-order.go (about) 1 package fixtures 2 3 func conditionalExpr(x, y bool) bool { 4 equal := x == y // should not match, not AND or OR operators 5 if x || y { // should not match, no caller 6 return true 7 } 8 or := caller(x, y) || y // MATCH /for better performance 'caller(x, y) || y' might be rewritten as 'y || caller(x, y)'/ 9 if caller(x, y) || y { // MATCH /for better performance 'caller(x, y) || y' might be rewritten as 'y || caller(x, y)'/ 10 return true 11 } 12 13 switch { 14 case x == y: 15 return y 16 case caller(x, y) && y: // MATCH /for better performance 'caller(x, y) && y' might be rewritten as 'y && caller(x, y)'/ 17 return x 18 } 19 20 complexExpr := caller(caller(x, y) && y, y) || y 21 // MATCH:20 /for better performance 'caller(caller(x, y) && y, y) || y' might be rewritten as 'y || caller(caller(x, y) && y, y)'/ 22 // MATCH:20 /for better performance 'caller(x, y) && y' might be rewritten as 'y && caller(x, y)'/ 23 24 noSwap := caller(x, y) || (x && caller(y, x)) // should not match, caller in the right operand 25 26 callRight := caller(x, y) && (x && caller(y, x)) // should not match, caller in the right operand 27 return caller(x, y) && y // MATCH /for better performance 'caller(x, y) && y' might be rewritten as 'y && caller(x, y)'/ 28 } 29 30 func caller(x, y bool) bool { 31 return true 32 }