Skip to content

Commit

Permalink
Support Parser::Ruby32
Browse files Browse the repository at this point in the history
Parser gem has been started development for Ruby 3.2 (edge Ruby).
whitequark/parser#841

This PR supports `Parser::Ruby32`, the early adapters will be able to
try edge Ruby with RuboCop.

And this PR update to require Parser 3.1.1.0 or higher, which contains
`Parser::Ruby32`.
https://github.com/whitequark/parser/blob/master/CHANGELOG.md#v3110-2022-02-21
  • Loading branch information
koic authored and marcandre committed Feb 22, 2022
1 parent eb4d51c commit 221f84d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/new_support_ruby_3_2_parser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#223](https://github.com/rubocop-hq/rubocop-ast/pull/223): Support `Parser::Ruby32` for Ruby 3.2 parser (experimental). ([@koic][])
7 changes: 5 additions & 2 deletions lib/rubocop/ast/processed_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def tokenize(parser)
[ast, comments, tokens]
end

# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
def parser_class(ruby_version)
case ruby_version
when 2.4
Expand All @@ -247,12 +247,15 @@ def parser_class(ruby_version)
when 3.1
require 'parser/ruby31'
Parser::Ruby31
when 3.2
require 'parser/ruby32'
Parser::Ruby32
else
raise ArgumentError,
"RuboCop found unknown Ruby version: #{ruby_version.inspect}"
end
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength

def create_parser(ruby_version)
builder = RuboCop::AST::Builder.new
Expand Down
2 changes: 1 addition & 1 deletion rubocop-ast.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Gem::Specification.new do |s|
'rubygems_mfa_required' => 'true'
}

s.add_runtime_dependency('parser', '>= 3.0.1.1')
s.add_runtime_dependency('parser', '>= 3.1.1.0')

s.add_development_dependency('bundler', '>= 1.15.0', '< 3.0')

Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
let(:ruby_version) { 3.1 }
end

RSpec.shared_context 'ruby 3.2', :ruby32 do
let(:ruby_version) { 3.2 }
end

# ...
module DefaultRubyVersion
extend RSpec::SharedContext
Expand Down

0 comments on commit 221f84d

Please sign in to comment.