Parser: Analyze and transform Action View helpers#1347
Merged
Conversation
f9648ca to
f6f7904
Compare
f6f7904 to
4e94e0d
Compare
commit: |
🌿 Interactive Playground and Documentation PreviewA preview deployment has been built for this pull request. Try out the changes live in the interactive playground: 🌱 Grown from commit ✅ Preview deployment has been cleaned up. |
marcoroth
added a commit
that referenced
this pull request
Mar 10, 2026
This pull request implements two new built-in rewriters `action-view-tag-helper-to-html` and `html-to-action-view-tag-helper` using the infrastructure implemented in #1347. This allows us to rewrite an Action View Tag Helper like: ```html+erb <%= tag.div class: classes, data: { controller: "hello" } do %> Content <% end %> ``` to HTML: ```html+erb <div class="<%= classes %>" data-controller="hello"> Content </div> ``` and back!
marcoroth
added a commit
that referenced
this pull request
Mar 11, 2026
) This pull request implements a hover provider for Action View Tag Helpers to show what they evaluate to. It uses the foundation introduced in #1347 and uses the rewriters introduced in #1348 to show the "HTML equivalent" in the hover box. https://github.com/user-attachments/assets/1878a044-716c-4aab-b019-f13ad056cd32 Related #1282
marcoroth
added a commit
that referenced
this pull request
Mar 11, 2026
Based on the foundation of #1347 and #1348, this pull request implements Code Actions to transform Action View Tag Helpers to pure HTML, and from pure HTML back to Action View tag helpers. This should help to make it easier to refactor between the two syntaxes. https://github.com/user-attachments/assets/10229a78-9316-4f2c-a864-f5cc1536ad9e
This was referenced Mar 11, 2026
marcoroth
added a commit
that referenced
this pull request
Mar 12, 2026
Based on the infrastructure introduced in #1347 we can now start making the linter rules aware of the Action View Tag Helpers. The `html-anchor-require-href` linter rule is now also able to flag the following: ```erb <%= link_to "Home", "#" %> ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds the foundation for parsing and analyzing Action View tag helpers. To start with, only a few helpers are supported,
tag.*,content_tag, andlink_to. But more can be added by extending the handler registry.A new
action_view_helpersparser option is available to enable this analysis (defaults to false). When enabled, the parser detects supported helper calls and transforms them into syntheticHTMLElementNodeAST representations. HTML attributes are extracted from Ruby keyword arguments, includingdata/arianested hashes, attribute splats, interpolated strings, andmethod/remotetodata-*conversions.This also introduces several new AST node types:
ERBOpenTagNode,HTMLVirtualCloseTagNode,RubyHTMLAttributesSplatNode, andRubyLiteralNode.For example, the following template:
Gets parsed and transformed to:
The location reporting for the HTML attribute nodes can still be improved and is going be necessary if we want to improve
stimulus-lintfor example, so we can accurately show which part of Ruby is relevant.Resolves #1122