Skip to content

Commit 8d8efff

Browse files
committed
[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 jsx-eslint#836
1 parent ea877c4 commit 8d8efff

11 files changed

+153
-69
lines changed

.eslintrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,11 @@
3333
"jest": true,
3434
},
3535
},
36-
],
36+
{
37+
"files": "markdown.config.js",
38+
"rules": {
39+
"no-console": 0,
40+
},
41+
},
42+
]
3743
}

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

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
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",
@@ -51,6 +53,7 @@
5153
"in-publish": "^2.0.1",
5254
"jest": "^24.9.0",
5355
"jscodeshift": "^0.7.1",
56+
"markdown-magic": "^2.6.0",
5457
"minimist": "^1.2.5",
5558
"object.assign": "^4.1.2",
5659
"rimraf": "^3.0.2",

src/rules/no-interactive-element-to-noninteractive-role.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default ({
4444
uniqueItems: true,
4545
},
4646
}],
47+
errorOptions: true,
4748
},
4849

4950
create: (context: ESLintContext): ESLintVisitorSelectorConfig => {

src/rules/no-noninteractive-element-interactions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export default ({
4848
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-noninteractive-element-interactions.md',
4949
},
5050
schema: [schema],
51+
errorOptions: true,
5152
},
5253

5354
create: (context: ESLintContext): ESLintVisitorSelectorConfig => {

src/rules/no-noninteractive-element-to-interactive-role.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default ({
4242
uniqueItems: true,
4343
},
4444
}],
45+
errorOptions: true,
4546
},
4647

4748
create: (context: ESLintContext): ESLintVisitorSelectorConfig => {

src/rules/no-noninteractive-tabindex.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default ({
4242
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-noninteractive-tabindex.md',
4343
},
4444
schema: [schema],
45+
errorOptions: true,
4546
},
4647

4748
create: (context: ESLintContext): ESLintVisitorSelectorConfig => {

src/rules/no-static-element-interactions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export default ({
4747
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-static-element-interactions.md',
4848
},
4949
schema: [schema],
50+
errorOptions: true,
5051
},
5152

5253
create: (context: ESLintContext): ESLintVisitorSelectorConfig => {

src/rules/scope.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default {
2121
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/scope.md',
2222
},
2323
schema: [schema],
24+
errorOptions: true,
2425
},
2526

2627
create: (context) => ({

0 commit comments

Comments
 (0)