Skip to content

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
johanrd:night_fix/template-require-input-label
Open

Post-merge-review: Fix template-require-input-label mustache branch: apply strict-mode guard#2672
johanrd wants to merge 1 commit intoember-cli:masterfrom
johanrd:night_fix/template-require-input-label

Conversation

@johanrd
Copy link
Copy Markdown
Contributor

@johanrd johanrd commented Apr 13, 2026

What's broken on master

template-require-input-label handles Ember's built-in Input/Textarea in two separate branches:

  1. Mustache form (GlimmerMustacheStatement) — for {{input}} / {{textarea}}.
  2. Element form (GlimmerElementNode) — for <Input> / <Textarea>.

Two issues on master:

  • The mustache branch runs in both HBS and strict mode (.gjs/.gts). But {{input}}/{{textarea}} in a .gjs/.gts are user-imported JS bindings, unrelated to the classic Ember helpers — so the rule should not treat them as form controls requiring a label.
  • The element branch matches <Input> / <Textarea> by bare tag name. In strict mode this both false-positives on user-authored <Input> components (anything locally named Input gets flagged) and false-negatives on renamed framework imports like import { Input as Field } from '@ember/component'; <Field />.

Fix

  • Mustache branch: gate with isStrictMode so the check only runs in HBS, where {{input}}/{{textarea}} are unambiguously the classic helpers.
  • Element branch: in strict mode, track ImportDeclaration specifiers from '@ember/component' (for Input and Textarea, 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 as template-no-builtin-form-components.

Net effect in strict mode:

Code Before After
<Input /> with no @ember/component import not flagged (skipped) not flagged (user component)
import { Input } from '@ember/component'; <Input /> not flagged (skipped) flagged (no label)
import { Textarea as TA } from '@ember/component'; <TA /> not flagged (bare-name miss) flagged (no label)
{{input}} in .gjs flagged (wrong) not flagged

HBS behavior is unchanged.

Test plan

  • pnpm vitest run tests/lib/rules/template-require-input-label.js — 113 tests pass.
  • Added invalid GJS test: import { Input } from '@ember/component'; <template><Input /></template>.
  • Added invalid GTS test for renamed import: import { Textarea as TA } from '@ember/component'; <template><TA /></template>.
  • Added valid GJS test: <Input /> in a .gjs file with no @ember/component import (user-authored).
  • Added valid GJS test: import { Input } from '@ember/component'; <template><label>Name <Input /></label></template>.
  • Existing HBS and strict-mode mustache tests still pass.

@johanrd johanrd marked this pull request as ready for review April 13, 2026 10:33
…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.
@johanrd johanrd force-pushed the night_fix/template-require-input-label branch from 31500bb to 8804d2f Compare April 13, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant