mm_eslint 1.6.2 → 1.6.4

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.
@@ -1,6 +1,6 @@
1
1
  /**
2
- * JavaScript内置函数列表
3
- * 这些函数不应该被命名规范检测器检测
2
+ * JavaScript内置函数和全局变量列表
3
+ * 这些标识符不应该被命名规范检测器检测
4
4
  */
5
5
 
6
6
  /**
@@ -19,6 +19,65 @@ function getBuiltinFunctions() {
19
19
  ];
20
20
  }
21
21
 
22
+ /**
23
+ * 获取Node.js内置全局变量列表
24
+ * @returns {Array} 内置全局变量名称数组
25
+ */
26
+ function getBuiltinGlobals() {
27
+ return [
28
+ // Node.js 全局变量
29
+ '__dirname',
30
+ '__filename',
31
+ 'exports',
32
+ 'module',
33
+ 'require',
34
+ 'process',
35
+ 'global',
36
+ 'console',
37
+ 'Buffer',
38
+ 'setTimeout',
39
+ 'clearTimeout',
40
+ 'setInterval',
41
+ 'clearInterval',
42
+ 'setImmediate',
43
+ 'clearImmediate',
44
+
45
+ // 浏览器全局变量
46
+ 'window',
47
+ 'document',
48
+ 'navigator',
49
+ 'location',
50
+ 'history',
51
+ 'localStorage',
52
+ 'sessionStorage',
53
+ 'alert',
54
+ 'confirm',
55
+ 'prompt',
56
+
57
+ // JavaScript 内置对象
58
+ 'Object',
59
+ 'Array',
60
+ 'Function',
61
+ 'String',
62
+ 'Number',
63
+ 'Boolean',
64
+ 'Date',
65
+ 'RegExp',
66
+ 'Error',
67
+ 'Math',
68
+ 'JSON',
69
+ 'Promise',
70
+ 'Map',
71
+ 'Set',
72
+ 'WeakMap',
73
+ 'WeakSet',
74
+ 'Symbol',
75
+ 'Proxy',
76
+ 'Reflect',
77
+ 'Intl'
78
+ ];
79
+ }
80
+
22
81
  /**
23
82
  * 检查是否为内置函数
24
83
  * @param {string} name 函数名
@@ -33,7 +92,33 @@ function isBuiltinFunction(name) {
33
92
  return builtinFunctions.includes(name);
34
93
  }
35
94
 
95
+ /**
96
+ * 检查是否为内置全局变量
97
+ * @param {string} name 变量名
98
+ * @returns {boolean} 是否为内置全局变量
99
+ */
100
+ function isBuiltinGlobal(name) {
101
+ if (!name || typeof name !== 'string') {
102
+ return false;
103
+ }
104
+
105
+ const builtinGlobals = getBuiltinGlobals();
106
+ return builtinGlobals.includes(name);
107
+ }
108
+
109
+ /**
110
+ * 检查是否为内置标识符(函数或全局变量)
111
+ * @param {string} name 标识符名
112
+ * @returns {boolean} 是否为内置标识符
113
+ */
114
+ function isBuiltinIdentifier(name) {
115
+ return isBuiltinFunction(name) || isBuiltinGlobal(name);
116
+ }
117
+
36
118
  module.exports = {
37
119
  getBuiltinFunctions,
38
- isBuiltinFunction
120
+ getBuiltinGlobals,
121
+ isBuiltinFunction,
122
+ isBuiltinGlobal,
123
+ isBuiltinIdentifier
39
124
  };
package/lib/config.js CHANGED
@@ -501,7 +501,7 @@ Config.prototype.getIgnoreWords = function (name_type) {
501
501
  'constructor', 'prototype', 'hasOwnProperty',
502
502
  'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString',
503
503
  'arguments',
504
- 'Middleware', 'Component', 'Controller', 'Repository', 'Interface', 'Transform', 'Template'
504
+ 'Middleware', 'Component', 'Controller', 'Repository', 'Interface', 'Transform', 'Template', 'Listeners'
505
505
  ],
506
506
  'variable': [
507
507
  'i', 'k', 'x', 'y', 'z', 'n', 'm', 'o', 'middleware', 'component', 'controller', 'repository', 'interface', 'transformer', 'template', '$',
@@ -1,4 +1,5 @@
1
1
  const { Name } = require('./name.js');
2
+ const { isBuiltinIdentifier } = require('../builtin_functions.js');
2
3
 
3
4
  /**
4
5
  * 参数名检测器类
@@ -22,6 +23,12 @@ ParamName.prototype.FunctionDeclaration = function (node) {
22
23
  let param = node.params[i];
23
24
  if (param.type === 'Identifier') {
24
25
  let name = param.name;
26
+
27
+ // 跳过内置标识符的检测
28
+ if (isBuiltinIdentifier(name)) {
29
+ continue;
30
+ }
31
+
25
32
  // 根据函数体内的使用方式判断参数类型
26
33
  let original_type = this._getParameterType(node, param);
27
34
  if (original_type === 'unknown') {
@@ -50,6 +57,12 @@ ParamName.prototype.FunctionExpression = function (node) {
50
57
  let param = node.params[i];
51
58
  if (param.type === 'Identifier') {
52
59
  let name = param.name;
60
+
61
+ // 跳过内置标识符的检测
62
+ if (isBuiltinIdentifier(name)) {
63
+ continue;
64
+ }
65
+
53
66
  // 根据函数体内的使用方式判断参数类型
54
67
  let original_type = this._getParameterType(node, param);
55
68
  if (original_type === 'unknown') {
@@ -78,6 +91,12 @@ ParamName.prototype.ArrowFunctionExpression = function (node) {
78
91
  let param = node.params[i];
79
92
  if (param.type === 'Identifier') {
80
93
  let name = param.name;
94
+
95
+ // 跳过内置标识符的检测
96
+ if (isBuiltinIdentifier(name)) {
97
+ continue;
98
+ }
99
+
81
100
  // 根据函数体内的使用方式判断参数类型
82
101
  let original_type = this._getParameterType(node, param);
83
102
  if (original_type === 'unknown') {
@@ -100,12 +119,18 @@ ParamName.prototype.ArrowFunctionExpression = function (node) {
100
119
  * @returns {Object|undefined} - 检测结果对象或undefined
101
120
  */
102
121
  ParamName.prototype.MethodDefinition = function (node) {
103
- // 检测类方法参数
122
+ // 检测方法参数
104
123
  if (node.value && node.value.params && node.value.params.length > 0) {
105
124
  for (let i = 0; i < node.value.params.length; i++) {
106
125
  let param = node.value.params[i];
107
126
  if (param.type === 'Identifier') {
108
127
  let name = param.name;
128
+
129
+ // 跳过内置标识符的检测
130
+ if (isBuiltinIdentifier(name)) {
131
+ continue;
132
+ }
133
+
109
134
  // 根据函数体内的使用方式判断参数类型
110
135
  let original_type = this._getParameterType(node.value, param);
111
136
  if (original_type === 'unknown') {
@@ -122,29 +147,16 @@ ParamName.prototype.MethodDefinition = function (node) {
122
147
  }
123
148
  }
124
149
 
125
- /**
126
- * 新表达式节点检测函数(参数检测)
127
- * @param {Object} node - 新表达式节点
128
- * @returns {Object|undefined} - 检测结果对象或undefined
129
- */
130
- ParamName.prototype.NewExpression = function (node) {
131
- // 检测新表达式中的参数
132
- if (node.arguments && node.arguments.length > 0) {
133
- for (let i = 0; i < node.arguments.length; i++) {
134
- let arg = node.arguments[i];
135
- if (arg.type === 'Identifier') {
136
- let name = arg.name;
137
- let original_type = 'param';
138
- let error = this.check(node, name, original_type);
139
- this.report(node, error, original_type);
140
-
141
- if (error) {
142
- return error;
143
- }
144
- }
145
- }
146
- }
147
- }
150
+ // /**
151
+ // * 新表达式节点检测函数(参数检测)
152
+ // * @param {Object} node - 新表达式节点
153
+ // * @returns {Object|undefined} - 检测结果对象或undefined
154
+ // */
155
+ // ParamName.prototype.NewExpression = function (node) {
156
+ // // 参数检测器不应该检测参数使用,只检测参数声明
157
+ // // 因此 NewExpression 方法应该为空
158
+ // return;
159
+ // }
148
160
 
149
161
  /**
150
162
  * 根据函数体内的使用方式判断参数类型
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_eslint",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
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": [