Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #282] Remove Prism from runtime dependency #285

Merged
merged 1 commit into from Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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."
Comment on lines +290 to +292
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to enforce a minimum version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to specify a minimum version, as using the latest version is sufficient. Additionally, it is not always possible to align the development status of Prism with intentions behind released warning of rubocop-ast. So, this approach to warnings is the same as that for gemified Ruby standard libraries.

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