Skip to content

Commit 5b26521

Browse files
committed
fix(no-wildcard-imports): use local name when changing imports
1 parent 1036a5e commit 5b26521

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/rules/__tests__/no-wildcard-imports.test.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ ruleTester.run('no-wildcard-imports', rule, {
105105
],
106106
},
107107

108+
// Test renamed wildcard imports
109+
{
110+
code: `import type {ItemProps} from '@primer/react/lib-esm/deprecated/ActionList/Item'`,
111+
output: `import type {ActionListItemProps as ItemProps} from '@primer/react/deprecated'`,
112+
errors: [
113+
{
114+
messageId: 'wildcardMigration',
115+
data: {
116+
wildcardEntrypoint: '@primer/react/lib-esm/deprecated/ActionList/Item',
117+
},
118+
},
119+
],
120+
},
121+
108122
// Test migrations
109123

110124
// Components --------------------------------------------------------------
@@ -226,7 +240,7 @@ import type {ButtonBaseProps} from '@primer/react'`,
226240
},
227241
{
228242
code: `import type {ItemProps} from '@primer/react/lib-esm/deprecated/ActionList'`,
229-
output: `import type {ActionListItemProps} from '@primer/react/deprecated'`,
243+
output: `import type {ActionListItemProps as ItemProps} from '@primer/react/deprecated'`,
230244
errors: [
231245
{
232246
messageId: 'wildcardMigration',
@@ -238,7 +252,7 @@ import type {ButtonBaseProps} from '@primer/react'`,
238252
},
239253
{
240254
code: `import type {GroupedListProps} from '@primer/react/lib-esm/deprecated/ActionList/List'`,
241-
output: `import type {ActionListGroupedListProps} from '@primer/react/deprecated'`,
255+
output: `import type {ActionListGroupedListProps as GroupedListProps} from '@primer/react/deprecated'`,
242256
errors: [
243257
{
244258
messageId: 'wildcardMigration',
@@ -250,7 +264,7 @@ import type {ButtonBaseProps} from '@primer/react'`,
250264
},
251265
{
252266
code: `import {ItemInput} from '@primer/react/lib-esm/deprecated/ActionList/List'`,
253-
output: `import {ActionListItemInput} from '@primer/react/deprecated'`,
267+
output: `import {ActionListItemInput as ItemInput} from '@primer/react/deprecated'`,
254268
errors: [
255269
{
256270
messageId: 'wildcardMigration',
@@ -262,7 +276,7 @@ import type {ButtonBaseProps} from '@primer/react'`,
262276
},
263277
{
264278
code: `import type {ItemProps} from '@primer/react/lib-esm/deprecated/ActionList/Item'`,
265-
output: `import type {ActionListItemProps} from '@primer/react/deprecated'`,
279+
output: `import type {ActionListItemProps as ItemProps} from '@primer/react/deprecated'`,
266280
errors: [
267281
{
268282
messageId: 'wildcardMigration',

src/rules/no-wildcard-imports.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ module.exports = {
237237
},
238238
},
239239
create(context) {
240+
const sourceCode = context.sourceCode
240241
return {
241242
ImportDeclaration(node) {
242243
if (!node.source.value.startsWith('@primer/react/lib-esm')) {
@@ -282,7 +283,7 @@ module.exports = {
282283
}
283284

284285
if (migration.as) {
285-
changes.get(migration.from).push([migration.as, migration.as, migration.type])
286+
changes.get(migration.from).push([migration.as, specifier.local.name, migration.type])
286287
} else {
287288
changes.get(migration.from).push([migration.name, specifier.local.name, migration.type])
288289
}

0 commit comments

Comments
 (0)