Navigation Menu

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

Layout/EndAlignment can't autocorrect condensed case statements #7778

Closed
tas50 opened this issue Mar 5, 2020 · 0 comments · Fixed by #7794
Closed

Layout/EndAlignment can't autocorrect condensed case statements #7778

tas50 opened this issue Mar 5, 2020 · 0 comments · Fixed by #7794

Comments

@tas50
Copy link
Contributor

tas50 commented Mar 5, 2020

Expected behavior

Given an oddly condensed case statement where the end is on the same line as the else RuboCop should be able to autocorrect the end onto its own line.

        case other
        when IniFile then other.instance_variable_get(:@ini).keys
        when Hash then other.keys
        else raise "cannot merge contents from '#{other.class.name}'" end

Actual behavior

The issue is identified, but doesn't autocorrect

Layout/EndAlignment: end at 201, 70 is not aligned with case at 198, 8.
        else raise "cannot merge contents from '#{other.class.name}'" end
                                                                      ^^^

Steps to reproduce the problem

Run RuboCop 0.80.1 against the code block above.

RuboCop version

0.80.1
koic added a commit to koic/rubocop that referenced this issue Mar 19, 2020
Resolves rubocop#7778.

This PR resolves a false positive for `Layout/EndAlignment`
when a non-whitespace is used before the `end` keyword.

```console
% cat example.rb
if cond
else 'foo' end

% bundle exec rubocop -a --only Layout/EndAlignment
(snip)

Inspecting 1 file
W

Offenses:

example.rb:2:12: W: Layout/EndAlignment: end at 2, 11 is not aligned
with if at 1, 0.
else 'foo' end
           ^^^

1 file inspected, 1 offense detected
```

This PR changes to not offense it.

I think the responsibility will be clear if different (maybe new) cop like
`Layout/BlockEndNewline` cop handle the offense case.
So I think this role is preferably separated by `Layout/EndAlignment` cop.
koic added a commit that referenced this issue Mar 19, 2020
…rd_alignment

[Fix #7778] Fix a false positive for `Layout/EndAlignment`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant