Skip to content

Parser: Detect image_tag Action View helper#1437

Merged
marcoroth merged 1 commit intomainfrom
parser-image-tag
Mar 21, 2026
Merged

Parser: Detect image_tag Action View helper#1437
marcoroth merged 1 commit intomainfrom
parser-image-tag

Conversation

@marcoroth
Copy link
Owner

@marcoroth marcoroth commented Mar 21, 2026

This pull request allows the parser to be able to detect and transform the image_tag helper using the action_view_helpers parser option.

For example:

<%= image_tag image_path("picture.png"), class: "image" %>

Gets parsed as:

@ DocumentNode (location: (1:0)-(1:58))
└── children: (1 item)
    └── @ HTMLElementNode (location: (1:0)-(1:58))
        ├── open_tag:
           └── @ ERBOpenTagNode (location: (1:0)-(1:58))
               ├── tag_opening: "<%=" (location: (1:0)-(1:3))├── content: " image_tag image_path("picture.png"), class: "image" " (location: (1:3)-(1:56))
               ├── tag_closing: "%>" (location: (1:56)-(1:58))├── tag_name: "img" (location: (1:4)-(1:13))
               └── children: (2 items)
                   ├── @ HTMLAttributeNode (location: (1:14)-(1:39))
                      ├── name:
                         └── @ HTMLAttributeNameNode (location: (1:14)-(1:39))
                             └── children: (1 item)
                                 └── @ LiteralNode (location: (1:14)-(1:39))
                                     └── content: "src"
                         ├── equals: ":" (location: (1:14)-(1:39))
                      └── value:
                          └── @ HTMLAttributeValueNode (location: (1:14)-(1:39))
                              ├── open_quote: 
                              ├── children: (1 item)
                                 └── @ RubyLiteralNode (location: (1:14)-(1:39))
                                     └── content: "image_path(\"picture.png\")"
                              
                              ├── close_quote: 
                              └── quoted: false
                   
                   └── @ HTMLAttributeNode (location: (1:41)-(1:48))
                       ├── name:
                          └── @ HTMLAttributeNameNode (location: (1:41)-(1:48))
                              └── children: (1 item)
                                  └── @ LiteralNode (location: (1:41)-(1:48))
                                      └── content: "class"
                       ├── equals: "=" (location: (1:41)-(1:48))
                       └── value:
                           └── @ HTMLAttributeValueNode (location: (1:41)-(1:48))
                               ├── open_quote: """ (location: (1:41)-(1:48))
                               ├── children: (1 item)
                                  └── @ LiteralNode (location: (1:41)-(1:48))
                                      └── content: "image"
                               ├── close_quote: """ (location: (1:48)-(1:48))
                               └── quoted: true
        
        ├── tag_name: "img" (location: (1:4)-(1:13))
        ├── body: []
        ├── close_tag: 
        ├── is_void: true
        └── element_source: "ActionView::Helpers::AssetTagHelper#image_tag"

This pull request also updates the rewriters to be able to rewrite from/to the image_path syntax. The above example can be transformed to this and back:

<img src="<%= image_path("picture.png") %>" class="image" />

Follow up on #1122
Follow up on #1354
Follow up on #1374

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 21, 2026

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

commit: b089e4d

@github-actions
Copy link

github-actions bot commented Mar 21, 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 b089e4d


✅ Preview deployment has been cleaned up.

@marcoroth marcoroth merged commit 2ec3a5d into main Mar 21, 2026
32 checks passed
@marcoroth marcoroth deleted the parser-image-tag branch March 21, 2026 01:42
marcoroth added a commit that referenced this pull request Mar 21, 2026
With #1437, we can now also make the `html-img-require-alt` linter rule
Action View helper aware, so that we can catch missing `[alt]`
attributes on `<%= image_tag %>` helpers.

The following snippets is now also flagged by the `html-img-require-alt`
linter rule:

```erb
<%= image_tag image_path("picture.png"), class: "image" %>
```
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.

1 participant