-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Style/GuardClause weird parsing problem #2557
Comments
compare to this:
which produces expected result:
|
The reason for the weird behavior is the interaction between When |
Ah, yes, that makes sense, thanks! |
The reason for this is that |
Regarding
What makes more sense? |
Second one please - this is still a useful cop in the exit scope case even if the guard doesn't fit on one line.
|
@alexdowad What if my_var != 'd'
fail "ERROR #{my_var}" \
'ERROR'
else
puts 'ok wtf'
end to fail "ERROR #{my_var}" 'ERROR' if my_var != 'd'
puts 'ok wtf' or something, which I think is overstepping its authority. What it should want (and ideally auto-correct to) is IMO if my_var != 'd'
fail "ERROR #{my_var}" \
'ERROR'
end
puts 'ok wtf' and then let |
in case it's useful @alexdowad here's a better test case:
demo of the unexpected behaviour:
Expected behaviour: fail both cops when doing the first ( |
of course, if everyone stuck to line length limits this wouldn't be a problem... |
I'm thinking that |
I think that's fine as a solution for the problem reported here. I see some other problems with the current behavior of |
Sure. File those issues! Btw, my initial idea was to have GuardClase operate only upon trivial conditions (e.g. just one term), but for some reason I never got to actually changing this behaviour. It seems to me that guard clauses are a great option for simple conditions, but they hamper the readability otherwise. |
I've been experiencing weird behaviour on our codebase using the latest git version of rubocop, where
--auto-gen-config
does not detect cop offenses but subsequent runs of rubocop do. Here is the smallest reproducing piece of code I can create that triggers the bug with Style/GuardClause - there are several features in this code snippet that should be removed but if I remove any one of them I no longer trigger the bug (eg. the line >80 chars, the attribute in the string in the multi-line fail).And here is the weird behaviour:
The text was updated successfully, but these errors were encountered: