Skip to content

Commit 5fc19f6

Browse files
authored
Update link lint rule to skip Link with className (#193)
* Update link lint rule to skip Link with className * Create slow-dolphins-float.md
1 parent e839a19 commit 5fc19f6

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

.changeset/slow-dolphins-float.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-primer-react": patch
3+
---
4+
5+
Update link lint rule to skip Link with className

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ ruleTester.run('a11y-link-in-text-block', rule, {
115115
includes:
116116
</Heading>
117117
`,
118+
`import {Link} from '@primer/react';
119+
<p>bla blah
120+
<Link className={styles.someClass}>Link text</Link>
121+
</p>
122+
`,
123+
`import {Link} from '@primer/react';
124+
<p>bla blah
125+
<Link className='some-class'>Link text</Link>
126+
</p>
127+
`,
118128
],
119129
invalid: [
120130
{

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ module.exports = {
2828
name === 'Link' &&
2929
node.parent.children
3030
) {
31+
// Skip if Link has className because we cannot deduce what styles are applied.
32+
const classNameAttribute = getJSXOpeningElementAttribute(node.openingElement, 'className')
33+
if (classNameAttribute) return
34+
3135
let siblings = node.parent.children
3236
const parentName = node.parent.openingElement?.name?.name
3337
// Skip if Link is nested inside of a heading.

0 commit comments

Comments
 (0)