Skip to content

Commit 613795b

Browse files
add a fix to replace aria-label with text
1 parent 27c7e24 commit 613795b

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/rules/__tests__/use-next-tooltip.test.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ ruleTester.run('use-next-tooltip', rule, {
2626
output: `import {Tooltip} from '@primer/react/next';`,
2727
},
2828
{
29-
code: `import {Tooltip, Button} from '@primer/react';`,
30-
errors: [{messageId: 'useNextTooltip'}],
31-
output: `import {Button} from '@primer/react';\nimport {Tooltip} from '@primer/react/next';`,
29+
code: `import {Tooltip, Button} from '@primer/react';\n<Tooltip aria-label="tooltip text"><Button>Button</Button></Tooltip>`,
30+
errors: [{messageId: 'useNextTooltip'}, {messageId: 'useTextProp'}],
31+
output: `import {Button} from '@primer/react';\nimport {Tooltip} from '@primer/react/next';\n<Tooltip text="tooltip text"><Button>Button</Button></Tooltip>`,
3232
},
3333
{
34-
code: `import {ActionList, ActionMenu, Tooltip, Button} from '@primer/react';`,
35-
errors: [{messageId: 'useNextTooltip'}],
36-
output: `import {ActionList, ActionMenu, Button} from '@primer/react';\nimport {Tooltip} from '@primer/react/next';`,
34+
code: `import {ActionList, ActionMenu, Tooltip, Button} from '@primer/react';\n<Tooltip aria-label="tooltip text"><Button>Button</Button></Tooltip>`,
35+
errors: [
36+
{messageId: 'useNextTooltip', line: 1},
37+
{messageId: 'useTextProp', line: 2},
38+
],
39+
output: `import {ActionList, ActionMenu, Button} from '@primer/react';\nimport {Tooltip} from '@primer/react/next';\n<Tooltip text="tooltip text"><Button>Button</Button></Tooltip>`,
3740
},
3841
],
3942
})

src/rules/use-next-tooltip.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict'
2+
const {getJSXOpeningElementAttribute} = require('../utils/get-jsx-opening-element-attribute')
23

34
module.exports = {
45
meta: {
@@ -12,6 +13,7 @@ module.exports = {
1213
schema: [],
1314
messages: {
1415
useNextTooltip: 'Please use @primer/react/next Tooltip component that has accessibility improvements',
16+
useTextProp: 'Please use the text prop instead of aria-label',
1517
},
1618
},
1719
create(context) {
@@ -55,6 +57,17 @@ module.exports = {
5557
},
5658
})
5759
},
60+
JSXAttribute(node) {
61+
if (node.name.name === 'aria-label') {
62+
context.report({
63+
node,
64+
messageId: 'useTextProp',
65+
fix(fixer) {
66+
return fixer.replaceText(node.name, 'text')
67+
},
68+
})
69+
}
70+
},
5871
}
5972
},
6073
}

0 commit comments

Comments
 (0)