Skip to content

[Formatting] Syntax error for if condition that spans an each do ... end blockΒ #74

@rdimartino

Description

@rdimartino
ERB-snippet
<ul>
<% if @items.each do |i|%>
<li><%= i %></li>
<% end.blank? %>
<li>No items</li>
<% end %>
</ul>
Expected formatting
<ul>
  <% if @items.each do |i|%>
    <li><%= i %></li>
  <% end.blank? %>
    <li>No items</li>
  <% end %>
</ul>
Actual formatting
Error: syntax error, unexpected `end'
> 1 | <ul>
    | ^
  2 |   <% if @items.each do |i|%>
  3 |     <li><%= i %></li>
  4 |   <% end.blank? %>

Comment

This may be an anti-pattern but it's valid ERB. Instead of checking the size of @items directly, you can check if the each block rendered anything and if not (i.e. .blank? is true) then you render the fallback.

If this pattern can't be supported, it would be nice if the syntax error pointed to a better spot at least.

Versions

syntax_tree: 6.1.1
syntax_tree-erb: 0.10.5

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions