Skip to content

Post-merge-review: Fix template-no-inline-linkto false positive in GJS/GTS#2679

Open
johanrd wants to merge 2 commits intoember-cli:masterfrom
johanrd:night_fix/template-no-inline-linkto
Open

Post-merge-review: Fix template-no-inline-linkto false positive in GJS/GTS#2679
johanrd wants to merge 2 commits intoember-cli:masterfrom
johanrd:night_fix/template-no-inline-linkto

Conversation

@johanrd
Copy link
Copy Markdown
Contributor

@johanrd johanrd commented Apr 13, 2026

What's broken on master

The angle-bracket visitor checks node.tag === 'LinkTo' by bare name. In GJS/GTS this produces two false signals:

  • A user-authored <LinkTo> from any non-@ember/routing source is falsely flagged when childless:

    import LinkTo from './my-link-to-component';
    <template><LinkTo /></template>   // false-positive on master
  • A renamed framework import is missed entirely:

    import { LinkTo as Link } from '@ember/routing';
    <template><Link /></template>   // false-negative on master — should flag

Fix

Track ImportDeclaration from @ember/routing for LinkTo (including renamed imports) in .gjs/.gts. Only flag elements whose tag is in the tracked set. The curly {{link-to ...}} handler is now gated to HBS only — link-to is not a valid JS identifier, so it cannot be a user binding in strict mode, and the strict-mode compiler would already reject the source. Skipping the autofix in strict mode avoids producing also-broken {{#link-to ...}}.

Note on related rules

The same bug class (bare-name LinkTo/link-to match with no awareness of @ember/routing imports) also exists in template-no-link-to-tagname, template-no-invalid-link-text, and template-no-invalid-link-title on master. Those should be fixed in follow-up PRs using the same pattern.

Limitations

Namespace imports (import * as routing from '@ember/routing'; <routing.LinkTo />) are not tracked — dotted tag paths would need a separate match and are not a realistic usage pattern for this component. Documented in a code comment.

Test plan

21 tests pass on the branch (was 14). New cases:

  • 2 valid GJS/GTS without import (.gjs and .gts) — user component, not flagged
  • 2 valid GJS with @ember/routing import — block-form <LinkTo>...</LinkTo> and renamed <Link>...</Link> not flagged (have children)
  • 2 invalid GJS/GTS with import — childless <LinkTo /> flagged
  • 1 invalid GJS with renamed import — childless <Link /> flagged

HBS path is unchanged. Lint and prettier pass.

johanrd added 2 commits April 13, 2026 13:23
The angle-bracket visitor checks `node.tag === 'LinkTo'` by bare name,
which causes two GJS/GTS bugs (the same class as PR ember-cli#2652 fixed for
template-no-link-to-tagname):

- A user-authored `<LinkTo>` from any non-`@ember/routing` source is
  falsely flagged when childless.
- A renamed framework import (`import { LinkTo as Link } from '@ember/routing'`)
  used as `<Link />` is missed entirely.

Adopt the same `@ember/routing` import-tracker pattern: in strict mode,
only flag elements whose tag is in the tracked map (covers renamed
imports). HBS path uses bare-name match (no imports possible). Curly
`{{link-to ...}}` handler is gated to HBS only — `link-to` is not a
valid JS identifier, so it cannot be a user binding in strict mode, and
the strict-mode compiler would already reject the source.

Tests: 21 (was 14) — adds 4 new valid GJS/GTS cases (no-import bare
`<LinkTo>` in .gjs and .gts, with-import block-form `<LinkTo>...</LinkTo>`,
with-renamed-import block-form `<Link>...</Link>`) and 3 new invalid
cases (with-import childless `<LinkTo />` in .gjs and .gts, renamed
childless `<Link />`).

Docs updated to document the strict-mode behavior.
…mitation

- importedLinkComponents: Map<string, true> → Set<string>
- Move const sourceCode inside the curly-fixer (only user)
- Comment: namespace imports (import * as routing from '@ember/routing')
  are not tracked; dotted tag paths are not a realistic usage pattern.
@johanrd johanrd marked this pull request as ready for review April 13, 2026 11:40
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