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

rubocop-1.61.0 crashes when the project's gemspec dynamically sets spec.required_ruby_version #12744

Closed
postmodern opened this issue Mar 5, 2024 · 1 comment · Fixed by #12732

Comments

@postmodern
Copy link

postmodern commented Mar 5, 2024

If a ruby project's .gemspec file dynamically sets the required_ruby_version value, this causes rubocop to crash while attempting to parse the right-hand side of the spec.required_ruby_version assignment.

Expected behavior

rubocop does not raise an exception.

Actual behavior

Exception during parsing of the .gemspec file.

For /home/postmodern/test/ruby/rubocop: Default configuration from /home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/config/default.yml
Use parallel by default.
Running parallel inspection
Loading cache from /home/postmodern/.cache/rubocop_cache/63946c0a4b45db596847d31eeb2af70462172a01/6d7a3b621ca1730e04accd938619e4bdab66cfb1/8a1678080d7059e7ca65c4e59b9279c0c996b758
Loading cache from /home/postmodern/.cache/rubocop_cache/63946c0a4b45db596847d31eeb2af70462172a01/6d7a3b621ca1730e04accd938619e4bdab66cfb1/3ad87dc6dd6f42e6ea5cba216e50c80c2fc1b1e3
undefined method `value' for s(:send,
  s(:send, nil, :data), :[],
  s(:str, "ruby_version")):RuboCop::AST::SendNode
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/target_ruby.rb:111:in `version_from_right_hand_side'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/target_ruby.rb:120:in `find_default_minimal_known_ruby'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/target_ruby.rb:83:in `find_version'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/target_ruby.rb:29:in `initialize'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/target_ruby.rb:257:in `new'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/target_ruby.rb:257:in `block in source'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/target_ruby.rb:257:in `each'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/target_ruby.rb:257:in `each'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/target_ruby.rb:257:in `each'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/target_ruby.rb:257:in `each'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/target_ruby.rb:257:in `each'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/target_ruby.rb:257:in `detect'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/target_ruby.rb:257:in `source'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/target_ruby.rb:261:in `version'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/config_validator.rb:63:in `target_ruby_version'
/usr/share/ruby/forwardable.rb:240:in `target_ruby_version'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/runner.rb:472:in `get_processed_source'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/runner.rb:273:in `do_inspection_loop'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/runner.rb:164:in `block in file_offenses'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/runner.rb:189:in `file_offense_cache'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/runner.rb:163:in `file_offenses'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/runner.rb:99:in `block in warm_cache'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:627:in `call_with_index'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:597:in `process_incoming_jobs'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:577:in `block in worker'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:568:in `fork'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:568:in `worker'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:559:in `block in create_workers'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:558:in `each'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:558:in `each_with_index'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:558:in `create_workers'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:497:in `work_in_processes'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:291:in `map'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/parallel-1.24.0/lib/parallel.rb:235:in `each'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/runner.rb:99:in `warm_cache'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/runner.rb:72:in `run'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/cli/command.rb:11:in `run'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/cli/environment.rb:18:in `run'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/cli.rb:118:in `run_command'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/cli.rb:125:in `execute_runners'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/cli.rb:51:in `block in run'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/cli.rb:77:in `profile_if_needed'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/lib/rubocop/cli.rb:43:in `run'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/exe/rubocop:19:in `block in <top (required)>'
/usr/share/ruby/benchmark.rb:311:in `realtime'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/gems/rubocop-1.61.0/exe/rubocop:19:in `<top (required)>'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/bin/rubocop:25:in `load'
/home/postmodern/test/ruby/rubocop/vendor/bundle/ruby/3.2.0/bin/rubocop:25:in `<top (required)>'
/usr/local/share/gems/gems/bundler-2.4.20/lib/bundler/cli/exec.rb:58:in `load'
/usr/local/share/gems/gems/bundler-2.4.20/lib/bundler/cli/exec.rb:58:in `kernel_load'
/usr/local/share/gems/gems/bundler-2.4.20/lib/bundler/cli/exec.rb:23:in `run'
/usr/local/share/gems/gems/bundler-2.4.20/lib/bundler/cli.rb:492:in `exec'
/usr/local/share/gems/gems/bundler-2.4.20/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/share/gems/gems/bundler-2.4.20/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/share/gems/gems/bundler-2.4.20/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/usr/local/share/gems/gems/bundler-2.4.20/lib/bundler/cli.rb:34:in `dispatch'
/usr/local/share/gems/gems/bundler-2.4.20/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/usr/local/share/gems/gems/bundler-2.4.20/lib/bundler/cli.rb:28:in `start'
/usr/local/share/gems/gems/bundler-2.4.20/exe/bundle:37:in `block in <top (required)>'
/usr/local/share/gems/gems/bundler-2.4.20/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/usr/local/share/gems/gems/bundler-2.4.20/exe/bundle:29:in `<top (required)>'
/usr/local/bin/bundle:25:in `load'
/usr/local/bin/bundle:25:in `<main>'
Finished in 0.3068897270022717 seconds

Steps to reproduce the problem

  1. bundle gem test
  2. cd test/
  3. Edit test.gemspec and add the line spec.required_ruby_version = ENV['required_ruby_version'] to the Gem::Specification.new block.
  4. Edit the Gemfile:
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'rubocop'
  1. bundle install
  2. bundle exec rubocop

RuboCop version

$ bundle exec rubocop -V
1.61.0 (using Parser 3.3.0.5, rubocop-ast 1.31.1, running on ruby 3.2.2) [x86_64-linux]
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 a pull request may close this issue.

2 participants