Skip to content

Commit

Permalink
Fix default target Ruby version from 2.5 to 2.6
Browse files Browse the repository at this point in the history
This PR fixes default Ruby version from 2.5 to 2.6.

In rubocop#10626 (RuboCop 1.29.1) , the default target Ruby version is 2.5. This is an unexpected
regression behavior and the default target Ruby version is expected to be 2.6.
  • Loading branch information
koic committed May 13, 2022
1 parent aabdf0a commit 5db174d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog/fix_default_target_ruby_version.md
@@ -0,0 +1 @@
* [#10629](https://github.com/rubocop/rubocop/pull/10629): Fix default Ruby version from 2.5 to 2.6. ([@koic][])
10 changes: 6 additions & 4 deletions lib/rubocop/target_ruby.rb
Expand Up @@ -5,7 +5,7 @@ module RuboCop
# @api private
class TargetRuby
KNOWN_RUBIES = [2.5, 2.6, 2.7, 3.0, 3.1, 3.2].freeze
DEFAULT_VERSION = KNOWN_RUBIES.first
DEFAULT_VERSION = 2.6

OBSOLETE_RUBIES = {
1.9 => '0.41',
Expand Down Expand Up @@ -172,7 +172,7 @@ def find_version
right_hand_side = version_from_gemspec_file(file)
return if right_hand_side.nil?

find_minimal_known_ruby(right_hand_side)
find_default_minimal_known_ruby(right_hand_side)
end

def gemspec_filename
Expand Down Expand Up @@ -206,11 +206,13 @@ def version_from_array(array)
array.children.map(&:value)
end

def find_minimal_known_ruby(right_hand_side)
def find_default_minimal_known_ruby(right_hand_side)
version = version_from_right_hand_side(right_hand_side)
requirement = Gem::Requirement.new(version)

KNOWN_RUBIES.detect { |v| requirement.satisfied_by?(Gem::Version.new("#{v}.99")) }
KNOWN_RUBIES.detect do |v|
v >= DEFAULT_VERSION && requirement.satisfied_by?(Gem::Version.new("#{v}.99"))
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cli_spec.rb
Expand Up @@ -150,7 +150,7 @@ def and_with_args
expect($stderr.string).to eq ''
expect($stdout.string)
.to eq(["#{abs('example.rb')}:3:1: E: Lint/Syntax: unexpected " \
'token $end (Using Ruby 2.5 parser; configure using ' \
'token $end (Using Ruby 2.6 parser; configure using ' \
'`TargetRubyVersion` parameter, under `AllCops`)',
''].join("\n"))
end
Expand Down

0 comments on commit 5db174d

Please sign in to comment.