eslint-plugin-absolute 0.4.0 → 0.5.0
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/dist/index.js +186 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -194,7 +194,9 @@ var PURE_GLOBAL_IDENTIFIERS = new Set([
|
|
|
194
194
|
"Boolean",
|
|
195
195
|
"Date",
|
|
196
196
|
"Function",
|
|
197
|
+
"JSON",
|
|
197
198
|
"Map",
|
|
199
|
+
"Math",
|
|
198
200
|
"Number",
|
|
199
201
|
"Object",
|
|
200
202
|
"Promise",
|
|
@@ -203,16 +205,131 @@ var PURE_GLOBAL_IDENTIFIERS = new Set([
|
|
|
203
205
|
"String",
|
|
204
206
|
"Symbol",
|
|
205
207
|
"URL",
|
|
208
|
+
"globalThis",
|
|
206
209
|
"undefined"
|
|
207
210
|
]);
|
|
208
|
-
var PURE_GLOBAL_FUNCTIONS = new Set([
|
|
211
|
+
var PURE_GLOBAL_FUNCTIONS = new Set([
|
|
212
|
+
"Boolean",
|
|
213
|
+
"Number",
|
|
214
|
+
"String",
|
|
215
|
+
"decodeURI",
|
|
216
|
+
"decodeURIComponent",
|
|
217
|
+
"encodeURI",
|
|
218
|
+
"encodeURIComponent",
|
|
219
|
+
"isFinite",
|
|
220
|
+
"isNaN",
|
|
221
|
+
"parseFloat",
|
|
222
|
+
"parseInt"
|
|
223
|
+
]);
|
|
209
224
|
var PURE_MEMBER_METHODS = new Set([
|
|
225
|
+
"toString",
|
|
226
|
+
"valueOf",
|
|
227
|
+
"at",
|
|
228
|
+
"charAt",
|
|
229
|
+
"charCodeAt",
|
|
230
|
+
"codePointAt",
|
|
231
|
+
"endsWith",
|
|
232
|
+
"includes",
|
|
233
|
+
"indexOf",
|
|
234
|
+
"lastIndexOf",
|
|
235
|
+
"match",
|
|
236
|
+
"matchAll",
|
|
237
|
+
"normalize",
|
|
238
|
+
"padEnd",
|
|
239
|
+
"padStart",
|
|
240
|
+
"repeat",
|
|
241
|
+
"replace",
|
|
242
|
+
"replaceAll",
|
|
243
|
+
"search",
|
|
244
|
+
"slice",
|
|
245
|
+
"split",
|
|
246
|
+
"startsWith",
|
|
247
|
+
"substr",
|
|
248
|
+
"substring",
|
|
249
|
+
"toLocaleLowerCase",
|
|
250
|
+
"toLocaleUpperCase",
|
|
251
|
+
"toLowerCase",
|
|
252
|
+
"toUpperCase",
|
|
253
|
+
"trim",
|
|
254
|
+
"trimEnd",
|
|
255
|
+
"trimStart",
|
|
256
|
+
"toExponential",
|
|
257
|
+
"toFixed",
|
|
258
|
+
"toPrecision",
|
|
259
|
+
"isInteger",
|
|
260
|
+
"isSafeInteger",
|
|
261
|
+
"getDate",
|
|
210
262
|
"getDay",
|
|
263
|
+
"getFullYear",
|
|
211
264
|
"getHours",
|
|
212
265
|
"getMilliseconds",
|
|
213
266
|
"getMinutes",
|
|
267
|
+
"getMonth",
|
|
214
268
|
"getSeconds",
|
|
215
|
-
"
|
|
269
|
+
"getTime",
|
|
270
|
+
"getTimezoneOffset",
|
|
271
|
+
"getUTCDate",
|
|
272
|
+
"getUTCDay",
|
|
273
|
+
"getUTCFullYear",
|
|
274
|
+
"getUTCHours",
|
|
275
|
+
"getUTCMilliseconds",
|
|
276
|
+
"getUTCMinutes",
|
|
277
|
+
"getUTCMonth",
|
|
278
|
+
"getUTCSeconds",
|
|
279
|
+
"toDateString",
|
|
280
|
+
"toISOString",
|
|
281
|
+
"toJSON",
|
|
282
|
+
"toLocaleDateString",
|
|
283
|
+
"toLocaleString",
|
|
284
|
+
"toLocaleTimeString",
|
|
285
|
+
"toTimeString",
|
|
286
|
+
"toUTCString",
|
|
287
|
+
"abs",
|
|
288
|
+
"acos",
|
|
289
|
+
"acosh",
|
|
290
|
+
"asin",
|
|
291
|
+
"asinh",
|
|
292
|
+
"atan",
|
|
293
|
+
"atan2",
|
|
294
|
+
"atanh",
|
|
295
|
+
"cbrt",
|
|
296
|
+
"ceil",
|
|
297
|
+
"clz32",
|
|
298
|
+
"cos",
|
|
299
|
+
"cosh",
|
|
300
|
+
"exp",
|
|
301
|
+
"expm1",
|
|
302
|
+
"floor",
|
|
303
|
+
"fround",
|
|
304
|
+
"hypot",
|
|
305
|
+
"log",
|
|
306
|
+
"log10",
|
|
307
|
+
"log1p",
|
|
308
|
+
"log2",
|
|
309
|
+
"max",
|
|
310
|
+
"min",
|
|
311
|
+
"pow",
|
|
312
|
+
"round",
|
|
313
|
+
"sign",
|
|
314
|
+
"sin",
|
|
315
|
+
"sinh",
|
|
316
|
+
"sqrt",
|
|
317
|
+
"tan",
|
|
318
|
+
"tanh",
|
|
319
|
+
"trunc",
|
|
320
|
+
"entries",
|
|
321
|
+
"fromEntries",
|
|
322
|
+
"getOwnPropertyNames",
|
|
323
|
+
"getOwnPropertySymbols",
|
|
324
|
+
"getPrototypeOf",
|
|
325
|
+
"hasOwn",
|
|
326
|
+
"isArray",
|
|
327
|
+
"keys",
|
|
328
|
+
"values",
|
|
329
|
+
"concat",
|
|
330
|
+
"join",
|
|
331
|
+
"parse",
|
|
332
|
+
"stringify"
|
|
216
333
|
]);
|
|
217
334
|
var hasDuplicateNames = (names) => {
|
|
218
335
|
const seen = new Set;
|
|
@@ -828,6 +945,59 @@ var sortKeysFixable = {
|
|
|
828
945
|
}
|
|
829
946
|
return isPureImportedCallExpression(callExpression);
|
|
830
947
|
};
|
|
948
|
+
const getCallReturnTypeSymbol = (node) => {
|
|
949
|
+
if (!tsChecker || !esTreeNodeToTSNodeMap)
|
|
950
|
+
return;
|
|
951
|
+
const tsNode = esTreeNodeToTSNodeMap.get(node);
|
|
952
|
+
if (!tsNode)
|
|
953
|
+
return;
|
|
954
|
+
const type = tsChecker.getTypeAtLocation(tsNode);
|
|
955
|
+
return type.symbol ?? type.aliasSymbol;
|
|
956
|
+
};
|
|
957
|
+
const callReturnsNominalInstance = (node) => {
|
|
958
|
+
const symbol = getCallReturnTypeSymbol(node);
|
|
959
|
+
if (!symbol)
|
|
960
|
+
return false;
|
|
961
|
+
const declarations = symbol.declarations;
|
|
962
|
+
if (!declarations)
|
|
963
|
+
return false;
|
|
964
|
+
return declarations.some((declaration) => ts.isClassDeclaration(declaration) || ts.isClassExpression(declaration) || ts.isInterfaceDeclaration(declaration));
|
|
965
|
+
};
|
|
966
|
+
const isEncapsulatedFreshExpression = (node, stableLocals) => {
|
|
967
|
+
if (!node)
|
|
968
|
+
return false;
|
|
969
|
+
if (node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSInstantiationExpression") {
|
|
970
|
+
return isEncapsulatedFreshExpression(node.expression, stableLocals);
|
|
971
|
+
}
|
|
972
|
+
if (node.type === "ObjectExpression" || node.type === "ArrayExpression") {
|
|
973
|
+
return isPureRuntimeExpression(node, stableLocals);
|
|
974
|
+
}
|
|
975
|
+
if (node.type === "NewExpression") {
|
|
976
|
+
return node.arguments.every((argument) => {
|
|
977
|
+
if (argument.type === "SpreadElement") {
|
|
978
|
+
return isPureRuntimeExpression(argument.argument, stableLocals);
|
|
979
|
+
}
|
|
980
|
+
return isPureRuntimeExpression(argument, stableLocals);
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
if (node.type === "CallExpression") {
|
|
984
|
+
const argsArePure = node.arguments.every((argument) => {
|
|
985
|
+
if (argument.type === "SpreadElement") {
|
|
986
|
+
return isPureRuntimeExpression(argument.argument, stableLocals);
|
|
987
|
+
}
|
|
988
|
+
return isPureRuntimeExpression(argument, stableLocals);
|
|
989
|
+
});
|
|
990
|
+
if (!argsArePure)
|
|
991
|
+
return false;
|
|
992
|
+
if (node.callee.type === "MemberExpression") {
|
|
993
|
+
return isEncapsulatedFreshExpression(node.callee.object, stableLocals);
|
|
994
|
+
}
|
|
995
|
+
if (node.callee.type === "Identifier") {
|
|
996
|
+
return callReturnsNominalInstance(node);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
return false;
|
|
1000
|
+
};
|
|
831
1001
|
const isPureRuntimeExpression = (node, stableLocals) => {
|
|
832
1002
|
if (!node || node.type === "PrivateIdentifier") {
|
|
833
1003
|
return false;
|
|
@@ -858,9 +1028,12 @@ var sortKeysFixable = {
|
|
|
858
1028
|
return isPureRuntimeExpression(node.test, stableLocals) && isPureRuntimeExpression(node.consequent, stableLocals) && isPureRuntimeExpression(node.alternate, stableLocals);
|
|
859
1029
|
case "ArrayExpression":
|
|
860
1030
|
return node.elements.every((element) => {
|
|
861
|
-
if (!element
|
|
1031
|
+
if (!element) {
|
|
862
1032
|
return false;
|
|
863
1033
|
}
|
|
1034
|
+
if (element.type === "SpreadElement") {
|
|
1035
|
+
return isPureRuntimeExpression(element.argument, stableLocals);
|
|
1036
|
+
}
|
|
864
1037
|
return isPureRuntimeExpression(element, stableLocals);
|
|
865
1038
|
});
|
|
866
1039
|
case "ObjectExpression":
|
|
@@ -900,7 +1073,10 @@ var sortKeysFixable = {
|
|
|
900
1073
|
return true;
|
|
901
1074
|
}
|
|
902
1075
|
if (node.callee.type === "Identifier") {
|
|
903
|
-
|
|
1076
|
+
if (isPureIdentifierCall(node)) {
|
|
1077
|
+
return true;
|
|
1078
|
+
}
|
|
1079
|
+
return callReturnsNominalInstance(node);
|
|
904
1080
|
}
|
|
905
1081
|
if (node.callee.type !== "MemberExpression") {
|
|
906
1082
|
return false;
|
|
@@ -909,6 +1085,12 @@ var sortKeysFixable = {
|
|
|
909
1085
|
if (memberName && PURE_MEMBER_METHODS.has(memberName)) {
|
|
910
1086
|
return isPureRuntimeExpression(node.callee.object, stableLocals);
|
|
911
1087
|
}
|
|
1088
|
+
if (isEncapsulatedFreshExpression(node.callee.object, stableLocals)) {
|
|
1089
|
+
return true;
|
|
1090
|
+
}
|
|
1091
|
+
if (isPureRuntimeExpression(node.callee.object, stableLocals) && callReturnsNominalInstance(node)) {
|
|
1092
|
+
return true;
|
|
1093
|
+
}
|
|
912
1094
|
return isPureImportedCallExpression(node);
|
|
913
1095
|
}
|
|
914
1096
|
default:
|
package/package.json
CHANGED