mm_eslint 1.3.7 → 1.3.8
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 +12 -9
- package/detector.js +59 -5
- package/package.json +1 -1
package/config.js
CHANGED
|
@@ -500,20 +500,23 @@ Config.prototype.getIgnoredWords = function (name_type) {
|
|
|
500
500
|
'Middleware', 'Component', 'Controller', 'Repository', 'Interface', 'Transform', 'Template'
|
|
501
501
|
],
|
|
502
502
|
'variable-name': [
|
|
503
|
-
'i', 'k', 'x', 'y', 'z', 'n', 'm', 'o', 'middleware', 'component', 'controller', 'repository', 'interface', 'transformer', 'template', '$'
|
|
503
|
+
'i', 'k', 'x', 'y', 'z', 'n', 'm', 'o', 'middleware', 'component', 'controller', 'repository', 'interface', 'transformer', 'template', '$',
|
|
504
|
+
'timestamp', 'extensions'
|
|
504
505
|
],
|
|
505
506
|
'param-name': [
|
|
506
|
-
'middleware', 'component', 'controller', 'repository', 'interface', 'transformer', 'template'
|
|
507
|
+
'middleware', 'component', 'controller', 'repository', 'interface', 'transformer', 'template',
|
|
508
|
+
'timestamp', 'extensions'
|
|
507
509
|
],
|
|
508
510
|
'value-name': [
|
|
509
511
|
'$', // 忽略$符号的属性值名
|
|
510
|
-
'middleware',
|
|
511
|
-
'component',
|
|
512
|
-
'controller',
|
|
513
|
-
'repository',
|
|
514
|
-
'interface',
|
|
515
|
-
'transformer',
|
|
516
|
-
'template'
|
|
512
|
+
'middleware',
|
|
513
|
+
'component',
|
|
514
|
+
'controller',
|
|
515
|
+
'repository',
|
|
516
|
+
'interface',
|
|
517
|
+
'transformer',
|
|
518
|
+
'template',
|
|
519
|
+
'timestamp', 'extensions'
|
|
517
520
|
]
|
|
518
521
|
};
|
|
519
522
|
|
package/detector.js
CHANGED
|
@@ -627,17 +627,71 @@ Detector.prototype._checkForbiddenWords = function (name, name_type) {
|
|
|
627
627
|
}
|
|
628
628
|
}
|
|
629
629
|
|
|
630
|
-
//
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
630
|
+
// 按单词边界分割名称
|
|
631
|
+
var words = this._splitNameIntoWords(name_lower);
|
|
632
|
+
|
|
633
|
+
// 检查每个单词是否在禁止词汇列表中
|
|
634
|
+
for (var i = 0; i < words.length; i++) {
|
|
635
|
+
var word = words[i];
|
|
636
|
+
// 跳过空字符串和单个字符
|
|
637
|
+
if (!word || word.length <= 1) {
|
|
638
|
+
continue;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
for (var j = 0; j < forbidden_words.length; j++) {
|
|
642
|
+
var forbidden_word = forbidden_words[j].toLowerCase();
|
|
643
|
+
if (word === forbidden_word) {
|
|
644
|
+
return name_type_desc + '\'' + name + '\'包含禁止拼接词\'' + forbidden_word + '\'';
|
|
645
|
+
}
|
|
635
646
|
}
|
|
636
647
|
}
|
|
637
648
|
|
|
638
649
|
return null;
|
|
639
650
|
};
|
|
640
651
|
|
|
652
|
+
/**
|
|
653
|
+
* 按单词边界分割名称
|
|
654
|
+
* @param {string} name 名称
|
|
655
|
+
* @returns {Array} 单词数组
|
|
656
|
+
*/
|
|
657
|
+
Detector.prototype._splitNameIntoWords = function (name) {
|
|
658
|
+
if (!name) {
|
|
659
|
+
return [];
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
var words = [];
|
|
663
|
+
var processed_name = name;
|
|
664
|
+
var has_private_prefix = false;
|
|
665
|
+
|
|
666
|
+
// 处理私有标识符(开头的下划线)
|
|
667
|
+
if (name.startsWith('_')) {
|
|
668
|
+
has_private_prefix = true;
|
|
669
|
+
processed_name = name.substring(1); // 去掉开头的下划线
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// 根据命名风格分割单词
|
|
673
|
+
if (processed_name.includes('_')) {
|
|
674
|
+
words = processed_name.split('_');
|
|
675
|
+
} else if (processed_name.includes('-')) {
|
|
676
|
+
words = processed_name.split('-');
|
|
677
|
+
} else {
|
|
678
|
+
// 驼峰命名法分割(保持原词大小写)
|
|
679
|
+
words = processed_name.split(/(?=[A-Z])/);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// 如果存在私有标识符,添加下划线作为第一个单词
|
|
683
|
+
if (has_private_prefix) {
|
|
684
|
+
words.unshift('_');
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// 过滤空字符串
|
|
688
|
+
words = words.filter(function(word) {
|
|
689
|
+
return word && word.length > 0;
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
return words;
|
|
693
|
+
};
|
|
694
|
+
|
|
641
695
|
/**
|
|
642
696
|
* 获取属性类型
|
|
643
697
|
* @param {object} val_node 属性值节点
|