mm_eslint 1.4.1 → 1.4.3

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.
Files changed (5) hide show
  1. package/config.js +81 -45
  2. package/detector.js +2374 -376
  3. package/index.js +977 -77
  4. package/package.json +1 -1
  5. 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
- name_type = name_type.replace('property-', '').replace('instance-', '');
191
- if (name_type == 'method-name') {
192
- name_type = 'method-name';
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,14 @@ 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
+ 'middleware',
322
+ 'component',
323
+ 'provider'
311
324
  ],
312
325
  'constant-name': [
313
326
  'manager',
@@ -355,12 +368,18 @@ Config.prototype.getForbiddenWords = function (name_type) {
355
368
  'cached',
356
369
  'buffer',
357
370
  'buffered'
371
+ ],
372
+ "param-name": [
373
+ 'param',
374
+ 'params',
375
+ 'parameter',
376
+ 'parameters'
358
377
  ]
359
378
  };
360
379
 
361
380
  // 优先返回配置中的禁用词,其次返回硬编码禁用词
362
- var config = this.config.forbidden_words[name_type];
363
- var hardcoded = forbidden[name_type];
381
+ var config = this.config.forbidden_words[type];
382
+ var hardcoded = forbidden[type];
364
383
 
365
384
  // 如果配置中的禁用词为空数组,则使用硬编码禁用词
366
385
  if (config && config.length > 0) {
@@ -378,9 +397,12 @@ Config.prototype.getForbiddenWords = function (name_type) {
378
397
  * @returns {object} 推荐词映射
379
398
  */
380
399
  Config.prototype.getRecommendedWords = function (name_type) {
381
- name_type = name_type.replace('property-', '').replace('instance-', '');
382
- if (name_type == 'method-name') {
383
- name_type = 'method-name';
400
+ let type = name_type.replace('property-', '').replace('instance-', '');
401
+ if (type == 'function-name') {
402
+ type = 'method-name';
403
+ }
404
+ else if (type == 'value-name') {
405
+ type = 'variable-name';
384
406
  }
385
407
  var recommend = {
386
408
  'class-name': {
@@ -398,7 +420,6 @@ Config.prototype.getRecommendedWords = function (name_type) {
398
420
  'Proc': ['Processor'],
399
421
  'Dcr': ['Decorator'],
400
422
  'Prov': ['Provider'],
401
- 'Facade': ['Facade'],
402
423
  'Obs': ['Observer'],
403
424
  'Strat': ['Strategy'],
404
425
  'Mnt': ['Memento'],
@@ -407,17 +428,17 @@ Config.prototype.getRecommendedWords = function (name_type) {
407
428
  'Info': ['Information'],
408
429
  'Conn': ['Connection'],
409
430
  'Ext': ['Extension'],
410
- 'Asst': ['Assistant']
431
+ 'Asst': ['Assistant'],
432
+ 'Const': ['Constants', 'Constant']
411
433
  },
412
434
  'method-name': {
413
435
  'get': ['fetch', 'retrieve', 'obtain', 'query'],
414
- 'set': ['assign', 'setting', 'update'],
436
+ 'set': ['setting', 'update'],
415
437
  'add': ['append', 'insert'],
416
438
  'del': ['delete'],
417
439
  'check': ['validate', 'verify'],
418
440
  'calc': ['calculate', 'compute', 'evaluate'],
419
441
  'init': ['initialize', 'initialization', 'prepare'],
420
- 'calc': ['calculate'],
421
442
  'gen': ['generate'],
422
443
  'exec': ['execute'],
423
444
  'run': ['process', 'handle'],
@@ -427,14 +448,10 @@ Config.prototype.getRecommendedWords = function (name_type) {
427
448
  'copy': ['duplicate'],
428
449
  'move': ['transfer'],
429
450
  'to': ['convert', 'transform', 'transformation'],
430
- 'check': ['verify', 'validate'],
431
451
  'create': ['construct'],
432
- 'calc': ['compute', 'calculate'],
433
452
  'avg': ['average'],
434
453
  'zip': ['compress'],
435
454
  'unzip': ['decompress'],
436
- 'App': ['Application'],
437
- 'config': ['configure', 'Configuration'],
438
455
  'env': ['Environment'],
439
456
  'auth': ['authorize', 'Authentication'],
440
457
  'authz': ['Authorization'],
@@ -442,8 +459,11 @@ Config.prototype.getRecommendedWords = function (name_type) {
442
459
  'stringify': ['serialize', 'serialization'],
443
460
  'parse': ['deserialize', 'deserialization'],
444
461
  'impl': ['Implementation'],
445
- 'info': ['Information'],
446
- 'conn': ['Connection']
462
+ // 名词
463
+ 'App': ['Application'],
464
+ 'Conn': ['Connection'],
465
+ 'Info': ['Information'],
466
+ 'Config': ['Configure', 'Configuration']
447
467
  },
448
468
  'variable-name': {
449
469
  'obj': ['object'],
@@ -456,18 +476,33 @@ Config.prototype.getRecommendedWords = function (name_type) {
456
476
  'def': ['default'],
457
477
  'max': ['maximum'],
458
478
  'min': ['minimum'],
459
- 'avg': ['average']
479
+ 'avg': ['average'],
480
+ 'app': ['application'],
481
+ 'connect': ['connection'],
482
+ 'info': ['information'],
483
+ 'config': ['configure', 'configuration'],
484
+ 'var': ['variable']
460
485
  },
461
486
  'constant-name': {
462
- 'MAX': ['Maximum'],
463
- 'MIN': ['Minimum'],
464
- 'AVG': ['Average']
487
+ 'MAX': ['MAXIMUM'],
488
+ 'MIN': ['MINIMUM'],
489
+ 'AVG': ['AVERAGE'],
490
+ 'APP': ['APPLICATION'],
491
+ 'INFO': ['INFORMATION'],
492
+ 'CONFIG': ['CONFIGURE', 'CONFIGURATION'],
493
+ 'VAL': ['VALUE'],
494
+ 'NUM': ['NUMBER'],
495
+ 'STR': ['STRING'],
496
+ 'BOOL': ['BOOLEAN'],
497
+ 'ARR': ['ARRAY'],
498
+ 'OBJ': ['OBJECT'],
499
+ 'FUNC': ['FUNCTION']
465
500
  }
466
501
  };
467
502
 
468
503
  // 优先返回配置中的推荐词,其次返回硬编码推荐词
469
- var config = this.config.recommended_words[name_type];
470
- var hardcoded = recommend[name_type];
504
+ var config = this.config.recommended_words[type];
505
+ var hardcoded = recommend[type];
471
506
 
472
507
  // 如果配置中的推荐词不为空对象,则使用配置推荐词
473
508
  if (config && Object.keys(config).length > 0) {
@@ -485,9 +520,9 @@ Config.prototype.getRecommendedWords = function (name_type) {
485
520
  * @returns {Array} 忽略词列表
486
521
  */
487
522
  Config.prototype.getIgnoredWords = function (name_type) {
488
- name_type = name_type.replace('property-', '').replace('instance-', '');
489
- if (name_type == 'function-name') {
490
- name_type = 'method-name';
523
+ let type = name_type.replace('property-', '').replace('instance-', '');
524
+ if (type == 'function-name') {
525
+ type = 'method-name';
491
526
  }
492
527
  var ignore = {
493
528
  'class-name': [
@@ -512,6 +547,7 @@ Config.prototype.getIgnoredWords = function (name_type) {
512
547
  'middleware',
513
548
  'component',
514
549
  'controller',
550
+ 'service',
515
551
  'repository',
516
552
  'interface',
517
553
  'transformer',
@@ -521,8 +557,8 @@ Config.prototype.getIgnoredWords = function (name_type) {
521
557
  };
522
558
 
523
559
  // 优先返回配置中的忽略词,其次返回硬编码忽略词
524
- var config = this.config.ignored_words[name_type];
525
- var hardcoded = ignore[name_type];
560
+ var config = this.config.ignored_words[type];
561
+ var hardcoded = ignore[type];
526
562
 
527
563
  // 如果配置中的忽略词为空数组,则使用硬编码忽略词
528
564
  if (config && config.length > 0) {