diff --git a/changelog/fix_default_target_ruby_version.md b/changelog/fix_default_target_ruby_version.md new file mode 100644 index 000000000000..0012ff70f401 --- /dev/null +++ b/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][]) diff --git a/lib/rubocop/target_ruby.rb b/lib/rubocop/target_ruby.rb index 66f36dae80ae..741eecd55f00 100644 --- a/lib/rubocop/target_ruby.rb +++ b/lib/rubocop/target_ruby.rb @@ -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', @@ -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 @@ -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 diff --git a/spec/rubocop/cli_spec.rb b/spec/rubocop/cli_spec.rb index ca4bff738a9f..3ebc19a85b98 100644 --- a/spec/rubocop/cli_spec.rb +++ b/spec/rubocop/cli_spec.rb @@ -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