ruby-formatter/rufo

syntax error, unexpected end-of-input on erb

Closed this issue · 8 comments

rufo --version
rufo 0.13.0

rufo _head.erb   
_head.erb:11 syntax error, unexpected end-of-input

image

Might be the errant space in there, is this still an issue if you replace it with LocationService::LANGUAGE_REGION_CODES_WITH_ENGLISH?

@effleurager the issue still exists if I remove the space

@effleurager the issue still exists if I remove the space

Can you send the full block for that if-statement?

@effleurager does this work?

<% if @alternates
  Service::SOMETHING.each do |code| %>
    <link rel="alternate" hreflang="<%= code[0..1] %>" href="">
  <% end
  @alternates[:with].each do |language, replacement| %>
    <link rel="alternate" hreflang="<%= language %>" href="">
  <% end %>
<% else %>
  <link rel="alternate" hreflang="en" href="">
<% end %>

That gives a syntax error on line 2.
The following does work:

<% if @alternates %>
  <% Service::SOMETHING.each do |code| %>
    <link rel="alternate" hreflang="<%= code[0..1] %>" href="">
  <% end %>
  <% @alternates[:with].each do |language, replacement| %>
    <link rel="alternate" hreflang="<%= language %>" href="">
  <% end %>
<% else %>
  <link rel="alternate" hreflang="en" href="">
<% end %>

@effleurager thanks for the workaround but isn't the code I pasted valid too?

Just checked, it actually is a workaround. The problem lies in Ripper requiring the block and if statements to be completed with end. That requires taking adding \nend twice as a code wrapper in

def determine_code_wrappers(code_str)
. While entirely possible to hack a fix together, it'd be better to figure out the required number of \nend to be added for a given code string