Skip to content

Linter: Make html-no-self-closing Action View Helper aware#1432

Merged
marcoroth merged 1 commit intomainfrom
html-no-self-closing-action-view-helpers
Mar 20, 2026
Merged

Linter: Make html-no-self-closing Action View Helper aware#1432
marcoroth merged 1 commit intomainfrom
html-no-self-closing-action-view-helpers

Conversation

@marcoroth
Copy link
Owner

@marcoroth marcoroth commented Mar 20, 2026

Now that we have support for detecting Action View Tag helpers we can update the html-no-self-closing linter rule to make it Action View Tag helpers aware.

Since the parser already transforms the nodes we don't need to change anything else about the existing rule.

With this pull request, the following doesn't get flagged anymore:

<%= tag.svg(height:, width:) do %>
  <path d="M29.396,2.303 L27.867,2.924 L25.13,18.045 L25.735,18.571 L27.167,18.045 L29.953,2.781 z" fill="currentColor" />
<% end %>

Previously, this was flagged as:

Use `<path></path>` instead of self-closing `<path />` for HTML compatibility. [html-no-self-closing]

Resolves #567

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 20, 2026

npx https://pkg.pr.new/@herb-tools/formatter@1432
npx https://pkg.pr.new/@herb-tools/language-server@1432
npx https://pkg.pr.new/@herb-tools/linter@1432

commit: 3717d7a

@github-actions
Copy link

github-actions bot commented Mar 20, 2026

🌿 Interactive Playground and Documentation Preview

A preview deployment has been built for this pull request. Try out the changes live in the interactive playground:


🌱 Grown from commit 3717d7a


✅ Preview deployment has been cleaned up.

@marcoroth marcoroth merged commit a097e9e into main Mar 20, 2026
20 checks passed
@marcoroth marcoroth deleted the html-no-self-closing-action-view-helpers branch March 20, 2026 02:54
marcoroth added a commit that referenced this pull request Mar 20, 2026
)

While working on #1432 I noticed that our keyword argument extraction
logic for Action View Tag Helpers doesn't 100% produce the right syntax
tree for attributes.

Given the following example:
```erb
<%= tag.div(id:) %>
```
Now with this pull request and `action_view_helpers: true` it parses as:
```diff
@ DocumentNode (location: (1:0)-(1:19))
└── children: (1 item)
    └── @ HTMLElementNode (location: (1:0)-(1:19))
        ├── open_tag: 
        │   └── @ ERBOpenTagNode (location: (1:0)-(1:19))
        │       ├── tag_opening: "<%=" (location: (1:0)-(1:3))
        │       ├── content: " tag.div(id:) " (location: (1:3)-(1:17))
        │       ├── tag_closing: "%>" (location: (1:17)-(1:19))
        │       ├── tag_name: "div" (location: (1:8)-(1:11))
        │       └── children: (1 item)
        │           └── @ HTMLAttributeNode (location: (1:12)-(1:12))
        │               ├── name: 
        │               │   └── @ HTMLAttributeNameNode (location: (1:12)-(1:12))
        │               │       └── children: (1 item)
        │               │           └── @ LiteralNode (location: (1:12)-(1:12))
        │               │               └── content: "id"
        │               │       
        │               ├── equals: ":" (location: (1:12)-(1:12))
        │               └── value: 
        │                   └── @ HTMLAttributeValueNode (location: (1:12)-(1:12))
        │                       ├── open_quote: ∅
        │                       ├── children: (1 item)
        │                       │   └── @ RubyLiteralNode (location: (1:12)-(1:12))
-       │                       │       └── content: "id:"
+       │                       │       └── content: "id"
        │                       │       
        │                       ├── close_quote: ∅
        │                       └── quoted: false
        │                       
        ├── tag_name: "div" (location: (1:8)-(1:11))
        ├── body: []
        ├── close_tag: 
        │   └── @ HTMLVirtualCloseTagNode (location: (1:19)-(1:19))
        │       └── tag_name: "div" (location: (1:8)-(1:11))
        │       
        ├── is_void: false
        └── element_source: "ActionView::Helpers::TagHelper#tag"
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linter: html-no-self-closing should not be applied to nodes within tag.svg

1 participant