7
7
const fs = require ( 'fs' )
8
8
const path = require ( 'path' )
9
9
const rules = require ( './lib/rules' )
10
- const categories = require ( './lib/categories' )
10
+ const { getPresetIds, formatItems } = require ( './lib/utils' )
11
+
12
+ const VUE3_EMOJI = ':three:'
13
+ const VUE2_EMOJI = ':two:'
11
14
12
15
// -----------------------------------------------------------------------------
16
+ const categorizedRules = rules . filter (
17
+ ( rule ) =>
18
+ rule . meta . docs . categories &&
19
+ ! rule . meta . docs . extensionRule &&
20
+ ! rule . meta . deprecated
21
+ )
13
22
const uncategorizedRules = rules . filter (
14
23
( rule ) =>
15
24
! rule . meta . docs . categories &&
@@ -24,16 +33,23 @@ const uncategorizedExtensionRule = rules.filter(
24
33
)
25
34
const deprecatedRules = rules . filter ( ( rule ) => rule . meta . deprecated )
26
35
27
- function toRuleRow ( rule ) {
36
+ const TYPE_MARK = {
37
+ problem : ':warning:' ,
38
+ suggestion : ':hammer:' ,
39
+ layout : ':lipstick:'
40
+ }
41
+
42
+ function toRuleRow ( rule , kindMarks = [ ] ) {
28
43
const mark = [
29
44
rule . meta . fixable ? ':wrench:' : '' ,
30
45
rule . meta . hasSuggestions ? ':bulb:' : '' ,
31
46
rule . meta . deprecated ? ':warning:' : ''
32
47
] . join ( '' )
48
+ const kindMark = [ ...kindMarks , TYPE_MARK [ rule . meta . type ] ] . join ( '' )
33
49
const link = `[${ rule . ruleId } ](./${ rule . name } .md)`
34
50
const description = rule . meta . docs . description || '(no description)'
35
51
36
- return `| ${ link } | ${ description } | ${ mark } |`
52
+ return `| ${ link } | ${ description } | ${ mark } | ${ kindMark } | `
37
53
}
38
54
39
55
function toDeprecatedRuleRow ( rule ) {
@@ -46,25 +62,97 @@ function toDeprecatedRuleRow(rule) {
46
62
return `| ${ link } | ${ replacedBy || '(no replacement)' } |`
47
63
}
48
64
49
- // -----------------------------------------------------------------------------
50
- let rulesTableContent = categories
51
- . map (
52
- ( category ) => `
53
- ## ${ category . title . vuepress }
54
-
55
- Enforce all the rules in this category, as well as all higher priority rules, with:
65
+ const categoryGroups = [
66
+ {
67
+ title : 'Base Rules (Enabling Correct ESLint Parsing)' ,
68
+ description :
69
+ 'Rules in this category are enabled for all presets provided by eslint-plugin-vue.' ,
70
+ categoryIdForVue3 : 'base' ,
71
+ categoryIdForVue2 : 'base' ,
72
+ useMark : false
73
+ } ,
74
+ {
75
+ title : 'Priority A: Essential (Error Prevention)' ,
76
+ categoryIdForVue3 : 'vue3-essential' ,
77
+ categoryIdForVue2 : 'essential' ,
78
+ useMark : true
79
+ } ,
80
+ {
81
+ title : 'Priority B: Strongly Recommended (Improving Readability)' ,
82
+ categoryIdForVue3 : 'vue3-strongly-recommended' ,
83
+ categoryIdForVue2 : 'strongly-recommended' ,
84
+ useMark : true
85
+ } ,
86
+ {
87
+ title : 'Priority C: Recommended (Potentially Dangerous Patterns)' ,
88
+ categoryIdForVue3 : 'vue3-recommended' ,
89
+ categoryIdForVue2 : 'recommended' ,
90
+ useMark : true
91
+ }
92
+ ]
56
93
57
- \`\`\`json
58
- {
59
- "extends": "plugin:vue/${ category . categoryId } "
60
- }
61
- \`\`\`
94
+ // -----------------------------------------------------------------------------
95
+ let rulesTableContent = categoryGroups
96
+ . map ( ( group ) => {
97
+ const rules = categorizedRules . filter (
98
+ ( rule ) =>
99
+ rule . meta . docs . categories . includes ( group . categoryIdForVue3 ) ||
100
+ rule . meta . docs . categories . includes ( group . categoryIdForVue2 )
101
+ )
102
+ let content = `
103
+ ## ${ group . title }
104
+ `
62
105
63
- | Rule ID | Description | |
64
- |:--------|:------------|:---|
65
- ${ category . rules . map ( toRuleRow ) . join ( '\n' ) }
106
+ if ( group . description ) {
107
+ content += `
108
+ ${ group . description }
109
+ `
110
+ }
111
+ if ( group . useMark ) {
112
+ const presetsForVue3 = getPresetIds ( [ group . categoryIdForVue3 ] ) . map (
113
+ ( categoryId ) => `\`"plugin:vue/${ categoryId } "\``
114
+ )
115
+ const presetsForVue2 = getPresetIds ( [ group . categoryIdForVue2 ] ) . map (
116
+ ( categoryId ) => `\`"plugin:vue/${ categoryId } "\``
117
+ )
118
+ content += `
119
+ - ${ VUE3_EMOJI } Indicates that the rule is for Vue 3 and is included in ${ formatItems (
120
+ presetsForVue3 ,
121
+ [ 'preset' , 'presets' ]
122
+ ) } .
123
+ - ${ VUE2_EMOJI } Indicates that the rule is for Vue 2 and is included in ${ formatItems (
124
+ presetsForVue2 ,
125
+ [ 'preset' , 'presets' ]
126
+ ) } .
66
127
`
67
- )
128
+ }
129
+
130
+ content += `
131
+ <rules-table>
132
+
133
+ | Rule ID | Description | | |
134
+ |:--------|:------------|:--:|:--:|
135
+ ${ rules
136
+ . map ( ( rule ) => {
137
+ const mark = group . useMark
138
+ ? [
139
+ rule . meta . docs . categories . includes ( group . categoryIdForVue3 )
140
+ ? [ VUE3_EMOJI ]
141
+ : [ ] ,
142
+ rule . meta . docs . categories . includes ( group . categoryIdForVue2 )
143
+ ? [ VUE2_EMOJI ]
144
+ : [ ]
145
+ ] . flat ( )
146
+ : [ ]
147
+ return toRuleRow ( rule , mark )
148
+ } )
149
+ . join ( '\n' ) }
150
+
151
+ </rules-table>
152
+ `
153
+
154
+ return content
155
+ } )
68
156
. join ( '' )
69
157
70
158
// -----------------------------------------------------------------------------
@@ -90,9 +178,13 @@ For example:
90
178
}
91
179
if ( uncategorizedRules . length > 0 ) {
92
180
rulesTableContent += `
93
- | Rule ID | Description | |
94
- |:--------|:------------|:---|
95
- ${ uncategorizedRules . map ( toRuleRow ) . join ( '\n' ) }
181
+ <rules-table>
182
+
183
+ | Rule ID | Description | | |
184
+ |:--------|:------------|:--:|:--:|
185
+ ${ uncategorizedRules . map ( ( rule ) => toRuleRow ( rule ) ) . join ( '\n' ) }
186
+
187
+ </rules-table>
96
188
`
97
189
}
98
190
if ( uncategorizedExtensionRule . length > 0 ) {
@@ -101,9 +193,13 @@ if (uncategorizedExtensionRule.length > 0) {
101
193
102
194
The following rules extend the rules provided by ESLint itself and apply them to the expressions in the \`<template>\`.
103
195
104
- | Rule ID | Description | |
105
- |:--------|:------------|:---|
106
- ${ uncategorizedExtensionRule . map ( toRuleRow ) . join ( '\n' ) }
196
+ <rules-table>
197
+
198
+ | Rule ID | Description | | |
199
+ |:--------|:------------|:--:|:--:|
200
+ ${ uncategorizedExtensionRule . map ( ( rule ) => toRuleRow ( rule ) ) . join ( '\n' ) }
201
+
202
+ </rules-table>
107
203
`
108
204
}
109
205
@@ -127,6 +223,7 @@ fs.writeFileSync(
127
223
readmeFilePath ,
128
224
`---
129
225
sidebarDepth: 0
226
+ pageClass: rule-list
130
227
---
131
228
132
229
# Available rules
@@ -139,5 +236,12 @@ sidebarDepth: 0
139
236
:bulb: Indicates that some problems reported by the rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
140
237
:::
141
238
142
- ${ rulesTableContent } `
239
+ Mark indicating rule type:
240
+
241
+ - <span class="emoji">:warning:</span> Possible Problems: These rules relate to possible logic errors in code.
242
+ - :hammer: Suggestions: These rules suggest alternate ways of doing things.
243
+ - :lipstick: Layout & Formatting: These rules care about how the code looks rather than how it executes.
244
+
245
+ ${ rulesTableContent . trim ( ) }
246
+ `
143
247
)
0 commit comments