-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Support Prism as a Ruby parser #446
Conversation
ea2bc14
to
231cea8
Compare
Follow up rubocop/rubocop-ast#277 In Prism (`Prism::Translation::Parser`), `match-with-lvasgn` can be distinctly differentiated. It is unclear whether to conform to the current behavior of the Parser gem, but initially, `def_node_matcher` has been updated to accept the following incompatibilities for `Performance/EndWith`, `Performance/StringInclude`, and `Performance/StartWith` cops to ensure it works with Prism 0.24.0 as well. ## Parser gem Returns an `match_with_lvasgn` node: ```console $ bundle exec ruby -rparser/ruby33 -ve 'p Parser::Ruby33.parse("/foo/ =~ bar")' ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22] s(:match_with_lvasgn, s(:regexp, s(:str, "foo"), s(:regopt)), s(:send, nil, :bar)) ``` Returns an `match_with_lvasgn` node: ```console $ bundle exec ruby -rparser/ruby33 -ve 'p Parser::Ruby33.parse("/(?<foo>)foo/ =~ bar")' ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22] s(:match_with_lvasgn, s(:regexp, s(:str, "(?<foo>)foo"), s(:regopt)), s(:send, nil, :bar)) ``` This lvar-injecting feature appears to have not been supported by Parser gem for a long time: whitequark/parser#69 (comment) ## Prism Returns an `send` node: ```console $ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve 'p Prism::Translation::Parser33.parse("/foo/ =~ bar")' ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22] s(:send, s(:regexp, s(:str, "foo"), s(:regopt)), :=~, s(:send, nil, :bar)) ``` Returns an `match_with_lvasgn` node: ```console $ bundle exec ruby -Ilib -rprism -rprism/translation/parser33 -ve 'p Prism::Translation::Parser33.parse("/(?<foo>)foo/ =~ bar")' ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22] s(:match_with_lvasgn, s(:regexp, s(:str, "(?<foo>)foo"), s(:regopt)), s(:send, nil, :bar)) ```
@@ -36,7 +41,7 @@ end | |||
desc 'Run RuboCop over itself' | |||
RuboCop::RakeTask.new(:internal_investigation) | |||
|
|||
task default: %i[documentation_syntax_check spec internal_investigation] | |||
task default: %i[documentation_syntax_check spec prism_spec internal_investigation] |
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.
Isn’t prism_spec effectively just a duplicate of rspec task when executed from non-prism CI jobs, @koic ? Same in rubocop-rails.
The suggestion is to run the default rake task in the prism ci job, and remove prism_spec. Wdyt?
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.
Normally, efforts are made to ensure that prism_spec
passes locally. If it becomes too troublesome, it might be removed, but currently, having prism_spec
operational is more convenient. So, I'd like to quickly identify issues related to Prism. Cases where tests cannot pass with Prism can be handled with unsupported_on: :prism
or broken_on: :prism
.
Follow up rubocop/rubocop-ast#277
In Prism (
Prism::Translation::Parser
),match-with-lvasgn
can be distinctly differentiated.It is unclear whether to conform to the current behavior of the Parser gem, but initially,
def_node_matcher
has been updated to accept the following incompatibilities forPerformance/EndWith
,Performance/StringInclude
, andPerformance/StartWith
cops to ensure it works with Prism 0.24.0 as well.Parser gem
Returns an
match_with_lvasgn
node:Returns an
match_with_lvasgn
node:This lvar-injecting feature appears to have not been supported by Parser gem for a long time: whitequark/parser#69 (comment)
Prism
Returns an
send
node:Returns an
match_with_lvasgn
node:Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.