8000 Linter Rule: Disallow ActionView tag helpers without ERB output · Issue #180 · marcoroth/herb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Linter Rule: Disallow ActionView tag helpers without ERB output #180
Open
@marcoroth

Description

@marcoroth

Rule: erb-no-unused-tag-helpers

Description

Disallow calling ActionView tag helpers (like tag.div, content_tag, link_to, etc.) without output. These helpers return HTML-safe strings but do not produce any visible effect unless rendered to the template via <%= %>.

Using them inside control tags (<% %>) silently discards the output, which is likely a mistake.

Rationale

Rails' view helpers such as tag.div, content_tag, and link_to return HTML elements as strings. If these are used inside <% ... %>, their return value is computed but never rendered, making them effectively useless.

This often happens due to typos or misunderstanding and leads to invisible bugs where expected output is simply missing.

Examples

✅ Good
<%= tag.div "Hello", class: "greeting" %>

<%= content_tag :section, "Welcome", id: "welcome" %>

<%= link_to "Click here", root_path %>
🚫 Bad
<% tag.div "Hello", class: "greeting" %>

<% content_tag :section, "Welcome", id: "welcome" %>

<% link_to "Click here", root_path %>

References

-

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0