Skip to content

Commit

Permalink
[Fix #12162] Fix an error for Bundler/DuplicatedGroup
Browse files Browse the repository at this point in the history
Fixes #12162.

This PR fixes an error for `Bundler/DuplicatedGroup` when
there's a duplicate set of groups and the `group` value contains a splat.
  • Loading branch information
koic authored and bbatsov committed Aug 30, 2023
1 parent 0b3fbae commit 1a83509
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_bundler_duplicated_group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12162](https://github.com/rubocop/rubocop/issues/12162): Fix an error for `Bundler/DuplicatedGroup` when there's a duplicate set of groups and the `group` value contains a splat. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/bundler/duplicated_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def group_attributes(node)
if argument.hash_type?
argument.pairs.map(&:source).sort.join(', ')
else
argument.value.to_s
argument.respond_to?(:value) ? argument.value.to_s : argument.source
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/rubocop/cop/bundler/duplicated_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@
end
end

context 'and a set of groups is duplicated and `group` value is a splat value' do
it 'registers an offense' do
expect_offense(<<~RUBY, 'Gemfile')
group(*LIVE_ENVS) do
gem 'admin_ui'
end
group(*LIVE_ENVS) do
^^^^^^^^^^^^^^^^^ Gem group `*LIVE_ENVS` already defined on line 1 of the Gemfile.
gem 'public_ui'
end
RUBY
end
end

context 'and a set of groups is duplicated but `source` URLs are different' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY, 'Gemfile')
Expand Down

0 comments on commit 1a83509

Please sign in to comment.