1
0
mirror of https://github.com/mgechev/revive.git synced 2025-11-23 22:04:49 +02:00

rule optimize-operands-order: do not consider built-in len as a caller (#1005)

This commit is contained in:
Kostas Stamatakis
2024-07-02 09:22:13 +03:00
committed by GitHub
parent 0df1bb0860
commit 689291fbcb
2 changed files with 25 additions and 2 deletions

View File

@@ -27,6 +27,20 @@ func conditionalExpr(x, y bool) bool {
return caller(x, y) && y // MATCH /for better performance 'caller(x, y) && y' might be rewritten as 'y && caller(x, y)'/
}
func conditionalExprSlice(s []string) bool {
if len(s) > 0 || s[0] == "" { // should not match, not safe
return false
}
f := func() bool {
len(s) > 1
}
if f() || s[0] == "test" { // MATCH /for better performance 'f() || s[0] == "test"' might be rewritten as 's[0] == "test" || f()'/
return true
}
}
func caller(x, y bool) bool {
return true
}