Linter: Implement html-no-nested-forms rule - #1
Closed
irinanazarova wants to merge 1 commit into
Closed
Conversation
irinanazarova
force-pushed
the
html-no-nested-forms
branch
2 times, most recently
from
August 2, 2026 06:08
a08c298 to
f2da265
Compare
irinanazarova
force-pushed
the
html-no-nested-forms
branch
from
August 2, 2026 06:11
f2da265 to
d17e2db
Compare
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 implements a new
html-no-nested-formsrule that disallows placing one<form>element inside another<form>element, including forms rendered by Action View helpers.HTML does not support nested forms: browsers silently drop or re-parent the inner form, leading to broken submissions and buttons that submit the wrong form. The helper case is particularly easy to miss because the nested
<form>never appears in the template. In the example above, the form rendered bybutton_tois dropped during parsing and clicking "Delete" submits the outer form instead, performing an update.The rule detects literal
<form>elements with a depth counter (same approach ashtml-no-nested-links) and form-rendering helpers via Prism (same approach asactionview-no-silent-helper). The helper list comes from the Action View helper registry viagetHelpersForTag("form"), filtered to helpers the parser does not transform yet: once a form helper becomessupported, the element branch catches its synthesized<form>element and the Prism branch stops covering it automatically.button_tois included per the discussion in marcoroth#166, since it is effectively a hidden form. The offense is reported on the inner form's tag name, or on the helper call for helper-rendered forms.Nesting composed across partials (an outer form in one template, an inner form in a rendered partial) is not detectable with per-file linting.
tag.formandcontent_tag(:form)are not detected yet; the registry'sdetectStylemetadata encodes how to find these. This could be a follow-up.Resolves marcoroth#166