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
Fix Lint/ElseLayout when using multi-branch statements #10147
Comments
Thank you, this is a really well reasoned issue. You are absolutely right, the inline style is going to be affected by this change, and it may in fact be the missing reason that As a I have a few thoughts that I need to think further on:
|
🙇 Daniel. Ha, yeah, it is definitely confusing that layout is in the
There is one other situation that might be worth pointing out. Take this mixed layout scenerio, for example (again, ignore the silly logic, just focus on the layout): if number == 1 then puts "One"
elsif number == 2
puts "Pellentque morbi-trist sentus et netus et malesuada fames ac turpis egestas."
else "Unknown"
end Notice that the second logic branch needs to be indented because it's too long (assumption being that the line limit cop would flag this otherwise so you switch to indented style for this branch). Granted, and depending on the situation, if you had more complex logic you might extract a private method to be called for the second branch logic rather than make the whole condition itself bloated but sometimes there is value in have a mixed layout too, I think. I think the above mixed layout scenerio is fine? Maybe? ...or would there need to be a configuration for indented, compact, mixed? |
Maybe the best solution would be to revert @bbatsov any thoughts? |
Hi everyone, here with the same oddity
I'm also getting Rubocop warnings regarding snippets like those, which... IMHO, seem perfectly fine (i.e. Looking forward to see how this develops. Cheers! |
@cetinajero I get that this isn't real code, but there are three different styles in that |
That's true @dvandersluis! As you mentioned, "... a new layout cop to check for consistent |
ℹ️ Closing this issue as I've verified this is fixed in Rubocop 1.24.0 by running Rubocop 124.0 against 30+ projects which use the one-line |
Apologies, everyone. I was able to prove this still occurs. I believe the reason I didn't detect this sooner was due to running Rubocop against some projects which hadn't cleared their local Rubocop cache which initially gave me a false positive. |
+1. Was just about to post the very same. What's the status on this one? Using 1.62.1.
|
Expected behavior
With the latest release of Rubocop, I'm noticing a behavioral change that I think is a bug or at least an oddity. This issue is related to this original issue. If I understand the intent of the original issue, I think it was intended for single
if
andelse
statement -- which makes sense -- but I think this breaks when used in anif..elsif..else
statement?Actual behavior
I'm seeing
Lint/ElseLayout
issues with single lineelse
in aif
statement that didn't get flagged before the change in the latest release. Below is the full output:Debug Trace
You can ignore the
Style/CaseLikeIf
issue as that's legit because I'm using acase
statement for comparison purposes below.Steps to reproduce the problem
Throw the following in
snippet.rb
and run Rubocop against it:The above code is silly but notice how the
else
in thecase
andif
statements used to be allowed. However, with the latest version, you now have to write theif
statement like this to fix theLint/ElseLayout
issue:This seems wrong to me because it's not consisent with
case
statements but, more importantly, if you have simple statements above theelse
all on one line, why can'telse
be a one liner as well in order to maintain symmetry?RuboCop version
The text was updated successfully, but these errors were encountered: