es-check 9.6.1 → 9.6.2
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/constants/es-features/13.js +1 -0
- package/lib/helpers/ast.js +116 -1
- package/package.json +1 -1
package/lib/helpers/ast.js
CHANGED
|
@@ -32,6 +32,117 @@ function hasNumericArgument(node) {
|
|
|
32
32
|
return isNumericLiteral || isNegativeNumeric;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
const ARRAY_LIKE_NAMES = new Set([
|
|
36
|
+
"arr",
|
|
37
|
+
"array",
|
|
38
|
+
"list",
|
|
39
|
+
"items",
|
|
40
|
+
"values",
|
|
41
|
+
"arguments",
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
const ARRAY_CONSTRUCTOR_FUNCTIONS = new Set([
|
|
45
|
+
"Array",
|
|
46
|
+
"from",
|
|
47
|
+
"of",
|
|
48
|
+
"slice",
|
|
49
|
+
"filter",
|
|
50
|
+
"map",
|
|
51
|
+
"concat",
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
const ARRAY_METHODS = new Set([
|
|
55
|
+
"slice",
|
|
56
|
+
"filter",
|
|
57
|
+
"map",
|
|
58
|
+
"concat",
|
|
59
|
+
"from",
|
|
60
|
+
"of",
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
const COMMON_NON_ARRAY_NAMES = new Set([
|
|
64
|
+
"obj",
|
|
65
|
+
"object",
|
|
66
|
+
"foo",
|
|
67
|
+
"bar",
|
|
68
|
+
"baz",
|
|
69
|
+
"data",
|
|
70
|
+
"config",
|
|
71
|
+
"options",
|
|
72
|
+
"params",
|
|
73
|
+
"props",
|
|
74
|
+
"state",
|
|
75
|
+
"item",
|
|
76
|
+
"element",
|
|
77
|
+
"node",
|
|
78
|
+
"target",
|
|
79
|
+
"source",
|
|
80
|
+
"result",
|
|
81
|
+
"response",
|
|
82
|
+
"request",
|
|
83
|
+
"payload",
|
|
84
|
+
"model",
|
|
85
|
+
"view",
|
|
86
|
+
"controller",
|
|
87
|
+
"service",
|
|
88
|
+
"utils",
|
|
89
|
+
"helpers",
|
|
90
|
+
"custom",
|
|
91
|
+
]);
|
|
92
|
+
function isArrayExpression(calleeObject) {
|
|
93
|
+
return calleeObject.type === "ArrayExpression";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function isArrayLikeIdentifier(calleeObject) {
|
|
97
|
+
const isIdentifier = calleeObject.type === "Identifier";
|
|
98
|
+
if (!isIdentifier) return false;
|
|
99
|
+
|
|
100
|
+
const objectName = calleeObject.name.toLowerCase();
|
|
101
|
+
|
|
102
|
+
const isCommonNonArrayName = COMMON_NON_ARRAY_NAMES.has(objectName);
|
|
103
|
+
if (isCommonNonArrayName) return false;
|
|
104
|
+
|
|
105
|
+
return ARRAY_LIKE_NAMES.has(objectName);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function isArrayConstructorCall(calleeObject) {
|
|
109
|
+
const isCallExpression = calleeObject.type === "CallExpression";
|
|
110
|
+
if (!isCallExpression) return false;
|
|
111
|
+
|
|
112
|
+
const innerCallee = calleeObject.callee;
|
|
113
|
+
const isIdentifierCallee = innerCallee?.type === "Identifier";
|
|
114
|
+
const isMemberExpressionCallee = innerCallee?.type === "MemberExpression";
|
|
115
|
+
|
|
116
|
+
if (isIdentifierCallee) {
|
|
117
|
+
const functionName = innerCallee.name;
|
|
118
|
+
return ARRAY_CONSTRUCTOR_FUNCTIONS.has(functionName);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (isMemberExpressionCallee) {
|
|
122
|
+
const innerProperty = innerCallee.property;
|
|
123
|
+
const hasPropertyName = innerProperty?.name;
|
|
124
|
+
const isArrayMethod = hasPropertyName && ARRAY_METHODS.has(innerProperty.name);
|
|
125
|
+
return isArrayMethod;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function isArrayLikeCall(node) {
|
|
132
|
+
const callee = node.callee;
|
|
133
|
+
const calleeObject = callee?.object;
|
|
134
|
+
const hasCalleeObject = calleeObject != null;
|
|
135
|
+
|
|
136
|
+
if (!hasCalleeObject) return false;
|
|
137
|
+
|
|
138
|
+
const isArrayExpr = isArrayExpression(calleeObject);
|
|
139
|
+
const isArrayIdent = isArrayLikeIdentifier(calleeObject);
|
|
140
|
+
const isArrayConstr = isArrayConstructorCall(calleeObject);
|
|
141
|
+
const isArray = isArrayExpr || isArrayIdent || isArrayConstr;
|
|
142
|
+
|
|
143
|
+
return isArray;
|
|
144
|
+
}
|
|
145
|
+
|
|
35
146
|
function checkMap(node, astInfo) {
|
|
36
147
|
const callee = node.callee;
|
|
37
148
|
const calleeObject = callee?.object;
|
|
@@ -82,6 +193,9 @@ function checkMap(node, astInfo) {
|
|
|
82
193
|
const hasNumericArgMismatch =
|
|
83
194
|
astInfo.requireNumericArg && !hasNumericArgument(node);
|
|
84
195
|
|
|
196
|
+
const hasArrayLikeCallMismatch =
|
|
197
|
+
astInfo.requireArrayLikeCall && !isArrayLikeCall(node);
|
|
198
|
+
|
|
85
199
|
const hasMismatch =
|
|
86
200
|
hasKindMismatch ||
|
|
87
201
|
hasOperatorMismatch ||
|
|
@@ -93,7 +207,8 @@ function checkMap(node, astInfo) {
|
|
|
93
207
|
hasObjectAndPropertyMismatch ||
|
|
94
208
|
hasOptionsCauseMismatch ||
|
|
95
209
|
hasExcludedCallerType ||
|
|
96
|
-
hasNumericArgMismatch
|
|
210
|
+
hasNumericArgMismatch ||
|
|
211
|
+
hasArrayLikeCallMismatch;
|
|
97
212
|
|
|
98
213
|
if (hasMismatch) return false;
|
|
99
214
|
|