-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Docs] Auto-generate list of rules in README
This adds a script to auto-generate the list of rules and embeds special tags to README. Usage: $ npm run generate-list-of-rules Check whether the auto-generated changes are committed: $ npm run generate-list-of-rules:check
- Loading branch information
1 parent
b08d8c3
commit 7d4b55b
Showing
5 changed files
with
108 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const {rules} = require('../index'); | ||
|
||
const ruleListItems = Object.keys(rules) | ||
.sort() | ||
.map((id) => { | ||
const {meta} = rules[id]; | ||
return `* [react/${id}](docs/rules/${id}.md): ${meta.docs.description}${ | ||
meta.fixable ? ' (fixable)' : '' | ||
}`; | ||
}); | ||
|
||
const targetFile = process.argv[2]; | ||
const targetFileContent = fs.readFileSync(targetFile, 'utf8'); | ||
|
||
const NOTICE = '<!-- THIS SECTION IS AUTO-GENERATED. DO NOT EDIT. -->'; | ||
const TAG_BASIC_RULES = '<!-- BASIC_RULES_SECTION -->'; | ||
const TAG_JSX_RULES = '<!-- JSX_RULES_SECTION -->'; | ||
|
||
const newContent = targetFileContent.replace( | ||
new RegExp(`${TAG_BASIC_RULES}.+${TAG_BASIC_RULES}`, 's'), | ||
[ | ||
TAG_BASIC_RULES, | ||
NOTICE, | ||
...ruleListItems.filter(rule => !rule.includes('react/jsx-')), | ||
TAG_BASIC_RULES | ||
].join('\n') | ||
).replace( | ||
new RegExp(`${TAG_JSX_RULES}.+${TAG_JSX_RULES}`, 's'), | ||
[ | ||
TAG_JSX_RULES, | ||
NOTICE, | ||
...ruleListItems.filter(rule => rule.includes('react/jsx-')), | ||
TAG_JSX_RULES | ||
].join('\n') | ||
); | ||
fs.writeFileSync(targetFile, newContent, 'utf8'); |