Commit 0338b6c
committed
Fix template-no-link-to-tagname: only flag @TagName, with @ember/routing import tracking in strict mode
What was broken on master:
- The rule matched every `<LinkTo>` tag by bare name. In strict-mode templates
(.gjs/.gts) a component named `LinkTo` is only Ember's router link if it is
imported from `@ember/routing`. This caused two bugs:
1. False positive: a user-authored `<LinkTo @TagName="button">` component
(no import) was flagged even though it has nothing to do with Ember's
router LinkTo.
2. False negative: a renamed import such as
`import { LinkTo as Link } from '@ember/routing'` used as
`<Link @TagName="button">` was not detected because the tag name no
longer matches the bare string `LinkTo`.
- Additionally: on angle-bracket `<LinkTo>` the rule previously flagged the
bare HTML-attribute `tagName` as well as the Ember argument `@tagName`.
Bare `tagName` on angle-bracket invocation is just a passthrough HTML
attribute and is not deprecated; only `@tagName` is.
Fix:
- Detect strict mode via `context.filename` (.gjs / .gts).
- Add an `ImportDeclaration` visitor (strict mode only) that records every
local alias imported as `LinkTo` from `@ember/routing` into
`importedLinkComponents`. Mirrors the pattern used in
`template-no-invalid-link-text`.
- In strict mode the angle-bracket visitor only flags elements whose tag is
in the tracked set. In classic HBS it keeps the previous behavior
(`LinkTo` / `link-to`), since HBS has no imports.
- The curly (`{{link-to}}` / `{{#link-to}}`) visitor is unchanged: there are
no imports in HBS curly form.
- Only flag `@tagName` (not bare `tagName`) on angle-bracket `<LinkTo>`.
Test plan:
- Valid: `<LinkTo @TagName="button">` in .gjs and .gts with no
`@ember/routing` import (user-authored component must not be flagged).
- Invalid: `import { LinkTo } from '@ember/routing';` +
`<LinkTo @TagName=...>` in both .gjs and .gts.
- Invalid: renamed import
`import { LinkTo as Link } from '@ember/routing';` +
`<Link @TagName="button">` flags `<Link>` in both .gjs and .gts.
- Existing HBS cases still covered (including `<link-to @TagName>` via
angle-bracket kebab form in classic templates).1 parent b705850 commit 0338b6c
2 files changed
Lines changed: 71 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | 1 | | |
13 | 2 | | |
14 | 3 | | |
| |||
32 | 21 | | |
33 | 22 | | |
34 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
35 | 43 | | |
36 | 44 | | |
37 | 45 | | |
| |||
46 | 54 | | |
47 | 55 | | |
48 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
49 | 71 | | |
50 | 72 | | |
51 | 73 | | |
52 | 74 | | |
53 | 75 | | |
54 | 76 | | |
55 | | - | |
56 | | - | |
| 77 | + | |
57 | 78 | | |
58 | 79 | | |
59 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
27 | 45 | | |
28 | 46 | | |
29 | 47 | | |
| |||
35 | 53 | | |
36 | 54 | | |
37 | 55 | | |
38 | | - | |
| 56 | + | |
39 | 57 | | |
40 | 58 | | |
41 | 59 | | |
42 | 60 | | |
43 | | - | |
44 | | - | |
| 61 | + | |
| 62 | + | |
45 | 63 | | |
46 | 64 | | |
47 | 65 | | |
| 66 | + | |
48 | 67 | | |
49 | 68 | | |
50 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
51 | 76 | | |
52 | 77 | | |
53 | 78 | | |
| |||
80 | 105 | | |
81 | 106 | | |
82 | 107 | | |
| 108 | + | |
| 109 | + | |
83 | 110 | | |
84 | 111 | | |
85 | 112 | | |
| |||
93 | 120 | | |
94 | 121 | | |
95 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
96 | 128 | | |
97 | 129 | | |
98 | 130 | | |
| |||
0 commit comments