-
Notifications
You must be signed in to change notification settings - Fork 172
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 parsing erb with bare yield
#2444
Conversation
Are there any possible downsides to using eval mode here? (cc @kddnewton) |
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.
Thanks for the fix. Let's add a comment to explain what it does as well.
Some things that are valid in erb would not be valid in a standalone ruby file. This particularly impacts `yield`. Instead treat the provided code as being evaled Closes Shopify#2442
f992128
to
4a7a6a2
Compare
It will also turn off unused local variable warnings and void statement warnings, which is probably fine. |
From what I've seen of using Rubocop on ERB, this is actually preferred, because if you assign a variable in one ERB block and use it in another, Rubocop thinks the variable is unused, because it checks each ERB block independently. For example: <% foos = [1,2,3] %>
<div>
<% foos.each do |foo| %>
<span><%= foo %></span>
<% end %>
</div> Rubocop via ERB Lint will complain on line 1 that |
That wouldn't be the case for Kevin's comment though. We strip out the Ruby code from the ERB template and parse it with Prism as if it were a regular Ruby file, so in that particular example it would be able to tell you if the local variable was indeed unused inside the entire template. We don't yet run RuboCop or ERB Lint on ERB files, so all of the existing diagnostics were coming from Prism itself. |
Motivation
Some things that are valid in erb would not be valid in a standalone ruby file. This particularly impacts
yield
.Instead treat the provided code as being evaled
Closes #2442
Implementation
Switch prism into eval mode. Prior work for the prism parser translator at ruby/prism#2741
Automated Tests
Yup
Manual Tests
I'd guess that this is neovim/editor specific since I'm not seeing anything for syntax errors in vscode but the added test does fail previously.