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

[Fix #6566] Fix a false positive for Layout/EmptyLinesAroundAccessModifier #6576

Conversation

koic
Copy link
Member

@koic koic commented Dec 12, 2018

Fixes #6566.

This PR fixes a false positive for Layout/EmptyLinesAroundAccessModifier when at the end of specifying a superclass is missing blank line.

The following is originally no offense code.
(It is probably a regression by #6307 💦)

% cat example.rb
class SomeController < SomeOtherController
  def index; end

  private
end

% rubocop example.rb --only Layout/EmptyLinesAroundAccessModifier -a
Inspecting 1 file
C

Offenses:

example.rb:4:3: C: [Corrected] Layout/EmptyLinesAroundAccessModifier:
Keep a blank line before and after private.
  private
  ^^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected

Auto-correct adds a blank line after private. This is due to false positives.

 % cat example.rb
 class SomeController < SomeOtherController
   def index; end

   private
+
 end

This caused the infinite loop in Layout/EmptyLinesAroundAccessModifier and Layout/EmptyLinesAroundClassBody.

% rubocop example.rb --only Layout/EmptyLinesAroundClassBody -a
Inspecting 1 file
C

Offenses:

example.rb:5:1: C: [Corrected] Layout/EmptyLinesAroundClassBody: Extra
empty line detected at class body end.

1 file inspected, 1 offense detected, 1 offense corrected

Auto-correct removes the blank line from after of private.

 % cat example.rb
 class SomeController < SomeOtherController
   def index; end

   private
-
 end

It loops to the first code. This PR fixes the infinite loop.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

Copy link
Collaborator

@Drenmi Drenmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

…ccessModifier`

Fixes rubocop#6566.

This PR fixes a false positive for `Layout/EmptyLinesAroundAccessModifier`
when at the end of specifying a superclass is missing blank line.

The following is originally no offense code.
(It is probably a regression by rubocop#6307)

```console
% cat example.rb
class SomeController < SomeOtherController
  def index; end

  private
end

% rubocop example.rb --only Layout/EmptyLinesAroundAccessModifier -a
Inspecting 1 file
C

Offenses:

example.rb:4:3: C: [Corrected] Layout/EmptyLinesAroundAccessModifier:
Keep a blank line before and after private.
  private
  ^^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected
```

Auto-correct adds a blank line after `private`. This is due to false positives.

```diff
 % cat example.rb
 class SomeController < SomeOtherController
   def index; end

   private
+
 end
```

This caused the infinite loop in `Layout/EmptyLinesAroundAccessModifier` and
`Layout/EmptyLinesAroundClassBody`.

```console
% rubocop example.rb --only Layout/EmptyLinesAroundClassBody -a
Inspecting 1 file
C

Offenses:

example.rb:5:1: C: [Corrected] Layout/EmptyLinesAroundClassBody: Extra
empty line detected at class body end.

1 file inspected, 1 offense detected, 1 offense corrected
```

Auto-correct removes the blank line from after of `private`.

```diff
 % cat example.rb
 class SomeController < SomeOtherController
   def index; end

   private
-
 end
```

It loops to the first code. This PR fixes the infinite loop.
@koic koic force-pushed the fix_a_false_positive_for_empty_lines_around_access_modifier branch from f68b0dc to d663841 Compare December 14, 2018 04:48
@bbatsov bbatsov merged commit ab49526 into rubocop:master Dec 14, 2018
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 14, 2018

Thanks!

@koic koic deleted the fix_a_false_positive_for_empty_lines_around_access_modifier branch December 14, 2018 09:33
koic added a commit to koic/rubocop that referenced this pull request Apr 26, 2019
This PR fixes a false positive for `Layout/EmptyLinesAroundAccessModifier`
when at the end of specifying `self` is missing blank line.

It is a regression with the following commits.
rubocop@4d70950

This PR fixes an infinite loop similar to rubocop#6576.

This issue occurred only on master branch, it will not be described
in the changelog.
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 this pull request may close these issues.

Infinite loop detected with trailing private keyword in controller
3 participants