-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
generate-list-of-rules.js
executable file
·41 lines (35 loc) · 1.08 KB
/
generate-list-of-rules.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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');