mm_eslint 1.4.9 → 1.5.0

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.
@@ -16,8 +16,9 @@ class VariableName extends Name {
16
16
  * @returns {Object|undefined} - 检测结果对象或undefined
17
17
  */
18
18
  VariableName.prototype.VariableDeclaration = function (node) {
19
- // 检测变量声明(let、var 和需要修正的const)
20
- if (node.kind === 'let' || node.kind === 'var' || node.kind === 'const') {
19
+ // 检测变量声明
20
+ if (node.kind === 'let' || node.kind === 'var') {
21
+ // 处理let和var声明
21
22
  for (let i = 0; i < node.declarations.length; i++) {
22
23
  let decl = node.declarations[i];
23
24
  if (decl.id && decl.id.type === 'Identifier') {
@@ -54,24 +55,10 @@ VariableName.prototype.VariableDeclaration = function (node) {
54
55
  // 检测变量名
55
56
  let name = decl.id.name;
56
57
 
58
+ // 对于let和var声明,正常进行变量命名检测
57
59
  // 使用精确的类型识别逻辑
58
60
  let original_type = this._getOriginalType(decl, 'VariableDeclaration');
59
61
 
60
- // 对于const声明,检查是否需要改为let
61
- if (node.kind === 'const') {
62
- // 如果右边是函数调用,应该使用let而不是const
63
- if (decl.init && decl.init.type === 'CallExpression') {
64
- let error = {
65
- message: `变量'${name}'应该使用let标签声明而不是const标签声明`,
66
- fix: function(fixer) {
67
- return fixer.replaceTextRange([node.range[0], node.range[0] + 5], 'let');
68
- }
69
- };
70
- this.report(node, error, 'variable');
71
- return error;
72
- }
73
- }
74
-
75
62
  // 只有当确实是变量时才进行变量命名规则检测
76
63
  if (original_type === 'variable' || original_type === 'unknown') {
77
64
  let error = this.check(node, name, original_type);
@@ -84,6 +71,46 @@ VariableName.prototype.VariableDeclaration = function (node) {
84
71
  }
85
72
  }
86
73
  }
74
+ } else if (node.kind === 'const') {
75
+ // 单独处理const声明
76
+ for (let i = 0; i < node.declarations.length; i++) {
77
+ let decl = node.declarations[i];
78
+ if (decl.id && decl.id.type === 'Identifier') {
79
+ // 检测变量名
80
+ let name = decl.id.name;
81
+
82
+ // 对于const声明,只处理右边是CallExpression的情况
83
+ if (decl.init && decl.init.type === 'CallExpression') {
84
+ // 排除require()调用,因为导入的模块类型无法确定
85
+ if (decl.init.callee && decl.init.callee.type === 'Identifier' && decl.init.callee.name === 'require') {
86
+ return; // 跳过require()调用
87
+ }
88
+
89
+ // 排除Object.freeze()等常量函数调用
90
+ if (decl.init.callee && decl.init.callee.type === 'MemberExpression' &&
91
+ decl.init.callee.object && decl.init.callee.object.type === 'Identifier' &&
92
+ decl.init.callee.object.name === 'Object' && decl.init.callee.property &&
93
+ decl.init.callee.property.type === 'Identifier' && (
94
+ decl.init.callee.property.name === 'freeze' ||
95
+ decl.init.callee.property.name === 'seal' ||
96
+ decl.init.callee.property.name === 'preventExtensions'
97
+ )) {
98
+ return; // 跳过常量函数调用
99
+ }
100
+
101
+ let error = {
102
+ message: `变量'${name}'应该使用let标签声明而不是const标签声明`,
103
+ fix: function(fixer) {
104
+ return fixer.replaceTextRange([node.range[0], node.range[0] + 5], 'let');
105
+ }
106
+ };
107
+ this.report(node, error, 'variable');
108
+ return error;
109
+ }
110
+ // 对于const声明的其他情况,跳过变量规则检测(由常量规则处理)
111
+ return;
112
+ }
113
+ }
87
114
  }
88
115
  }
89
116
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_eslint",
3
- "version": "1.4.9",
3
+ "version": "1.5.0",
4
4
  "description": "ESLint plugin for personal naming conventions - supports PascalCase, camelCase, snake_case, and UPPER_SNAKE_CASE naming rules with intelligent recommendations",
5
5
  "main": "index.js",
6
6
  "keywords": [