mm_eslint 1.3.0 → 1.3.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.
Files changed (2) hide show
  1. package/detector.js +55 -8
  2. package/package.json +1 -1
package/detector.js CHANGED
@@ -399,6 +399,17 @@ Detector.prototype._checkConstantName = function (constant_name, node, val_node)
399
399
  return null;
400
400
  }
401
401
 
402
+ // 检查是否应该使用let而不是const
403
+ var should_use_let = this._shouldUseLetInsteadOfConst(node, val_node);
404
+
405
+ // 如果应该使用let,则提示开发者
406
+ if (should_use_let) {
407
+ return {
408
+ node: node,
409
+ message: `变量'${constant_name}'应该使用let而不是const声明,因为它不是真正的常量`
410
+ };
411
+ }
412
+
402
413
  // 检查是否为复杂类型(方法、函数、实例等)
403
414
  var is_complex_type = this._isComplexType(val_node);
404
415
 
@@ -659,6 +670,12 @@ Detector.prototype._getPropType = function (val_node, prop_name, parent_node) {
659
670
  val_node.name &&
660
671
  val_node.name[0] === val_node.name[0].toUpperCase()
661
672
  ) {
673
+ // 检查是否是特殊全局变量(如__dirname、__filename、process等)
674
+ var special_globals = ['__dirname', '__filename', 'process', 'console', 'module', 'exports', 'require', 'global'];
675
+ if (special_globals.includes(val_node.name)) {
676
+ return 'value'; // 特殊全局变量应该识别为属性值
677
+ }
678
+
662
679
  // 检查是否是类名引用(通常类名使用PascalCase)
663
680
  return 'class'; // 属性类类型
664
681
  }
@@ -885,6 +902,38 @@ Detector.prototype._isBaseValue = function (val_node) {
885
902
  }
886
903
  };
887
904
 
905
+ /**
906
+ * 检查是否应该使用let而不是const声明变量
907
+ * @param {object} node 变量声明节点
908
+ * @param {object} val_node 值节点
909
+ * @returns {boolean} 是否应该使用let
910
+ */
911
+ Detector.prototype._shouldUseLetInsteadOfConst = function (node, val_node) {
912
+ try {
913
+ if (!node || !val_node) {
914
+ return false;
915
+ }
916
+
917
+ // 检查是否为解构赋值
918
+ var is_destructuring = false;
919
+ if (node.parent && node.parent.type === 'VariableDeclarator') {
920
+ var declarator = node.parent;
921
+ if (declarator.id && (declarator.id.type === 'ObjectPattern' || declarator.id.type === 'ArrayPattern')) {
922
+ is_destructuring = true;
923
+ }
924
+ }
925
+
926
+ // 检查右侧是否为复杂类型(类实例、函数、对象等)
927
+ var is_complex_type = this._isComplexType(val_node);
928
+
929
+ // 如果是解构赋值且右侧是复杂类型,建议使用let
930
+ return is_destructuring && is_complex_type;
931
+ } catch (error) {
932
+ console.error('检查是否应该使用let时出错:', error);
933
+ return false;
934
+ }
935
+ };
936
+
888
937
  /**
889
938
  * 检查值是否为复杂类型(方法、函数、实例等)
890
939
  * @param {object} val_node 值节点
@@ -1159,14 +1208,12 @@ Detector.prototype._checkConstantNameForDestructuring = function (constant_name,
1159
1208
  return null;
1160
1209
  }
1161
1210
 
1162
- // 检查命名风格
1163
- var style_err = this._validate_naming_style(constant_name, rule.styles, 'constant-name');
1164
- if (style_err) {
1165
- return {
1166
- node: node,
1167
- message: style_err,
1168
- };
1169
- }
1211
+ // 对于解构赋值,直接提示使用let而不是const
1212
+ // 因为解构赋值通常不是真正的常量
1213
+ return {
1214
+ node: node,
1215
+ message: `变量'${constant_name}'应该使用let而不是const声明,因为它不是真正的常量`
1216
+ };
1170
1217
 
1171
1218
  // 检查并推荐更合适的词汇
1172
1219
  var rec_err = this._checkAndRecommend(constant_name, 'constant-name');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_eslint",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
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": [