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 restrictive_version_specifiers to Bundler/GemComment #9358

Merged

Conversation

RobinDaugherty
Copy link
Contributor

@RobinDaugherty RobinDaugherty commented Jan 9, 2021

The problem I'm trying to solve:

There are multiple reasons one might lock the version of a gem in the Gemfile:

  1. When a minimum version of the gem is needed to support the project. (Like ">= 2.0".)
  2. When a specific version of the gem has a known bug. (Should be done like "!= 2.4.0".)
  3. When a major version of the gem is incompatible with the project. (Usually looks like "< 3.0".)
  4. For no reason. Some gems even provide instructions like "add gem 'mygem', '~> 2.3' to your Gemfile".

The last two reasons lead to a project's dependencies falling behind because the bundle update process will not update to 3.0 without manual intervention. This would cause dependencies to continue to fall behind and in some cases even limit other non-locked dependencies because of cross-dependencies.

To combat this, good practice would include a periodic cleanup of Gemfile version specifications that limit updating of gems.

Another good practice is a rule that when a gem has a limiting version specifier like items 3 and 4 above, there's a comment in the Gemfile explaining the reason. This allows the periodic cleanup process to be more effective, since one can determine whether a bug is fixed, or know what kind of breakage or test failure to look for when updating the gem past the version specification.

Currently, the version_specifiers option for this cop checks a gem specification for any version specifier, requiring a gem comment if one exists. This means that a non-limiting version specification like ">= 1.0" without a justification would warrant a complaint.

This new option, limiting_version_specifiers, requires a gem comment only for version specifications that are limiting in nature, but not for other version specifications.

So the following version specifications are permitted without comment:

gem "rubocop", ">= 1.0"
gem "rubocop", "!= 2.3.4"

while the following require an accompanying gem comment:

gem "rubocop", "< 3.0"
gem "rubocop", ">= 1.0", "< 3.0"
gem "rubocop", "~> 2.0"
gem "rubocop", "= 2.3.5"

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.

@RobinDaugherty RobinDaugherty force-pushed the feature/bundler-gemcomment-version-limit branch from 156ad1a to f56f502 Compare January 9, 2021 17:54
@bbatsov
Copy link
Collaborator

bbatsov commented Feb 15, 2021

I'm fine with the proposed change, but I think you should expand the cop's documentation to account for its rationale.

@bbatsov bbatsov self-assigned this Feb 15, 2021
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 17, 2021

@RobinDaugherty ping :-)

@RobinDaugherty RobinDaugherty changed the title Add limiting_version_specifiers to Bundler/GemComment Add restrictive_version_specifiers to Bundler/GemComment Mar 25, 2021
@RobinDaugherty RobinDaugherty force-pushed the feature/bundler-gemcomment-version-limit branch from 2eb73d0 to 7b73d03 Compare March 25, 2021 17:23
@RobinDaugherty RobinDaugherty force-pushed the feature/bundler-gemcomment-version-limit branch from 842c4d3 to 08f5b87 Compare March 31, 2021 00:24
CHANGELOG.md Outdated
@@ -5485,6 +5485,7 @@
[@wcmonty]: https://github.com/wcmonty
[@nguyenquangminh0711]: https://github.com/nguyenquangminh0711
[@chocolateboy]: https://github.com/chocolateboy
[@RobinDaugherty]: https://github.com/RobinDaugherty
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that's not needed, as it will added automatically once we regen the changelog.

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 31, 2021

The changes look good, but your branch has to be rebased on top of the current master branch due to merge conflicts.

@RobinDaugherty RobinDaugherty force-pushed the feature/bundler-gemcomment-version-limit branch from 08f5b87 to bb6f25e Compare April 11, 2021 01:14
@RobinDaugherty
Copy link
Contributor Author

✅ I've rebased it.

@bbatsov bbatsov merged commit aa5f841 into rubocop:master Apr 11, 2021
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 11, 2021

Thanks!

@RobinDaugherty RobinDaugherty deleted the feature/bundler-gemcomment-version-limit branch May 6, 2021 22:48
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

2 participants