-
-
Notifications
You must be signed in to change notification settings - Fork 58
Support Prism::Translation::Parser35
for Ruby 3.5 parser
#370
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
Conversation
6c19492
to
2685ff7
Compare
2685ff7
to
a4b5f25
Compare
a4b5f25
to
1b7ec6d
Compare
prism
with the translation parser on Ruby >= 3.4Prism::Translation::Parser35
for Ruby 3.5 parser
lib/rubocop/ast/processed_source.rb
Outdated
@@ -35,25 +35,21 @@ class ProcessedSource # rubocop:disable Metrics/ClassLength | |||
INVALID_LEVELS = %i[error fatal].freeze | |||
private_constant :INVALID_LEVELS | |||
|
|||
PARSER_ENGINES = %i[parser_whitequark parser_prism].freeze | |||
PARSER_ENGINES = %i[automatic parser_whitequark parser_prism].freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The term "automatic" might not be the most suitable. "default" might be more preferable.
PARSER_ENGINES = %i[automatic parser_whitequark parser_prism].freeze | |
PARSER_ENGINES = %i[default parser_whitequark parser_prism].freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if default
is actually better but I also don't like automatic
particularly.
In the original version, I opted to simply use nil
to signify this instead. But that has backwards compatibility concerns, where it might choose prism when it previously wouldn't when the user doesn't pass parser_engine
to the method at all.
I changed it to :default
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm not sure if default
is the most suitable choice, but it's a simple term. It's understood that this is a parameter for compatibility and it would be nice if a better name were suggested :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, most users won't have to configure this. So I wouldn't think too much about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
1b7ec6d
to
c2ea41b
Compare
c2ea41b
to
8d4ad5a
Compare
docs/modules/ROOT/pages/index.adoc
Outdated
@@ -109,10 +109,14 @@ for the `:prism_result` keyword argument. Otherwise, the source code is parsed. | |||
|
|||
[source,ruby] | |||
---- | |||
# Using the Parser gem with `prism_result: nil` is the default, meaning the source code is parsed. | |||
# Using the Parser gem with `prism_result: nil` is the default, meaning the source code is parsed until `ruby_version` is 3.4. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Using the Parser gem with `prism_result: nil` is the default, meaning the source code is parsed until `ruby_version` is 3.4. | |
# Using the Parser gem with `prism_result: nil` is the default, meaning the source code is parsed until `ruby_version` is 3.4. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, butchered the copy-paste
lib/rubocop/ast/processed_source.rb
Outdated
# The Parser gem does not support Ruby 3.5 or later. | ||
# It is also not fully compatible with Ruby 3.4 but for | ||
# now respects using parser for backwards compatibility. | ||
def best_parser_engine(ruby_version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename it to the following?
def best_parser_engine(ruby_version) | |
def default_parser_engine(ruby_version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that name makes good sense now
It chooses the prism parser automatically when Ruby 3.5 is selected. In RuboCop, The `ParserEngine` must be set to `automatic` to make use of this. In the future, the prism gem can also be chosen for Ruby 3.4 Co-authored-by: Koichi ITO <koic.ito@gmail.com>
8d4ad5a
to
c17948b
Compare
Prism::Translation::Parser35
for Ruby 3.5 parserPrism::Translation::Parser35
for Ruby 3.5 parser
🚀 |
Thanks for working with me on this @koic |
This builds on top of rubocop/rubocop-ast#370, to let `rubocop-ast` choose the parser engine automatically
This builds on top of rubocop/rubocop-ast#370, to let `rubocop-ast` choose the parser engine automatically
This builds on top of rubocop/rubocop-ast#370, to let `rubocop-ast` choose the parser engine automatically
This builds on top of rubocop/rubocop-ast#370, to let `rubocop-ast` choose the parser engine automatically
I openend rubocop/rubocop#14025 since I already had half of it in rubocop/rubocop#14010 to make it work. Hope that's ok. |
Of course! |
This builds on top of rubocop/rubocop-ast#370, to let `rubocop-ast` choose the parser engine automatically
This builds on top of rubocop/rubocop-ast#370, to let `rubocop-ast` choose the parser engine automatically
One step further towards rubocop/rubocop#13617
In RuboCop, the parser engine in the default config can be set to
default
, and with Ruby 3.5, RuboCop will then automatically choose prism to do its job.More discussion and considerations in #371