diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0ba3c46..b8782a9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/Gemfile b/Gemfile index d6204d7..19f8772 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Rakefile b/Rakefile index 7f37039..0a6e8b9 100644 --- a/Rakefile +++ b/Rakefile @@ -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| diff --git a/changelog/change_support_prism.md b/changelog/change_support_prism.md new file mode 100644 index 0000000..5d8761c --- /dev/null +++ b/changelog/change_support_prism.md @@ -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][]) diff --git a/lib/rubocop/minitest/assert_offense.rb b/lib/rubocop/minitest/assert_offense.rb index 8bd5be6..414ab42 100644 --- a/lib/rubocop/minitest/assert_offense.rb +++ b/lib/rubocop/minitest/assert_offense.rb @@ -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. @@ -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 diff --git a/rubocop-minitest.gemspec b/rubocop-minitest.gemspec index 0992db4..86c0f08 100644 --- a/rubocop-minitest.gemspec +++ b/rubocop-minitest.gemspec @@ -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