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

Auto-correct for Style/MultilineArrayBraceLayout produces invalid code #3150

Closed
jspanjers opened this issue May 20, 2016 · 0 comments
Closed

Comments

@jspanjers
Copy link
Contributor

When you run auto-correct for Style/MultilineArrayBraceLayout on code with arrays containing trailing comma's, the output code contains errors.


Steps to reproduce the problem


$ cat > test.rb << EOF
# encoding: utf-8
# frozen_string_literal: true
class Test
  def test
    [a, # a
     b, # b
    ]
  end
end
EOF

$ bundle exec rubocop test.rb
Inspecting 1 file
C

Offenses:

test.rb:5:5: C: Closing array brace must be on the same line as the last array element when opening brace is on the same line as the first array element.
    [a, # a ...
    ^^^^^^^

1 file inspected, 1 offense detected


$ bundle exec rubocop --auto-correct test.rb
Inspecting 1 file
E

Offenses:

test.rb:5:5: C: [Corrected] Closing array brace must be on the same line as the last array element when opening brace is on the same line as the first array element.
    [a, # a ...
    ^^^^^^^
test.rb:6:8: E: unexpected token tCOMMA
(Using Ruby 1.9 parser; configure using TargetRubyVersion parameter, under AllCops)
     b], # b
       ^

1 file inspected, 2 offenses detected, 1 offense corrected


$ cat test.rb
# encoding: utf-8
# frozen_string_literal: true
class Test
  def test
    [a, # a
     b], # b
  end
end

RuboCop version

$ bundle exec rubocop -V
0.40.0 (using Parser 2.3.1.0, running on ruby 2.3.1 x86_64-linux)
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