Skip to content

Commit efd7e2c

Browse files
Build: autogenerate the table in README.md (fixes #43)
1 parent 3597af5 commit efd7e2c

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Then configure the rules you want to use under the rules section.
4848

4949
Name | ✔️ | 🛠 | Description
5050
----- | ----- | ----- | -----
51+
<<<<<<< HEAD
5152
[consistent-output](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/consistent-output.md) | | | Enforces consistent use of output assertions in rule tests
5253
[fixer-return](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/fixer-return.md) | ✔️ | | Enforces always return from a fixer function
5354
[no-deprecated-context-methods](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-deprecated-context-methods.md) | | 🛠 | Disallows usage of deprecated methods on rule context objects
@@ -62,6 +63,24 @@ Name | ✔️ | 🛠 | Description
6263
[require-meta-fixable](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/require-meta-fixable.md) | ✔️ | | Requires a `meta.fixable` property for fixable rules
6364
[test-case-property-ordering](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/test-case-property-ordering.md) | | 🛠 | Requires the properties of a test case to be placed in a consistent order.
6465
[test-case-shorthand-strings](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/test-case-shorthand-strings.md) | | 🛠 | Enforces consistent usage of shorthand strings for test cases with no options
66+
=======
67+
<!-- __BEGIN AUTOGENERATED TABLE__ -->
68+
[consistent-output](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/consistent-output.md) | | | Enforce consistent use of output assertions in rule tests
69+
[fixer-return](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/fixer-return.md) | ✔️ | | Expected fixer function to always return a value.
70+
[no-deprecated-context-methods](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-deprecated-context-methods.md) | | 🛠 | Disallows usage of deprecated methods on rule context objects
71+
[no-deprecated-report-api](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-deprecated-report-api.md) | ✔️ | 🛠 | disallow use of the deprecated context.report() API
72+
[no-identical-tests](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-identical-tests.md) | ✔️ | 🛠 | disallow identical tests
73+
[no-missing-placeholders](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-missing-placeholders.md) | ✔️ | | Disallow missing placeholders in rule report messages
74+
[no-unused-placeholders](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-unused-placeholders.md) | ✔️ | | Disallow unused placeholders in rule report messages
75+
[no-useless-token-range](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-useless-token-range.md) | ✔️ | 🛠 | Disallow unnecessary calls to sourceCode.getFirstToken and sourceCode.getLastToken
76+
[prefer-output-null](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/prefer-output-null.md) | | | disallows invalid RuleTester test cases with the output the same as the code.
77+
[prefer-placeholders](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/prefer-placeholders.md) | | | disallow template literals as report messages
78+
[report-message-format](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/report-message-format.md) | | | enforce a consistent format for rule report messages
79+
[require-meta-fixable](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/require-meta-fixable.md) | ✔️ | | require rules to implement a meta.fixable property
80+
[test-case-property-ordering](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/test-case-property-ordering.md) | | 🛠 | Requires the properties of a test case to be placed in a consistent order
81+
[test-case-shorthand-strings](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/test-case-shorthand-strings.md) | | 🛠 | Enforce consistent usage of shorthand strings for test cases with no options
82+
<!-- __END AUTOGENERATED TABLE__ -->
83+
>>>>>>> Build: autogenerate the table in README.md (fixes #43)
6584
6685
## Supported Presets
6786

build/generate-readme-table.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const rules = require('..').rules;
6+
7+
const README_LOCATION = path.resolve(__dirname, '..', 'README.md');
8+
const BEGIN_TABLE_MARKER = '<!-- __BEGIN AUTOGENERATED TABLE__ -->\n';
9+
const END_TABLE_MARKER = '\n<!-- __END AUTOGENERATED TABLE__ -->';
10+
11+
const expectedTableLines = Object.keys(rules)
12+
.sort()
13+
.reduce((lines, ruleId) => {
14+
const rule = rules[ruleId];
15+
16+
lines.push([
17+
`[${ruleId}](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/${ruleId}.md)`,
18+
rule.meta.docs.recommended ? '✔️' : '',
19+
rule.meta.fixable ? '🛠' : '',
20+
rule.meta.docs.description,
21+
].join(' | '));
22+
23+
return lines;
24+
}, [])
25+
.join('\n');
26+
27+
const readmeContents = fs.readFileSync(README_LOCATION, 'utf8');
28+
29+
if (!readmeContents.includes(BEGIN_TABLE_MARKER)) {
30+
throw new Error(`Could not find '${BEGIN_TABLE_MARKER}' marker in README.md.`);
31+
}
32+
33+
if (!readmeContents.includes(END_TABLE_MARKER)) {
34+
throw new Error(`Could not find '${END_TABLE_MARKER}' marker in README.md.`);
35+
}
36+
37+
const linesStartIndex = readmeContents.indexOf(BEGIN_TABLE_MARKER) + BEGIN_TABLE_MARKER.length;
38+
const linesEndIndex = readmeContents.indexOf(END_TABLE_MARKER);
39+
40+
const updatedReadmeContents = readmeContents.slice(0, linesStartIndex) +
41+
expectedTableLines +
42+
readmeContents.slice(linesEndIndex);
43+
44+
if (module.parent) {
45+
module.exports = updatedReadmeContents;
46+
} else {
47+
fs.writeFileSync(README_LOCATION, updatedReadmeContents);
48+
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"scripts": {
99
"lint": "eslint . --ignore-pattern \"!.*\"",
1010
"pretest": "npm run lint",
11+
"generate-readme-table": "node build/generate-readme-table.js",
1112
"generate-release": "node-release-script",
1213
"test": "mocha tests --recursive"
1314
},

tests/build/generate-readme-table.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const assert = require('chai').assert;
6+
7+
describe('table in README.md', () => {
8+
it('is up-to-date', () => {
9+
const actualReadme = fs.readFileSync(path.resolve(__dirname, '..', '..', 'README.md'), 'utf8');
10+
const expectedReadme = require('../../build/generate-readme-table');
11+
12+
assert(
13+
actualReadme === expectedReadme,
14+
'The table in README.md is out of date. Please use `npm run generate-readme-table` to update it.'
15+
);
16+
});
17+
});

0 commit comments

Comments
 (0)