Skip to content

[FEATURE] Consider ERB indentationΒ #422

@Splines

Description

@Splines

HTML ESLint supports integrating a template engine like Ruby ERB, which works like a charm. It would be amazing if indentation could also be detected and exposed via a config option. Consider this example:

<%= form_with(model: @event) do |f| %>
<div class="form-floating">
  <%= f.text_field :name, required: true, class: "form-control", placeholder: "" %>
  <%= f.label :name %>
</div>
<% end %>

A config option could allow us to specify that we want indentation here as well:

<%= form_with(model: @event) do |f| %>
  <div class="form-floating">
    <%= f.text_field :name, required: true, class: "form-control", placeholder: "" %>
    <%= f.label :name %>
  </div>
<% end %>

Possible problems

  • I'm not sure if this issue is something html-eslint can provide since you'd probably have to use a whole ERB parser to detect these scenarios holistically. E.g. consider already that not all ERB expressions require nesting, e.g. a simple variable assignment is a one-liner.
  • Also, nesting should be properly detected, e.g. imagine another ERB block inside the form_with block.

Workarounds

Accept that this indentation is currently not detected and see it as incentive to avoid deeply nesting your forms. Instead use ViewComponents and/or Rails helpers to make your code more structured.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions