Skip to content

The Layout/EmptyLinesAfterModuleInclusion cop behaves incorrectly when using Module.new #14399

@willnet

Description

@willnet

Expected behavior

The code I wrote in the “step to reproduce” should not be flagged as a violation.

Actual behavior

The code I wrote in the “step to reproduce” section is flagged by Layout/EmptyLinesAfterModuleInclusion.
When I follow its suggestion and add a blank line after prepend Module.new do, it then causes a Layout/EmptyLinesAroundBlockBody violation.

Steps to reproduce the problem

rubocop --enable-pending-cops

# frozen_string_literal: true

# class C document
class C
  prepend Module.new do
    def foo
      puts 'foo'
      super
    end
  end
end

RuboCop version

1.79.0 (using Parser 3.3.9.0, rubocop-ast 1.46.0, analyzing as Ruby 2.7, running on ruby 3.4.5) [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