Skip to content

Commit

Permalink
[Fix #12079] Fix an error for Style/MixinGrouping
Browse files Browse the repository at this point in the history
Fixes #12079.

This PR fixes an error for `Style/MixinGrouping` when mixin method has no arguments.
  • Loading branch information
koic authored and bbatsov committed Jul 31, 2023
1 parent ee26d06 commit 6e01713
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_style_mixin_grouping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12079](https://github.com/rubocop/rubocop/issues/12079): Fix an error for `Style/MixinGrouping` when mixin method has no arguments. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/mixin_grouping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MixinGrouping < Base
def on_class(node)
begin_node = node.child_nodes.find(&:begin_type?) || node
begin_node.each_child_node(:send).select(&:macro?).each do |macro|
next unless MIXIN_METHODS.include?(macro.method_name)
next if !MIXIN_METHODS.include?(macro.method_name) || macro.arguments.empty?

check(macro)
end
Expand Down
24 changes: 24 additions & 0 deletions spec/rubocop/cop/style/mixin_grouping_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ class Foo
end
RUBY
end

it 'does not register an offense when `include` has no arguments' do
expect_no_offenses(<<~RUBY)
class Foo
include
end
RUBY
end
end

context 'when using `extend`' do
Expand All @@ -60,6 +68,14 @@ class Foo
end
RUBY
end

it 'does not register an offense when `extend` has no arguments' do
expect_no_offenses(<<~RUBY)
class Foo
extend
end
RUBY
end
end

context 'when using `prepend`' do
Expand All @@ -78,6 +94,14 @@ class Foo
end
RUBY
end

it 'does not register an offense when `prepend` has no arguments' do
expect_no_offenses(<<~RUBY)
class Foo
prepend
end
RUBY
end
end

context 'when using a mix of different methods' do
Expand Down

0 comments on commit 6e01713

Please sign in to comment.