Skip to content

Linter Rule: Only allow strict local definitions in partial files

Rule: actionview-strict-locals-partial-only

Description

Detects strict locals declarations in files that are not Rails partials. Strict locals are only supported in partials (templates whose filename begins with an underscore), so a declaration in any other template has no effect.

Rationale

A <%# locals: (...) %> comment in a non-partial file (such as a view or layout) is misleading. It looks like it constrains the available local variables, but Rails only processes strict locals in partials. Flagging these declarations prevents confusion and keeps templates honest about their actual contract.

Examples

✅ Good

app/views/users/_card.html.erb
erb
<%# locals: (user:) %>

<div class="user-card">
  <%= user.name %>
</div>

🚫 Bad

app/views/users/show.html.erb
erb
<%# locals: (user:) %>

<div class="user-card">
  <%= user.name %>
</div>

Configuration

This rule only applies to Action View projects, so it needs framework to be set:

yaml
framework: actionview

References

Released under the MIT License.