Skip to content

Infinite loop detected between Layout/EmptyLinesAroundBlockBody and Layout/EmptyLinesAroundAccessModifier #13900

@saviokmua

Description

@saviokmua

RuboCop autocorrection results in an infinite loop when an access modifier is located at the bottom of a block with no following code.

block do
  def foo
  end

  private
end
$ rubocop test.rb --except Lint/UselessAccessModifier -A
Inspecting 1 file
Infinite loop detected in /Users/daniel/RubymineProjects/rubocop/test.rb and caused by Layout/EmptyLinesAroundBlockBody -> Layout/EmptyLinesAroundAccessModifier
C

Offenses:

test.rb:4:3: C: [Corrected] Style/EmptyMethod: Put empty method definitions on a single line.
  def foo ...
  ^^^^^^^
test.rb:6:3: C: [Corrected] Layout/EmptyLinesAroundAccessModifier: Keep a blank line before and after private.
  private
  ^^^^^^^
test.rb:7:1: C: [Corrected] Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end.
test.rb:7:3: C: [Corrected] Layout/EmptyLinesAroundAccessModifier: Keep a blank line before and after private.
  private
  ^^^^^^^

1 file inspected, 4 offenses detected, 4 offenses corrected

1 error occurred:
Infinite loop detected in /Users/daniel/RubymineProjects/rubocop/test.rb and caused by Layout/EmptyLinesAroundBlockBody -> Layout/EmptyLinesAroundAccessModifier
Errors are usually caused by RuboCop bugs.
Please, update to the latest RuboCop version if not already in use, and report a bug if the issue still occurs on this version.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.72.2 (using Parser 3.3.7.1, rubocop-ast 1.38.0, analyzing as Ruby 2.7, running on ruby 3.4.1) [arm64-darwin24]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions