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 generates invalid code #7776

Closed
adfoster-r7 opened this issue Mar 5, 2020 · 2 comments
Closed

Rubocop generates invalid code #7776

adfoster-r7 opened this issue Mar 5, 2020 · 2 comments
Labels

Comments

@adfoster-r7
Copy link

adfoster-r7 commented Mar 5, 2020

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

class Bar
  def initialize(*args)
  end
end

class Foo < Bar
  def initialize
    super(foo(bar,
      'ExpiresAt' => {'Hours' => 60 * 60 * 24} # 24h
    ))
  end
end

Expected behavior

Not to generate invalid ruby code

Actual behavior

Invalid ruby code is created due to the comment handling of # 24 h

# frozen_string_literal: true
class Bar
  def initialize(*args); end
end

class Foo < Bar
  def initialize
    super(foo(bar,
              'ExpiresAt' => { 'Hours' => 60 * 60 * 24 }) # 24h)
  end
end

Steps to reproduce the problem

  1. Create new ruby file
  2. add original code snippet
  3. bundle exec rubocop -a 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)
@Drenmi Drenmi added the bug label Mar 5, 2020
@bmorrall
Copy link
Contributor

bmorrall commented Mar 9, 2020

Had a quick look at this, running autocorrect with only the Layout/MultilineMethodCallBraceLayout Cop produces this error.

@MattBeaty
Copy link

I'd like to help out on this project. Mind if I take a crack at this issue?

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

No branches or pull requests

4 participants