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

Rubocop places commas into comments, generating invalid ruby code #7777

Closed
adfoster-r7 opened this issue Mar 5, 2020 · 2 comments · Fixed by #8237
Closed

Rubocop places commas into comments, generating invalid ruby code #7777

adfoster-r7 opened this issue Mar 5, 2020 · 2 comments · Fixed by #8237
Labels

Comments

@adfoster-r7
Copy link

When formatting the following code, rubocop will generate invalid ruby:

class Bar
  def initialize(*args)
  end
end

class Foo < Bar
  def initialize
    super(
      'firstKey' => [ 'value a', #description1
                      'value b' #description2
      ],
      'secondKey' => 'Bar'
    )
  end
end

Expected behavior

Not to generate invalid ruby code

Actual behavior

Invalid ruby code is created due to incorrectly handling the comment and placing a comma on the comment line:

class Bar
  def initialize(*args)
  end
end

class Foo < Bar
  def initialize
    super(
      'firstKey' => ['value a', # description1
                      'value b'] # description2,
      'secondKey' => 'Bar'
    )
  end
end

Steps to reproduce the problem

  1. Create new ruby file
  2. add original code snippet
  3. bundle exec rubocop -x --safe-auto-correct new_file.rb
  4. Run again, verify invalid ruby code has been generated

RuboCop version

$ [bundle exec] rubocop -V
0.80.0 (using Parser 2.7.0.2, running on ruby 2.6.5 x86_64-darwin18)
@bbatsov bbatsov added the bug label Mar 5, 2020
@MattBeaty
Copy link

whoever works on #7776 should also work on this issue.

@shekhar-patil
Copy link
Contributor

I am working on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment