Skip to content

Commit 23e2eb6

Browse files
khiga8JoyceZhuericwbailey
authored
Introduce rule documentation (#26)
* Update library structure * Add docs folder * Update information link * Update docs/rules/GH002-no-generic-link-text.md Co-authored-by: Joyce Zhu <joycezhu@github.com> * Update docs/rules/GH002-no-generic-link-text.md Co-authored-by: Joyce Zhu <joycezhu@github.com> * Update GH001-no-default-alt-text.md * Update docs/rules/GH001-no-default-alt-text.md Co-authored-by: Eric Bailey <ericwbailey@users.noreply.github.com> Co-authored-by: Joyce Zhu <joycezhu@github.com> Co-authored-by: Eric Bailey <ericwbailey@users.noreply.github.com>
1 parent ccf8f37 commit 23e2eb6

File tree

6 files changed

+97
-5
lines changed

6 files changed

+97
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ However, others of these rules should **NOT** be disabled because they encourage
2222

2323
The following are custom rules defined in this plugin.
2424

25-
- **GH001** _no-default-alt-text_
26-
- **GH002** _no-generic-link-text_
25+
- [**GH001** _no-default-alt-text_](./docs/rules/GH001-no-default-alt-text.md)
26+
- [**GH002** _no-generic-link-text_](./docs/rules/GH002-no-generic-link-text.md)
2727

2828
See [`markdownlint` rules](https://github.com/DavidAnson/markdownlint#rules--aliases) for documentation on rules pulled in from `markdownlint`.
2929

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# GH001 No default alt text
2+
3+
## Rule details
4+
5+
Images should not use the macOS default screenshot filename as alternate text (alt text) which does not convey any meaningful information.
6+
7+
Alternative text should concisely describe what is conveyed in the image. If the image is decorative, the alternative text should be set to an empty string (`alt=""`).
8+
9+
Learn more at [Primer: Alternative text for images](https://primer.style/design/accessibility/alternative-text-for-images).
10+
11+
## Examples
12+
13+
### Incorrect 👎
14+
15+
```md
16+
![Screen Shot 2022-06-26 at 7 41 30 PM](https://user-images.githubusercontent.com/abcdef.png)
17+
```
18+
19+
```md
20+
<img alt="Screen Shot 2022-06-26 at 7 41 30 PM" src="https://user-images.githubusercontent.com/abcdef.png">
21+
```
22+
23+
### Correct 👍
24+
25+
```md
26+
<!-- Mark decorative images with an empty string -->
27+
28+
![""](https://user-images.githubusercontent.com/abcdef.png)
29+
```
30+
31+
```md
32+
<img alt="A fluffy, orange kitten plays with a ball of yarn" src="https://user-images.githubusercontent.com/defgh.png">
33+
```
34+
35+
```md
36+
<img alt="A GitHub Discussion page with the heading structure visually surfaced with a text overlay" src="https://user-images.githubusercontent.com/xyz.png">
37+
```
38+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# GH002 No generic link text
2+
3+
## Rule details
4+
5+
Avoid setting generic link text like, "Click here", "Read more", and "Learn more" which do not make sense when read out of context.
6+
7+
Screen reader users often tab through links on a page to quickly find content without needing to listen to the full page. When link text does not clearly describe the actual linked content, it becomes difficult to quickly identify whether it's worth following the link.
8+
9+
Ensure that your link text is descriptive and the purpose of the link is clear even when read without the context provided by surrounding text.
10+
11+
Learn more about how to write descriptive link text at [Access Guide: Write descriptive link text](https://www.accessguide.io/guide/descriptive-link-text).
12+
13+
**Note**: For now, this rule only flags inline markdown implementation of links given the complexities of determining the accessible name of an HTML anchor tag,
14+
15+
## Configuration
16+
17+
You can configure additional link texts to flag by setting the rule configuration like the following:
18+
19+
```.js
20+
{
21+
"no-generic-link-text": {
22+
"additional_banned_texts": ["Something", "Go here"]
23+
}
24+
}
25+
```
26+
## Examples
27+
28+
### Incorrect 👎
29+
30+
```md
31+
Go [here](https://github.com/)
32+
```
33+
34+
```md
35+
[Learn more](https://docs.github.com)
36+
```
37+
38+
```md
39+
[Click here](https://github.com/new) to create a new repository.
40+
```
41+
42+
### Correct 👍
43+
44+
```md
45+
[GitHub](https://github.com/)
46+
```
47+
48+
```md
49+
[GitHub Docs](https://docs.github.com)
50+
```
51+
52+
```md
53+
[Create a new repository](https://github.com/new)
54+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"scripts": {
1010
"publish": "npm publish --access public --@github:registry=https://registry.npmjs.org",
1111
"test": "npm run lint && jest",
12-
"lint": "markdownlint-cli2 \"**/*.{md,mdx}\" \"!node_modules\" \"!test/example.md\" && eslint .",
12+
"lint": "markdownlint-cli2 \"**/*.{md,mdx}\" \"!node_modules\" \"!docs/rules\" \"!test/example.md\" && eslint .",
1313
"lint:fix": "npm run lint -- --fix"
1414
},
1515
"dependencies": {

src/rules/no-default-alt-text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
description:
1212
"Images should not use the MacOS default screenshot filename as alternate text (alt text). If you have not changed this file, try merging main with your branch. For more information see: https://primer.style/design/accessibility/alternative-text-for-images",
1313
information: new URL(
14-
"https://primer.style/design/accessibility/alternative-text-for-images"
14+
"https://github.com/github/markdownlint-github/blob/main/docs/rules/GH001-no-default-alt-text.md"
1515
),
1616
tags: ["accessibility", "images"],
1717
function: function GH001(params, onError) {

src/rules/no-generic-link-text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
description:
1515
"Avoid using generic link text like `Learn more` or `Click here`",
1616
information: new URL(
17-
"https://primer.style/design/accessibility/links#writing-link-text"
17+
"https://github.com/github/markdownlint-github/blob/main/docs/rules/GH002-no-generic-link-text.md"
1818
),
1919
tags: ["accessibility", "links"],
2020
function: function GH002(params, onError) {

0 commit comments

Comments
 (0)