mm_eslint 1.2.7 → 1.2.9
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/config.js +523 -0
- package/detector.js +1214 -0
- package/index.js +88 -20
- package/package.json +3 -1
package/index.js
CHANGED
|
@@ -121,19 +121,52 @@ function createNamingRules() {
|
|
|
121
121
|
},
|
|
122
122
|
create: function (context) {
|
|
123
123
|
return {
|
|
124
|
-
|
|
124
|
+
VariableDeclaration: function (node) {
|
|
125
125
|
// 排除const声明,只检测let和var声明的变量
|
|
126
|
-
if (node.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
126
|
+
if (node.kind !== 'const') {
|
|
127
|
+
node.declarations.forEach(function(decl) {
|
|
128
|
+
// 处理简单变量声明
|
|
129
|
+
if (decl.id && decl.id.type === 'Identifier') {
|
|
130
|
+
var variable_name = decl.id.name;
|
|
131
|
+
var err = detector._checkVariableName(variable_name, decl);
|
|
132
|
+
if (err) {
|
|
133
|
+
context.report({
|
|
134
|
+
node: decl.id,
|
|
135
|
+
message: err.message,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// 处理解构赋值 - ObjectPattern
|
|
140
|
+
else if (decl.id && decl.id.type === 'ObjectPattern') {
|
|
141
|
+
decl.id.properties.forEach(function(property) {
|
|
142
|
+
if (property.key && property.key.type === 'Identifier') {
|
|
143
|
+
var variable_name = property.key.name;
|
|
144
|
+
var err = detector._checkVariableName(variable_name, decl);
|
|
145
|
+
if (err) {
|
|
146
|
+
context.report({
|
|
147
|
+
node: property.key,
|
|
148
|
+
message: err.message,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
134
152
|
});
|
|
135
153
|
}
|
|
136
|
-
|
|
154
|
+
// 处理解构赋值 - ArrayPattern
|
|
155
|
+
else if (decl.id && decl.id.type === 'ArrayPattern') {
|
|
156
|
+
decl.id.elements.forEach(function(element, index) {
|
|
157
|
+
if (element && element.type === 'Identifier') {
|
|
158
|
+
var variable_name = element.name;
|
|
159
|
+
var err = detector._checkVariableName(variable_name, decl);
|
|
160
|
+
if (err) {
|
|
161
|
+
context.report({
|
|
162
|
+
node: element,
|
|
163
|
+
message: err.message,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
});
|
|
137
170
|
}
|
|
138
171
|
},
|
|
139
172
|
};
|
|
@@ -219,18 +252,53 @@ function createNamingRules() {
|
|
|
219
252
|
},
|
|
220
253
|
create: function (context) {
|
|
221
254
|
return {
|
|
222
|
-
|
|
223
|
-
if (node.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
255
|
+
VariableDeclaration: function (node) {
|
|
256
|
+
if (node.kind === 'const') {
|
|
257
|
+
node.declarations.forEach(function(decl) {
|
|
258
|
+
// 处理简单变量声明
|
|
259
|
+
if (decl.id && decl.id.type === 'Identifier') {
|
|
260
|
+
var constant_name = decl.id.name;
|
|
261
|
+
var err = detector._checkConstantName(constant_name, decl, decl.init);
|
|
262
|
+
if (err) {
|
|
263
|
+
context.report({
|
|
264
|
+
node: decl.id,
|
|
265
|
+
message: err.message,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// 处理解构赋值 - ObjectPattern
|
|
270
|
+
else if (decl.id && decl.id.type === 'ObjectPattern') {
|
|
271
|
+
decl.id.properties.forEach(function(property) {
|
|
272
|
+
if (property.key && property.key.type === 'Identifier') {
|
|
273
|
+
var constant_name = property.key.name;
|
|
274
|
+
// 对于解构赋值,使用专门的检测方法
|
|
275
|
+
var err = detector._checkConstantNameForDestructuring(constant_name, property.key);
|
|
276
|
+
if (err) {
|
|
277
|
+
context.report({
|
|
278
|
+
node: property.key,
|
|
279
|
+
message: err.message,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
231
283
|
});
|
|
232
284
|
}
|
|
233
|
-
|
|
285
|
+
// 处理解构赋值 - ArrayPattern
|
|
286
|
+
else if (decl.id && decl.id.type === 'ArrayPattern') {
|
|
287
|
+
decl.id.elements.forEach(function(element, index) {
|
|
288
|
+
if (element && element.type === 'Identifier') {
|
|
289
|
+
var constant_name = element.name;
|
|
290
|
+
// 对于解构赋值,使用专门的检测方法
|
|
291
|
+
var err = detector._checkConstantNameForDestructuring(constant_name, element);
|
|
292
|
+
if (err) {
|
|
293
|
+
context.report({
|
|
294
|
+
node: element,
|
|
295
|
+
message: err.message,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
});
|
|
234
302
|
}
|
|
235
303
|
},
|
|
236
304
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_eslint",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
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": [
|
|
@@ -37,6 +37,8 @@
|
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"index.js",
|
|
40
|
+
"detector.js",
|
|
41
|
+
"config.js",
|
|
40
42
|
"README.md",
|
|
41
43
|
"README_EN.md",
|
|
42
44
|
"LICENSE"
|