eslint-plugin-skuba 1.0.4-node-24-20251215224735 → 2.0.0-esbuild-bundle-support-20260101042604
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/index.cjs +43 -43
- package/package.json +5 -5
package/lib/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
let
|
|
1
|
+
let _typescript_eslint_utils = require("@typescript-eslint/utils");
|
|
2
2
|
|
|
3
3
|
//#region src/rules/no-sync-in-promise-iterable.ts
|
|
4
4
|
/**
|
|
@@ -30,7 +30,7 @@ const PROMISE_INSTANCE_METHODS = new Set([
|
|
|
30
30
|
"finally"
|
|
31
31
|
]);
|
|
32
32
|
const isChainedPromise = (node, esTreeNodeToTSNodeMap, checker) => {
|
|
33
|
-
if (!(node.callee.type ===
|
|
33
|
+
if (!(node.callee.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.MemberExpression && node.callee.property.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier && PROMISE_INSTANCE_METHODS.has(node.callee.property.name))) return false;
|
|
34
34
|
const parent = esTreeNodeToTSNodeMap.get(node.callee.object);
|
|
35
35
|
return isThenableType(checker.getTypeAtLocation(parent), checker);
|
|
36
36
|
};
|
|
@@ -118,18 +118,18 @@ const SAFE_ISH_INSTANCE_METHODS = new Set([
|
|
|
118
118
|
"toLocaleString",
|
|
119
119
|
"toString"
|
|
120
120
|
]);
|
|
121
|
-
const isArrayFromAsync = (node) => node.callee.type ===
|
|
122
|
-
const isPromiseTry = (node) => node.callee.type ===
|
|
121
|
+
const isArrayFromAsync = (node) => node.callee.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.MemberExpression && node.callee.object.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier && node.callee.property.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier && node.callee.object.name === "Array" && node.callee.property.name === "fromAsync";
|
|
122
|
+
const isPromiseTry = (node) => node.callee.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.MemberExpression && node.callee.object.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier && node.callee.object.name === "Promise" && node.callee.property.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier && node.callee.property.name === "try";
|
|
123
123
|
/**
|
|
124
124
|
* Whether a call expression represents a safe-ish built-in.
|
|
125
125
|
*
|
|
126
126
|
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
|
|
127
127
|
*/
|
|
128
128
|
const isSafeIshBuiltIn = (node) => {
|
|
129
|
-
if (node.callee.type ===
|
|
130
|
-
if (node.callee.type ===
|
|
129
|
+
if (node.callee.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier) return SAFE_ISH_FUNCTIONS.has(node.callee.name);
|
|
130
|
+
if (node.callee.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.MemberExpression) {
|
|
131
131
|
const { object, property } = node.callee;
|
|
132
|
-
if (object.type ===
|
|
132
|
+
if (object.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier && property.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier) return SAFE_ISH_STATIC_METHODS[object.name]?.has(property.name) ?? SAFE_ISH_INSTANCE_METHODS.has(property.name);
|
|
133
133
|
}
|
|
134
134
|
return false;
|
|
135
135
|
};
|
|
@@ -175,7 +175,7 @@ const SAFE_ISH_ITERABLE_INSTANCE_METHODS = new Set([
|
|
|
175
175
|
* unlikely to internally throw a synchronous error.
|
|
176
176
|
*/
|
|
177
177
|
const isSafeIshIterableMethod = (node, esTreeNodeToTSNodeMap, checker) => {
|
|
178
|
-
if (!(node.callee.type ===
|
|
178
|
+
if (!(node.callee.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.MemberExpression && node.callee.property.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier && SAFE_ISH_ITERABLE_INSTANCE_METHODS.has(node.callee.property.name))) return false;
|
|
179
179
|
const tsNode = esTreeNodeToTSNodeMap.get(node.callee.object);
|
|
180
180
|
return isIterableType(checker.getTypeAtLocation(tsNode), checker);
|
|
181
181
|
};
|
|
@@ -185,8 +185,8 @@ const isSafeIshIterableMethod = (node, esTreeNodeToTSNodeMap, checker) => {
|
|
|
185
185
|
* This is currently overfitted to `knex`.
|
|
186
186
|
*/
|
|
187
187
|
const isSafeIshBuilder = (node) => {
|
|
188
|
-
if (node.callee.type ===
|
|
189
|
-
if (node.callee.type ===
|
|
188
|
+
if (node.callee.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.MemberExpression && node.callee.object.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.CallExpression) return isSafeIshBuilder(node.callee.object);
|
|
189
|
+
if (node.callee.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier && node.callee.name === "knex" || node.callee.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.MemberExpression && node.callee.object.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier && node.callee.object.name === "knex") return true;
|
|
190
190
|
return false;
|
|
191
191
|
};
|
|
192
192
|
/**
|
|
@@ -195,55 +195,55 @@ const isSafeIshBuilder = (node) => {
|
|
|
195
195
|
*/
|
|
196
196
|
const possibleNodesWithSyncError = (node, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls) => {
|
|
197
197
|
switch (node.type) {
|
|
198
|
-
case
|
|
199
|
-
case
|
|
200
|
-
case
|
|
201
|
-
case
|
|
198
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.ArrayExpression: return node.elements.flatMap((arg) => arg ? possibleNodesWithSyncError(arg, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls) : []);
|
|
199
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression:
|
|
200
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.FunctionExpression:
|
|
201
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.FunctionDeclaration:
|
|
202
202
|
if (calls < 1) return [];
|
|
203
203
|
if (node.async) return [];
|
|
204
|
-
if (node.body.type ===
|
|
204
|
+
if (node.body.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.BlockStatement) return [node.parent];
|
|
205
205
|
return possibleNodesWithSyncError(node.body, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls - 1);
|
|
206
|
-
case
|
|
207
|
-
case
|
|
208
|
-
case
|
|
209
|
-
case
|
|
206
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.AssignmentExpression: return possibleNodesWithSyncError(node.right, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls);
|
|
207
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.BinaryExpression:
|
|
208
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.LogicalExpression: return [node.left, node.right].flatMap((arg) => possibleNodesWithSyncError(arg, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls));
|
|
209
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.CallExpression: {
|
|
210
210
|
if (isSafeIshBuilder(node)) return [];
|
|
211
211
|
if (isPromiseTry(node)) return node.arguments.flatMap((arg, index) => possibleNodesWithSyncError(arg, esTreeNodeToTSNodeMap, checker, sourceCode, visited, index === 0 ? calls : calls + 1));
|
|
212
212
|
if (isArrayFromAsync(node)) return node.arguments.flatMap((arg, index) => possibleNodesWithSyncError(arg, esTreeNodeToTSNodeMap, checker, sourceCode, visited, index === 1 ? calls : calls + 1));
|
|
213
213
|
if (isSafeIshBuiltIn(node)) return node.arguments.flatMap((arg) => possibleNodesWithSyncError(arg, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls + 1));
|
|
214
214
|
const collectCalleeArgumentErrors = (callee) => {
|
|
215
|
-
if (callee.type ===
|
|
215
|
+
if (callee.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.CallExpression) {
|
|
216
216
|
const nestedErrors = collectCalleeArgumentErrors(callee.callee);
|
|
217
217
|
const argErrors = callee.arguments.flatMap((arg) => possibleNodesWithSyncError(arg, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls + 1));
|
|
218
218
|
return [...nestedErrors, ...argErrors];
|
|
219
219
|
}
|
|
220
220
|
return [];
|
|
221
221
|
};
|
|
222
|
-
const expression = node.callee.type ===
|
|
223
|
-
if (expression?.type ===
|
|
222
|
+
const expression = node.callee.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier ? findExpression(node.callee, sourceCode, visited) : node.callee;
|
|
223
|
+
if (expression?.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression || expression?.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.FunctionExpression) return [expression, ...node.arguments].flatMap((arg) => possibleNodesWithSyncError(arg, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls + 1));
|
|
224
224
|
const calleeErrors = collectCalleeArgumentErrors(node.callee);
|
|
225
225
|
if (isChainedPromise(node, esTreeNodeToTSNodeMap, checker)) return [...calleeErrors, ...node.arguments.flatMap((arg) => possibleNodesWithSyncError(arg, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls))];
|
|
226
226
|
if (isSafeIshIterableMethod(node, esTreeNodeToTSNodeMap, checker) || isThenableNode(node, esTreeNodeToTSNodeMap, checker)) return [...calleeErrors, ...node.arguments.flatMap((arg) => possibleNodesWithSyncError(arg, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls + 1))];
|
|
227
227
|
if (calleeErrors.length) return calleeErrors;
|
|
228
228
|
return [node];
|
|
229
229
|
}
|
|
230
|
-
case
|
|
231
|
-
case
|
|
230
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.ChainExpression: return possibleNodesWithSyncError(node.expression, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls);
|
|
231
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.ConditionalExpression: return [
|
|
232
232
|
node.test,
|
|
233
233
|
node.consequent,
|
|
234
234
|
node.alternate
|
|
235
235
|
].flatMap((arg) => possibleNodesWithSyncError(arg, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls));
|
|
236
|
-
case
|
|
237
|
-
case
|
|
238
|
-
case
|
|
239
|
-
case
|
|
240
|
-
if (node.callee.type ===
|
|
241
|
-
if (node.callee.type ===
|
|
236
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier: return [];
|
|
237
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Literal: return [];
|
|
238
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.MemberExpression: return possibleNodesWithSyncError(node.object, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls);
|
|
239
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.NewExpression:
|
|
240
|
+
if (node.callee.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier && node.callee.name === "Promise") return node.arguments.flatMap((arg, index) => possibleNodesWithSyncError(arg, esTreeNodeToTSNodeMap, checker, sourceCode, visited, index === 0 ? calls : calls + 1));
|
|
241
|
+
if (node.callee.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier && SAFE_ISH_CONSTRUCTORS.has(node.callee.name)) return node.arguments.flatMap((arg) => possibleNodesWithSyncError(arg, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls + 1));
|
|
242
242
|
return [node];
|
|
243
|
-
case
|
|
244
|
-
case
|
|
245
|
-
case
|
|
246
|
-
case
|
|
243
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.SequenceExpression: return node.expressions.flatMap((arg) => possibleNodesWithSyncError(arg, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls));
|
|
244
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.SpreadElement: return possibleNodesWithSyncError(node.argument, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls);
|
|
245
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.TaggedTemplateExpression: return [node];
|
|
246
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.TemplateLiteral: return node.expressions.flatMap((arg) => possibleNodesWithSyncError(arg, esTreeNodeToTSNodeMap, checker, sourceCode, visited, calls));
|
|
247
247
|
}
|
|
248
248
|
return [];
|
|
249
249
|
};
|
|
@@ -288,34 +288,34 @@ const findExpression = (node, sourceCode, visited) => {
|
|
|
288
288
|
if (!definition) continue;
|
|
289
289
|
if (visited.has(variable.name)) return;
|
|
290
290
|
visited.add(variable.name);
|
|
291
|
-
if (definition.node.type ===
|
|
291
|
+
if (definition.node.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.VariableDeclarator && definition.node.init) return definition.node.init;
|
|
292
292
|
} while (currentScope = currentScope.upper);
|
|
293
293
|
};
|
|
294
294
|
const resolveArrayElements = (node, sourceCode, visited = /* @__PURE__ */ new Set(), reference) => {
|
|
295
295
|
switch (node.type) {
|
|
296
|
-
case
|
|
296
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.ArrayExpression: return node.elements.flatMap((element, index) => {
|
|
297
297
|
if (!element) return [];
|
|
298
|
-
if (element.type ===
|
|
298
|
+
if (element.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.SpreadElement) return resolveArrayElements(element.argument, sourceCode, visited, reference ?? element);
|
|
299
299
|
if (index === 0) return [];
|
|
300
300
|
return {
|
|
301
301
|
element,
|
|
302
302
|
reference
|
|
303
303
|
};
|
|
304
304
|
});
|
|
305
|
-
case
|
|
305
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.CallExpression: return [{
|
|
306
306
|
element: node,
|
|
307
307
|
reference
|
|
308
308
|
}];
|
|
309
|
-
case
|
|
309
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier: {
|
|
310
310
|
const expression = findExpression(node, sourceCode, visited);
|
|
311
311
|
if (!expression) return [];
|
|
312
312
|
return resolveArrayElements(expression, sourceCode, visited, reference ?? node);
|
|
313
313
|
}
|
|
314
|
-
case
|
|
314
|
+
case _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.SpreadElement: return resolveArrayElements(node.argument, sourceCode, visited, reference ?? node);
|
|
315
315
|
}
|
|
316
316
|
return [];
|
|
317
317
|
};
|
|
318
|
-
const createRule =
|
|
318
|
+
const createRule = _typescript_eslint_utils.ESLintUtils.RuleCreator((name) => `https://github.com/seek-oss/skuba/tree/main/docs/eslint-plugin/${name}.md`);
|
|
319
319
|
var no_sync_in_promise_iterable_default = createRule({
|
|
320
320
|
defaultOptions: [],
|
|
321
321
|
name: "no-sync-in-promise-iterable",
|
|
@@ -333,10 +333,10 @@ var no_sync_in_promise_iterable_default = createRule({
|
|
|
333
333
|
}
|
|
334
334
|
},
|
|
335
335
|
create: (context) => {
|
|
336
|
-
const { esTreeNodeToTSNodeMap, program } =
|
|
336
|
+
const { esTreeNodeToTSNodeMap, program } = _typescript_eslint_utils.ESLintUtils.getParserServices(context);
|
|
337
337
|
const checker = program.getTypeChecker();
|
|
338
338
|
return { CallExpression: (node) => {
|
|
339
|
-
if (!(node.callee.type ===
|
|
339
|
+
if (!(node.callee.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.MemberExpression && node.callee.object.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier && node.callee.object.name === "Promise" && node.callee.property.type === _typescript_eslint_utils.TSESTree.AST_NODE_TYPES.Identifier && [
|
|
340
340
|
"all",
|
|
341
341
|
"allSettled",
|
|
342
342
|
"any",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-skuba",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-esbuild-bundle-support-20260101042604",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "ESLint plugin for skuba",
|
|
6
6
|
"homepage": "https://github.com/seek-oss/skuba/tree/main/packages/eslint-plugin-skuba#readme",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
|
-
"
|
|
20
|
-
"
|
|
19
|
+
"require": "./lib/index.cjs",
|
|
20
|
+
"import": "./lib/index.mjs"
|
|
21
21
|
},
|
|
22
22
|
"./package.json": "./package.json"
|
|
23
23
|
},
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@typescript-eslint/rule-tester": "^8.26.0",
|
|
38
38
|
"eslint": "^9.39.1",
|
|
39
|
-
"tsdown": "^0.
|
|
39
|
+
"tsdown": "^0.18.0",
|
|
40
40
|
"tsx": "^4.16.2",
|
|
41
41
|
"typescript-eslint": "^8.39.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"eslint": ">=9.
|
|
44
|
+
"eslint": ">=9.22.0",
|
|
45
45
|
"typescript-eslint": ">=8.39.0"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|