Skip to content

Commit fbe6078

Browse files
committed
Do not flag if only adjacent text is a dot
1 parent 6283589 commit fbe6078

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

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

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,24 @@ const ruleTester = new RuleTester({
1313

1414
ruleTester.run('a11y-link-in-text-block', rule, {
1515
valid: [
16+
`import {Link} from '@primer/react';
17+
<Box>
18+
19+
<Link href="something">
20+
Blah blah
21+
</Link>{' '}
22+
.
23+
</Box>
24+
`,
1625
`import {Text, Link} from '@primer/react';
17-
<Something>
18-
<Link href='blah'>
19-
blah
20-
</Link>
21-
</Something>
22-
`,
26+
<Something>
27+
<Link href='blah'>
28+
blah
29+
</Link>
30+
</Something>
31+
`,
2332
`import {Link} from '@primer/react';
24-
<p>bla blah <Link inline={true}>Link level 1</Link></p>;
33+
<p>bla blah <Link inline={true}>Link level 1</Link></p>;
2534
`,
2635
`import {Link} from '@primer/react';
2736
<p>bla blah<Link inline>Link level 1</Link></p>;
@@ -71,6 +80,23 @@ ruleTester.run('a11y-link-in-text-block', rule, {
7180
Blah blah
7281
</Link>
7382
</span>
83+
`,
84+
`import {Link} from '@primer/react';
85+
<span>
86+
by
87+
<Link href="something" sx={{fontWeight: 'bold'}}>
88+
Blah blah
89+
</Link>
90+
</span>
91+
`,
92+
`import {Link} from '@primer/react';
93+
<Box>
94+
95+
<Link href="something">
96+
Blah blah
97+
</Link>{' '}
98+
.
99+
</Box>
74100
`,
75101
],
76102
invalid: [

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ module.exports = {
4848
})
4949
const prevSibling = siblings[index - 1]
5050
const nextSibling = siblings[index + 1]
51-
if ((prevSibling && prevSibling.type === 'JSXText') || (nextSibling && nextSibling.type === 'JSXText')) {
51+
52+
const prevSiblingIsText = prevSibling && prevSibling.type === 'JSXText'
53+
const nextSiblingIsText = nextSibling && nextSibling.type === 'JSXText'
54+
if (prevSiblingIsText || nextSiblingIsText) {
55+
// If the only text adjacent to the link is a period, then skip it.
56+
if (!prevSiblingIsText && /^\s*.+\s*$/.test(nextSibling.value)) {
57+
return
58+
}
5259
const sxAttribute = getJSXOpeningElementAttribute(node.openingElement, 'sx')
5360
const inlineAttribute = getJSXOpeningElementAttribute(node.openingElement, 'inline')
5461

0 commit comments

Comments
 (0)