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

Migrate TargetRailsVersion to the new requires_gem RuboCop API #1137

Merged
merged 1 commit into from
Apr 9, 2024

Conversation

amomchilov
Copy link
Contributor

@amomchilov amomchilov commented Sep 30, 2023

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:

  • 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.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@amomchilov amomchilov changed the title Fix invalid Gemfile.lock examples Migrate TargetRailsVersion to the new requires_gem RuboCop API Sep 30, 2023
@amomchilov amomchilov marked this pull request as ready for review September 30, 2023 16:07
@amomchilov
Copy link
Contributor Author

Hey @bbatsov @koic,

Now that rubocop/rubocop#12186 is shipped, this is ready to review/merge.

@koic
Copy link
Member

koic commented Apr 6, 2024

@amomchilov This looks good to me. Can you squash your commits into one?

@amomchilov
Copy link
Contributor Author

@koic Are you sure these should be squashed? The first commit is a correction to the test data, which is incorrect to begin with, unrelated to the changes in the second commit.

I was also apprehensive to change tests and impl in the same commit, but I can squash if you're sure

@koic
Copy link
Member

koic commented Apr 9, 2024

@amomchilov Yes, due to the test not passing when using the new API, please squash the related changes into a single commit for maintenance purposes.

... and fix invalid Gemfile.lock examples
@amomchilov
Copy link
Contributor Author

Done, I squashed the two together, and rebased over the latest master.

@koic koic merged commit 891de22 into rubocop:master Apr 9, 2024
14 checks passed
@koic
Copy link
Member

koic commented Apr 9, 2024

Great! Thank you!

@amomchilov amomchilov deleted the migrate-to-requires_gem-api branch April 13, 2024 15:55
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.

2 participants