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

Add new Bundler/DuplicatedGroup cop #12074

Merged

Conversation

OwlKing
Copy link
Contributor

@OwlKing OwlKing commented Jul 27, 2023

New cop validating each gem group (or a set of groups) is only defined once.

# bad
group :development do
  gem 'rubocop'
end

group :development do
  gem 'rubocop-rails'
end

# bad
group :development, :test do
  gem 'rubocop'
end

group :test, :development do
  gem 'rspec'
end

# good
group :development do
  gem 'rubocop'
end

group :development, :test do
  gem 'rspec'
end

# good
gem 'rubocop', groups: [:development, :test]
gem 'rspec', groups: [:development, :test]

This has been suggested many years ago here #3600 but I couldn't find any attempts at implementing it.


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.

module RuboCop
module Cop
module Bundler
# A Gem group should be listed only once in a Gemfile.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given the examples that's not exactly true, so you might want to expand this description.

# gem 'rubocop-rails'
# end
#
# # bad
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be nice to explain why this is bad and the next example is good, as it's not obvious to me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(to be clear - it took me a moment to see that the names were the same, but in different order)

@OwlKing OwlKing requested a review from bbatsov August 8, 2023 20:16
@bbatsov bbatsov merged commit 964235c into rubocop:master Aug 9, 2023
19 checks passed
@matthewhively
Copy link

@bbatsov
Forgive the necro post.
I'm just curious, why was this cop added as Enabled: true? shouldn't it have been pending?

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 25, 2024

@matthewhively An oversight on my part. :-) At any rate, it's more or less a Lint cop, so I'm guessing most people would have enabled it anyways.

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.

None yet

3 participants