Skip to content

Commit

Permalink
[Fix #282] Remove Prism from runtime dependency
Browse files Browse the repository at this point in the history
Fixes #282.

This PR removes Prism from runtime dependency.

If it is decided that Prism will not be a runtime dependency for the time being,
error message and documentation will be used to communicate the dependency on Prism to users.

Making it a default runtime dependency will be avoided until at least #282 installation error with Prism is resolved.
  • Loading branch information
koic authored and bbatsov committed Mar 1, 2024
1 parent 63a0eba commit 5d24fec
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -11,6 +11,7 @@ gemspec
gem 'bump', require: false
gem 'bundler', '>= 1.15.0', '< 3.0'
gem 'oedipus_lex', '>= 2.6.0', require: false
gem 'prism', '>= 0.24.0'
gem 'racc'
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.7'
Expand Down
1 change: 1 addition & 0 deletions changelog/change_remove_parser_from_runtime_dependency.md
@@ -0,0 +1 @@
* [#282](https://github.com/rubocop/rubocop-ast/issues/282): Remove Prism from runtime dependency. ([@koic][])
10 changes: 9 additions & 1 deletion docs/modules/ROOT/pages/index.adoc
Expand Up @@ -83,7 +83,15 @@ rule = MyRule.new
source.ast.each_node { |n| rule.process(n) }
----

In RuboCop AST, you can specify Prism as the parser engine backend by setting `parser_engine: :parser_prism`:
In RuboCop AST, you can specify Prism as the parser engine backend.

If running through Bundler, please first add `gem 'prism'` to your Gemfile:

```ruby
gem 'prism'
```

By specifying `parser_engine: :parser_prism`, parsing with Prism can be processed:

```ruby
# Using the Parser gem with `parser_engine: parser_whitequark` is the default.
Expand Down
7 changes: 6 additions & 1 deletion lib/rubocop/ast/processed_source.rb
Expand Up @@ -286,7 +286,12 @@ def parser_class(ruby_version, parser_engine)
raise ArgumentError, "RuboCop found unknown Ruby version: #{ruby_version.inspect}"
end
when :parser_prism
require 'prism'
begin
require 'prism'
rescue LoadError
warn "Error: Unable to load Prism. Add `gem 'prism'` to your Gemfile."
exit!
end

case ruby_version
when 3.3
Expand Down
1 change: 0 additions & 1 deletion rubocop-ast.gemspec
Expand Up @@ -34,7 +34,6 @@ Gem::Specification.new do |s|
}

s.add_runtime_dependency('parser', '>= 3.3.0.4')
s.add_runtime_dependency('prism', '>= 0.24.0')

##### Do NOT add `rubocop` (or anything depending on `rubocop`) here. See Gemfile
end

0 comments on commit 5d24fec

Please sign in to comment.