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

Bundler/DuplicatedGroup raises false positive when the same groups are defined with different sources #12113

Closed
timon opened this issue Aug 10, 2023 · 1 comment · Fixed by #12116
Labels

Comments

@timon
Copy link
Contributor

timon commented Aug 10, 2023

Rubocop 1.56 introduced new Bundler/DuplicatedGroup cop, which complains on our gemfile

We use both standard rubygems repository as well as private github gems storage, nesting private gems into source private_github_repo block. This is how our Gemfile looks like:

# frozen_string_literal: true

source 'https://rubygems.org'
source 'https://gems.contribsys.com/' do
  gem 'sidekiq-pro', '7.1.3'
end

git_source(:github) { |repo| "https://github.com/#{repo}" }

source 'https://rubygems.pkg.github.com/private-org' do
  gem 'private-runtime-dependency'

  group :development, :test do
    gem 'private-dev-dependency'
  end
end

ruby '3.2.2'

gem 'rails', '~> 7'

group :development, :test do
  gem 'bundler-audit', '~> 0.9.0'
end

group :development, :test do
  gem 'web-console', '>= 4.1.0'
end

group :test do
  gem 'factory_bot_rails'
end

This Gemfile has group :development, :test block defined twice: on line 13, nested into source block, and on line 22, without nesting.

Expected behavior

No offense should be reported, since block defined on line 13 has extra options (source) which the block on line 22 does not have

Actual behavior

Rubocop registers offence for line 22, claiming that "the same" group was declared on line 13:

$ bundle exec rubocop --debug Gemfile 2>&1 | sed s,`pwd`,'[Rails.root]',g
For [Rails.root]: configuration from [Rails.root]/.rubocop.yml
configuration from [Rails.root]/vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.18.0/config/default.yml
configuration from [Rails.root]/vendor/bundle/ruby/3.2.0/gems/rubocop-performance-1.18.0/config/default.yml
Default configuration from [Rails.root]/vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/config/default.yml
configuration from [Rails.root]/vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.20.2/config/default.yml
configuration from [Rails.root]/vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.20.2/config/default.yml
configuration from [Rails.root]/vendor/bundle/ruby/3.2.0/gems/rubocop-capybara-2.18.0/config/default.yml
configuration from [Rails.root]/vendor/bundle/ruby/3.2.0/gems/rubocop-capybara-2.18.0/lib/../config/default.yml
configuration from [Rails.root]/vendor/bundle/ruby/3.2.0/gems/rubocop-factory_bot-2.23.1/config/default.yml
configuration from [Rails.root]/vendor/bundle/ruby/3.2.0/gems/rubocop-factory_bot-2.23.1/lib/../config/default.yml
configuration from [Rails.root]/vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.23.2/config/default.yml
configuration from [Rails.root]/vendor/bundle/ruby/3.2.0/gems/rubocop-rspec-2.23.2/config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning [Rails.root]/Gemfile
Loading cache from /Users/artemignatyev/.cache/rubocop_cache/ea73f893fd75fed6eb3813edaaceafed125998c9/431d3268f19f244d7cfb330d6e2b8d2d9996286a/11f439d95cfe2aa0aebd37556039f22050a11e81
W

Offenses:

Gemfile:22:1: W: Bundler/DuplicatedGroup: Gem group development, test already defined on line 13 of the Gemfile.
group :development, :test do
^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected
Finished in 0.4624439999461174 seconds

Steps to reproduce the problem

  1. Author a gemfile, that has the same group defined within different source blocks (or one nested within the source block and one defined at top level)
  2. Run rubocop against this Gemfile

RuboCop version

$ bundle exec rubocop -V
1.56.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [arm64-darwin21]
  - rubocop-performance 1.18.0
  - rubocop-rails 2.20.2
  - rubocop-rspec 2.23.2
@ixti
Copy link

ixti commented Aug 11, 2023

I my case it simply fails:

An error occurred while Bundler/DuplicatedGroup cop was inspecting /home/ixti/Projects/sidekiq-pauzer/Gemfile.
undefined method `value' for s(:hash,
  s(:pair,
    s(:sym, :optional),
    s(:true))):RuboCop::AST::HashNode
/home/ixti/.gem/ruby/3.2.2/gems/rubocop-1.56.0/lib/rubocop/cop/bundler/duplicated_group.rb:63:in `map'
/home/ixti/.gem/ruby/3.2.2/gems/rubocop-1.56.0/lib/rubocop/cop/bundler/duplicated_group.rb:63:in `block in duplicated_group_nodes'
/home/ixti/.gem/ruby/3.2.2/gems/rubocop-1.56.0/lib/rubocop/cop/bundler/duplicated_group.rb:69:in `block in group_declarations'

1.56.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 3.2.2) [x86_64-linux]
  - rubocop-capybara 2.18.0
  - rubocop-performance 1.18.0
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.23.2

# frozen_string_literal: true

source "https://rubygems.org"

gem "appraisal"
gem "rake"

group :test do
  gem "sidekiq"

  gem "capybara"

  gem "rack"
  gem "rack-session"
  gem "rack-test"

  gem "rspec"
  gem "rspec-parameterized"
  gem "simplecov"

  gem "rubocop", require: false
  gem "rubocop-capybara", require: false
  gem "rubocop-performance", require: false
  gem "rubocop-rake", require: false
  gem "rubocop-rspec", require: false
end

group :development, optional: true do
  gem "debug"

  gem "guard"
  gem "guard-rspec"
end

group :doc, optional: true do
  gem "asciidoctor"
  gem "yard"
end

gemspec

@koic koic added the bug label Aug 11, 2023
koic added a commit to koic/rubocop that referenced this issue Aug 14, 2023
Fix rubocop#12113.

This PR fixes a false positive for `Bundler/DuplicatedGroup`
when groups are duplicated but `source`, `git`, `platforms`,
or `path` values are different.
bbatsov pushed a commit that referenced this issue Aug 16, 2023
Fix #12113.

This PR fixes a false positive for `Bundler/DuplicatedGroup`
when groups are duplicated but `source`, `git`, `platforms`,
or `path` values are different.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants