Skip to content

Infinite loop caused by Layout/EmptyLinesAfterModuleInclusion -> Layout/EmptyLinesAroundBlockBody #14443

@p-linnane

Description

@p-linnane

Expected behavior

RuboCop corrects only true module inclusions with Layout/EmptyLinesAfterModuleInclusion.

Actual behavior

We are seeing an infinite loop caused by the introduction of Layout/EmptyLinesAfterModuleInclusion. As you can see below, this is not actually a module inclusion, it just seems to be finding instances of include.

includes = [include, sdk_include].compact.map do |inc|
  "'#{inc}',"
end.join(" ")

https://github.com/Homebrew/homebrew-core/blob/6459e6e64fcb1296eaf2bac13cda045fc409b4a4/Formula/lib/libxml2.rb#L109-L111

The below is from our wrapper around RuboCop

╰─ brew style --fix libxml2
Infinite loop detected in /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/lib/libxml2.rb and caused by Layout/EmptyLinesAfterModuleInclusion -> Layout/EmptyLinesAroundBlockBody
Taps/homebrew/homebrew-core/Formula/lib/libxml2.rb:109:17: C: [Corrected] Layout/EmptyLinesAfterModuleInclusion: Add an empty line after module inclusion.
    includes = [include, sdk_include].compact.map do |inc|
                ^^^^^^^
Taps/homebrew/homebrew-core/Formula/lib/libxml2.rb:110:1: C: [Corrected] Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.

1 file inspected, 2 offenses detected, 2 offenses corrected

1 error occurred:
Infinite loop detected in /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/lib/libxml2.rb and caused by Layout/EmptyLinesAfterModuleInclusion -> Layout/EmptyLinesAroundBlockBody
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.

Mention the following information in the issue report:

Steps to reproduce the problem

The code provided above triggers the infinite loop. False positives can also be found in our LLVM formulae:

(xctoolchain/"usr").install_symlink [bin, include, lib, libexec, share]

RuboCop version

1.79.2 (using Parser 3.3.9.0, rubocop-ast 1.46.0, analyzing as Ruby 2.7, running on ruby 3.4.5) [arm64-darwin20]

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