Skip to content

Commit

Permalink
Update link lint rule to skip Link with className (#193)
Browse files Browse the repository at this point in the history
* Update link lint rule to skip Link with className

* Create slow-dolphins-float.md
  • Loading branch information
khiga8 committed Jun 11, 2024
1 parent e839a19 commit 5fc19f6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-dolphins-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-primer-react": patch
---

Update link lint rule to skip Link with className
10 changes: 10 additions & 0 deletions src/rules/__tests__/a11y-link-in-text-block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ ruleTester.run('a11y-link-in-text-block', rule, {
includes:
</Heading>
`,
`import {Link} from '@primer/react';
<p>bla blah
<Link className={styles.someClass}>Link text</Link>
</p>
`,
`import {Link} from '@primer/react';
<p>bla blah
<Link className='some-class'>Link text</Link>
</p>
`,
],
invalid: [
{
Expand Down
4 changes: 4 additions & 0 deletions src/rules/a11y-link-in-text-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ module.exports = {
name === 'Link' &&
node.parent.children
) {
// Skip if Link has className because we cannot deduce what styles are applied.
const classNameAttribute = getJSXOpeningElementAttribute(node.openingElement, 'className')
if (classNameAttribute) return

let siblings = node.parent.children
const parentName = node.parent.openingElement?.name?.name
// Skip if Link is nested inside of a heading.
Expand Down

0 comments on commit 5fc19f6

Please sign in to comment.