Skip to content

Commit

Permalink
Support Prism as a Ruby parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Mar 21, 2024
1 parent 866f2b2 commit 1fea9e9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,19 @@ jobs:
ruby-version: "3.3"
bundler-cache: true
- run: NO_COVERAGE=true bundle exec rake ${{ matrix.task }}

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: spec
env:
PARSER_ENGINE: parser_prism
run: NO_COVERAGE=true bundle exec rake prism_spec
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Master (Unreleased)

- Support Prism as a Ruby parser (experimental). ([@ydah])

## 2.25.1 (2024-01-08)

- Fix a false positive for `FactoryBot/CreateList` when create call does have method calls and repeat multiple times with other argument. ([@ydah])
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gemspec

gem 'bump'
gem 'danger'
gem 'prism'
gem 'rack'
gem 'rake'
gem 'rspec', '~> 3.11'
Expand Down
5 changes: 5 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ task confirm_documentation: :generate_cops_documentation do
end
end

desc 'Run RSpec with Prism'
task :prism_spec do
sh('PARSER_ENGINE=parser_prism bundle exec rake spec')
end

task default: %i[build_config spec
internal_investigation
confirm_config
Expand Down
1 change: 1 addition & 0 deletions rubocop-factory_bot.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ Gem::Specification.new do |spec|
}

spec.add_runtime_dependency 'rubocop', '~> 1.41'
spec.add_runtime_dependency 'rubocop-ast', '>= 1.31.1', '< 2.0'
end
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@
end

%w[&& ||].each do |operator|
context "with #{operator}" do
# FIXME: `undefined method `[]' for nil` occurs Prism 0.24.0. It has been
# resolved in the development line. This will be resolved in
# Prism > 0.24.0 and higher releases.
context "with #{operator}", broken_on: :prism do
it 'does not flag the call' do
expect_no_offenses(<<~RUBY)
can_create_user? #{operator} create(:user)
Expand All @@ -210,7 +213,10 @@
end
end

context 'with ternary operator' do
# FIXME: `undefined method `[]' for nil` occurs Prism 0.24.0. It has been
# resolved in the development line. This will be resolved in
# Prism > 0.24.0 and higher releases.
context 'with ternary operator', broken_on: :prism do
it 'does not flag the call' do
expect_no_offenses(<<~RUBY)
can_create_user? ? create(:user) : nil
Expand Down
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ module SpecHelper

# Run focused tests with `fdescribe`, `fit`, `:focus` etc.
config.filter_run_when_matching :focus
if ENV['PARSER_ENGINE'] == 'parser_prism'
config.filter_run_excluding broken_on: :prism
end

# We should address configuration warnings when we upgrade
config.raise_errors_for_deprecations!
Expand Down

0 comments on commit 1fea9e9

Please sign in to comment.