Skip to content

Commit

Permalink
Merge pull request #304 from koic/support_prism
Browse files Browse the repository at this point in the history
Support Prism as a Ruby parser
  • Loading branch information
koic authored Mar 4, 2024
2 parents 2448f36 + 43b6ddb commit b73940d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ jobs:
- name: internal_investigation
run: bundle exec rake internal_investigation

prism:
runs-on: ubuntu-latest
name: Prism
steps:
- uses: actions/checkout@v4
- name: set up Ruby
uses: ruby/setup-ruby@v1
with:
# Specify the minimum Ruby version 2.7 required for Prism to run.
ruby-version: 2.7
bundler-cache: true
- name: test
env:
PARSER_ENGINE: parser_prism
run: bundle exec rake prism_test

documentation_checks:
runs-on: ubuntu-latest
name: Check documentation syntax
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gemspec
gem 'bump', require: false
gem 'minitest', '~> 5.11'
gem 'minitest-proveit'
gem 'prism'
gem 'rake'
gem 'rubocop', github: 'rubocop/rubocop'
gem 'rubocop-performance', '~> 1.18.0'
Expand Down
7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ else
end
end

desc 'Run tests with Prism'
task :prism_test do
sh('PARSER_ENGINE=parser_prism bundle exec rake test')
end

desc 'Run RuboCop over itself'
RuboCop::RakeTask.new(:internal_investigation)

task default: %i[documentation_syntax_check test internal_investigation]
task default: %i[documentation_syntax_check test prism_test internal_investigation]

desc 'Generate a new cop template'
task :new_cop, [:cop] do |_task, args|
Expand Down
1 change: 1 addition & 0 deletions changelog/change_support_prism.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#304](https://github.com/rubocop/rubocop-minitest/pull/304): Require RuboCop AST >= 1.31.1 to support Prism as a Ruby Parser. ([@koic][])
9 changes: 7 additions & 2 deletions lib/rubocop/minitest/assert_offense.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def parse_source!(source, file = nil)
file = file.path
end

processed_source = RuboCop::ProcessedSource.new(source, ruby_version, file)
processed_source = RuboCop::ProcessedSource.new(source, ruby_version, file, parser_engine: parser_engine)

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

def ruby_version
RuboCop::TargetRuby::DEFAULT_VERSION
# Prism supports parsing Ruby 3.3+.
ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : RuboCop::TargetRuby::DEFAULT_VERSION
end

def parser_engine
ENV.fetch('PARSER_ENGINE', :parser_whitequark).to_sym
end
end
# rubocop:enable Metrics/ModuleLength
Expand Down
2 changes: 1 addition & 1 deletion rubocop-minitest.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

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

0 comments on commit b73940d

Please sign in to comment.