mm_eslint 1.4.3 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +336 -0
- package/README_EN.md +336 -0
- package/config.js +626 -573
- package/corrector.js +375 -0
- package/detector.js +1040 -3413
- package/eslint.config.js +25 -0
- package/fix.js +441 -0
- package/handler.js +993 -0
- package/index.js +211 -1164
- package/package.json +59 -49
- package/tip.js +85 -0
- package/util.js +241 -0
- package/validator.js +266 -0
package/config.js
CHANGED
|
@@ -1,573 +1,626 @@
|
|
|
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
|
-
}, config);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 获取命名风格的正则表达式
|
|
45
|
-
* @param {string} style 命名风格
|
|
46
|
-
* @returns {RegExp} 正则表达式
|
|
47
|
-
*/
|
|
48
|
-
Config.prototype.getRegex = function (style) {
|
|
49
|
-
var regex = {
|
|
50
|
-
PascalCase: /^[A-Z][a-z]
|
|
51
|
-
camelCase: /^[a-z][a-z]*([A-Z][a-z]*)*$/,
|
|
52
|
-
snake_case: /^[a-z][a-z0-9]*(_[a-z0-9]+)*$/,
|
|
53
|
-
UPPER_SNAKE_CASE: /^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$/,
|
|
54
|
-
lowercase: /^[a-z][a-z0-9]*$/,
|
|
55
|
-
UPPERCASE: /^[A-Z][A-Z0-9]*$/,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
'
|
|
202
|
-
'
|
|
203
|
-
'
|
|
204
|
-
'
|
|
205
|
-
'
|
|
206
|
-
'
|
|
207
|
-
'
|
|
208
|
-
'
|
|
209
|
-
'
|
|
210
|
-
'
|
|
211
|
-
'
|
|
212
|
-
'
|
|
213
|
-
'
|
|
214
|
-
'
|
|
215
|
-
'
|
|
216
|
-
'
|
|
217
|
-
'
|
|
218
|
-
'
|
|
219
|
-
'
|
|
220
|
-
'
|
|
221
|
-
'
|
|
222
|
-
'
|
|
223
|
-
'
|
|
224
|
-
'
|
|
225
|
-
'
|
|
226
|
-
'
|
|
227
|
-
'
|
|
228
|
-
'
|
|
229
|
-
'
|
|
230
|
-
'
|
|
231
|
-
'
|
|
232
|
-
'
|
|
233
|
-
'
|
|
234
|
-
'
|
|
235
|
-
'
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
'
|
|
239
|
-
'
|
|
240
|
-
'
|
|
241
|
-
'
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
'
|
|
245
|
-
'
|
|
246
|
-
'
|
|
247
|
-
'
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
'
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
'
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
'
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
'
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
'
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
'
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
'
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
'
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
'
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
'
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
'
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
'
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
'
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
'
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
'
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
'
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
'
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
'
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
'
|
|
410
|
-
'
|
|
411
|
-
'
|
|
412
|
-
'
|
|
413
|
-
'
|
|
414
|
-
'
|
|
415
|
-
'
|
|
416
|
-
'
|
|
417
|
-
'
|
|
418
|
-
'
|
|
419
|
-
'
|
|
420
|
-
'
|
|
421
|
-
'
|
|
422
|
-
'
|
|
423
|
-
'
|
|
424
|
-
'
|
|
425
|
-
'
|
|
426
|
-
'
|
|
427
|
-
'
|
|
428
|
-
'
|
|
429
|
-
'
|
|
430
|
-
'
|
|
431
|
-
'
|
|
432
|
-
'
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
'
|
|
437
|
-
'
|
|
438
|
-
'
|
|
439
|
-
'
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
'
|
|
443
|
-
'
|
|
444
|
-
'
|
|
445
|
-
'
|
|
446
|
-
'
|
|
447
|
-
'
|
|
448
|
-
'
|
|
449
|
-
'
|
|
450
|
-
'
|
|
451
|
-
'
|
|
452
|
-
'avg': ['average'],
|
|
453
|
-
'
|
|
454
|
-
'
|
|
455
|
-
'
|
|
456
|
-
'
|
|
457
|
-
'
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
'
|
|
461
|
-
'
|
|
462
|
-
|
|
463
|
-
'
|
|
464
|
-
'
|
|
465
|
-
'
|
|
466
|
-
'
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
'
|
|
470
|
-
'
|
|
471
|
-
'
|
|
472
|
-
'
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
'
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 命名规范检测配置类
|
|
3
|
+
* 负责提供配置,风格、长度等
|
|
4
|
+
*/
|
|
5
|
+
class Config {
|
|
6
|
+
/**
|
|
7
|
+
* 构造函数
|
|
8
|
+
* @param {object} config 配置对象
|
|
9
|
+
*/
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.config = Object.assign({
|
|
12
|
+
// 忽略词
|
|
13
|
+
ignore_words: {
|
|
14
|
+
'class': [],
|
|
15
|
+
'class-instance': [],
|
|
16
|
+
'function': [],
|
|
17
|
+
'param': [],
|
|
18
|
+
'variable': [],
|
|
19
|
+
'constant': []
|
|
20
|
+
},
|
|
21
|
+
// 禁止拼接词
|
|
22
|
+
forbidden_words: {
|
|
23
|
+
'class': [],
|
|
24
|
+
'class-instance': [],
|
|
25
|
+
'function': [],
|
|
26
|
+
'param': [],
|
|
27
|
+
'variable': [],
|
|
28
|
+
'constant': []
|
|
29
|
+
},
|
|
30
|
+
// 推荐词
|
|
31
|
+
recommended_words: {
|
|
32
|
+
'class': {},
|
|
33
|
+
'class-instance': {},
|
|
34
|
+
'function': {},
|
|
35
|
+
'param': {},
|
|
36
|
+
'variable': {},
|
|
37
|
+
'constant': {}
|
|
38
|
+
}
|
|
39
|
+
}, config || {});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 获取命名风格的正则表达式
|
|
45
|
+
* @param {string} style 命名风格
|
|
46
|
+
* @returns {RegExp} 正则表达式
|
|
47
|
+
*/
|
|
48
|
+
Config.prototype.getRegex = function (style) {
|
|
49
|
+
var regex = {
|
|
50
|
+
"PascalCase": /^[A-Z][a-z]+[A-Za-z]*$/,
|
|
51
|
+
"camelCase": /^[a-z][a-z]*([A-Z][a-z]*)*[a-z0-9]*$/,
|
|
52
|
+
"snake_case": /^[a-z][a-z0-9]*(_[a-z0-9]+)*$/,
|
|
53
|
+
"UPPER_SNAKE_CASE": /^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$/,
|
|
54
|
+
"lowercase": /^[a-z]+([a-z0-9]+)*$/,
|
|
55
|
+
"UPPERCASE": /^[A-Z]+([A-Z0-9]+)*$/,
|
|
56
|
+
"kebab-case": /^[a-z]+([a-z0-9-])*$/,
|
|
57
|
+
"UPPER-KEBAB-CASE": /^[A-Z]+([A-Z0-9-])*$/
|
|
58
|
+
};
|
|
59
|
+
return regex[style] || null;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 获取命名类型的禁止拼接词列表
|
|
64
|
+
* @param {string} name_type 命名类型
|
|
65
|
+
* @returns {Array} 禁止拼接词列表
|
|
66
|
+
*/
|
|
67
|
+
Config.prototype.getForbiddenWords = function (name_type) {
|
|
68
|
+
let type = name_type.replace('property-', '').replace('instance-', '').replace('private-', '').replace('internal-', '').replace('prototype-', '');
|
|
69
|
+
var forbidden = {
|
|
70
|
+
'class': [
|
|
71
|
+
'manager',
|
|
72
|
+
'handler',
|
|
73
|
+
'processor',
|
|
74
|
+
'controller',
|
|
75
|
+
'service',
|
|
76
|
+
'provider',
|
|
77
|
+
'factory',
|
|
78
|
+
'builder',
|
|
79
|
+
'adapter',
|
|
80
|
+
'decorator',
|
|
81
|
+
'proxy',
|
|
82
|
+
'facade',
|
|
83
|
+
'mediator',
|
|
84
|
+
'observer',
|
|
85
|
+
'strategy',
|
|
86
|
+
'command',
|
|
87
|
+
'visitor',
|
|
88
|
+
'iterator',
|
|
89
|
+
'template',
|
|
90
|
+
'flyweight',
|
|
91
|
+
'memento',
|
|
92
|
+
'interpreter',
|
|
93
|
+
'model',
|
|
94
|
+
'view',
|
|
95
|
+
'route',
|
|
96
|
+
'router',
|
|
97
|
+
'component',
|
|
98
|
+
'widget',
|
|
99
|
+
'panel',
|
|
100
|
+
'dialog',
|
|
101
|
+
'window',
|
|
102
|
+
'form',
|
|
103
|
+
'field',
|
|
104
|
+
'property',
|
|
105
|
+
'entity',
|
|
106
|
+
'data'
|
|
107
|
+
],
|
|
108
|
+
'function': [
|
|
109
|
+
'data',
|
|
110
|
+
'result',
|
|
111
|
+
'output',
|
|
112
|
+
'input',
|
|
113
|
+
'param',
|
|
114
|
+
'params',
|
|
115
|
+
'parameter',
|
|
116
|
+
'parameters',
|
|
117
|
+
'value',
|
|
118
|
+
'values',
|
|
119
|
+
'item',
|
|
120
|
+
'items',
|
|
121
|
+
'process',
|
|
122
|
+
'processor',
|
|
123
|
+
'provider',
|
|
124
|
+
'builder',
|
|
125
|
+
'adapter',
|
|
126
|
+
'decorator',
|
|
127
|
+
'proxy',
|
|
128
|
+
'facade',
|
|
129
|
+
'mediator',
|
|
130
|
+
'observer',
|
|
131
|
+
'strategy',
|
|
132
|
+
'command',
|
|
133
|
+
'visitor',
|
|
134
|
+
'iterator',
|
|
135
|
+
'template',
|
|
136
|
+
'flyweight',
|
|
137
|
+
'memento',
|
|
138
|
+
'interpreter',
|
|
139
|
+
'temp',
|
|
140
|
+
'tmp',
|
|
141
|
+
'temporary',
|
|
142
|
+
'cached',
|
|
143
|
+
'buffered',
|
|
144
|
+
'idx',
|
|
145
|
+
'counter',
|
|
146
|
+
'with'
|
|
147
|
+
],
|
|
148
|
+
'variable': [
|
|
149
|
+
'object',
|
|
150
|
+
'array',
|
|
151
|
+
'map',
|
|
152
|
+
'set',
|
|
153
|
+
'container',
|
|
154
|
+
'instance',
|
|
155
|
+
'data',
|
|
156
|
+
'collection',
|
|
157
|
+
'item',
|
|
158
|
+
'items',
|
|
159
|
+
'element',
|
|
160
|
+
'elements',
|
|
161
|
+
'entry',
|
|
162
|
+
'entries',
|
|
163
|
+
'temp',
|
|
164
|
+
'tmp',
|
|
165
|
+
'temporary',
|
|
166
|
+
'cached',
|
|
167
|
+
'buffer',
|
|
168
|
+
'buffered',
|
|
169
|
+
'input',
|
|
170
|
+
'output',
|
|
171
|
+
'result',
|
|
172
|
+
'destination',
|
|
173
|
+
'index',
|
|
174
|
+
'idx',
|
|
175
|
+
'counter',
|
|
176
|
+
'length',
|
|
177
|
+
'total',
|
|
178
|
+
'sum',
|
|
179
|
+
'pointer',
|
|
180
|
+
'reference',
|
|
181
|
+
'ref',
|
|
182
|
+
'handle',
|
|
183
|
+
'handler',
|
|
184
|
+
'entity',
|
|
185
|
+
'column',
|
|
186
|
+
'property',
|
|
187
|
+
'attribute',
|
|
188
|
+
'manager',
|
|
189
|
+
'processor',
|
|
190
|
+
'controller',
|
|
191
|
+
'service',
|
|
192
|
+
'middleware',
|
|
193
|
+
'component',
|
|
194
|
+
'provider'
|
|
195
|
+
],
|
|
196
|
+
'constant': [
|
|
197
|
+
'manager',
|
|
198
|
+
'handler',
|
|
199
|
+
'processor',
|
|
200
|
+
'controller',
|
|
201
|
+
'service',
|
|
202
|
+
'provider',
|
|
203
|
+
'factory',
|
|
204
|
+
'builder',
|
|
205
|
+
'adapter',
|
|
206
|
+
'decorator',
|
|
207
|
+
'proxy',
|
|
208
|
+
'facade',
|
|
209
|
+
'mediator',
|
|
210
|
+
'observer',
|
|
211
|
+
'strategy',
|
|
212
|
+
'command',
|
|
213
|
+
'visitor',
|
|
214
|
+
'iterator',
|
|
215
|
+
'template',
|
|
216
|
+
'flyweight',
|
|
217
|
+
'memento',
|
|
218
|
+
'interpreter',
|
|
219
|
+
'model',
|
|
220
|
+
'view',
|
|
221
|
+
'route',
|
|
222
|
+
'router',
|
|
223
|
+
'component',
|
|
224
|
+
'widget',
|
|
225
|
+
'panel',
|
|
226
|
+
'dialog',
|
|
227
|
+
'window',
|
|
228
|
+
'form',
|
|
229
|
+
'field',
|
|
230
|
+
'property',
|
|
231
|
+
'entity',
|
|
232
|
+
'data',
|
|
233
|
+
'result',
|
|
234
|
+
'output',
|
|
235
|
+
'input',
|
|
236
|
+
'temp',
|
|
237
|
+
'tmp',
|
|
238
|
+
'temporary',
|
|
239
|
+
'cached',
|
|
240
|
+
'buffer',
|
|
241
|
+
'buffered'
|
|
242
|
+
],
|
|
243
|
+
"param": [
|
|
244
|
+
'param',
|
|
245
|
+
'params',
|
|
246
|
+
'parameter',
|
|
247
|
+
'parameters'
|
|
248
|
+
]
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// 优先返回配置中的禁用词,其次返回硬编码禁用词
|
|
252
|
+
var config = this.config.forbidden_words[type];
|
|
253
|
+
var hardcoded = forbidden[type];
|
|
254
|
+
|
|
255
|
+
// 如果配置中的禁用词为空数组,则使用硬编码禁用词
|
|
256
|
+
if (config && config.length > 0) {
|
|
257
|
+
return config;
|
|
258
|
+
} else if (hardcoded && hardcoded.length > 0) {
|
|
259
|
+
return hardcoded;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return [];
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* 获取基础规则配置
|
|
267
|
+
* @param {string} name_type 命名类型
|
|
268
|
+
* @returns {object} 规则配置对象
|
|
269
|
+
*/
|
|
270
|
+
Config.prototype.getBaseRule = function (name_type) {
|
|
271
|
+
var rule = {
|
|
272
|
+
'class': {
|
|
273
|
+
name: '类名',
|
|
274
|
+
min: 1,
|
|
275
|
+
max: 20,
|
|
276
|
+
styles: ['PascalCase'],
|
|
277
|
+
single_word: true,
|
|
278
|
+
single_word_len: 8 // 类名允许更长的单词,因为需要表达复杂语义
|
|
279
|
+
},
|
|
280
|
+
'class-instance': {
|
|
281
|
+
name: '类实例名',
|
|
282
|
+
min: 1,
|
|
283
|
+
max: 20,
|
|
284
|
+
styles: ['camelCase'],
|
|
285
|
+
single_word: true,
|
|
286
|
+
single_word_len: 8
|
|
287
|
+
},
|
|
288
|
+
'function': {
|
|
289
|
+
name: '函数名',
|
|
290
|
+
min: 1,
|
|
291
|
+
max: 20,
|
|
292
|
+
styles: ['camelCase'],
|
|
293
|
+
single_word: true,
|
|
294
|
+
single_word_len: 8
|
|
295
|
+
},
|
|
296
|
+
'param': {
|
|
297
|
+
name: '参数名',
|
|
298
|
+
min: 1,
|
|
299
|
+
max: 20,
|
|
300
|
+
styles: ['snake_case', 'camelCase', 'PascalCase'],
|
|
301
|
+
single_word: true,
|
|
302
|
+
single_word_len: 8
|
|
303
|
+
},
|
|
304
|
+
'param-function': {
|
|
305
|
+
name: '函数类型参数',
|
|
306
|
+
min: 1,
|
|
307
|
+
max: 20,
|
|
308
|
+
styles: ['camelCase'],
|
|
309
|
+
single_word: true,
|
|
310
|
+
single_word_len: 8
|
|
311
|
+
},
|
|
312
|
+
'param-class': {
|
|
313
|
+
name: '类类型参数',
|
|
314
|
+
min: 1,
|
|
315
|
+
max: 20,
|
|
316
|
+
styles: ['PascalCase'],
|
|
317
|
+
single_word: true,
|
|
318
|
+
single_word_len: 8
|
|
319
|
+
},
|
|
320
|
+
'param-object': {
|
|
321
|
+
name: '对象类型参数',
|
|
322
|
+
min: 1,
|
|
323
|
+
max: 20,
|
|
324
|
+
styles: ['snake_case'],
|
|
325
|
+
single_word: true,
|
|
326
|
+
single_word_len: 8
|
|
327
|
+
},
|
|
328
|
+
'param-variable': {
|
|
329
|
+
name: '变量类型参数',
|
|
330
|
+
min: 1,
|
|
331
|
+
max: 20,
|
|
332
|
+
styles: ['snake_case'],
|
|
333
|
+
single_word: true,
|
|
334
|
+
single_word_len: 8
|
|
335
|
+
},
|
|
336
|
+
'variable': {
|
|
337
|
+
name: '变量名',
|
|
338
|
+
min: 1,
|
|
339
|
+
max: 20,
|
|
340
|
+
styles: ['snake_case'],
|
|
341
|
+
single_word: true,
|
|
342
|
+
single_word_len: 8
|
|
343
|
+
},
|
|
344
|
+
'constant': {
|
|
345
|
+
name: '常量名',
|
|
346
|
+
min: 1,
|
|
347
|
+
max: 20,
|
|
348
|
+
styles: ['UPPER_SNAKE_CASE'],
|
|
349
|
+
single_word: true,
|
|
350
|
+
single_word_len: 8
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
return rule[name_type] || null;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* 获取命名类型的规则配置
|
|
358
|
+
* @param {string} name_type 命名类型
|
|
359
|
+
* @returns {object} 规则配置对象
|
|
360
|
+
*/
|
|
361
|
+
Config.prototype.getRule = function (name_type) {
|
|
362
|
+
var rule = this.getBaseRule(name_type);
|
|
363
|
+
if (rule) {
|
|
364
|
+
rule.ignore_words = this.getIgnoreWords(name_type);
|
|
365
|
+
rule.forbidden_words = this.getForbiddenWords(name_type);
|
|
366
|
+
rule.recommend_words = this.getRecommendWords(name_type);
|
|
367
|
+
}
|
|
368
|
+
return rule;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* 获取推荐词映射
|
|
373
|
+
* @param {string} name_type 名称类型
|
|
374
|
+
* @returns {object} 推荐词映射
|
|
375
|
+
*/
|
|
376
|
+
Config.prototype.getRecommendWords = function (name_type) {
|
|
377
|
+
let type = name_type.replace('property-', '').replace('instance-', '').replace('private-', '').replace('internal-', '').replace('prototype-', '');
|
|
378
|
+
var recommend = {
|
|
379
|
+
'class': {
|
|
380
|
+
'App': ['Application'],
|
|
381
|
+
'Config': ['Configuration'],
|
|
382
|
+
'Env': ['Environment'],
|
|
383
|
+
'Init': ['Initialization'],
|
|
384
|
+
'Auth': ['Authentication'],
|
|
385
|
+
'Authz': ['Authorization'],
|
|
386
|
+
'Valid': ['Validation'],
|
|
387
|
+
'Serializer': ['Serialization'],
|
|
388
|
+
'Deserializer': ['Deserialization'],
|
|
389
|
+
'Transformer': ['Transformation'],
|
|
390
|
+
'Impl': ['Implementation'],
|
|
391
|
+
'Proc': ['Processor'],
|
|
392
|
+
'Dcr': ['Decorator'],
|
|
393
|
+
'Prov': ['Provider'],
|
|
394
|
+
'Obs': ['Observer'],
|
|
395
|
+
'Strat': ['Strategy'],
|
|
396
|
+
'Mnt': ['Memento'],
|
|
397
|
+
'Intp': ['Interpreter'],
|
|
398
|
+
'Cmp': ['Component'],
|
|
399
|
+
'Info': ['Information'],
|
|
400
|
+
'Conn': ['Connection'],
|
|
401
|
+
'Ext': ['Extension'],
|
|
402
|
+
'Asst': ['Assistant'],
|
|
403
|
+
'Const': ['Constants', 'Constant'],
|
|
404
|
+
'Info': ['Information'],
|
|
405
|
+
'Store': ['Repository']
|
|
406
|
+
},
|
|
407
|
+
'function': {
|
|
408
|
+
'get': ['fetch', 'retrieve', 'obtain', 'query'],
|
|
409
|
+
'set': ['setting', 'update'],
|
|
410
|
+
'add': ['append', 'insert'],
|
|
411
|
+
'del': ['delete'],
|
|
412
|
+
'check': ['validate', 'verify'],
|
|
413
|
+
'calc': ['calculate', 'compute', 'evaluate'],
|
|
414
|
+
'init': ['initialize', 'initialization', 'prepare'],
|
|
415
|
+
'gen': ['generate'],
|
|
416
|
+
'exec': ['execute'],
|
|
417
|
+
'run': ['process', 'handle'],
|
|
418
|
+
'load': ['retrieve'],
|
|
419
|
+
'save': ['persist'],
|
|
420
|
+
'cmp': ['compare'],
|
|
421
|
+
'copy': ['duplicate'],
|
|
422
|
+
'move': ['transfer'],
|
|
423
|
+
'to': ['convert', 'transform', 'transformation'],
|
|
424
|
+
'create': ['construct'],
|
|
425
|
+
'avg': ['average'],
|
|
426
|
+
'zip': ['compress'],
|
|
427
|
+
'unzip': ['decompress'],
|
|
428
|
+
'env': ['Environment'],
|
|
429
|
+
'auth': ['authorize', 'Authentication'],
|
|
430
|
+
'authz': ['Authorization'],
|
|
431
|
+
'valid': ['Validation'],
|
|
432
|
+
'stringify': ['serialize', 'serialization'],
|
|
433
|
+
'parse': ['deserialize', 'deserialization'],
|
|
434
|
+
'impl': ['Implementation'],
|
|
435
|
+
// 名词
|
|
436
|
+
'App': ['Application'],
|
|
437
|
+
'Conn': ['Connection'],
|
|
438
|
+
'Info': ['Information'],
|
|
439
|
+
'Config': ['Configure', 'Configuration']
|
|
440
|
+
},
|
|
441
|
+
'variable': {
|
|
442
|
+
'obj': ['object'],
|
|
443
|
+
'arr': ['array'],
|
|
444
|
+
'str': ['string'],
|
|
445
|
+
'num': ['number'],
|
|
446
|
+
'bool': ['boolean'],
|
|
447
|
+
'fn': ['function'],
|
|
448
|
+
'tmp': ['temporary'],
|
|
449
|
+
'def': ['default'],
|
|
450
|
+
'max': ['maximum'],
|
|
451
|
+
'min': ['minimum'],
|
|
452
|
+
'avg': ['average'],
|
|
453
|
+
'app': ['application'],
|
|
454
|
+
'connect': ['connection'],
|
|
455
|
+
'info': ['information'],
|
|
456
|
+
'config': ['configure', 'configuration'],
|
|
457
|
+
'var': ['variable']
|
|
458
|
+
},
|
|
459
|
+
'constant': {
|
|
460
|
+
'MAX': ['MAXIMUM'],
|
|
461
|
+
'MIN': ['MINIMUM'],
|
|
462
|
+
'AVG': ['AVERAGE'],
|
|
463
|
+
'APP': ['APPLICATION'],
|
|
464
|
+
'INFO': ['INFORMATION'],
|
|
465
|
+
'CONFIG': ['CONFIGURE', 'CONFIGURATION'],
|
|
466
|
+
'VAL': ['VALUE'],
|
|
467
|
+
'NUM': ['NUMBER'],
|
|
468
|
+
'STR': ['STRING'],
|
|
469
|
+
'BOOL': ['BOOLEAN'],
|
|
470
|
+
'ARR': ['ARRAY'],
|
|
471
|
+
'OBJ': ['OBJECT'],
|
|
472
|
+
'FUNC': ['FUNCTION']
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
// 优先返回配置中的推荐词,其次返回硬编码推荐词
|
|
477
|
+
var config = this.config.recommended_words[type];
|
|
478
|
+
var hardcoded = recommend[type];
|
|
479
|
+
|
|
480
|
+
// 如果配置中的推荐词不为空对象,则使用配置推荐词
|
|
481
|
+
if (config && Object.keys(config).length > 0) {
|
|
482
|
+
return config;
|
|
483
|
+
} else if (hardcoded && Object.keys(hardcoded).length > 0) {
|
|
484
|
+
return hardcoded;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return {};
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* 获取忽略词列表
|
|
492
|
+
* @param {string} name_type 名称类型
|
|
493
|
+
* @returns {Array} 忽略词列表
|
|
494
|
+
*/
|
|
495
|
+
Config.prototype.getIgnoreWords = function (name_type) {
|
|
496
|
+
let type = name_type.replace('property-', '').replace('instance-', '').replace('private-', '').replace('internal-', '').replace('prototype-', '');
|
|
497
|
+
var ignore = {
|
|
498
|
+
'class': [
|
|
499
|
+
'exports', 'Middleware', 'Component', 'Controller', 'Repository', 'Interface', 'Transformer', 'Template'
|
|
500
|
+
],
|
|
501
|
+
'function': [
|
|
502
|
+
'constructor', 'prototype', 'hasOwnProperty',
|
|
503
|
+
'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString',
|
|
504
|
+
'arguments',
|
|
505
|
+
'Middleware', 'Component', 'Controller', 'Repository', 'Interface', 'Transform', 'Template'
|
|
506
|
+
],
|
|
507
|
+
'variable': [
|
|
508
|
+
'i', 'k', 'x', 'y', 'z', 'n', 'm', 'o', 'middleware', 'component', 'controller', 'repository', 'interface', 'transformer', 'template', '$',
|
|
509
|
+
'timestamp', 'extensions'
|
|
510
|
+
],
|
|
511
|
+
'param': [
|
|
512
|
+
'middleware', 'component', 'controller', 'repository', 'interface', 'transformer', 'template',
|
|
513
|
+
'timestamp', 'extensions'
|
|
514
|
+
],
|
|
515
|
+
'value': [
|
|
516
|
+
'$', // 忽略$符号的属性值名
|
|
517
|
+
'middleware',
|
|
518
|
+
'component',
|
|
519
|
+
'controller',
|
|
520
|
+
'service',
|
|
521
|
+
'repository',
|
|
522
|
+
'interface',
|
|
523
|
+
'transformer',
|
|
524
|
+
'template',
|
|
525
|
+
'timestamp', 'extensions'
|
|
526
|
+
]
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
// 优先返回配置中的忽略词,其次返回硬编码忽略词
|
|
530
|
+
var config = this.config.ignore_words[type];
|
|
531
|
+
var hardcoded = ignore[type];
|
|
532
|
+
|
|
533
|
+
// 如果配置中的忽略词为空数组,则使用硬编码忽略词
|
|
534
|
+
if (config && config.length > 0) {
|
|
535
|
+
return config;
|
|
536
|
+
} else if (hardcoded && hardcoded.length > 0) {
|
|
537
|
+
return hardcoded;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
return [];
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* 获取命名类型的中文描述
|
|
545
|
+
* @param {string} name_type 命名类型
|
|
546
|
+
* @returns {string} 中文描述
|
|
547
|
+
*/
|
|
548
|
+
Config.prototype.getTypeName = function (name_type) {
|
|
549
|
+
var type_name_map = this.getTypeNameMap();
|
|
550
|
+
return type_name_map[name_type] || '名称';
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* 获取命名类型的中文描述
|
|
555
|
+
* @returns {object} 命名类型映射表
|
|
556
|
+
*/
|
|
557
|
+
Config.prototype.getTypeNameMap = function () {
|
|
558
|
+
var type_name_map = {
|
|
559
|
+
'function': '函数',
|
|
560
|
+
'variable': '变量',
|
|
561
|
+
'param': '参数',
|
|
562
|
+
'class-instance': '类实例',
|
|
563
|
+
'class': '类',
|
|
564
|
+
'constant': '常量',
|
|
565
|
+
'property-function': '属性—函数',
|
|
566
|
+
'property-variable': '属性—变量',
|
|
567
|
+
'property-class-instance': '属性—类实例',
|
|
568
|
+
'property-class': '属性—类',
|
|
569
|
+
'property-constant': '属性—常量',
|
|
570
|
+
'static-function': '静态属性—函数',
|
|
571
|
+
'static-variable': '静态属性—变量',
|
|
572
|
+
'static-class-instance': '静态属性—类实例',
|
|
573
|
+
'static-class': '静态属性—类',
|
|
574
|
+
'static-constant': '静态属性—常量',
|
|
575
|
+
'prototype-function': '原型函数',
|
|
576
|
+
'prototype-variable': '原型变量',
|
|
577
|
+
'prototype-class-instance': '原型类实例',
|
|
578
|
+
'private-function': '私有属性—函数',
|
|
579
|
+
'private-variable': '私有属性—变量',
|
|
580
|
+
'private-class-instance': '私有属性—类实例',
|
|
581
|
+
'internal-function': '内部属性—函数',
|
|
582
|
+
'internal-variable': '内部属性—变量',
|
|
583
|
+
'internal-class-instance': '内部属性—类实例',
|
|
584
|
+
'use-variable': '引用-变量',
|
|
585
|
+
'use-function': '引用-函数',
|
|
586
|
+
'use-class': '引用-类',
|
|
587
|
+
'use-constant': '引用-常量',
|
|
588
|
+
'use-class-instance': '引用-类实例',
|
|
589
|
+
'param-class': '参数—类',
|
|
590
|
+
'param-class-instance': '参数—类实例',
|
|
591
|
+
'param-variable': '参数—变量',
|
|
592
|
+
'param-function': '参数—函数'
|
|
593
|
+
};
|
|
594
|
+
return type_name_map;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* 获取风格名称的中文描述
|
|
599
|
+
* @param {string} style 风格
|
|
600
|
+
* @returns {string} 中文描述
|
|
601
|
+
*/
|
|
602
|
+
Config.prototype.getStyleName = function (style) {
|
|
603
|
+
var style_name_map = this.getStyleNameMap();
|
|
604
|
+
return style_name_map[style] || style;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* 获取风格名称的中文描述
|
|
609
|
+
* @returns {object} 风格名称映射表
|
|
610
|
+
*/
|
|
611
|
+
Config.prototype.getStyleNameMap = function () {
|
|
612
|
+
var style_name_map = {
|
|
613
|
+
'snake_case': '小写蛇形命名法',
|
|
614
|
+
'camelCase': '小驼峰命名法',
|
|
615
|
+
'PascalCase': '大驼峰命名法',
|
|
616
|
+
'UPPER_CASE': '大写蛇形命名法',
|
|
617
|
+
'lowercase': '小写命名法',
|
|
618
|
+
'UPPERCASE': '大写命名法',
|
|
619
|
+
'lowercase': '小写命名法',
|
|
620
|
+
'kebab-case': '短横线命名法',
|
|
621
|
+
'UPPERCASE_KEBAB_CASE': '大写短横线命名法'
|
|
622
|
+
};
|
|
623
|
+
return style_name_map;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
module.exports = { Config };
|