user18646557
user18646557

Reputation: 125

Rubocop: RuboCop found unknown Ruby version 3.1 in `.ruby-version`

I recently upgraded ruby version from 2.7.5 to 3.1.1 and when I try to run rubocop I get error Error: RuboCop found unknown Ruby version 3.1 in .ruby-version. Supported versions: 2.3, 2.4, 2.5, 2.6, 2.7 Looking at the rubocop compatibility documentation it supports 3.1 version. Any idea why I am getting the error?

.rubocop.yml:

require: rubocop-rspec
AllCops:
  Exclude:
    - 'bin/*'
    - 'vendor/**/*'
Metrics/BlockLength:
  Exclude:
    - 'spec/**/*'
Metrics/LineLength:
  Exclude:
    - 'spec/**/*'
RSpec/AnyInstance:
  Enabled: false
RSpec/ExampleLength:
  Exclude:
    - 'spec/**/*'
Style/BracesAroundHashParameters:
  Enabled: false

Upvotes: 6

Views: 5537

Answers (1)

maikhel
maikhel

Reputation: 416

Rubocop version 0.77.0 doesn't support newest ruby versions. Make sure to use newer rubocop:

gem install rubocop -v 1.14.0

You can check what ruby versions are supported by which rubocop version in lib/rubocop/target_ruby.rb file, KNOWN_RUBIES const.

E. g. supported ruby versions for rubocop version 1.14.0: https://github.com/rubocop/rubocop/blob/v1.14.0/lib/rubocop/target_ruby.rb#L7

Upvotes: 7

Related Questions