Skip to content

Commit ccc2e99

Browse files
authored
Clean up docs for link lint rule (#195)
* Clean up docs, make clear that this rule is experimental * Fix lint issue * Create lemon-turtles-talk.md
1 parent 5fc19f6 commit ccc2e99

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

.changeset/lemon-turtles-talk.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+
Clean up docs for link lint rule

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ ESLint rules for Primer React
3333

3434
- [direct-slot-children](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/direct-slot-children.md)
3535
- [no-system-props](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/no-system-props.md)
36-
- [a11y-tooltip-interactive-trigger](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/a11y-tooltip-interactive-trigger.md)
37-
- [a11y-explicit-heading](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/a11y-explicit-heading.md)
3836
- [new-css-color-vars](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/new-css-color-vars.md)
3937
- [no-deprecated-props](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/no-deprecated-props.md)
38+
- [a11y-tooltip-interactive-trigger](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/a11y-tooltip-interactive-trigger.md)
39+
- [a11y-explicit-heading](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/a11y-explicit-heading.md)
40+
- [a11y-link-in-text-block](https://github.com/primer/eslint-plugin-primer-react/blob/main/docs/rules/a11y-link-in-text-block.md)

docs/rules/a11y-link-in-text-block.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
## Require `inline` prop on `<Link>` component inside a text block
1+
# EXPERIMENTAL: Require `inline` prop on `<Link>` in text block
22

3-
The `Link` component should have the `inline` prop when it is used inside of a text block.
3+
This is an experimental rule. If you suspect any false positives reported by this rule, please file an issue so we can make this rule better.
44

55
## Rule Details
66

7-
This rule enforces setting `inline` on the `<Link>` component when a `<Link>` is detected inside of a text block without distiguishable styling.
7+
The `Link` component should have the `inline` prop when it is used within a text block and has no styles (aside from color) to distinguish itself from surrounding plain text.
88

9-
The lint rule will essentially flag any `<Link>` without the `inline` property (equal to `true`) detected with string nodes on either side.
9+
Related: [WCAG 1.4.1 Use of Color issues](https://www.w3.org/WAI/WCAG21/Understanding/use-of-color.html)
1010

11-
This rule will not catch all instances of link in text block due to the limitations of static analysis, so be sure to also have in-browser checks in place such as the [link-in-text-block Axe rule](https://dequeuniversity.com/rules/axe/4.9/link-in-text-block) for additional coverage.
11+
The lint rule will flag any `<Link>` without the `inline` property (equal to `true`) detected with string nodes on either side.
1212

13-
The edge cases that the linter skips to avoid false positives will include:
13+
There are certain edge cases that the linter skips to avoid false positives including:
1414

15+
- `<Link className="...">` because there may be distinguishing styles applied.
1516
- `<Link sx={{fontWeight:...}}>` or `<Link sx={{fontFamily:...}}>` because these technically may provide sufficient distinguishing styling.
1617
- `<Link>` where the only adjacent text is a period, since that can't really be considered a text block.
1718
- `<Link>` where the children is a JSX component, rather than a string literal, because then it might be an icon link rather than a text link.
1819
- `<Link>` that are nested inside of headings as these have often been breadcrumbs.
1920

21+
This rule will not catch all instances of link in text block due to the limitations of static analysis, so be sure to also have in-browser checks in place such as the [link-in-text-block Axe rule](https://dequeuniversity.com/rules/axe/4.9/link-in-text-block) for additional coverage.
22+
2023
👎 Examples of **incorrect** code for this rule
2124

2225
```jsx
@@ -93,8 +96,18 @@ function ExampleComponent() {
9396
}
9497
```
9598

99+
This rule will skip `Link`s with a `className`.
100+
101+
```jsx
102+
function ExampleComponent() {
103+
return (
104+
Learn more at <Link className={styles.someDistinguishingStyle}>GitHub</Link>
105+
)
106+
}
107+
```
108+
96109
## Options
97110

98111
- `skipImportCheck` (default: `false`)
99112

100-
By default, the `a11y-explicit-heading` rule will only check for `<Heading>` components imported directly from `@primer/react`. You can disable this behavior by setting `skipImportCheck` to `true`.
113+
By default, the `a11y-link-in-text-block` rule will only check for `<Link>` components imported directly from `@primer/react`. You can disable this behavior by setting `skipImportCheck` to `true`.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const {getJSXOpeningElementAttribute} = require('../utils/get-jsx-opening-elemen
44

55
module.exports = {
66
meta: {
7+
docs: {
8+
url: require('../url')(module),
9+
},
710
type: 'problem',
811
schema: [
912
{
@@ -15,7 +18,8 @@ module.exports = {
1518
},
1619
],
1720
messages: {
18-
linkInTextBlock: '<Link>s that are used within a text block should have the inline prop.',
21+
linkInTextBlock:
22+
'Links should have the inline prop if it appear in a text block and only uses color to distinguish itself from surrounding text.',
1923
},
2024
},
2125
create(context) {

0 commit comments

Comments
 (0)