Skip to content

Commit cb31a75

Browse files
committed
Add check for ID(s)
1 parent a4ad769 commit cb31a75

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/rules/__tests__/a11y-link-in-text-block.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ ruleTester.run('a11y-link-in-text-block', rule, {
1515
valid: [
1616
`import {Link} from '@primer/react';
1717
<Box>
18-
18+
1919
<Link href="something">
2020
Blah blah
2121
</Link>{' '}
22-
.
22+
.
2323
</Box>
2424
`,
2525
`import {Text, Link} from '@primer/react';
@@ -138,6 +138,9 @@ ruleTester.run('a11y-link-in-text-block', rule, {
138138
`<div>
139139
<a href="/link">Link</a>.
140140
</div>`,
141+
`<div>
142+
<a href="/link" id="custom-link">Link</a>.
143+
</div>`,
141144
],
142145
invalid: [
143146
{

src/rules/a11y-link-in-text-block.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ module.exports = {
8484
const classNameAttribute = getJSXOpeningElementAttribute(node.openingElement, 'className')
8585
if (classNameAttribute) return
8686

87+
// Skip if anchor has an ID (might have distinguishing styles)
88+
const idAttribute = getJSXOpeningElementAttribute(node.openingElement, 'id')
89+
if (idAttribute) return
90+
8791
// Check for anchor in text block
8892
if (isNodeInTextBlock(node)) {
8993
// Skip if anchor child is a JSX element

0 commit comments

Comments
 (0)