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

Style/EmptyLinesAroundAccessModifier autocorrection splits comment after access modifier #4268

Closed
vergenzt opened this issue Apr 12, 2017 · 0 comments · Fixed by #4273
Closed

Comments

@vergenzt
Copy link
Contributor

vergenzt commented Apr 12, 2017

When an access modifier has a comment on the same line and is not followed by an empty line, the autocorrection for Style/EmptyLinesAroundAccessModifier inserts the newline before the comment. I would expect it to insert the newline after the comment.

(I discovered this while working on #4127 because this bug broke the # rubocop:disable Lint/UselessAccessModifier my change added to a line. I'm working on a fix.)

Example

class Example
  something

  private # let's make the rest private
  def example; end
end

Expected correction

class Example
  something

  private # let's make the rest private

  def example; end
end

Actual correction

(one iteration)

class Example
  something

  private
 # let's make the rest private
  def example; end
end

Steps to reproduce

From an updated rubocop clone:

  1. git checkout fd25562
  2. curl https://gist.githubusercontent.com/vergenzt/ac933335208576084a9e464e42f12ad6/raw/f15b4b6cabbf603032e9cc111be9ba2e7f4a0c1f/spec.diff | git apply
  3. rspec spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb

(Gist link)

RuboCop version

$ rubocop -V
0.48.1 (using Parser 2.4.0.0, running on ruby 2.2.1 x86_64-darwin14)
vergenzt added a commit to vergenzt/rubocop that referenced this issue Apr 13, 2017
…oundAccessModifier

Previously the autocorrect implementation inserted a newline at the end of the access modifier
_node_ instead of at the end of the line. This fixes that.
bbatsov pushed a commit that referenced this issue Apr 14, 2017
…essModifier

Previously the autocorrect implementation inserted a newline at the end of the access modifier
_node_ instead of at the end of the line. This fixes that.
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.

1 participant