KEMBAR78
Add new cop Layout/EmptyLinesAfterModuleInclusion by lovro-bikic · Pull Request #14348 · rubocop/rubocop · GitHub
Skip to content

Conversation

lovro-bikic
Copy link
Contributor

@lovro-bikic lovro-bikic commented Jul 8, 2025

Follow-up to rubocop/ruby-style-guide#960.

Registers code like:

class Foo
  include Bar
  attr_reader :baz
end

as an offense, and autocorrects to:

class Foo
  include Bar

  attr_reader :baz
end

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@@ -0,0 +1,99 @@
# frozen_string_literal: true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used Layout/EmptyLinesAroundAttributeAccessor as the starting point for this cop.

Enabled: true
VersionAdded: '0.49'

Layout/EmptyLinesAfterModuleInclusion:
Copy link
Contributor Author

@lovro-bikic lovro-bikic Jul 8, 2025

Choose a reason for hiding this comment

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

I wasn't sure whether to name this cop EmptyLinesAfter or EmptyLinesAround. This cop for example:

module Layout
# Checks for a newline after an attribute accessor or a group of them.

is named "around", but it only checks the line after.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you picked the right name. Seems the other cop is misbehaving as the idea there was to ensure that a group of attributes was surrounded by blank lines. (unless at the very beginning of a class definition, that is)

@bbatsov bbatsov merged commit 92d7da0 into rubocop:master Jul 11, 2025
24 checks passed
@bbatsov
Copy link
Collaborator

bbatsov commented Jul 11, 2025

Good work! Thanks!

@lovro-bikic lovro-bikic deleted the empty-lines-module-inclusion branch July 11, 2025 09:03
koic added a commit to rubocop/rubocop-ast that referenced this pull request Jul 23, 2025
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.

2 participants