Skip to content
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

Lint/ElseLayout does not warn when else contains only one line code #10130

Closed
ivodimitrov opened this issue Sep 27, 2021 · 2 comments · Fixed by #10131
Closed

Lint/ElseLayout does not warn when else contains only one line code #10130

ivodimitrov opened this issue Sep 27, 2021 · 2 comments · Fixed by #10131
Assignees
Labels

Comments

@ivodimitrov
Copy link

ivodimitrov commented Sep 27, 2021

Expected behavior

Warn when having an expression on the same line as the else keyword.

Actual behavior

Does not warn when having an expression on the same line as the else keyword and else statement contains only one line code.

Steps to reproduce the problem

Write one line code on the same line with else statement. Example:

if something
  # ...
else do_this
end

RuboCop version

$ [bundle exec] rubocop -V
1.21.0 (using Parser 3.0.2.0, rubocop-ast 1.11.0, running on ruby 2.7.2 x86_64-darwin19)
@dvandersluis dvandersluis changed the title Lint::ElseLayout does not warn when else contains only one line code Layout/ElseLayout does not warn when else contains only one line code Sep 27, 2021
@dvandersluis
Copy link
Member

dvandersluis commented Sep 27, 2021

Layout/ElseLayout is only concerned with the actual alignment of the else and elsif keywords, not for not having other code on the same line.

That being said though, we probably should have a Layout cop for making sure the else body is not on the same line as the keyword.

Sorry I misunderstood the issue, I was looking at the wrong cop and didn't realize we had both ElseAlignment and ElseLayout 🤦 .

@dvandersluis dvandersluis changed the title Layout/ElseLayout does not warn when else contains only one line code Layout/ElseAlignment does not warn when else contains only one line code Sep 27, 2021
@dvandersluis dvandersluis changed the title Layout/ElseAlignment does not warn when else contains only one line code Layout/ElseLayout does not warn when else contains only one line code Sep 27, 2021
@dvandersluis dvandersluis self-assigned this Sep 27, 2021
@dvandersluis dvandersluis changed the title Layout/ElseLayout does not warn when else contains only one line code Lint/ElseLayout does not warn when else contains only one line code Sep 27, 2021
dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Sep 27, 2021
koic added a commit that referenced this issue Sep 28, 2021
[Fix #10130] Update `Lint/ElseLayout` to be able to handle an `else` with only a single line
@ivodimitrov
Copy link
Author

That issue was fixed really fast. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants