Skip to content

Commit 427e5b2

Browse files
Copilotpksjce
andcommitted
Fix review comments: remove auto-fixing, remove sx prop, add experimental import test
Co-authored-by: pksjce <[email protected]>
1 parent 67bed06 commit 427e5b2

File tree

3 files changed

+13
-130
lines changed

3 files changed

+13
-130
lines changed

docs/rules/no-deprecated-flash.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ import {Flash} from '@primer/react'
2121

2222
function ExampleComponent() {
2323
return (
24-
<Flash
25-
variant="warning"
26-
sx={{fontSize: 0, borderRadius: 0, py: 2, px: 3}}
27-
className="custom-class"
28-
>
24+
<Flash variant="warning" sx={{fontSize: 0, borderRadius: 0, py: 2, px: 3}} className="custom-class">
2925
Banner content
3026
</Flash>
3127
)
@@ -47,11 +43,7 @@ import {Banner} from '@primer/react/experimental'
4743

4844
function ExampleComponent() {
4945
return (
50-
<Banner
51-
variant="warning"
52-
sx={{fontSize: 0, borderRadius: 0, py: 2, px: 3}}
53-
className="custom-class"
54-
>
46+
<Banner variant="warning" className="custom-class">
5547
Banner content
5648
</Banner>
5749
)
@@ -61,8 +53,9 @@ function ExampleComponent() {
6153
## Auto-fix
6254

6355
This rule provides automatic fixes that:
56+
6457
- Replace `Flash` component usage with `Banner`
6558
- Update import statements from `@primer/react` to `@primer/react/experimental`
6659
- Preserve all props, attributes, and children content
6760
- Handle mixed imports appropriately
68-
- Avoid duplicate Banner imports when they already exist
61+
- Avoid duplicate Banner imports when they already exist

src/rules/__tests__/no-deprecated-flash.test.js

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ function Component() {
4949
5050
function Component() {
5151
return <Flash variant="warning">Banner content</Flash>
52-
}`,
53-
output: `import {Banner} from '@primer/react/experimental'
54-
55-
function Component() {
56-
return <Banner variant="warning">Banner content</Banner>
5752
}`,
5853
errors: [{messageId: 'flashDeprecated'}, {messageId: 'flashDeprecated'}],
5954
},
@@ -66,25 +61,11 @@ function Component() {
6661
return (
6762
<Flash
6863
variant="warning"
69-
sx={{fontSize: 0, borderRadius: 0, py: 2, px: 3}}
7064
className="custom-class"
7165
>
7266
Banner content
7367
</Flash>
7468
)
75-
}`,
76-
output: `import {Banner} from '@primer/react/experimental'
77-
78-
function Component() {
79-
return (
80-
<Banner
81-
variant="warning"
82-
sx={{fontSize: 0, borderRadius: 0, py: 2, px: 3}}
83-
className="custom-class"
84-
>
85-
Banner content
86-
</Banner>
87-
)
8869
}`,
8970
errors: [{messageId: 'flashDeprecated'}, {messageId: 'flashDeprecated'}],
9071
},
@@ -101,18 +82,6 @@ function Component() {
10182
<Text>Some text</Text>
10283
</div>
10384
)
104-
}`,
105-
output: `import {Button, Text} from '@primer/react'
106-
import {Banner} from '@primer/react/experimental'
107-
108-
function Component() {
109-
return (
110-
<div>
111-
<Button>Click me</Button>
112-
<Banner variant="error">Error message</Banner>
113-
<Text>Some text</Text>
114-
</div>
115-
)
11685
}`,
11786
errors: [{messageId: 'flashDeprecated'}, {messageId: 'flashDeprecated'}],
11887
},
@@ -123,11 +92,6 @@ function Component() {
12392
12493
function Component() {
12594
return <Flash>Just Flash</Flash>
126-
}`,
127-
output: `import {Banner} from '@primer/react/experimental'
128-
129-
function Component() {
130-
return <Banner>Just Flash</Banner>
13195
}`,
13296
errors: [{messageId: 'flashDeprecated'}, {messageId: 'flashDeprecated'}],
13397
},
@@ -138,11 +102,6 @@ function Component() {
138102
139103
function Component() {
140104
return <Flash variant="info" />
141-
}`,
142-
output: `import {Banner} from '@primer/react/experimental'
143-
144-
function Component() {
145-
return <Banner variant="info" />
146105
}`,
147106
errors: [{messageId: 'flashDeprecated'}, {messageId: 'flashDeprecated'}],
148107
},
@@ -158,16 +117,6 @@ function Component() {
158117
<Flash variant="error">Error</Flash>
159118
</div>
160119
)
161-
}`,
162-
output: `import {Banner} from '@primer/react/experimental'
163-
164-
function Component() {
165-
return (
166-
<div>
167-
<Banner variant="warning">Warning</Banner>
168-
<Banner variant="error">Error</Banner>
169-
</div>
170-
)
171120
}`,
172121
errors: [{messageId: 'flashDeprecated'}, {messageId: 'flashDeprecated'}, {messageId: 'flashDeprecated'}],
173122
},
@@ -185,13 +134,19 @@ function Component() {
185134
</div>
186135
)
187136
}`,
188-
output: `import {Banner} from '@primer/react/experimental'
137+
errors: [{messageId: 'flashDeprecated'}, {messageId: 'flashDeprecated'}],
138+
},
139+
140+
// Flash with existing experimental imports like TooltipV2
141+
{
142+
code: `import {Flash} from '@primer/react'
143+
import {TooltipV2} from '@primer/react/experimental'
189144
190145
function Component() {
191146
return (
192147
<div>
193-
<Banner variant="warning">Flash message</Banner>
194-
<Banner variant="info">Banner message</Banner>
148+
<Flash variant="warning">Flash message</Flash>
149+
<TooltipV2>Tooltip content</TooltipV2>
195150
</div>
196151
)
197152
}`,

src/rules/no-deprecated-flash.js

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ module.exports = {
1515
recommended: true,
1616
url: url(module),
1717
},
18-
fixable: 'code',
1918
schema: [],
2019
messages: {
2120
flashDeprecated: 'Flash component is deprecated. Use Banner from @primer/react/experimental instead.',
@@ -42,61 +41,6 @@ module.exports = {
4241
context.report({
4342
node: flashSpecifier,
4443
messageId: 'flashDeprecated',
45-
*fix(fixer) {
46-
// Check if there's already a Banner import from @primer/react/experimental
47-
const program = node.parent
48-
const existingBannerImport = program.body.find(
49-
stmt =>
50-
stmt.type === 'ImportDeclaration' &&
51-
stmt.source.value === '@primer/react/experimental' &&
52-
stmt.specifiers.some(spec => spec.imported?.name === 'Banner'),
53-
)
54-
55-
// Remove Flash from current import
56-
const otherSpecifiers = node.specifiers.filter(spec => spec !== flashSpecifier)
57-
58-
if (otherSpecifiers.length === 0) {
59-
// If Flash was the only import, replace entire import with Banner
60-
if (!existingBannerImport) {
61-
yield fixer.replaceText(node, "import {Banner} from '@primer/react/experimental'")
62-
} else {
63-
// Banner import already exists, remove this import entirely including newline
64-
const nextToken = sourceCode.getTokenAfter(node)
65-
if (nextToken && sourceCode.getText().substring(node.range[1], nextToken.range[0]).includes('\n')) {
66-
// Remove including the newline after
67-
yield fixer.removeRange([node.range[0], nextToken.range[0]])
68-
} else {
69-
yield fixer.remove(node)
70-
}
71-
}
72-
} else {
73-
// Remove Flash specifier and handle commas properly
74-
const indexOfFlash = node.specifiers.indexOf(flashSpecifier)
75-
76-
if (indexOfFlash === 0) {
77-
// Flash is first, remove Flash and the trailing comma
78-
const tokenAfter = sourceCode.getTokenAfter(flashSpecifier)
79-
if (tokenAfter && tokenAfter.value === ',') {
80-
yield fixer.removeRange([flashSpecifier.range[0], tokenAfter.range[1]])
81-
} else {
82-
yield fixer.remove(flashSpecifier)
83-
}
84-
} else {
85-
// Flash is not first, remove the preceding comma and Flash
86-
const tokenBefore = sourceCode.getTokenBefore(flashSpecifier)
87-
if (tokenBefore && tokenBefore.value === ',') {
88-
yield fixer.removeRange([tokenBefore.range[0], flashSpecifier.range[1]])
89-
} else {
90-
yield fixer.remove(flashSpecifier)
91-
}
92-
}
93-
94-
// Add Banner import if it doesn't exist
95-
if (!existingBannerImport) {
96-
yield fixer.insertTextAfter(node, "\nimport {Banner} from '@primer/react/experimental'")
97-
}
98-
}
99-
},
10044
})
10145
},
10246

@@ -116,15 +60,6 @@ module.exports = {
11660
context.report({
11761
node: node.openingElement.name,
11862
messageId: 'flashDeprecated',
119-
*fix(fixer) {
120-
// Replace opening tag
121-
yield fixer.replaceText(node.openingElement.name, 'Banner')
122-
123-
// Replace closing tag if it exists
124-
if (node.closingElement) {
125-
yield fixer.replaceText(node.closingElement.name, 'Banner')
126-
}
127-
},
12863
})
12964
},
13065
}

0 commit comments

Comments
 (0)