4
4
5
5
const { rules } = require ( './index' ) ;
6
6
7
- const ruleTableRows = Object . keys ( rules )
8
- . sort ( )
9
- . map ( ( id ) => {
10
- const { meta } = rules [ id ] ;
11
- const { fixable, docs } = meta ;
12
- return [
13
- docs . recommended ? '✔' : '' ,
14
- fixable ? '🔧' : '' ,
15
- `[react/${ id } ](docs/rules/${ id } .md)` ,
16
- docs . description ,
17
- ] . join ( ' | ' ) ;
18
- } ) ;
7
+ const buildRuleRow = ( id ) => {
8
+ const { meta } = rules [ id ] ;
9
+ const { fixable, docs } = meta ;
10
+ return [
11
+ docs . recommended ? '✔' : '' ,
12
+ fixable ? '🔧' : '' ,
13
+ `[react/${ id } ](docs/rules/${ id } .md)` ,
14
+ docs . description ,
15
+ ] . join ( ' | ' ) ;
16
+ } ;
19
17
20
18
const buildRulesTable = ( rows ) => {
21
19
const header = '✔ | 🔧 | Rule | Description' ;
@@ -26,13 +24,31 @@ const buildRulesTable = (rows) => {
26
24
. join ( '\n' ) ;
27
25
} ;
28
26
29
- const BASIC_RULES = ( ) => buildRulesTable ( ruleTableRows . filter ( ( rule ) => ! rule . includes ( 'react/jsx-' ) ) ) ;
30
- const JSX_RULES = ( ) => buildRulesTable ( ruleTableRows . filter ( ( rule ) => rule . includes ( 'react/jsx-' ) ) ) ;
27
+ const buildTableOfCategory = ( category ) => buildRulesTable (
28
+ Object . keys ( rules )
29
+ . sort ( )
30
+ . filter ( ( rule ) => rules [ rule ] . meta . docs . category === category )
31
+ . map ( ( r ) => buildRuleRow ( r ) )
32
+ ) ;
33
+
34
+ for ( const rule in rules ) {
35
+ if (
36
+ ! [ 'Possible Errors' , 'Best Practices' , 'Stylistic Issues' ] . includes (
37
+ rules [ rule ] . meta . docs . category
38
+ )
39
+ ) {
40
+ console . error (
41
+ `Rule ${ rule } has wrong category: ${ rules [ rule ] . meta . docs . category } `
42
+ ) ;
43
+ process . exit ( 1 ) ;
44
+ }
45
+ }
31
46
32
47
module . exports = {
33
48
transforms : {
34
- BASIC_RULES ,
35
- JSX_RULES ,
49
+ POSSIBLE_ERRORS_RULES : ( ) => buildTableOfCategory ( 'Possible Errors' ) ,
50
+ BEST_PRACTICES_RULES : ( ) => buildTableOfCategory ( 'Best Practices' ) ,
51
+ STYLISTIC_ISSUES_RULES : ( ) => buildTableOfCategory ( 'Stylistic Issues' ) ,
36
52
} ,
37
53
callback : ( ) => {
38
54
console . log ( 'The auto-generating of rules finished!' ) ;
0 commit comments