@@ -35,55 +35,49 @@ const PRETTIER_OPTIONS: Options = {
35
35
plugins : [ require . resolve ( 'prettier-plugin-organize-imports' ) ] ,
36
36
37
37
parser : 'typescript' ,
38
- arrowParens : 'always' ,
39
- bracketSpacing : true ,
40
- printWidth : 120 ,
41
- semi : true ,
42
38
singleQuote : true ,
43
- tabWidth : 2 ,
44
- trailingComma : 'none' ,
45
- useTabs : false
39
+ trailingComma : 'all' ,
46
40
} ;
47
41
48
42
const generationMap : Record < string , Plugin > = {
49
43
eslint : {
50
44
name : 'Eslint' ,
51
- rules : Object . fromEntries ( new eslint . Linter ( ) . getRules ( ) . entries ( ) )
45
+ rules : Object . fromEntries ( new eslint . Linter ( ) . getRules ( ) . entries ( ) ) ,
52
46
} ,
53
47
'typescript-eslint' : {
54
48
name : 'TypeScript' ,
55
49
prefix : '@typescript-eslint' ,
56
- rules : ( eslintPluginTypeScript as Plugin ) . rules
50
+ rules : ( eslintPluginTypeScript as Plugin ) . rules ,
57
51
} ,
58
52
jsdoc : {
59
53
name : 'JSDoc' ,
60
- rules : ( eslintPluginJSDoc as Plugin ) . rules
54
+ rules : ( eslintPluginJSDoc as Plugin ) . rules ,
61
55
} ,
62
56
node : {
63
57
name : 'Node' ,
64
- rules : ( eslintPluginNode as Plugin ) . rules
58
+ rules : ( eslintPluginNode as Plugin ) . rules ,
65
59
} ,
66
60
spellcheck : {
67
61
name : 'Spellcheck' ,
68
- rules : ( eslintPluginSpellcheck as Plugin ) . rules
62
+ rules : ( eslintPluginSpellcheck as Plugin ) . rules ,
69
63
} ,
70
64
unicorn : {
71
65
name : 'Unicorn' ,
72
- rules : ( eslintPluginUnicorn as Plugin ) . rules
66
+ rules : ( eslintPluginUnicorn as Plugin ) . rules ,
73
67
} ,
74
68
vue : {
75
69
name : 'Vue' ,
76
- rules : ( eslintPluginVue as Plugin ) . rules
70
+ rules : ( eslintPluginVue as Plugin ) . rules ,
77
71
} ,
78
72
'vue-i18n' : {
79
73
name : 'VueI18n' ,
80
74
prefix : '@intlify/vue-i18n' ,
81
- rules : ( eslintPluginVueI18n as Plugin ) . rules
75
+ rules : ( eslintPluginVueI18n as Plugin ) . rules ,
82
76
} ,
83
77
'vue-pug-sfc' : {
84
78
name : 'VuePugSfc' ,
85
- rules : ( eslintPluginVuePugSfc as Plugin ) . rules
86
- }
79
+ rules : ( eslintPluginVuePugSfc as Plugin ) . rules ,
80
+ } ,
87
81
} ;
88
82
89
83
// Generating rule files
@@ -106,62 +100,73 @@ async function main(): Promise<void> {
106
100
try {
107
101
const nestedDepth : number = ruleName . split ( '/' ) . length ;
108
102
109
- const rulePath : string = path . resolve ( ruleProviderDir , `${ ruleName } .d.ts` ) ;
110
- let ruleContent : string = `import type { RuleConfig } from '${ '../' . repeat ( nestedDepth ) } rule-config';` ;
103
+ const rulePath : string = path . resolve (
104
+ ruleProviderDir ,
105
+ `${ ruleName } .d.ts` ,
106
+ ) ;
107
+ let ruleContent : string = `import type { RuleConfig } from '${ '../' . repeat (
108
+ nestedDepth ,
109
+ ) } rule-config';`;
111
110
112
111
const ruleNamePascalCase : string = pascalCase ( ruleName ) ;
113
112
114
113
let description : string = upperCaseFirst ( meta ?. docs ?. description ?? '' ) ;
115
114
if ( description . length > 0 && ! description . endsWith ( '.' ) ) {
116
115
description += '.' ;
117
116
}
118
- const seeDocLink : string = meta ?. docs ?. url ? `@see [${ ruleName } ](${ meta . docs . url } )` : '' ;
117
+ const seeDocLink : string = meta ?. docs ?. url
118
+ ? `@see [${ ruleName } ](${ meta . docs . url } )`
119
+ : '' ;
119
120
120
121
const deprecated : boolean | undefined = meta ?. deprecated ;
121
122
122
123
const schema : JSONSchema4 | JSONSchema4 [ ] | undefined = meta ?. schema ;
123
124
const schemaIsObject : boolean = ! Array . isArray ( schema ) ;
124
- const mainSchema : JSONSchema4 | undefined = Array . isArray ( schema ) ? schema [ 0 ] : schema ;
125
+ const mainSchema : JSONSchema4 | undefined = Array . isArray ( schema )
126
+ ? schema [ 0 ]
127
+ : schema ;
125
128
const sideSchema : JSONSchema4 | undefined =
126
- schema && Array . isArray ( schema ) && schema . length > 1 ? schema [ 1 ] : undefined ;
129
+ schema && Array . isArray ( schema ) && schema . length > 1
130
+ ? schema [ 1 ]
131
+ : undefined ;
127
132
const thirdSchema : JSONSchema4 | undefined =
128
- schema && Array . isArray ( schema ) && schema . length > 2 ? schema [ 2 ] : undefined ;
133
+ schema && Array . isArray ( schema ) && schema . length > 2
134
+ ? schema [ 2 ]
135
+ : undefined ;
129
136
if ( mainSchema ) {
130
137
if ( sideSchema ) {
131
138
if ( thirdSchema ) {
132
- const ruleSetting : string = await compile ( thirdSchema , ` ${ ruleNamePascalCase } Setting` , {
133
- bannerComment : '' ,
134
- style : {
135
- bracketSpacing : true ,
136
- printWidth : 120 ,
137
- semi : true ,
138
- singleQuote : true ,
139
- tabWidth : 2 ,
140
- trailingComma : 'none' ,
141
- useTabs : false
139
+ const ruleSetting : string = await compile (
140
+ thirdSchema ,
141
+ ` ${ ruleNamePascalCase } Setting` ,
142
+ {
143
+ bannerComment : '' ,
144
+ style : {
145
+ singleQuote : true ,
146
+ trailingComma : 'all' ,
147
+ } ,
148
+ unknownAny : false ,
142
149
} ,
143
- unknownAny : false
144
- } ) ;
150
+ ) ;
145
151
ruleContent += `
146
152
147
153
/**
148
154
* Setting.
149
155
*/
150
156
${ ruleSetting } `;
151
157
}
152
- const ruleConfig : string = await compile ( sideSchema , ` ${ ruleNamePascalCase } Config` , {
153
- bannerComment : '' ,
154
- style : {
155
- bracketSpacing : true ,
156
- printWidth : 120 ,
157
- semi : true ,
158
- singleQuote : true ,
159
- tabWidth : 2 ,
160
- trailingComma : 'none' ,
161
- useTabs : false
158
+ const ruleConfig : string = await compile (
159
+ sideSchema ,
160
+ ` ${ ruleNamePascalCase } Config` ,
161
+ {
162
+ bannerComment : '' ,
163
+ style : {
164
+ singleQuote : true ,
165
+ trailingComma : 'all' ,
166
+ } ,
167
+ unknownAny : false ,
162
168
} ,
163
- unknownAny : false
164
- } ) ;
169
+ ) ;
165
170
ruleContent += `
166
171
167
172
/**
@@ -170,19 +175,18 @@ ${ruleSetting}`;
170
175
${ ruleConfig } `;
171
176
}
172
177
173
- const ruleOption : string = await compile ( mainSchema , ` ${ ruleNamePascalCase } Option` , {
174
- bannerComment : '' ,
175
- style : {
176
- bracketSpacing : true ,
177
- printWidth : 120 ,
178
- semi : true ,
179
- singleQuote : true ,
180
- tabWidth : 2 ,
181
- trailingComma : 'none' ,
182
- useTabs : false
178
+ const ruleOption : string = await compile (
179
+ mainSchema ,
180
+ ` ${ ruleNamePascalCase } Option` ,
181
+ {
182
+ bannerComment : '' ,
183
+ style : {
184
+ singleQuote : true ,
185
+ trailingComma : 'all' ,
186
+ } ,
187
+ unknownAny : false ,
183
188
} ,
184
- unknownAny : false
185
- } ) ;
189
+ ) ;
186
190
187
191
ruleContent += `
188
192
@@ -199,7 +203,9 @@ export type ${ruleNamePascalCase}Options = ${
199
203
? `${ ruleNamePascalCase } Option`
200
204
: `[${ ruleNamePascalCase } Option?${
201
205
sideSchema
202
- ? `, ${ ruleNamePascalCase } Config?${ thirdSchema ? `, ${ ruleNamePascalCase } Setting?` : '' } `
206
+ ? `, ${ ruleNamePascalCase } Config?${
207
+ thirdSchema ? `, ${ ruleNamePascalCase } Setting?` : ''
208
+ } `
203
209
: ''
204
210
} ]`
205
211
} ;`;
@@ -220,7 +226,9 @@ export type ${ruleNamePascalCase}Options = ${
220
226
*
221
227
* ${ seeDocLink }
222
228
*/
223
- export type ${ ruleNamePascalCase } RuleConfig = RuleConfig<${ mainSchema ? `${ ruleNamePascalCase } Options` : '[]' } >;
229
+ export type ${ ruleNamePascalCase } RuleConfig = RuleConfig<${
230
+ mainSchema ? `${ ruleNamePascalCase } Options` : '[]'
231
+ } >;
224
232
225
233
/**
226
234
* ${ description } ${
@@ -254,13 +262,19 @@ export type ${ruleNamePascalCase}Options = ${
254
262
if ( nestedDepth > 1 ) {
255
263
const subPath : string = rulePath . replace ( / \/ [ \w - ] + .d .t s $ / , '' ) ;
256
264
if ( ! fs . existsSync ( subPath ) ) {
257
- fs . mkdirSync ( rulePath . replace ( / \/ [ \w - ] + .d .t s $ / , '' ) , { recursive : true } ) ;
265
+ fs . mkdirSync ( rulePath . replace ( / \/ [ \w - ] + .d .t s $ / , '' ) , {
266
+ recursive : true ,
267
+ } ) ;
258
268
}
259
269
}
260
270
fs . writeFileSync ( rulePath , ruleContent ) ;
261
271
} catch ( error ) {
262
272
if ( error instanceof Error ) {
263
- console . error ( `Failed to generate rule '${ ruleName } ' for ${ name } .\n` , error . stack , '\n' ) ;
273
+ console . error (
274
+ `Failed to generate rule '${ ruleName } ' for ${ name } .\n` ,
275
+ error . stack ,
276
+ '\n' ,
277
+ ) ;
264
278
}
265
279
failedRules . push ( ruleName ) ;
266
280
}
@@ -270,7 +284,9 @@ export type ${ruleNamePascalCase}Options = ${
270
284
const indexPath : string = path . resolve ( ruleProviderDir , 'index.d.ts' ) ;
271
285
let indexContent : string = Object . keys ( rules )
272
286
. filter ( ( name ) => ! failedRules . includes ( name ) )
273
- . map ( ( name ) => `import type { ${ pascalCase ( name ) } Rule } from './${ name } ';` )
287
+ . map (
288
+ ( name ) => `import type { ${ pascalCase ( name ) } Rule } from './${ name } ';` ,
289
+ )
274
290
. join ( '\n' ) ;
275
291
276
292
indexContent += `
0 commit comments