Skip to content

Commit 9980d1d

Browse files
uncommon-typeljharb
authored andcommitted
[Docs] Add infrastructure for auto-generating markdown table and list
- Add readme.yml file to ensure table and list markdown content is auto-generated from rules folder - Add md-magic dependency and scripts to package.json for updating readme markdown - Add markdown.config.js file to add transformation functions to the transforms object - Add scripts to README markdown to keep documentation content in sync with readme - Disable `no-console` rule in markdown.config file in .eslintrc - Add errorOptions property to source files for rules with extra options Closes #836
1 parent ea877c4 commit 9980d1d

38 files changed

+204
-70
lines changed

.eslintrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@
2323
"eslint-plugin/require-meta-type": "off",
2424
},
2525
},
26+
{
27+
"files": ["markdown.config.js"],
28+
"parserOptions": {
29+
"sourceType": "script",
30+
},
31+
"rules": {
32+
"no-console": 0,
33+
"import/no-extraneous-dependencies": [
34+
"error",
35+
{ "devDependencies": true },
36+
],
37+
"strict": ["error", "global"],
38+
},
39+
},
2640
{
2741
"files": ["__tests__/src/rules/*.js"],
2842
"extends": ["plugin:eslint-plugin/tests-recommended"],

.github/workflows/readme.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: 'Tests: readme'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
readme:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: ljharb/actions/node/install@main
12+
name: 'nvm install lts/* && npm install'
13+
with:
14+
node-version: 'lts/*'
15+
- run: npm run generate-list-of-rules:check

README.md

Lines changed: 78 additions & 67 deletions
Large diffs are not rendered by default.

markdown.config.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
require('@babel/register');
4+
5+
const { rules } = require('./src');
6+
7+
const ruleTableRows = Object.keys(rules)
8+
.sort()
9+
.map((id) => {
10+
const { meta } = rules[id];
11+
const { url, errorOptions } = meta.docs;
12+
return [
13+
`[${id}](${url})`,
14+
errorOptions ? 'error, with options' : 'error',
15+
'error',
16+
].join(' | ');
17+
});
18+
19+
const buildRulesTable = (rows) => {
20+
const header = 'Rule | Recommended | Strict';
21+
const separator = ':--- | :--- | :---';
22+
23+
return [header, separator].concat(rows)
24+
.map((row) => `| ${row} |`)
25+
.join('\n');
26+
};
27+
28+
const ruleList = Object.keys(rules)
29+
.sort()
30+
.map((id) => {
31+
const { meta } = rules[id];
32+
const { description, url } = meta.docs;
33+
return description ? [`- [${id}](${url}): ${description}`] : null;
34+
});
35+
36+
const buildRuleList = (listItems) => listItems.join('\n');
37+
38+
const LIST = () => buildRuleList(ruleList);
39+
const TABLE = () => buildRulesTable(ruleTableRows);
40+
41+
module.exports = {
42+
transforms: {
43+
TABLE,
44+
LIST,
45+
},
46+
callback: () => {
47+
console.log('The auto-generating of rules finished!');
48+
},
49+
};

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828
"test": "npm run jest",
2929
"posttest": "aud --production",
3030
"test:ci": "npm run jest -- --ci --runInBand",
31-
"jest": "jest --coverage __tests__/**/*"
31+
"jest": "jest --coverage __tests__/**/*",
32+
"generate-list-of-rules": "md-magic --path '**/*.md' --ignore 'node_modules'",
33+
"generate-list-of-rules:check": "npm run generate-list-of-rules && git diff --exit-code README.md"
3234
},
3335
"devDependencies": {
3436
"@babel/cli": "^7.17.0",
35-
"@babel/core": "^7.17.0",
37+
"@babel/core": "^7.17.5",
3638
"@babel/eslint-parser": "^7.17.0",
3739
"@babel/plugin-transform-flow-strip-types": "^7.16.7",
40+
"@babel/register": "^7.17.0",
3841
"ast-types-flow": "^0.0.7",
3942
"aud": "^2.0.0",
4043
"babel-jest": "^24.9.0",
@@ -51,6 +54,7 @@
5154
"in-publish": "^2.0.1",
5255
"jest": "^24.9.0",
5356
"jscodeshift": "^0.7.1",
57+
"markdown-magic": "^2.6.0",
5458
"minimist": "^1.2.5",
5559
"object.assign": "^4.1.2",
5660
"rimraf": "^3.0.2",

src/rules/alt-text.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ export default {
196196
meta: {
197197
docs: {
198198
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/alt-text.md',
199+
description: 'Enforce all elements that require alternative text have meaningful information to relay back to end user.',
199200
},
200201
schema: [schema],
201202
},

src/rules/anchor-has-content.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default {
1919
meta: {
2020
docs: {
2121
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/anchor-has-content.md',
22+
description: 'Enforce all anchors to contain accessible content.',
2223
},
2324
schema: [schema],
2425
},

src/rules/anchor-is-valid.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default ({
3131
meta: {
3232
docs: {
3333
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/anchor-is-valid.md',
34+
description: 'Enforce all anchors are valid, navigable elements.',
3435
},
3536
schema: [schema],
3637
},

src/rules/aria-activedescendant-has-tabindex.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default {
2323
meta: {
2424
docs: {
2525
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-activedescendant-has-tabindex.md',
26+
description: 'Enforce elements with aria-activedescendant are tabbable.',
2627
},
2728
schema: [schema],
2829
},

src/rules/aria-props.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default {
3131
meta: {
3232
docs: {
3333
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-props.md',
34+
description: 'Enforce all `aria-*` props are valid.',
3435
},
3536
schema: [schema],
3637
},

0 commit comments

Comments
 (0)