Skip to content

Commit 15a20fd

Browse files
committed
fix(no-wildcard-imports): add test case for mix-and-match
1 parent 827d70a commit 15a20fd

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,37 @@ ruleTester.run('no-wildcard-imports', rule, {
119119
],
120120
},
121121

122+
// Test mixed imports
123+
{
124+
code: `import {Dialog, type DialogProps} from '@primer/react/lib-esm/Dialog/Dialog'`,
125+
output: `import {Dialog} from '@primer/react/experimental'
126+
import type {DialogProps} from '@primer/react/experimental'`,
127+
errors: [
128+
{
129+
messageId: 'wildcardMigration',
130+
data: {
131+
wildcardEntrypoint: '@primer/react/lib-esm/Dialog/Dialog',
132+
},
133+
},
134+
],
135+
},
136+
122137
// Test migrations
123138

139+
// Test helpers ------------------------------------------------------------
140+
{
141+
code: `import '@primer/react/lib-esm/utils/test-helpers'`,
142+
output: `import '@primer/react/test-helpers'`,
143+
errors: [
144+
{
145+
messageId: 'wildcardMigration',
146+
data: {
147+
wildcardEntrypoint: '@primer/react/lib-esm/utils/test-helpers',
148+
},
149+
},
150+
],
151+
},
152+
124153
// Components --------------------------------------------------------------
125154
{
126155
code: `import {ButtonBase} from '@primer/react/lib-esm/Button/ButtonBase';

src/rules/no-wildcard-imports.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ const wildcardImports = new Map([
2828
},
2929
],
3030
],
31+
[
32+
'@primer/react/lib-esm/Dialog',
33+
[
34+
{
35+
name: 'Dialog',
36+
from: '@primer/react/experimental',
37+
},
38+
{
39+
name: 'DialogHeaderProps',
40+
from: '@primer/react/experimental',
41+
type: 'type',
42+
},
43+
],
44+
],
3145
[
3246
'@primer/react/lib-esm/Dialog/Dialog',
3347
[
@@ -40,6 +54,16 @@ const wildcardImports = new Map([
4054
from: '@primer/react/experimental',
4155
type: 'type',
4256
},
57+
{
58+
name: 'DialogProps',
59+
from: '@primer/react/experimental',
60+
type: 'type',
61+
},
62+
{
63+
name: 'DialogButtonProps',
64+
from: '@primer/react/experimental',
65+
type: 'type',
66+
},
4367
],
4468
],
4569
[
@@ -245,6 +269,20 @@ module.exports = {
245269
return
246270
}
247271

272+
if (node.source.value === '@primer/react/lib-esm/utils/test-helpers') {
273+
context.report({
274+
node,
275+
messageId: 'wildcardMigration',
276+
data: {
277+
wildcardEntrypoint: node.source.value,
278+
},
279+
fix(fixer) {
280+
return fixer.replaceText(node.source, `'@primer/react/test-helpers'`)
281+
},
282+
})
283+
return
284+
}
285+
248286
const wildcardImportMigrations = wildcardImports.get(node.source.value)
249287
if (!wildcardImportMigrations) {
250288
context.report({
@@ -353,7 +391,7 @@ module.exports = {
353391
yield fixer.replaceText(node, `import {${specifiers.join(', ')}} from '${entrypoint}'`)
354392

355393
if (typeSpecifiers.length > 0) {
356-
const specifiers = valueSpecifiers.map(([imported, local]) => {
394+
const specifiers = typeSpecifiers.map(([imported, local]) => {
357395
if (imported !== local) {
358396
return `${imported} as ${local}`
359397
}

0 commit comments

Comments
 (0)