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/DefEndAlignment #8653

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@

* [#8627](https://github.com/rubocop-hq/rubocop/issues/8627): Fix a false positive for `Lint/DuplicateRequire` when same feature argument but different require method. ([@koic][])
* [#8572](https://github.com/rubocop-hq/rubocop/issues/8572): Fix a false positive for `Style/RedundantParentheses` when parentheses are used like method argument parentheses. ([@koic][])
* [#8653](https://github.com/rubocop-hq/rubocop/pull/8653): Fix a false positive for `Layout/DefEndAlignment` when using refinements and `private def`. ([@koic][])

### Changes

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/def_end_alignment.rb
Expand Up @@ -46,7 +46,7 @@ def on_def(node)
alias on_defs on_def

def on_send(node)
return unless node.def_modifier?
return if !node.def_modifier? || node.method?(:using)

method_def = node.each_descendant(:def, :defs).first
expr = node.source_range
Expand Down
15 changes: 15 additions & 0 deletions spec/rubocop/cop/layout/def_end_alignment_spec.rb
Expand Up @@ -66,6 +66,21 @@ def Test.test
RUBY
end
end

context 'when using refinements and `private def`' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
using Module.new {
refine Hash do
class << Hash
private def _ruby2_keywords_hash(*args)
end
end
end
}
RUBY
end
end
end

context 'when EnforcedStyleAlignWith is def' do
Expand Down