mm_eslint 1.5.4 → 1.5.6
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.
|
@@ -68,6 +68,11 @@ ConstName.prototype.VariableDeclaration = function (node) {
|
|
|
68
68
|
continue;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
// 排除require()调用,因为导入的模块类型无法确定
|
|
72
|
+
if (this._isRequireCall(decl.init)) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
|
|
71
76
|
// 判断是否为常量(包括 Object.freeze() 等情况)
|
|
72
77
|
if (this._isConstantValue(decl.init)) {
|
|
73
78
|
// 检测常量名
|
|
@@ -597,6 +602,42 @@ ConstName.prototype.ExportNamedDeclaration = function (node) {
|
|
|
597
602
|
}
|
|
598
603
|
}
|
|
599
604
|
|
|
605
|
+
/**
|
|
606
|
+
* 判断节点是否为require()调用
|
|
607
|
+
* @param {Object} node - AST节点
|
|
608
|
+
* @returns {boolean} 是否为require()调用
|
|
609
|
+
*/
|
|
610
|
+
ConstName.prototype._isRequireCall = function (node) {
|
|
611
|
+
if (!node) {
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// 情况1:直接的require()调用,如 require('module')
|
|
616
|
+
if (node.type === 'CallExpression' &&
|
|
617
|
+
node.callee && node.callee.type === 'Identifier' &&
|
|
618
|
+
node.callee.name === 'require') {
|
|
619
|
+
return true;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// 情况2:require().property,如 require('module').property
|
|
623
|
+
if (node.type === 'MemberExpression' &&
|
|
624
|
+
node.object && node.object.type === 'CallExpression' &&
|
|
625
|
+
node.object.callee && node.object.callee.type === 'Identifier' &&
|
|
626
|
+
node.object.callee.name === 'require') {
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// 情况3:require('module')[property],如 require('module')['property']
|
|
631
|
+
if (node.type === 'MemberExpression' &&
|
|
632
|
+
node.object && node.object.type === 'CallExpression' &&
|
|
633
|
+
node.object.callee && node.object.callee.type === 'Identifier' &&
|
|
634
|
+
node.object.callee.name === 'require') {
|
|
635
|
+
return true;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
return false;
|
|
639
|
+
}
|
|
640
|
+
|
|
600
641
|
/**
|
|
601
642
|
* 判断名称是否符合变量命名规则
|
|
602
643
|
* @param {string} name - 名称
|
|
@@ -606,6 +647,11 @@ ConstName.prototype._isValidVariableName = function (name) {
|
|
|
606
647
|
// 变量命名规则:小写蛇形命名法 (snake_case)
|
|
607
648
|
const variable_regex = /^[a-z][a-z0-9]*(_[a-z0-9]+)*$/;
|
|
608
649
|
|
|
650
|
+
// 检查名称长度(1-20字符)
|
|
651
|
+
if (name.length < 1 || name.length > 20) {
|
|
652
|
+
return false;
|
|
653
|
+
}
|
|
654
|
+
|
|
609
655
|
// 检查是否符合变量命名风格
|
|
610
656
|
return variable_regex.test(name);
|
|
611
657
|
}
|
|
@@ -76,6 +76,37 @@ VariableName.prototype.VariableDeclaration = function (node) {
|
|
|
76
76
|
for (let i = 0; i < node.declarations.length; i++) {
|
|
77
77
|
let decl = node.declarations[i];
|
|
78
78
|
if (decl.id && decl.id.type === 'Identifier') {
|
|
79
|
+
|
|
80
|
+
// 排除对象字面量(ObjectExpression)
|
|
81
|
+
if (decl.init && decl.init.type === 'ObjectExpression') {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 排除数组字面量(ArrayExpression)
|
|
86
|
+
if (decl.init && decl.init.type === 'ArrayExpression') {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 排除类实例:如果右边是 new 表达式,则不是变量
|
|
91
|
+
if (decl.init && decl.init.type === 'NewExpression') {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 排除正则表达式字面量(RegExp实例)
|
|
96
|
+
if (decl.init && decl.init.type === 'Literal' && decl.init.regex) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 排除函数:如果右边是函数表达式或箭头函数,则不是变量
|
|
101
|
+
if (decl.init && (decl.init.type === 'FunctionExpression' || decl.init.type === 'ArrowFunctionExpression')) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 排除类:如果右边是类表达式,则不是变量
|
|
106
|
+
if (decl.init && decl.init.type === 'ClassExpression') {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
79
110
|
// 检测变量名
|
|
80
111
|
let name = decl.id.name;
|
|
81
112
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_eslint",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.6",
|
|
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": [
|