mm_eslint 1.4.2 → 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 (3) hide show
  1. package/config.js +3 -1
  2. package/detector.js +53 -27
  3. package/package.json +1 -1
package/config.js CHANGED
@@ -318,6 +318,8 @@ Config.prototype.getForbiddenWords = function (name_type) {
318
318
  'processor',
319
319
  'controller',
320
320
  'service',
321
+ 'middleware',
322
+ 'component',
321
323
  'provider'
322
324
  ],
323
325
  'constant-name': [
@@ -418,7 +420,6 @@ Config.prototype.getRecommendedWords = function (name_type) {
418
420
  'Proc': ['Processor'],
419
421
  'Dcr': ['Decorator'],
420
422
  'Prov': ['Provider'],
421
- 'Facade': ['Facade'],
422
423
  'Obs': ['Observer'],
423
424
  'Strat': ['Strategy'],
424
425
  'Mnt': ['Memento'],
@@ -546,6 +547,7 @@ Config.prototype.getIgnoredWords = function (name_type) {
546
547
  'middleware',
547
548
  'component',
548
549
  'controller',
550
+ 'service',
549
551
  'repository',
550
552
  'interface',
551
553
  'transformer',
package/detector.js CHANGED
@@ -1029,6 +1029,15 @@ Detector.prototype._checkForbiddenWords = function (name, name_type) {
1029
1029
  var name_type_desc = this.config.name_type_map[name_type] || "名称";
1030
1030
  var name_lower = name.toLowerCase();
1031
1031
 
1032
+ // 对于私有变量/方法(以_开头),如果是单个单词(移除_后没有其他分隔符),则跳过禁止词汇检查
1033
+ if (name_lower.startsWith("_") && name.length > 2) {
1034
+ // 移除前缀_后检查是否包含分隔符
1035
+ var name_without_prefix = name.substring(1);
1036
+ if (!name_without_prefix.includes("_") && !name_without_prefix.includes("-") && !/[A-Z]/.test(name_without_prefix)) {
1037
+ return null; // 单个单词的私有变量,跳过检查
1038
+ }
1039
+ }
1040
+
1032
1041
  // 如果名称本身就是禁止词汇(即单个单词),则允许使用
1033
1042
  for (var i = 0; i < forbidden_words.length; i++) {
1034
1043
  var forbidden_word = forbidden_words[i].toLowerCase();
@@ -1037,14 +1046,22 @@ Detector.prototype._checkForbiddenWords = function (name, name_type) {
1037
1046
  }
1038
1047
  }
1039
1048
 
1040
- // 按单词边界分割名称
1041
- var words = this._splitNameIntoWords(name_lower);
1049
+ // 按单词边界分割名称(使用原始名称进行拆分,保持大小写信息)
1050
+ var words = this._splitNameIntoWords(name);
1051
+
1052
+ // 将拆分后的单词转换为小写进行比较
1053
+ var words_lower = words.map(function(word) {
1054
+ return word.toLowerCase();
1055
+ });
1042
1056
 
1043
1057
  // 检查每个单词是否在禁止词汇列表中
1044
1058
  var found_forbidden_words = [];
1045
1059
 
1046
- for (var i = 0; i < words.length; i++) {
1047
- var word = words[i];
1060
+ // 对于私有变量(以_开头),跳过第一个单词(即_)
1061
+ var start_index = name_lower.startsWith("_") ? 1 : 0;
1062
+
1063
+ for (var i = start_index; i < words_lower.length; i++) {
1064
+ var word = words_lower[i];
1048
1065
  // 跳过空字符串和单个字符
1049
1066
  if (!word || word.length <= 1) {
1050
1067
  continue;
@@ -1101,6 +1118,11 @@ Detector.prototype._splitNameIntoWords = function (name) {
1101
1118
  processed_name = name.substring(1); // 去掉开头的下划线
1102
1119
  }
1103
1120
 
1121
+ // 如果移除_后为空,说明只有_,直接返回
1122
+ if (!processed_name) {
1123
+ return ["_"];
1124
+ }
1125
+
1104
1126
  // 根据命名风格分割单词
1105
1127
  if (processed_name.includes("_")) {
1106
1128
  words = processed_name.split("_");
@@ -1527,30 +1549,34 @@ Detector.prototype._checkPropertyName = function (
1527
1549
  }
1528
1550
 
1529
1551
  // 检查单词长度
1530
- var word_err = this._checkWordLength(
1531
- prop_name,
1532
- rule.single_word_len,
1533
- rule_type,
1534
- );
1535
- if (word_err) {
1536
- // 检查错误消息是否已经包含建议
1537
- var error_message = word_err;
1538
- if (!word_err.includes("建议使用")) {
1539
- // 如果错误消息中不包含建议,则添加建议
1540
- var smart_abbreviation = this._getSmartAbbreviation(
1541
- prop_name,
1542
- rule_type,
1543
- );
1544
- if (smart_abbreviation && smart_abbreviation !== prop_name) {
1545
- error_message = word_err + ",建议使用: " + smart_abbreviation;
1552
+ // 对于私有属性值名(以_开头且长度>2),跳过单词长度检查,视为单个单词
1553
+ var is_private_property = prop_name.startsWith("_");
1554
+ if (!(is_private_property && prop_name.length > 2)) {
1555
+ var word_err = this._checkWordLength(
1556
+ prop_name,
1557
+ rule.single_word_len,
1558
+ rule_type,
1559
+ );
1560
+ if (word_err) {
1561
+ // 检查错误消息是否已经包含建议
1562
+ var error_message = word_err;
1563
+ if (!word_err.includes("建议使用")) {
1564
+ // 如果错误消息中不包含建议,则添加建议
1565
+ var smart_abbreviation = this._getSmartAbbreviation(
1566
+ prop_name,
1567
+ rule_type,
1568
+ );
1569
+ if (smart_abbreviation && smart_abbreviation !== prop_name) {
1570
+ error_message = word_err + ",建议使用: " + smart_abbreviation;
1571
+ }
1546
1572
  }
1547
- }
1548
1573
 
1549
- return {
1550
- node: node,
1551
- message: error_message,
1552
- rule_type: rule_type, // 添加规则类型信息
1553
- };
1574
+ return {
1575
+ node: node,
1576
+ message: error_message,
1577
+ rule_type: rule_type, // 添加规则类型信息
1578
+ };
1579
+ }
1554
1580
  }
1555
1581
 
1556
1582
  // 检查禁止词汇
@@ -2959,7 +2985,7 @@ Detector.prototype._checkPropertyValueStyle = function (
2959
2985
  ) {
2960
2986
  try {
2961
2987
  // 首先检查禁止拼接词
2962
- var forbid_err = this._checkForbiddenWords(prop_name, "variable-name");
2988
+ var forbid_err = this._checkForbiddenWords(prop_name, rule_type);
2963
2989
  if (forbid_err) {
2964
2990
  return forbid_err;
2965
2991
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_eslint",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "ESLint plugin for naming conventions - PascalCase, camelCase, snake_case, and UPPER_SNAKE_CASE naming rules",
5
5
  "main": "index.js",
6
6
  "keywords": [