From 22d43973055924c20f76c6d08e68e00f0513aea6 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sun, 2 May 2021 19:56:20 +0900 Subject: [PATCH] Support `TargetRubyVersion 3.1` (experimental) RuboCop AST 1.5 supports Ruby 3.1. https://github.com/rubocop/rubocop-ast/pull/182. This PR supports `TargetRubyVersion 3.1`. --- changelog/new_support_ruby_3_1_experimental.md | 1 + docs/modules/ROOT/pages/compatibility.adoc | 1 + lib/rubocop/rspec/shared_contexts.rb | 4 ++++ lib/rubocop/target_ruby.rb | 2 +- rubocop.gemspec | 2 +- spec/rubocop/cli_spec.rb | 2 +- 6 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 changelog/new_support_ruby_3_1_experimental.md diff --git a/changelog/new_support_ruby_3_1_experimental.md b/changelog/new_support_ruby_3_1_experimental.md new file mode 100644 index 00000000000..f19659c7eab --- /dev/null +++ b/changelog/new_support_ruby_3_1_experimental.md @@ -0,0 +1 @@ +* [#9758](https://github.com/rubocop/rubocop/pull/9758): Support `TargetRubyVersion 3.1` (experimental). ([@koic][]) diff --git a/docs/modules/ROOT/pages/compatibility.adoc b/docs/modules/ROOT/pages/compatibility.adoc index 30af1bb067b..69a34dd9aea 100644 --- a/docs/modules/ROOT/pages/compatibility.adoc +++ b/docs/modules/ROOT/pages/compatibility.adoc @@ -31,6 +31,7 @@ The following table is the support matrix. | 2.6 | - | 2.7 | - | 3.0 | - +| 3.1 (experimental) | - |=== NOTE: The compatibility xref:configuration.adoc#setting-the-target-ruby-version[target Ruby version mentioned here] is about code analysis (what RuboCop can analyze), not runtime (is RuboCop capable of running on some Ruby or not). diff --git a/lib/rubocop/rspec/shared_contexts.rb b/lib/rubocop/rspec/shared_contexts.rb index 0176c416469..3934b95f8bd 100644 --- a/lib/rubocop/rspec/shared_contexts.rb +++ b/lib/rubocop/rspec/shared_contexts.rb @@ -131,3 +131,7 @@ def source_range(range, buffer: source_buffer) RSpec.shared_context 'ruby 3.0', :ruby30 do let(:ruby_version) { 3.0 } end + +RSpec.shared_context 'ruby 3.1', :ruby31 do + let(:ruby_version) { 3.1 } +end diff --git a/lib/rubocop/target_ruby.rb b/lib/rubocop/target_ruby.rb index f98bd6b01de..90948161c30 100644 --- a/lib/rubocop/target_ruby.rb +++ b/lib/rubocop/target_ruby.rb @@ -4,7 +4,7 @@ module RuboCop # The kind of Ruby that code inspected by RuboCop is written in. # @api private class TargetRuby - KNOWN_RUBIES = [2.5, 2.6, 2.7, 3.0].freeze + KNOWN_RUBIES = [2.5, 2.6, 2.7, 3.0, 3.1].freeze DEFAULT_VERSION = KNOWN_RUBIES.first OBSOLETE_RUBIES = { diff --git a/rubocop.gemspec b/rubocop.gemspec index db50e4d7e55..d1cac1db8bc 100644 --- a/rubocop.gemspec +++ b/rubocop.gemspec @@ -35,7 +35,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency('rainbow', '>= 2.2.2', '< 4.0') s.add_runtime_dependency('regexp_parser', '>= 1.8', '< 3.0') s.add_runtime_dependency('rexml') - s.add_runtime_dependency('rubocop-ast', '>= 1.2.0', '< 2.0') + s.add_runtime_dependency('rubocop-ast', '>= 1.5.0', '< 2.0') s.add_runtime_dependency('ruby-progressbar', '~> 1.7') s.add_runtime_dependency('unicode-display_width', '>= 1.4.0', '< 3.0') diff --git a/spec/rubocop/cli_spec.rb b/spec/rubocop/cli_spec.rb index e1ed55d8157..c84bc7c5cb4 100644 --- a/spec/rubocop/cli_spec.rb +++ b/spec/rubocop/cli_spec.rb @@ -1612,7 +1612,7 @@ def method(foo, bar, qux, fred, arg5, f) end #{'#' * 85} expect($stderr.string.strip).to start_with( 'Error: RuboCop found unknown Ruby version 4.0 in `TargetRubyVersion`' ) - expect($stderr.string.strip).to match(/Supported versions: 2.5, 2.6, 2.7, 3.0/) + expect($stderr.string.strip).to match(/Supported versions: 2.5, 2.6, 2.7, 3.0, 3.1/) end end