Style/GuardClause false positive for code like this:
b = nil
a =
if b
true || raise "err"
else
puts "else"
end
No trigger
Cop triggers on if statement
rubocop code above
$ [bundle exec] rubocop -V
0.82.0 (using Parser 2.7.1.2, running on ruby 2.6.6 x86_64-darwin19)
I think this is not a false positive, so it is an expected behavior:
# bad
if cond
foo || raise('hi')
else
bar
end
# good
foo || raise('hi') if cond
bar
OTOH, the offense message for that would be incorrect. I have opened a PR #7932. Thank you.
So:
# bad
a =
if cond
foo || raise('hi')
else
bar
end
# good
a = foo || raise('hi') if cond
a ||= bar
?
Ah, that case is a false positive. If assigned, this cop should be accept it. Seems to have multiple issues. I will open the patch for it.
I opened a PR #7935 to solve this issue.