diff --git a/README.md b/README.md index 00ec7ed8..e18a0fe0 100644 --- a/README.md +++ b/README.md @@ -46,22 +46,24 @@ Then configure the rules you want to use under the rules section. ✔️ indicates that a rule is recommended for all users. 🛠 indicates that a rule is fixable. + Name | ✔️ | 🛠 | Description ----- | ----- | ----- | ----- -[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 -[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 -[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 -[no-deprecated-report-api](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-deprecated-report-api.md) | ✔️ | 🛠 | Prohibits the deprecated `context.report(node, message)` API -[no-identical-tests](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-identical-tests.md) | ✔️ | 🛠 | Disallows identical tests -[no-missing-placeholders](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-missing-placeholders.md) | ✔️ | | Disallows missing placeholders in rule report messages -[no-unused-placeholders](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-unused-placeholders.md) | ✔️ | | Disallows unused placeholders in rule report messages -[no-useless-token-range](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-useless-token-range.md) | ✔️ | 🛠 | Disallows unnecessary calls to sourceCode.getFirstToken and sourceCode.getLastToken -[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. -[prefer-placeholders](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/prefer-placeholders.md) | | | Disallows template literals as report messages -[report-message-format](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/report-message-format.md) | | | Enforces a consistent format for report messages -[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 -[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. -[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 +[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 +[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. +[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 +[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 +[no-identical-tests](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/no-identical-tests.md) | ✔️ | 🛠 | disallow identical tests +[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 +[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 +[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 +[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. +[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 +[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 +[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 +[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 +[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 + ## Supported Presets diff --git a/build/generate-readme-table.js b/build/generate-readme-table.js new file mode 100644 index 00000000..d714ef51 --- /dev/null +++ b/build/generate-readme-table.js @@ -0,0 +1,48 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const rules = require('..').rules; + +const README_LOCATION = path.resolve(__dirname, '..', 'README.md'); +const BEGIN_TABLE_MARKER = '\n'; +const END_TABLE_MARKER = '\n'; + +const expectedTableLines = Object.keys(rules) + .sort() + .reduce((lines, ruleId) => { + const rule = rules[ruleId]; + + lines.push([ + `[${ruleId}](https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/${ruleId}.md)`, + rule.meta.docs.recommended ? '✔️' : '', + rule.meta.fixable ? '🛠' : '', + rule.meta.docs.description, + ].join(' | ')); + + return lines; + }, ['Name | ✔️ | 🛠 | Description', '----- | ----- | ----- | -----']) + .join('\n'); + +const readmeContents = fs.readFileSync(README_LOCATION, 'utf8'); + +if (!readmeContents.includes(BEGIN_TABLE_MARKER)) { + throw new Error(`Could not find '${BEGIN_TABLE_MARKER}' marker in README.md.`); +} + +if (!readmeContents.includes(END_TABLE_MARKER)) { + throw new Error(`Could not find '${END_TABLE_MARKER}' marker in README.md.`); +} + +const linesStartIndex = readmeContents.indexOf(BEGIN_TABLE_MARKER) + BEGIN_TABLE_MARKER.length; +const linesEndIndex = readmeContents.indexOf(END_TABLE_MARKER); + +const updatedReadmeContents = readmeContents.slice(0, linesStartIndex) + + expectedTableLines + + readmeContents.slice(linesEndIndex); + +if (module.parent) { + module.exports = updatedReadmeContents; +} else { + fs.writeFileSync(README_LOCATION, updatedReadmeContents); +} diff --git a/package.json b/package.json index 55506812..001346a4 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "scripts": { "lint": "eslint . --ignore-pattern \"!.*\"", "pretest": "npm run lint", + "generate-readme-table": "node build/generate-readme-table.js", "generate-release": "node-release-script", "test": "mocha tests --recursive" }, diff --git a/tests/build/generate-readme-table.js b/tests/build/generate-readme-table.js new file mode 100644 index 00000000..8bf36685 --- /dev/null +++ b/tests/build/generate-readme-table.js @@ -0,0 +1,17 @@ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const assert = require('chai').assert; + +describe('table in README.md', () => { + it('is up-to-date', () => { + const actualReadme = fs.readFileSync(path.resolve(__dirname, '..', '..', 'README.md'), 'utf8'); + const expectedReadme = require('../../build/generate-readme-table'); + + assert( + actualReadme === expectedReadme, + 'The table in README.md is out of date. Please use `npm run generate-readme-table` to update it.' + ); + }); +});