Navigation Menu

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 a false positive for Layout/EmptyLinesAroundAccessModifier #8756

Conversation

koic
Copy link
Member

@koic koic commented Sep 21, 2020

This PR fixes the following infinite loop error for Layout/EmptyLinesAroundAccessModifier with Layout/EmptyLinesAroundBlockBody when using access modifier with block argument.

% cat example.rb
FactoryBot.define do
  factory :model do
    name { 'hoge' }

    private { true }
  end
end

% rubocop -a --only Layout/EmptyLinesAroundAccessModifier,Layout/EmptyLinesAroundBlockBody
(snip)

Inspecting 1 file
C

Offenses:

example.rb:5:5: C: [Corrected] Layout/EmptyLinesAroundAccessModifier:
Keep a blank line before and after private.
    private { true }
    ^^^^^^^
example.rb:6:1: C: [Corrected] Layout/EmptyLinesAroundBlockBody: Extra
empty line detected at block body end.

0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in
/Users/koic/src/github.com/koic/rubocop-issues/factory_bot/example.rb
and caused by Layout/EmptyLinesAroundAccessModifier -> Layout/EmptyLinesAroundBlockBody

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.

This PR fixes the following infinite loop error for
`Layout/EmptyLinesAroundAccessModifier` with `Layout/EmptyLinesAroundBlockBody`
when using access modifier with block argument.

```console
% cat example.rb
FactoryBot.define do
  factory :model do
    name { 'hoge' }

    private { true }
  end
end

% rubocop -a --only Layout/EmptyLinesAroundAccessModifier,Layout/EmptyLinesAroundBlockBody
(snip)

Inspecting 1 file
C

Offenses:

example.rb:5:5: C: [Corrected] Layout/EmptyLinesAroundAccessModifier:
Keep a blank line before and after private.
    private { true }
    ^^^^^^^
example.rb:6:1: C: [Corrected] Layout/EmptyLinesAroundBlockBody: Extra
empty line detected at block body end.

0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in
/Users/koic/src/github.com/koic/rubocop-issues/factory_bot/example.rb
and caused by Layout/EmptyLinesAroundAccessModifier -> Layout/EmptyLinesAroundBlockBody
```
@koic koic force-pushed the fix_false_positive_for_empty_lines_around_access_modifier branch from d203f1f to e753311 Compare September 21, 2020 17:09
@koic koic merged commit fa97782 into rubocop:master Sep 21, 2020
@koic koic deleted the fix_false_positive_for_empty_lines_around_access_modifier branch September 21, 2020 17:39
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.

None yet

1 participant