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

False positive in Layout/EndAlignment for start_of_line style #5582

Closed
jonas054 opened this issue Feb 20, 2018 · 0 comments
Closed

False positive in Layout/EndAlignment for start_of_line style #5582

jonas054 opened this issue Feb 20, 2018 · 0 comments

Comments

@jonas054
Copy link
Collaborator

Here's a problem I found. I've made a fix myself. A PR will be submitted soon.

Expected behavior

No offense reported for the file.

Actual behavior

With the configuration

# .rubocop.yml
Layout/EndAlignment:
  EnforcedStyleAlignWith: start_of_line
  AutoCorrect: true

and the file

# file.rb
var =
  if test
  end

the command

rubocop --auto-correct

reports

Inspecting 1 file
W

Offenses:

file.rb:3:3: W: [Corrected] Layout/EndAlignment: end at 4, 2 is not aligned with var = at 2, 0.
  end
  ^^^

1 file inspected, 1 offense detected, 1 offense corrected

There are two problems with this.

  1. var = is not at the start of the line where if is, so end should not be aligned with it.
  2. It says [Corrected] but no correction is made.

Steps to reproduce the problem

Run rubocop -a in a directory with file.rb and .rubocop.yml as described.

RuboCop version

$ rubocop -V
0.52.1 (using Parser 2.5.0.0, running on ruby 2.5.0 x86_64-linux)
jonas054 added a commit to jonas054/rubocop that referenced this issue Feb 20, 2018
Correctly handle code like

var =
  if test
    do_something
  end

We do keyword alignment regadless of style, because aligning with the
variable:

var =
  if test
    do_something
end

doesn't look good when there's a line break.
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

No branches or pull requests

1 participant