Skip to content

Commit a426fad

Browse files
koicmarcandre
authored andcommitted
Support Ruby 4.1
Prism 1.7 adds support for `Prism::Translation::Parser41`. https://github.com/ruby/prism/releases/tag/v1.7.0 Ruby 4.1 development hasn't started yet, but it should be fine to start depending on Prism's published API as Ruby's parser.
1 parent 0d2f1f6 commit a426fad

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

changelog/new_support_ruby_4_1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [#394](https://github.com/rubocop/rubocop-ast/pull/394): Support Ruby 4.1 (experimental). ([@koic][])

lib/rubocop/ast/processed_source.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,9 @@ def parser_class(ruby_version, parser_engine)
314314
when 3.4
315315
Prism::Translation::Parser34
316316
when 3.5, 4.0
317-
# TODO: The meaning of the version numbers in `Parser35` (Ruby 3.5) is the same as in
318-
# `Parser40` (Ruby 4.0). Once the next version of Prism 1.6.0 is released,
319-
# `Parser35` should probably be replaced with `Parser40`:
320-
# See: https://github.com/ruby/prism/pull/3709
321-
Prism::Translation::Parser35
317+
Prism::Translation::Parser40
318+
when 4.1
319+
Prism::Translation::Parser41
322320
else
323321
raise ArgumentError, 'RuboCop supports target Ruby versions 3.3 and above with Prism. ' \
324322
"Specified target Ruby version: #{ruby_version.inspect}"

rubocop-ast.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
3434
}
3535

3636
s.add_dependency('parser', '>= 3.3.7.2')
37-
s.add_dependency('prism', '~> 1.4')
37+
s.add_dependency('prism', '~> 1.7')
3838

3939
##### Do NOT add `rubocop` (or anything depending on `rubocop`) here. See Gemfile
4040
end

spec/spec_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 4.0 : 3.3 }
7272
end
7373

74+
RSpec.shared_context 'ruby 4.1', :ruby41 do
75+
# Parser supports parsing Ruby <= 3.3.
76+
let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 4.1 : 3.3 }
77+
end
78+
7479
# ...
7580
module DefaultRubyVersion
7681
extend RSpec::SharedContext

0 commit comments

Comments
 (0)