KEMBAR78
Specifying parser engine in inherited file breaks with gemspec present · Issue #14541 · rubocop/rubocop · GitHub
Skip to content

Specifying parser engine in inherited file breaks with gemspec present #14541

@davue

Description

@davue

I have a gem using Ruby 3.3.5 and I want to use the Prism parser. The parse engine should be specified in a base configuration file called .rubocop_base.yml while the TargetRubyVersion should be specified in the .rubocop.yml.

Doing so breaks the TargetRubyVersion detection when a gemspec file is present.


Expected behavior

Everything should work normally.

Actual behavior

Rubocop crashes with:

RuboCop supports target Ruby versions 3.3 and above with Prism. Specified target Ruby version: 2.7

Even though we have specified TargetRubyVersion: 3.3 in our .rubocop.yml (see below for details about the file contents).

Workaround: It works to have the TargetRubyVersion and ParserEngine in the same file (.rubocop.yml or .rubocop_base.yml), but I want to have the parser in the inherited file while having the target Ruby version in the main file.

Stacktrace

> bundle exec rubocop --debug

For /home/denderlin/test/rubocop: configuration from /home/denderlin/test/rubocop/.rubocop.yml
Inheriting configuration from /home/denderlin/test/rubocop/.rubocop_base.yml
Default configuration from /home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/config/default.yml
RuboCop supports target Ruby versions 3.3 and above with Prism. Specified target Ruby version: 2.7
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-ast-1.46.0/lib/rubocop/ast/processed_source.rb:322:in `parser_class'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-ast-1.46.0/lib/rubocop/ast/processed_source.rb:342:in `create_parser'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-ast-1.46.0/lib/rubocop/ast/processed_source.rb:238:in `parse'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-ast-1.46.0/lib/rubocop/ast/processed_source.rb:66:in `initialize'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-ast-1.46.0/lib/rubocop/ast/processed_source.rb:46:in `new'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-ast-1.46.0/lib/rubocop/ast/processed_source.rb:46:in `from_file'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/target_ruby.rb:113:in `version_from_gemspec_file'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/target_ruby.rb:92:in `find_version'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/target_ruby.rb:29:in `initialize'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/target_ruby.rb:278:in `new'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/target_ruby.rb:278:in `block in source'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/target_ruby.rb:278:in `each'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/target_ruby.rb:278:in `each'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/target_ruby.rb:278:in `each'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/target_ruby.rb:278:in `each'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/target_ruby.rb:278:in `each'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/target_ruby.rb:278:in `detect'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/target_ruby.rb:278:in `source'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/target_ruby.rb:282:in `version'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_validator.rb:66:in `target_ruby_version'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-ast-1.46.0/lib/rubocop/ast/utilities/simple_forwardable.rb:20:in `target_ruby_version'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_obsoletion/parameter_rule.rb:36:in `applies_to_current_ruby_version?'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_obsoletion/parameter_rule.rb:22:in `violated?'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_obsoletion.rb:140:in `block in obsoletions'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_obsoletion.rb:139:in `map'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_obsoletion.rb:139:in `obsoletions'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_obsoletion.rb:73:in `reject_obsolete!'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_validator.rb:74:in `check_obsoletions'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_validator.rb:47:in `validate'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config.rb:87:in `check'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config.rb:25:in `create'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_loader.rb:66:in `load_file'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:240:in `block in base_configs'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:239:in `map'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:239:in `base_configs'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_loader_resolver.rb:40:in `resolve_inheritance'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_loader.rb:59:in `load_file'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_loader.rb:118:in `configuration_from_file'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_store.rb:68:in `for_dir'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/config_store.rb:47:in `for_pwd'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/cli.rb:155:in `parallel_by_default!'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/cli.rb:51:in `block in run'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/cli.rb:87:in `profile_if_needed'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/lib/rubocop/cli.rb:45:in `run'
/home/denderlin/test/rubocop/vendor/bundle/gems/rubocop-1.80.2/exe/rubocop:15:in `<top (required)>'
/home/denderlin/test/rubocop/vendor/bundle/bin/rubocop:25:in `load'
/home/denderlin/test/rubocop/vendor/bundle/bin/rubocop:25:in `<top (required)>'
Finished in 0.08588472509291023 seconds

Steps to reproduce the problem

Use the following files and try to run Rubocop.

test.gemspec:

Gem::Specification.new do |s|
  s.name = "test".freeze
  s.version = "0.0.1".freeze
  s.authors = ["test"]
  s.summary = "test".freeze

  s.add_runtime_dependency('rubocop', '1.80.2')
end

Gemfile:

source 'https://rubygems.org'

# Specify gem dependencies in the .gemspec file
gemspec

.rubocop.yml:

inherit_from: .rubocop_base.yml

AllCops:
  TargetRubyVersion: 3.3

.rubocop_base.yml:

AllCops:
  ParserEngine: parser_prism

RuboCop version

rubocop -V cannot be run because it also crashes with the same error. But rubocop -v returns 1.80.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions