mm_eslint 1.4.1 → 1.4.2
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/config.js +78 -44
- package/detector.js +2341 -369
- package/index.js +977 -77
- package/package.json +1 -1
- package/README_EN.md +0 -410
package/config.js
CHANGED
|
@@ -13,15 +13,15 @@ class Config {
|
|
|
13
13
|
'class-name': [],
|
|
14
14
|
'method-name': [],
|
|
15
15
|
'variable-name': [],
|
|
16
|
-
'constant-name': []
|
|
17
|
-
'property-value-name': [] // 忽略$符号的属性值名
|
|
16
|
+
'constant-name': []
|
|
18
17
|
},
|
|
19
|
-
//
|
|
18
|
+
// 禁止拼接词
|
|
20
19
|
forbidden_words: {
|
|
21
20
|
'class-name': [],
|
|
22
21
|
'method-name': [],
|
|
23
22
|
'variable-name': [],
|
|
24
|
-
'constant-name': []
|
|
23
|
+
'constant-name': [],
|
|
24
|
+
'param-name': []
|
|
25
25
|
},
|
|
26
26
|
// 推荐词
|
|
27
27
|
recommended_words: {
|
|
@@ -32,6 +32,8 @@ class Config {
|
|
|
32
32
|
'variable-name': {
|
|
33
33
|
},
|
|
34
34
|
'constant-name': {
|
|
35
|
+
},
|
|
36
|
+
'param-name': {
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
}, config);
|
|
@@ -79,7 +81,7 @@ Config.prototype.getRule = function (name_type) {
|
|
|
79
81
|
'function-name': {
|
|
80
82
|
name: '函数名',
|
|
81
83
|
message:
|
|
82
|
-
'必须使用小驼峰命名法(camelCase),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}
|
|
84
|
+
'必须使用小驼峰命名法(camelCase),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符,不允许使用私有函数',
|
|
83
85
|
min: 1,
|
|
84
86
|
max: 20,
|
|
85
87
|
styles: ['camelCase'],
|
|
@@ -129,40 +131,40 @@ Config.prototype.getRule = function (name_type) {
|
|
|
129
131
|
'property-class-name': {
|
|
130
132
|
name: '属性类名',
|
|
131
133
|
message:
|
|
132
|
-
'属性类必须使用大驼峰命名法(PascalCase),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
134
|
+
'属性类必须使用大驼峰命名法(PascalCase),私有属性类使用私有大驼峰命名法(_PascalCase),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
133
135
|
min: 1,
|
|
134
136
|
max: 20,
|
|
135
|
-
styles: ['PascalCase'],
|
|
137
|
+
styles: ['PascalCase', '_PascalCase'],
|
|
136
138
|
single_word: true,
|
|
137
139
|
single_word_len: 8
|
|
138
140
|
},
|
|
139
141
|
'property-instance-class-name': {
|
|
140
142
|
name: '属性实例类名',
|
|
141
143
|
message:
|
|
142
|
-
'属性实例类必须使用小驼峰命名法(camelCase),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
144
|
+
'属性实例类必须使用小驼峰命名法(camelCase),私有属性实例类使用私有小驼峰命名法(_camelCase),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
143
145
|
min: 1,
|
|
144
146
|
max: 20,
|
|
145
|
-
styles: ['camelCase'],
|
|
147
|
+
styles: ['camelCase', '_camelCase'],
|
|
146
148
|
single_word: true,
|
|
147
149
|
single_word_len: 8
|
|
148
150
|
},
|
|
149
151
|
'property-method-name': {
|
|
150
152
|
name: '属性方法名',
|
|
151
153
|
message:
|
|
152
|
-
'属性方法必须使用小驼峰命名法(camelCase),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
154
|
+
'属性方法必须使用小驼峰命名法(camelCase),私有属性方法使用私有小驼峰命名法(_camelCase),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
153
155
|
min: 1,
|
|
154
156
|
max: 20,
|
|
155
|
-
styles: ['camelCase'],
|
|
157
|
+
styles: ['camelCase', '_camelCase'],
|
|
156
158
|
single_word: true,
|
|
157
159
|
single_word_len: 8
|
|
158
160
|
},
|
|
159
161
|
'property-value-name': {
|
|
160
162
|
name: '属性值名',
|
|
161
163
|
message:
|
|
162
|
-
'属性值必须使用小写蛇形命名法(snake_case),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
164
|
+
'属性值必须使用小写蛇形命名法(snake_case),私有属性值使用私有蛇形命名法(_snake_case),常量属性值使用大写蛇形命名法(UPPER_SNAKE_CASE),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
163
165
|
min: 1,
|
|
164
166
|
max: 20,
|
|
165
|
-
styles: ['snake_case'],
|
|
167
|
+
styles: ['snake_case', '_snake_case', 'UPPER_SNAKE_CASE'],
|
|
166
168
|
single_word: true,
|
|
167
169
|
single_word_len: 8
|
|
168
170
|
},
|
|
@@ -182,14 +184,17 @@ Config.prototype.getRule = function (name_type) {
|
|
|
182
184
|
};
|
|
183
185
|
|
|
184
186
|
/**
|
|
185
|
-
*
|
|
187
|
+
* 获取命名类型的禁止拼接词列表
|
|
186
188
|
* @param {string} name_type 命名类型
|
|
187
|
-
* @returns {Array}
|
|
189
|
+
* @returns {Array} 禁止拼接词列表
|
|
188
190
|
*/
|
|
189
191
|
Config.prototype.getForbiddenWords = function (name_type) {
|
|
190
|
-
|
|
191
|
-
if (
|
|
192
|
-
|
|
192
|
+
let type = name_type.replace('property-', '').replace('instance-', '');
|
|
193
|
+
if (type == 'function-name') {
|
|
194
|
+
type = 'method-name';
|
|
195
|
+
}
|
|
196
|
+
else if (type == 'value-name') {
|
|
197
|
+
type = 'variable-name';
|
|
193
198
|
}
|
|
194
199
|
var forbidden = {
|
|
195
200
|
'class-name': [
|
|
@@ -267,6 +272,7 @@ Config.prototype.getForbiddenWords = function (name_type) {
|
|
|
267
272
|
'buffered',
|
|
268
273
|
'idx',
|
|
269
274
|
'counter',
|
|
275
|
+
'with'
|
|
270
276
|
],
|
|
271
277
|
'variable-name': [
|
|
272
278
|
'object',
|
|
@@ -307,7 +313,12 @@ Config.prototype.getForbiddenWords = function (name_type) {
|
|
|
307
313
|
'entity',
|
|
308
314
|
'column',
|
|
309
315
|
'property',
|
|
310
|
-
'attribute'
|
|
316
|
+
'attribute',
|
|
317
|
+
'manager',
|
|
318
|
+
'processor',
|
|
319
|
+
'controller',
|
|
320
|
+
'service',
|
|
321
|
+
'provider'
|
|
311
322
|
],
|
|
312
323
|
'constant-name': [
|
|
313
324
|
'manager',
|
|
@@ -355,12 +366,18 @@ Config.prototype.getForbiddenWords = function (name_type) {
|
|
|
355
366
|
'cached',
|
|
356
367
|
'buffer',
|
|
357
368
|
'buffered'
|
|
369
|
+
],
|
|
370
|
+
"param-name": [
|
|
371
|
+
'param',
|
|
372
|
+
'params',
|
|
373
|
+
'parameter',
|
|
374
|
+
'parameters'
|
|
358
375
|
]
|
|
359
376
|
};
|
|
360
377
|
|
|
361
378
|
// 优先返回配置中的禁用词,其次返回硬编码禁用词
|
|
362
|
-
var config = this.config.forbidden_words[
|
|
363
|
-
var hardcoded = forbidden[
|
|
379
|
+
var config = this.config.forbidden_words[type];
|
|
380
|
+
var hardcoded = forbidden[type];
|
|
364
381
|
|
|
365
382
|
// 如果配置中的禁用词为空数组,则使用硬编码禁用词
|
|
366
383
|
if (config && config.length > 0) {
|
|
@@ -378,9 +395,12 @@ Config.prototype.getForbiddenWords = function (name_type) {
|
|
|
378
395
|
* @returns {object} 推荐词映射
|
|
379
396
|
*/
|
|
380
397
|
Config.prototype.getRecommendedWords = function (name_type) {
|
|
381
|
-
|
|
382
|
-
if (
|
|
383
|
-
|
|
398
|
+
let type = name_type.replace('property-', '').replace('instance-', '');
|
|
399
|
+
if (type == 'function-name') {
|
|
400
|
+
type = 'method-name';
|
|
401
|
+
}
|
|
402
|
+
else if (type == 'value-name') {
|
|
403
|
+
type = 'variable-name';
|
|
384
404
|
}
|
|
385
405
|
var recommend = {
|
|
386
406
|
'class-name': {
|
|
@@ -407,17 +427,17 @@ Config.prototype.getRecommendedWords = function (name_type) {
|
|
|
407
427
|
'Info': ['Information'],
|
|
408
428
|
'Conn': ['Connection'],
|
|
409
429
|
'Ext': ['Extension'],
|
|
410
|
-
'Asst': ['Assistant']
|
|
430
|
+
'Asst': ['Assistant'],
|
|
431
|
+
'Const': ['Constants', 'Constant']
|
|
411
432
|
},
|
|
412
433
|
'method-name': {
|
|
413
434
|
'get': ['fetch', 'retrieve', 'obtain', 'query'],
|
|
414
|
-
'set': ['
|
|
435
|
+
'set': ['setting', 'update'],
|
|
415
436
|
'add': ['append', 'insert'],
|
|
416
437
|
'del': ['delete'],
|
|
417
438
|
'check': ['validate', 'verify'],
|
|
418
439
|
'calc': ['calculate', 'compute', 'evaluate'],
|
|
419
440
|
'init': ['initialize', 'initialization', 'prepare'],
|
|
420
|
-
'calc': ['calculate'],
|
|
421
441
|
'gen': ['generate'],
|
|
422
442
|
'exec': ['execute'],
|
|
423
443
|
'run': ['process', 'handle'],
|
|
@@ -427,14 +447,10 @@ Config.prototype.getRecommendedWords = function (name_type) {
|
|
|
427
447
|
'copy': ['duplicate'],
|
|
428
448
|
'move': ['transfer'],
|
|
429
449
|
'to': ['convert', 'transform', 'transformation'],
|
|
430
|
-
'check': ['verify', 'validate'],
|
|
431
450
|
'create': ['construct'],
|
|
432
|
-
'calc': ['compute', 'calculate'],
|
|
433
451
|
'avg': ['average'],
|
|
434
452
|
'zip': ['compress'],
|
|
435
453
|
'unzip': ['decompress'],
|
|
436
|
-
'App': ['Application'],
|
|
437
|
-
'config': ['configure', 'Configuration'],
|
|
438
454
|
'env': ['Environment'],
|
|
439
455
|
'auth': ['authorize', 'Authentication'],
|
|
440
456
|
'authz': ['Authorization'],
|
|
@@ -442,8 +458,11 @@ Config.prototype.getRecommendedWords = function (name_type) {
|
|
|
442
458
|
'stringify': ['serialize', 'serialization'],
|
|
443
459
|
'parse': ['deserialize', 'deserialization'],
|
|
444
460
|
'impl': ['Implementation'],
|
|
445
|
-
|
|
446
|
-
'
|
|
461
|
+
// 名词
|
|
462
|
+
'App': ['Application'],
|
|
463
|
+
'Conn': ['Connection'],
|
|
464
|
+
'Info': ['Information'],
|
|
465
|
+
'Config': ['Configure', 'Configuration']
|
|
447
466
|
},
|
|
448
467
|
'variable-name': {
|
|
449
468
|
'obj': ['object'],
|
|
@@ -456,18 +475,33 @@ Config.prototype.getRecommendedWords = function (name_type) {
|
|
|
456
475
|
'def': ['default'],
|
|
457
476
|
'max': ['maximum'],
|
|
458
477
|
'min': ['minimum'],
|
|
459
|
-
'avg': ['average']
|
|
478
|
+
'avg': ['average'],
|
|
479
|
+
'app': ['application'],
|
|
480
|
+
'connect': ['connection'],
|
|
481
|
+
'info': ['information'],
|
|
482
|
+
'config': ['configure', 'configuration'],
|
|
483
|
+
'var': ['variable']
|
|
460
484
|
},
|
|
461
485
|
'constant-name': {
|
|
462
|
-
'MAX': ['
|
|
463
|
-
'MIN': ['
|
|
464
|
-
'AVG': ['
|
|
486
|
+
'MAX': ['MAXIMUM'],
|
|
487
|
+
'MIN': ['MINIMUM'],
|
|
488
|
+
'AVG': ['AVERAGE'],
|
|
489
|
+
'APP': ['APPLICATION'],
|
|
490
|
+
'INFO': ['INFORMATION'],
|
|
491
|
+
'CONFIG': ['CONFIGURE', 'CONFIGURATION'],
|
|
492
|
+
'VAL': ['VALUE'],
|
|
493
|
+
'NUM': ['NUMBER'],
|
|
494
|
+
'STR': ['STRING'],
|
|
495
|
+
'BOOL': ['BOOLEAN'],
|
|
496
|
+
'ARR': ['ARRAY'],
|
|
497
|
+
'OBJ': ['OBJECT'],
|
|
498
|
+
'FUNC': ['FUNCTION']
|
|
465
499
|
}
|
|
466
500
|
};
|
|
467
501
|
|
|
468
502
|
// 优先返回配置中的推荐词,其次返回硬编码推荐词
|
|
469
|
-
var config = this.config.recommended_words[
|
|
470
|
-
var hardcoded = recommend[
|
|
503
|
+
var config = this.config.recommended_words[type];
|
|
504
|
+
var hardcoded = recommend[type];
|
|
471
505
|
|
|
472
506
|
// 如果配置中的推荐词不为空对象,则使用配置推荐词
|
|
473
507
|
if (config && Object.keys(config).length > 0) {
|
|
@@ -485,9 +519,9 @@ Config.prototype.getRecommendedWords = function (name_type) {
|
|
|
485
519
|
* @returns {Array} 忽略词列表
|
|
486
520
|
*/
|
|
487
521
|
Config.prototype.getIgnoredWords = function (name_type) {
|
|
488
|
-
|
|
489
|
-
if (
|
|
490
|
-
|
|
522
|
+
let type = name_type.replace('property-', '').replace('instance-', '');
|
|
523
|
+
if (type == 'function-name') {
|
|
524
|
+
type = 'method-name';
|
|
491
525
|
}
|
|
492
526
|
var ignore = {
|
|
493
527
|
'class-name': [
|
|
@@ -521,8 +555,8 @@ Config.prototype.getIgnoredWords = function (name_type) {
|
|
|
521
555
|
};
|
|
522
556
|
|
|
523
557
|
// 优先返回配置中的忽略词,其次返回硬编码忽略词
|
|
524
|
-
var config = this.config.ignored_words[
|
|
525
|
-
var hardcoded = ignore[
|
|
558
|
+
var config = this.config.ignored_words[type];
|
|
559
|
+
var hardcoded = ignore[type];
|
|
526
560
|
|
|
527
561
|
// 如果配置中的忽略词为空数组,则使用硬编码忽略词
|
|
528
562
|
if (config && config.length > 0) {
|