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/EmptyComment auto-correct incorrectly removes entire line #5674

Closed
DMA57361 opened this issue Mar 13, 2018 · 1 comment · Fixed by #5676
Closed

Layout/EmptyComment auto-correct incorrectly removes entire line #5674

DMA57361 opened this issue Mar 13, 2018 · 1 comment · Fixed by #5676

Comments

@DMA57361
Copy link


Expected behavior

Given the contrived example file example.rb:

def a_method #
  true
end

Rspec.describe Class do
  it 'will to a test' do #
    expect(true).to eq true
  end
end

When running rubocop example.rb --only Layout/EmptyComment --auto-correct

I expect two warnings for the two empty comments, and for them to be removed from the end of the two lines.

Actual behavior

The lines with the empty comments are completely removed from the source:

  true
end

Rspec.describe Class do
    expect(true).to eq true
  end
end

And the output of the Rubocop execution:

$ rubocop example.rb --only Layout/EmptyComment --auto-correct
Inspecting 1 file
E

Offenses:

example.rb:1:14: C: [Corrected] Layout/EmptyComment: Source code comment is empty.
def a_method #
             ^
example.rb:2:1: E: Lint/Syntax: unexpected token kEND
(Using Ruby 2.5 parser; configure using TargetRubyVersion parameter, under AllCops)
end
^^^
example.rb:6:26: C: [Corrected] Layout/EmptyComment: Source code comment is empty.
  it 'will to a test' do #
                         ^
example.rb:7:1: E: Lint/Syntax: unexpected token kEND
(Using Ruby 2.5 parser; configure using TargetRubyVersion parameter, under AllCops)
end
^^^

1 file inspected, 4 offenses detected, 2 offenses corrected

RuboCop version

$ rubocop -V
0.53.0 (using Parser 2.5.0.3, running on ruby 2.3.5 x86_64-darwin15)
@rrosenblum
Copy link
Contributor

It looks like this cop isn't accounting for empty comments next to code at all. The auto-correction is assuming that the line is going to be blank which is what is causing the issue.

rrosenblum added a commit to rrosenblum/rubocop that referenced this issue Mar 13, 2018
This was referenced Mar 21, 2018
This was referenced Mar 21, 2018
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.

2 participants