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

Support passing the target ruby version through an environment variable #13607

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

elliottt
Copy link

@elliottt elliottt commented Dec 19, 2024

In version 1.67, the search order for the target ruby version changed to prefer gemspec files over .ruby-version. While this is a good change as the gemspec is a better authority on what version of ruby a gem requires, it complicates some internal testing at Stripe where we forbid tests from globbing the filesystem, and finding the gemspec requires globbing in parent directories.

As a workaround, this PR adds a new source for the target ruby version: the RUBOCOP_TARGET_RUBY_VERSION environment variable. This is now the first tried source for the target ruby version, giving an environmental override for situations where searching the filesystem isn't permitted.


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.

@elliottt elliottt force-pushed the trevor/ruby-version-env-var branch from 143314e to ee4ec2c Compare December 19, 2024 00:44
@elliottt elliottt marked this pull request as ready for review December 19, 2024 00:55
@koic
Copy link
Member

koic commented Dec 19, 2024

Can you document how to use the environment variable RUBOCOP_TARGET_RUBY_VERSION and note that it is always given the highest priority?
https://docs.rubocop.org/rubocop/1.69/configuration.html#setting-the-target-ruby-version

Add a new search method for determining the target ruby version: the
RUBOCOP_TARGET_RUBY_VERSION environment variable. This is now the first
source checked, allowing it to override all other sources of the target
ruby version.
@elliottt elliottt force-pushed the trevor/ruby-version-env-var branch from ee4ec2c to ab42154 Compare December 19, 2024 16:59
@elliottt
Copy link
Author

@koic I've updated the docs, sorry for missing them initially!

Copy link
Member

@koic koic left a comment

Choose a reason for hiding this comment

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

This looks like a valuable feature to me.

@bbatsov bbatsov merged commit f9e9c01 into rubocop:master Dec 20, 2024
22 checks passed
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 20, 2024

Agreed!

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.

4 participants