diff --git a/Gemfile b/Gemfile index c7664a95c..9e083d748 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/changelog/change_remove_parser_from_runtime_dependency.md b/changelog/change_remove_parser_from_runtime_dependency.md new file mode 100644 index 000000000..647e86445 --- /dev/null +++ b/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][]) diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc index ad17f490a..af49f6c61 100644 --- a/docs/modules/ROOT/pages/index.adoc +++ b/docs/modules/ROOT/pages/index.adoc @@ -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. diff --git a/lib/rubocop/ast/processed_source.rb b/lib/rubocop/ast/processed_source.rb index 7f2c09d5b..fb18c0310 100644 --- a/lib/rubocop/ast/processed_source.rb +++ b/lib/rubocop/ast/processed_source.rb @@ -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 diff --git a/rubocop-ast.gemspec b/rubocop-ast.gemspec index cc3436b67..7d79bfd7e 100644 --- a/rubocop-ast.gemspec +++ b/rubocop-ast.gemspec @@ -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