rubocop-rails icon indicating copy to clipboard operation
rubocop-rails copied to clipboard

Migrate `TargetRailsVersion` to the new `requires_gem` RuboCop API

Open amomchilov opened this issue 2 years ago • 0 comments

This PR updates the TargetRailsVersion to conditionally use the requires_gem API when available (depending on the version of the base RuboCop gem). This has several advantages:

  1. It resolves a circular dependancy.
    • rubocop-rails depends on rubocop (e.g. for RuboCop::Cop::Base), and that's fine, but there's also a hidden reverse dependency, where rubocop implicitly depends on rubocop-rails.
    • Now it's just one-way. rubocop-rails registers its minimum version requirements, and rubocop knows how to understand those without needing to call back into rubcop-rails.
  2. It removes a "snowflake" case that's treated specially. For now we need to support both for backwards compatibility, but eventually when old versions are drop, it can just standardize on requires_gem.
  3. It adds rails requirements to a Cop's gem_requirements list, just like any other.

Before submitting the PR make sure the following are checked:

  • [x] The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • [x] Wrote good commit messages.
  • [x] Commit message starts with [Fix #issue-number] (if the related issue exists).
  • [x] Feature branch is up-to-date with master (if not - rebase it).
  • [x] Squashed related commits together.
  • [x] Added tests.
  • [x] Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • [x] 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.
  • [ ] ~If this is a new cop, consider making a corresponding update to the Rails Style Guide.~

amomchilov avatar Sep 30 '23 15:09 amomchilov