Skip to content

Commit e1c4d93

Browse files
update the tests and remove the space after title node is removed
1 parent 2918f64 commit e1c4d93

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

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

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,32 +64,27 @@ ruleTester.run('no-deprecated-props', rule, {
6464
],
6565
invalid: [
6666
{
67-
code: `
68-
import {ActionList} from '@primer/react';
69-
<ActionList>
70-
<ActionList.Group title="Group heading 1">
71-
<ActionList.Item>Item</ActionList.Item>
72-
</ActionList.Group>
73-
<ActionList.Group title="Group heading 2">
74-
<ActionList.Item>Item 2</ActionList.Item>
75-
</ActionList.Group>
76-
</ActionList>`,
77-
output: `
78-
import {ActionList} from '@primer/react';
79-
<ActionList>
80-
<ActionList.Group>
81-
<ActionList.GroupHeading>Group heading 1</ActionList.GroupHeading>
82-
<ActionList.Item>Item</ActionList.Item>
83-
</ActionList.Group>
84-
<ActionList.Group>
85-
<ActionList.GroupHeading>Group heading 2</ActionList.GroupHeading>
86-
<ActionList.Item>Item 2</ActionList.Item>
87-
</ActionList.Group>
88-
</ActionList>`,
67+
code: `<ActionList.Group title="Group heading 1"></ActionList.Group>`,
68+
output: `<ActionList.Group><ActionList.GroupHeading>Group heading 1</ActionList.GroupHeading></ActionList.Group>`,
8969
errors: [
9070
{
9171
messageId: 'titlePropDeprecated',
9272
},
73+
],
74+
},
75+
{
76+
code: `<ActionList.Group title="Group heading 1" sx={{padding: 2}}></ActionList.Group>`,
77+
output: `<ActionList.Group sx={{padding: 2}}><ActionList.GroupHeading>Group heading 1</ActionList.GroupHeading></ActionList.Group>`,
78+
errors: [
79+
{
80+
messageId: 'titlePropDeprecated',
81+
},
82+
],
83+
},
84+
{
85+
code: `<ActionList.Group variant="filled" title="Group heading 1"></ActionList.Group>`,
86+
output: `<ActionList.Group variant="filled"><ActionList.GroupHeading>Group heading 1</ActionList.GroupHeading></ActionList.Group>`,
87+
errors: [
9388
{
9489
messageId: 'titlePropDeprecated',
9590
},

src/rules/no-deprecated-props.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,20 @@ module.exports = {
2929
return
3030
}
3131
const title = getJSXOpeningElementAttribute(node, 'title')
32+
3233
if (title !== undefined) {
33-
console.log('hello', title.name.name, title.value.value)
3434
context.report({
3535
node,
3636
messageId: 'titlePropDeprecated',
3737
fix(fixer) {
3838
const groupTitle = title.value.value
39-
// const sourceCode = context.sourceCode
40-
// const start = title.range[0]
41-
// const end = sourceCode.getTokenAfter(title).range[1]
39+
const start = title.range[0]
40+
const end = title.range[1]
4241
return [
43-
// fixer.removeRange([start, end]),
44-
fixer.remove(title),
42+
fixer.removeRange([start - 1, end]), // remove the space before the title as well
4543
fixer.insertTextAfterRange(
4644
[node.range[1], node.range[1]],
47-
`\n<ActionList.GroupHeading>${groupTitle}</ActionList.GroupHeading>;`,
45+
`<ActionList.GroupHeading>${groupTitle}</ActionList.GroupHeading>`,
4846
),
4947
]
5048
},

0 commit comments

Comments
 (0)