Skip to content

Latest commit

 

History

History
86 lines (66 loc) · 1.38 KB

File metadata and controls

86 lines (66 loc) · 1.38 KB

Rule: erb-no-then-in-control-flow

Description

Disallow the use of the Ruby then keyword in control flow expressions inside ERB templates. This applies to:

  • if … then
  • elsif … then
  • unless … then
  • case … when … then
  • case … in … then

Rationale

While Ruby allows the then keyword, its use inside ERB templates significantly reduces readability and adds confusion/ambiguity.

In templates, clarity matters more than terseness. The multiline form:

  • Is easier to read and review
  • Works better with indentation and formatting rules
  • Avoids subtle parsing confusion in mixed HTML/Ruby contexts
  • Matches idiomatic Rails view style

This rule enforces a consistent, block-oriented style for control flow in ERB.

Examples

Good

<% if condition %>
  yes
<% end %>
<% unless logged_in? %>
  please log in
<% end %>
<% case status %>
<% when :ok %>
  success
<% when :error %>
  failure
<% else %>
  unknown
<% end %>
<% case value %>
<% in Integer %>
  number
<% in String %>
  string
<% end %>

Bad

<% if condition then %>
  yes
<% end %>
<% case status %>
<% when :ok then %>
  success
<% end %>
<% case value %>
<% in Integer then "number" %>
<% in String then "text" %>
<% end %>

References