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
Fix required_ruby_version
issue when using Gem::Requirement
#9037
Fix required_ruby_version
issue when using Gem::Requirement
#9037
Conversation
This fixes an issue when the `required_ruby_version` uses `Gem::Requirement` to define the Ruby version. e.g. ``` s.required_ruby_version = Gem::Requirement.new('< 3.0.0') ``` Related to rubocop#8761
lib/rubocop/target_ruby.rb
Outdated
@@ -141,9 +141,17 @@ def find_version | |||
return versions.compact.min | |||
end | |||
|
|||
return gem_requirement_version(version) if version.send_type? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably we should do a more precise node match here, as there's a slight chance some other code might be used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bbatsov!
There is now a more precise matching pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Maybe you can merge it with if version.array_type?
, also capturing the versions, and you can reuse the same map
, compact
, min
. Maybe not though, just a thought
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into it @marcandre!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ (array $str+) ... }
can help, and there's https://nodepattern.herokuapp.com/ to help test things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So now the map
, compact
and min
are reused and I definitely think it looks more DRY.
I managed to merge it by creating a version_from_array
method but didn't do any new NodePattern
.
lib/rubocop/target_ruby.rb
Outdated
version_from_str(version.str_content) | ||
end | ||
|
||
def gem_requirement_version(version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is still extracted from the gemspec it should probably be part of that existing method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New arrangement based on #9037 (comment), let me know your thoughts @bbatsov .
ca1ae44
to
03bc071
Compare
03bc071
to
b602d9c
Compare
Looks good! Thanks! |
This fixes an issue when the
required_ruby_version
usesGem::Requirement
to define the Ruby version.Gemspec:
Backtrace using v1.3.0:
Related to #8761
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.