Post-merge-review: Fix template-require-input-label mustache branch: apply strict-mode guard#2672
Open
johanrd wants to merge 1 commit intoember-cli:masterfrom
Open
Conversation
…ection in strict mode
The original fix gated the mustache branch (GlimmerMustacheStatement)
with isStrictMode, because in GJS/GTS {{input}}/{{textarea}} are
user-imported JS bindings, not the classic Ember helpers.
The element branch still matched <Input>/<Textarea> by bare tag name,
which in GJS/GTS:
- false-positives on user-authored <Input> (not the framework one),
- false-negatives on renamed framework imports such as
`import { Input as Field } from '@ember/component'; <Field />`.
Make the element branch import-aware in strict mode (mirroring the
pattern in template-no-builtin-form-components):
- Track ImportDeclaration specifiers from '@ember/component' for
Input and Textarea (only in .gjs/.gts).
- In strict mode, only treat a tag as the built-in if it resolves
to a tracked import (supports renames).
- In HBS, keep the existing bare-name match.
- Remove the blanket `if (isStrictMode && (Input|Textarea)) return`
short-circuit — we now want to flag tracked imports, not skip them.
The mustache branch remains strict-mode-gated as before.
31500bb to
8804d2f
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.
What's broken on master
template-require-input-labelhandles Ember's built-inInput/Textareain two separate branches:GlimmerMustacheStatement) — for{{input}}/{{textarea}}.GlimmerElementNode) — for<Input>/<Textarea>.Two issues on master:
.gjs/.gts). But{{input}}/{{textarea}}in a.gjs/.gtsare user-imported JS bindings, unrelated to the classic Ember helpers — so the rule should not treat them as form controls requiring a label.<Input>/<Textarea>by bare tag name. In strict mode this both false-positives on user-authored<Input>components (anything locally namedInputgets flagged) and false-negatives on renamed framework imports likeimport { Input as Field } from '@ember/component'; <Field />.Fix
isStrictModeso the check only runs in HBS, where{{input}}/{{textarea}}are unambiguously the classic helpers.ImportDeclarationspecifiers from'@ember/component'(forInputandTextarea, supporting renames) and only treat a tag as the built-in if it resolves to a tracked import. In HBS, keep the existing bare-name match. Same pattern astemplate-no-builtin-form-components.Net effect in strict mode:
<Input />with no@ember/componentimportimport { Input } from '@ember/component'; <Input />import { Textarea as TA } from '@ember/component'; <TA />{{input}}in.gjsHBS behavior is unchanged.
Test plan
pnpm vitest run tests/lib/rules/template-require-input-label.js— 113 tests pass.import { Input } from '@ember/component'; <template><Input /></template>.import { Textarea as TA } from '@ember/component'; <template><TA /></template>.<Input />in a.gjsfile with no@ember/componentimport (user-authored).import { Input } from '@ember/component'; <template><label>Name <Input /></label></template>.