feat: add template-valid-label-for#2760
Draft
johanrd wants to merge 4 commits intoember-cli:masterfrom
Draft
Conversation
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.
Note
This is part of a series where Claude has audited
eslint-plugin-emberagainst jsx-a11y, vuejs-accessibility, angular-eslint, lit-a11y and html-validate,ember-template-lint, and the HTML and WCAG specs.See html-validate
input-missing-labelfor the related peer rule (checks from the input side; this rule checks from the label side).Adds
template-valid-label-for: validates that<label for="x">points at a labelable form control in the same template, and flagsforas redundant when the target is already nested inside the label.What is checked
<label for="x">where the element withid="x"is a<div>or other non-labelable element is flagged. Labelable per HTML §4.6.19:button,input(excepttype=hidden),meter,output,progress,select,textarea. Ember's built-in<Input>and<Textarea>components (which render to native form controls) are also accepted as labelable targets.for—<label for="x"><input id="x" /></label>is flagged because theforattribute adds nothing when the target is the first labelable descendant already bound via containment. Ifforpoints at a non-first labelable descendant, the author is expressing an explicit choice and it is not flagged. HTML §4.6.19: "the first labelable element … that is a descendant of the label element."Dynamic
forvalues (mustache) are skipped. Targets not found in this template are also skipped (partial templates, yielded content).Ember
<Input>/<Textarea>resolution<Input>and<Textarea>resolve globally to the built-in components → always labelable.@ember/component(directly or aliased) counts as the built-in. A local binding that shadows the name from a different module → not labelable (false-negative acceptable).Flags
Allows
Prior art
label-has-associated-control— checks label has a text label and an associated controllabel-has-for— checksforpresent on labelinput-missing-label— checks from the input side (does the input have a label?)No peer checks labelable-target validity + redundant-for from the label side.