ruby-formatter / rufo

The Ruby Formatter
MIT License
894 stars 56 forks source link

"Invalid yield" error in ERB files on ruby 3.3.0 #319

Closed mloughran closed 3 months ago

mloughran commented 8 months ago

Formatting any ERB file containing <%= yield %> (as is customary in a template) returns an error on ruby 3.3.0:

% ruby -v
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
% rufo -v
rufo 0.17.0
% cat test.erb
<%= yield %>
% rufo test.erb
test.erb:1 Invalid yield
% echo $?
1

but worked fine on ruby 3.2.2:

% ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin23]
% rufo -v
rufo 0.17.0
% cat test.erb
<%= yield %>
% rufo test.erb
% echo $?
0
kzkn commented 8 months ago

Thanks for the report :smile: This is caused by a breaking change on Ripper. Ripper produces nil for just yield on Ruby 3.3.0.

$ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
$ ruby -rripper -e "p Ripper.sexp('yield')"
[:program, [[:yield0]]]

$ ruby -v
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-linux]
$ ruby -rripper -e "p Ripper.sexp('yield')"
nil

We may have to wait for Ruby itself to be fixed :thinking:

mloughran commented 8 months ago

Thanks for investigating and identifying the issue.

Is it worth raising an issue on the ruby tracker (I can't see anything related)? I suspect you're better placed to do so than me. 😄

kzkn commented 8 months ago

I've opened: https://bugs.ruby-lang.org/issues/20186