Skip to content

Commit b73940d

Browse files
authored
Merge pull request #304 from koic/support_prism
Support Prism as a Ruby parser
2 parents 2448f36 + 43b6ddb commit b73940d

6 files changed

Lines changed: 32 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ jobs:
5353
- name: internal_investigation
5454
run: bundle exec rake internal_investigation
5555

56+
prism:
57+
runs-on: ubuntu-latest
58+
name: Prism
59+
steps:
60+
- uses: actions/checkout@v4
61+
- name: set up Ruby
62+
uses: ruby/setup-ruby@v1
63+
with:
64+
# Specify the minimum Ruby version 2.7 required for Prism to run.
65+
ruby-version: 2.7
66+
bundler-cache: true
67+
- name: test
68+
env:
69+
PARSER_ENGINE: parser_prism
70+
run: bundle exec rake prism_test
71+
5672
documentation_checks:
5773
runs-on: ubuntu-latest
5874
name: Check documentation syntax

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ gemspec
99
gem 'bump', require: false
1010
gem 'minitest', '~> 5.11'
1111
gem 'minitest-proveit'
12+
gem 'prism'
1213
gem 'rake'
1314
gem 'rubocop', github: 'rubocop/rubocop'
1415
gem 'rubocop-performance', '~> 1.18.0'

Rakefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ else
3333
end
3434
end
3535

36+
desc 'Run tests with Prism'
37+
task :prism_test do
38+
sh('PARSER_ENGINE=parser_prism bundle exec rake test')
39+
end
40+
3641
desc 'Run RuboCop over itself'
3742
RuboCop::RakeTask.new(:internal_investigation)
3843

39-
task default: %i[documentation_syntax_check test internal_investigation]
44+
task default: %i[documentation_syntax_check test prism_test internal_investigation]
4045

4146
desc 'Generate a new cop template'
4247
task :new_cop, [:cop] do |_task, args|

changelog/change_support_prism.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#304](https://github.com/rubocop/rubocop-minitest/pull/304): Require RuboCop AST >= 1.31.1 to support Prism as a Ruby Parser. ([@koic][])

lib/rubocop/minitest/assert_offense.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def parse_source!(source, file = nil)
186186
file = file.path
187187
end
188188

189-
processed_source = RuboCop::ProcessedSource.new(source, ruby_version, file)
189+
processed_source = RuboCop::ProcessedSource.new(source, ruby_version, file, parser_engine: parser_engine)
190190

191191
# Follow up https://github.com/rubocop/rubocop/pull/10987.
192192
# When support for RuboCop 1.37.1 ends, this condition can be removed.
@@ -216,7 +216,12 @@ def registry
216216
end
217217

218218
def ruby_version
219-
RuboCop::TargetRuby::DEFAULT_VERSION
219+
# Prism supports parsing Ruby 3.3+.
220+
ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : RuboCop::TargetRuby::DEFAULT_VERSION
221+
end
222+
223+
def parser_engine
224+
ENV.fetch('PARSER_ENGINE', :parser_whitequark).to_sym
220225
end
221226
end
222227
# rubocop:enable Metrics/ModuleLength

rubocop-minitest.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ Gem::Specification.new do |spec|
3333
spec.require_paths = ['lib']
3434

3535
spec.add_runtime_dependency 'rubocop', '>= 1.61', '< 2.0'
36-
spec.add_runtime_dependency 'rubocop-ast', '>= 1.30.0', '< 2.0'
36+
spec.add_runtime_dependency 'rubocop-ast', '>= 1.31.1', '< 2.0'
3737
end

0 commit comments

Comments
 (0)