Closed moukoublen closed 5 days ago
Hi @moukoublen, thanks for reporting the issue and proposing a fix.
Personally, I use this rule to lint my code while I'm coding thus I can decide if the suggested modification is safe or not. That is because this rule can, as you pointed out, suggest unsafe/un-optimal code modifications.
@moukoublen thanks for identifying and fixed that
Personally, I use this rule to lint my code while I'm coding thus I can decide if the suggested modification is safe or not.
@chavacava I agree with you, but some people are applying suggested changes blindly. It's great that @moukoublen introduced a safeguard
Describe the bug In this case:
Rule
optimize-operands-order
reportsWhich could lead to panic if implemented.
To Reproduce Steps to reproduce the behavior:
go install github.com/mgechev/revive@latest
Expected behavior I think in this case, where the
len
check is essential to happen before slice accessing, the rule should not match.Additional context My first thought about fixing this was to not consider the built-in
len
function as a caller. I tried to change theisCaller
function in the optimize-operands-order.go file so that it does not consider the built-inlen
function as a caller.I opened a pr with this approach.