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

Error when inheriting and overriding TargetRubyVersion #9934

Closed
robertjlooby opened this issue Jul 15, 2021 · 1 comment · Fixed by #10112
Closed

Error when inheriting and overriding TargetRubyVersion #9934

robertjlooby opened this issue Jul 15, 2021 · 1 comment · Fixed by #10112

Comments

@robertjlooby
Copy link

Given a directory structure like:

ruby_projects/
             /.rubocop.yml
             /app1/...
             /app2/...
             /app3/
                  /.rubocop.yml

app1 and app2 are using Ruby 2.4 and rubocop 1.12.1. The .rubocop.yml in ruby_projects has

---
AllCops:
  TargetRubyVersion: 2.4

app3 is using Ruby 2.7 and rubocop 1.18.3. The .rubocop.yml in ruby_projects/app3 has

inherit_from: ../.rubocop.yml

AllCops:
  TargetRubyVersion: 2.7

Expected behavior

I would expect that within the app3 directory rubocop would use TargetRubyVersion 2.7 specified in the .rubocop.yml there and overriding the value from the inherited .rubocop.yml

Actual behavior

% bundle exec rubocop --debug
For /Users/rlooby/ruby_projects/app3: configuration from /Users/rlooby/ruby_projects/app3/.rubocop.yml
Inheriting configuration from /Users/rlooby/ruby_projects/.rubocop.yml
configuration from /Users/rlooby/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-performance-1.11.4/config/default.yml
configuration from /Users/rlooby/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-performance-1.11.4/config/default.yml
Default configuration from /Users/rlooby/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.18.3/config/default.yml
configuration from /Users/rlooby/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-rspec-2.4.0/config/default.yml
configuration from /Users/rlooby/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-rspec-2.4.0/config/default.yml
Error: RuboCop found unsupported Ruby version 2.4 in `TargetRubyVersion` parameter (in /Users/rlooby/ruby_projects/.rubocop.yml). 2.4-compatible analysis was dropped after version 1.12.
Supported versions: 2.5, 2.6, 2.7, 3.0, 3.1

Steps to reproduce the problem

Set up directory structure and configs as stated above and try to run rubocop commands.

RuboCop version

Initially this gives the same error. Changing the upper .rubocop.yml to 2.7:

% bundle exec rubocop -V
1.18.3 (using Parser 3.0.2.0, rubocop-ast 1.8.0, running on ruby 2.7.3 x86_64-darwin19)
@jonas054
Copy link
Collaborator

When RuboCop validates configuration, it does it file by file. Usually this is a good strategy since it allows us to show the right file name when there is a validation error. But the above description show us that for TargetRubyVersion, we need to skip the validation in each file and only validate the final merged configuration after inheritance has been resolved.

dvandersluis added a commit to dvandersluis/rubocop that referenced this issue Sep 22, 2021
…r an obsolete ruby version that is subsequently overridden.
bbatsov pushed a commit that referenced this issue Sep 27, 2021
…solete ruby version that is subsequently overridden.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants