mm_eslint 1.5.4 → 1.5.5
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/lib/detector/const_name.js +46 -0
- package/package.json +1 -1
|
@@ -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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_eslint",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5",
|
|
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": [
|