|
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). |
3 | 2 | const RENDER_MODIFIER_IMPORT_PATHS = { |
4 | 3 | '@ember/render-modifiers/modifiers/did-insert': 'did-insert', |
5 | 4 | '@ember/render-modifiers/modifiers/did-update': 'did-update', |
6 | 5 | '@ember/render-modifiers/modifiers/will-destroy': 'will-destroy', |
7 | 6 | }; |
8 | 7 |
|
| 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 | + |
9 | 15 | const KEBAB_NAMES = new Set(['did-insert', 'did-update', 'will-destroy']); |
| 16 | +const ROOT_PACKAGE = '@ember/render-modifiers'; |
10 | 17 |
|
11 | 18 | /** @type {import('eslint').Rule.RuleModule} */ |
12 | 19 | module.exports = { |
@@ -56,11 +63,27 @@ module.exports = { |
56 | 63 | if (!isStrictMode) { |
57 | 64 | return; |
58 | 65 | } |
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]; |
60 | 84 | if (!canonical) { |
61 | 85 | return; |
62 | 86 | } |
63 | | - // Default import (`import didInsert from '...'`) is the supported form |
64 | 87 | for (const specifier of node.specifiers) { |
65 | 88 | if (specifier.type === 'ImportDefaultSpecifier') { |
66 | 89 | importedModifiers.set(specifier.local.name, canonical); |
|
0 commit comments