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

Only parse target Ruby from gemspec if array elements are strings #12756

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1 @@
* [#12756](https://github.com/rubocop/rubocop/pull/12756): Only parse target Ruby from gemspec if array elements are strings. ([@davidrunger][])
2 changes: 1 addition & 1 deletion lib/rubocop/target_ruby.rb
Expand Up @@ -105,7 +105,7 @@ def version_from_gemspec_file(file)
def version_from_right_hand_side(right_hand_side)
gem_requirement_versions = gem_requirement_versions(right_hand_side)

if right_hand_side.array_type?
if right_hand_side.array_type? && right_hand_side.children.all?(&:str_type?)
version_from_array(right_hand_side)
elsif gem_requirement_versions
gem_requirement_versions.map(&:value)
Expand Down
19 changes: 17 additions & 2 deletions spec/rubocop/target_ruby_spec.rb
Expand Up @@ -188,10 +188,25 @@

context 'when file reads the required_ruby_version from another file' do
it 'uses the default target ruby version' do
Comment on lines 189 to 190
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(This is an existing spec that I only modified to have a heredoc without interpolation; it is otherwise unchanged.)

content = <<~HEREDOC
content = <<~'HEREDOC'
Gem::Specification.new do |s|
s.name = 'test'
s.required_ruby_version = Gem::Requirement.new(">= #{File.read('.ruby-version').rstrip}")
s.licenses = ['MIT']
end
HEREDOC

create_file(gemspec_file_path, content)
expect(target_ruby.version).to eq default_version
end
end

context 'when file reads the required_ruby_version from another file in an array' do
it 'uses the default target ruby version' do
Comment on lines +204 to +205
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the new spec that I am adding for this change. Unfortunately (due to how it looks similar to the spec changed above), GitHub is actually not even including the whole new spec in its rendering of this diff. You'll have to click the down arrow to see the last few lines of this new spec, which GitHub is rendering as if they are preexisting lines.

content = <<~'HEREDOC'
Gem::Specification.new do |s|
s.name = 'test'
s.required_ruby_version = Gem::Requirement.new(">= \#{File.read('.ruby-version').rstrip}")
s.required_ruby_version = [">= #{File.read('.ruby-version').rstrip}"]
s.licenses = ['MIT']
end
HEREDOC
Expand Down