Skip to content

Commit bb52db7

Browse files
committed
Also handle named imports from root '@ember/render-modifiers' package
1 parent ed02170 commit bb52db7

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

lib/rules/template-no-at-ember-render-modifiers.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
// Map of `@ember/render-modifiers` sub-path → canonical kebab-case modifier name.
2-
// Default-imported names are user-chosen, so we track local names to canonical.
1+
// Sub-path → canonical kebab-case modifier name (default import).
32
const RENDER_MODIFIER_IMPORT_PATHS = {
43
'@ember/render-modifiers/modifiers/did-insert': 'did-insert',
54
'@ember/render-modifiers/modifiers/did-update': 'did-update',
65
'@ember/render-modifiers/modifiers/will-destroy': 'will-destroy',
76
};
87

8+
// Named exports of the root package `@ember/render-modifiers` → canonical kebab name.
9+
const ROOT_NAMED_EXPORTS = {
10+
didInsert: 'did-insert',
11+
didUpdate: 'did-update',
12+
willDestroy: 'will-destroy',
13+
};
14+
915
const KEBAB_NAMES = new Set(['did-insert', 'did-update', 'will-destroy']);
16+
const ROOT_PACKAGE = '@ember/render-modifiers';
1017

1118
/** @type {import('eslint').Rule.RuleModule} */
1219
module.exports = {
@@ -56,11 +63,27 @@ module.exports = {
5663
if (!isStrictMode) {
5764
return;
5865
}
59-
const canonical = RENDER_MODIFIER_IMPORT_PATHS[node.source.value];
66+
const source = node.source.value;
67+
68+
if (source === ROOT_PACKAGE) {
69+
// `import { didInsert, didUpdate as x } from '@ember/render-modifiers'`
70+
for (const specifier of node.specifiers) {
71+
if (specifier.type === 'ImportSpecifier') {
72+
const exportedName = specifier.imported.name;
73+
const canonical = ROOT_NAMED_EXPORTS[exportedName];
74+
if (canonical) {
75+
importedModifiers.set(specifier.local.name, canonical);
76+
}
77+
}
78+
}
79+
return;
80+
}
81+
82+
// Sub-path: `import didInsert from '@ember/render-modifiers/modifiers/did-insert'`
83+
const canonical = RENDER_MODIFIER_IMPORT_PATHS[source];
6084
if (!canonical) {
6185
return;
6286
}
63-
// Default import (`import didInsert from '...'`) is the supported form
6487
for (const specifier of node.specifiers) {
6588
if (specifier.type === 'ImportDefaultSpecifier') {
6689
importedModifiers.set(specifier.local.name, canonical);

tests/lib/rules/template-no-at-ember-render-modifiers.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ ruleTester.run('template-no-at-ember-render-modifiers', rule, {
4545
code: `import didInsert from './my-lib';
4646
<template><div {{didInsert this.setup}}></div></template>`,
4747
},
48+
// Root-package import of an unknown named export is not a render modifier
49+
{
50+
filename: 'test.gjs',
51+
code: `import { somethingElse } from '@ember/render-modifiers';
52+
<template><div {{somethingElse this.setup}}></div></template>`,
53+
},
4854
],
4955

5056
invalid: [
@@ -131,6 +137,37 @@ ruleTester.run('template-no-at-ember-render-modifiers', rule, {
131137
output: null,
132138
errors: [{ messageId: 'noRenderModifier' }],
133139
},
140+
141+
// Root-package named imports — all three modifiers
142+
{
143+
filename: 'test.gjs',
144+
code: `import { didInsert } from '@ember/render-modifiers';
145+
<template><div {{didInsert this.setup}}></div></template>`,
146+
output: null,
147+
errors: [{ messageId: 'noRenderModifier' }],
148+
},
149+
{
150+
filename: 'test.gjs',
151+
code: `import { didUpdate } from '@ember/render-modifiers';
152+
<template><div {{didUpdate this.update}}></div></template>`,
153+
output: null,
154+
errors: [{ messageId: 'noRenderModifier' }],
155+
},
156+
{
157+
filename: 'test.gjs',
158+
code: `import { willDestroy } from '@ember/render-modifiers';
159+
<template><div {{willDestroy this.cleanup}}></div></template>`,
160+
output: null,
161+
errors: [{ messageId: 'noRenderModifier' }],
162+
},
163+
// Aliased root-package import still flags
164+
{
165+
filename: 'test.gjs',
166+
code: `import { didInsert as myModifier } from '@ember/render-modifiers';
167+
<template><div {{myModifier this.setup}}></div></template>`,
168+
output: null,
169+
errors: [{ messageId: 'noRenderModifier' }],
170+
},
134171
],
135172
});
136173

0 commit comments

Comments
 (0)