loadwise 0.7.0 → 0.8.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/README.md +23 -15
- package/dist/bin/loadwise.js +12 -24
- package/dist/lib/accessibility/analyze.js +5 -3
- package/dist/lib/accessibility/angular-inline.js +9 -11
- package/dist/lib/accessibility/angular-literal.js +39 -0
- package/dist/lib/accessibility/form-context.js +36 -0
- package/dist/lib/accessibility/frame-head.js +92 -0
- package/dist/lib/accessibility/frame-viewport.js +149 -0
- package/dist/lib/accessibility/jsx-elements.js +13 -3
- package/dist/lib/accessibility/markup-files.js +7 -2
- package/dist/lib/accessibility/rule-ids.js +3 -0
- package/dist/lib/accessibility/rules.js +128 -41
- package/dist/lib/accessibility/site-fixes/buttons.js +5 -1
- package/dist/lib/accessibility/template-attributes.js +5 -3
- package/dist/lib/accessibility/template-elements.js +25 -6
- package/dist/lib/accessibility/template-file.js +40 -25
- package/dist/lib/editor/accessibility-examples.js +6 -1
- package/dist/lib/editor/actions.js +46 -7
- package/dist/lib/editor/apply-fix.js +69 -4
- package/dist/lib/editor/configured-setup.js +5 -3
- package/dist/lib/editor/diagnostics.js +206 -17
- package/dist/lib/editor/dismissals.js +85 -26
- package/dist/lib/editor/editor-document.js +5 -2
- package/dist/lib/editor/editor-launcher.js +7 -2
- package/dist/lib/editor/language-server.js +64 -25
- package/dist/lib/editor/native-setup.js +3 -2
- package/dist/lib/editor/perf-watch.js +8 -6
- package/dist/lib/editor/reliability-examples.js +15 -0
- package/dist/lib/editor/scan-session.js +29 -8
- package/dist/lib/editor/server-commands.js +36 -9
- package/dist/lib/editor/setup-server.js +1 -1
- package/dist/lib/editor/setup-vim.js +6 -4
- package/dist/lib/editor/workspace-files.js +61 -7
- package/dist/lib/editor/workspace-paths.js +41 -1
- package/dist/lib/maintainability/analysis/analyze-source.js +1 -1
- package/dist/lib/maintainability/architecture/architecture.js +4 -4
- package/dist/lib/maintainability/cli/changed-lines.js +20 -2
- package/dist/lib/maintainability/cli/inputs.js +9 -1
- package/dist/lib/maintainability/cli.js +4 -0
- package/dist/lib/maintainability/entry-points/entry-points.js +44 -15
- package/dist/lib/maintainability/entry-points/html-entry-points.js +5 -1
- package/dist/lib/maintainability/quality/functions.js +9 -6
- package/dist/lib/maintainability/quality/limits.js +19 -0
- package/dist/lib/maintainability/quality/size-limits.js +8 -2
- package/dist/lib/maintainability/quality/stray-console.js +62 -1
- package/dist/lib/maintainability/quality/tsconfig-strict.js +2 -0
- package/dist/lib/maintainability/scan-changed.js +4 -1
- package/dist/lib/maintainability/scan-worker.js +6 -2
- package/dist/lib/maintainability/scan.js +21 -8
- package/dist/lib/maintainability/unused/module-usage.js +43 -21
- package/dist/lib/maintainability/unused/unused-modules.js +5 -10
- package/dist/lib/performance/analysis/source-inputs.js +7 -2
- package/dist/lib/performance/analysis/source-options.js +7 -6
- package/dist/lib/performance/analyze.js +16 -3
- package/dist/lib/performance/cli/cli-output.js +1 -0
- package/dist/lib/performance/cli/cli-scan.js +21 -2
- package/dist/lib/performance/cli.js +8 -3
- package/dist/lib/performance/collections/memory-growth.js +55 -12
- package/dist/lib/performance/contracts/openapi.js +13 -4
- package/dist/lib/performance/datastores/pg-integrity.js +61 -22
- package/dist/lib/performance/datastores/pg-session-release.js +114 -0
- package/dist/lib/performance/datastores/pg-session-sql.js +144 -0
- package/dist/lib/performance/datastores/pooling.js +56 -2
- package/dist/lib/performance/datastores/redis.js +94 -18
- package/dist/lib/performance/datastores/session-store.js +2 -1
- package/dist/lib/performance/db/checks.js +19 -8
- package/dist/lib/performance/db/gateway.js +3 -1
- package/dist/lib/performance/db/plan-estimates.js +4 -4
- package/dist/lib/performance/engine/native.js +11 -7
- package/dist/lib/performance/evidence/plans.js +7 -5
- package/dist/lib/performance/evidence/traces.js +21 -1
- package/dist/lib/performance/frontend/angular-teardown.js +96 -0
- package/dist/lib/performance/frontend/effect-cleanup.js +148 -0
- package/dist/lib/performance/frontend/frontend-dom-perf.js +14 -2
- package/dist/lib/performance/frontend/frontend-helpers.js +1 -9
- package/dist/lib/performance/frontend/frontend-perf.js +72 -57
- package/dist/lib/performance/migrations/extract-code-sql.js +16 -4
- package/dist/lib/performance/migrations/extract-code.js +13 -5
- package/dist/lib/performance/migrations/extract-sql.js +82 -38
- package/dist/lib/performance/migrations/operations.js +56 -13
- package/dist/lib/performance/migrations/postgres-lock-timeout.js +52 -0
- package/dist/lib/performance/migrations/postgres-registry.js +127 -26
- package/dist/lib/performance/migrations/postgres-settings.js +78 -0
- package/dist/lib/performance/migrations/rules-postgres-add-column.js +3 -3
- package/dist/lib/performance/migrations/rules-postgres-shared.js +9 -0
- package/dist/lib/performance/migrations/rules-postgres.js +88 -39
- package/dist/lib/performance/orm/offset-pagination.js +6 -4
- package/dist/lib/performance/orm/prisma-aggregates.js +69 -18
- package/dist/lib/performance/orm/unbounded-list-chain.js +29 -0
- package/dist/lib/performance/orm/unbounded-list-queries.js +18 -13
- package/dist/lib/performance/polyglot.js +111 -14
- package/dist/lib/performance/projects.js +3 -3
- package/dist/lib/performance/query-loops/sequential-loops.js +1 -0
- package/dist/lib/performance/request/backend-mastery.js +151 -42
- package/dist/lib/performance/request/mongoose-lean.js +175 -10
- package/dist/lib/performance/request/phase5-rules.js +74 -13
- package/dist/lib/performance/request/sql-select-star.js +150 -0
- package/dist/lib/performance/request/unbounded-promise-all.js +54 -29
- package/dist/lib/performance/request/upload-limits.js +5 -1
- package/dist/lib/performance/site-fix.js +4 -4
- package/dist/lib/performance/site-fixes/backend-mastery-fixes.js +298 -16
- package/dist/lib/performance/site-fixes/frontend-fixes.js +350 -10
- package/dist/lib/performance/site-fixes/migration-context.js +8 -1
- package/dist/lib/performance/site-fixes/migration-lock-rules.js +66 -30
- package/dist/lib/performance/site-fixes/prisma-aggregates.js +29 -9
- package/dist/lib/performance/site-fixes/small-rewrites.js +168 -10
- package/dist/lib/performance/site-fixes/sync-calls.js +14 -12
- package/dist/lib/performance/site-fixes/upload-limits.js +13 -7
- package/dist/lib/performance/sql/mysql-tokens.js +38 -12
- package/dist/lib/reliability/boundary-access.js +114 -57
- package/dist/lib/reliability/react-bugs.js +18 -4
- package/dist/lib/reliability/resource-leak-intervals.js +258 -0
- package/dist/lib/reliability/resource-leaks.js +209 -195
- package/dist/lib/reliability/rule-ids.js +10 -1
- package/dist/lib/reliability/site-fixes/resource-leaks.js +16 -1
- package/dist/lib/reliability/swallowed-errors.js +107 -21
- package/dist/lib/reliability/test-cleanup-after-await.js +92 -18
- package/dist/lib/reliability/walk.js +3 -2
- package/dist/lib/security/auth-crypto/hashing.js +24 -8
- package/dist/lib/security/auth-crypto/jwt.js +21 -6
- package/dist/lib/security/auth-crypto/secrets.js +44 -1
- package/dist/lib/security/auth-crypto/shared.js +3 -1
- package/dist/lib/security/auth-crypto/signing-algorithm.js +79 -0
- package/dist/lib/security/auth-crypto/transport-and-ciphers.js +85 -1
- package/dist/lib/security/cli.js +6 -2
- package/dist/lib/security/cookie-credentials.js +115 -0
- package/dist/lib/security/cookie-csrf.js +241 -0
- package/dist/lib/security/deps/advisory.js +50 -109
- package/dist/lib/security/deps/cli.js +1 -1
- package/dist/lib/security/deps/cvss-score.js +14 -0
- package/dist/lib/security/deps/fixed-version.js +97 -0
- package/dist/lib/security/deps/lockfiles.js +135 -74
- package/dist/lib/security/deps/osv.js +11 -3
- package/dist/lib/security/deps/scan.js +47 -20
- package/dist/lib/security/deps/yarn-lock.js +158 -0
- package/dist/lib/security/examples/injection.cjs +4 -0
- package/dist/lib/security/exposure/cookies.js +17 -2
- package/dist/lib/security/exposure/cors-origin-regex.js +2 -3
- package/dist/lib/security/exposure/frontend-security.js +21 -14
- package/dist/lib/security/exposure/jsx-url.js +18 -33
- package/dist/lib/security/exposure/logging.js +49 -10
- package/dist/lib/security/exposure/prototype-pollution.js +126 -56
- package/dist/lib/security/exposure/react-html.js +26 -0
- package/dist/lib/security/exposure/reflected-xss.js +34 -5
- package/dist/lib/security/files/compose.js +126 -1
- package/dist/lib/security/files/dockerfile.js +62 -4
- package/dist/lib/security/files/index.js +1 -1
- package/dist/lib/security/injection/command.js +46 -18
- package/dist/lib/security/injection/index.js +2 -0
- package/dist/lib/security/injection/ldap.js +86 -0
- package/dist/lib/security/injection/nosql.js +28 -4
- package/dist/lib/security/injection/redos.js +1 -1
- package/dist/lib/security/injection/rule-ids.js +1 -0
- package/dist/lib/security/injection/shared.js +5 -1
- package/dist/lib/security/injection/sql.js +28 -13
- package/dist/lib/security/lexical-declaration.js +113 -0
- package/dist/lib/security/pg-dynamic-query.js +28 -1
- package/dist/lib/security/pg-identifier-guards.js +107 -3
- package/dist/lib/security/phase5-rules.js +26 -135
- package/dist/lib/security/polyglot.js +2 -2
- package/dist/lib/security/redirect-settings.js +98 -0
- package/dist/lib/security/request-forgery/open-redirect.js +18 -5
- package/dist/lib/security/request-forgery/path-traversal.js +84 -6
- package/dist/lib/security/request-forgery/shared.js +1 -7
- package/dist/lib/security/request-forgery/ssrf.js +176 -14
- package/dist/lib/security/rule-descriptions.js +5 -1
- package/dist/lib/security/rule-ids.js +7 -0
- package/dist/lib/security/site-fixes/auth-crypto.js +5 -78
- package/dist/lib/security/site-fixes/exposure.js +21 -3
- package/dist/lib/security/site-fixes/files.js +11 -13
- package/dist/lib/security/site-fixes/frontend-security-fixes.js +2 -2
- package/dist/lib/security/site-fixes/injection.js +17 -4
- package/dist/lib/security/site-fixes/jwt.js +1 -20
- package/dist/lib/security/site-fixes/request-forgery.js +37 -29
- package/dist/lib/security/taint/binding-inputs.js +236 -0
- package/dist/lib/security/taint/filename-guard.js +45 -45
- package/dist/lib/security/taint/guards.js +14 -8
- package/dist/lib/security/taint/index.js +126 -154
- package/dist/lib/security/taint/propagate.js +43 -9
- package/dist/lib/security/taint/record-writes.js +161 -0
- package/dist/lib/security/taint/resolution-cache.js +13 -7
- package/dist/lib/security/taint/sanitizers.js +89 -5
- package/dist/lib/security/taint/trace-nodes.js +61 -0
- package/dist/lib/security/taint/validators.js +89 -9
- package/dist/lib/shared/agent/agent-init.js +2 -1
- package/dist/lib/shared/agent/agent-verify.js +4 -1
- package/dist/lib/shared/agent/git-hook.js +17 -6
- package/dist/lib/shared/agent/review-mcp.js +8 -2
- package/dist/lib/shared/analysis/ast-semantics.js +2 -2
- package/dist/lib/shared/analysis/scan-cache.js +96 -12
- package/dist/lib/shared/cli-dispatch.js +17 -0
- package/dist/lib/shared/config.js +27 -10
- package/dist/lib/shared/explain.js +1 -1
- package/dist/lib/shared/fix/fix-convergence.js +5 -3
- package/dist/lib/shared/fix/fix-imports.js +4 -171
- package/dist/lib/shared/fix/fix-presentation-comments.js +23 -9
- package/dist/lib/shared/fix/fix-presentation.js +5 -3
- package/dist/lib/shared/fix/fix-safety.js +7 -1
- package/dist/lib/shared/fix/fix-typecheck.js +8 -4
- package/dist/lib/shared/fix/import-text-edits.js +148 -0
- package/dist/lib/shared/fix.js +31 -7
- package/dist/lib/shared/formats/finding-location.js +4 -1
- package/dist/lib/shared/formats/github.js +3 -3
- package/dist/lib/shared/formats/sarif.js +9 -3
- package/dist/lib/shared/report-fp.js +6 -2
- package/dist/lib/shared/reporting/baseline.js +7 -5
- package/dist/lib/shared/reporting/pillars.js +9 -3
- package/dist/lib/shared/reporting/source-report.js +1 -0
- package/dist/lib/shared/system/glob.js +34 -8
- package/dist/lib/shared/system/sentry.js +26 -7
- package/dist/lib/shared/workspaces.js +15 -3
- package/package.json +5 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/hooks/check-edited-file.mjs +27 -5
- package/polyglot/performance/rules/csharp.yml +34 -5
- package/polyglot/performance/rules/java.yml +24 -1
- package/polyglot/performance/rules/python.yml +74 -2
- package/polyglot/performance/sgconfig.yml +1 -0
- package/polyglot/reliability/rules/csharp.yml +12 -6
- package/polyglot/reliability/rules/go.yml +86 -6
- package/polyglot/reliability/rules/java.yml +22 -1
- package/polyglot/reliability/sgconfig.yml +1 -0
- package/polyglot/security/rules/go.yml +100 -22
- package/polyglot/security/rules/python.yml +74 -6
- package/polyglot/security/rules/rust.yml +65 -0
- package/polyglot/security/sgconfig.yml +1 -0
- package/schema/loadwise.config.schema.json +554 -76
- /package/polyglot/{performance/rules → shared-rules}/input.yml +0 -0
|
@@ -24,7 +24,26 @@ const MONGOOSE_QUERY_MODIFIERS = new Set([
|
|
|
24
24
|
'batchSize',
|
|
25
25
|
'setOptions',
|
|
26
26
|
]);
|
|
27
|
-
const
|
|
27
|
+
const SAFE_ARRAY_METHODS = new Set([
|
|
28
|
+
'map',
|
|
29
|
+
'filter',
|
|
30
|
+
'slice',
|
|
31
|
+
'forEach',
|
|
32
|
+
'find',
|
|
33
|
+
'some',
|
|
34
|
+
'every',
|
|
35
|
+
'reduce',
|
|
36
|
+
'reduceRight',
|
|
37
|
+
'flatMap',
|
|
38
|
+
'concat',
|
|
39
|
+
'includes',
|
|
40
|
+
'indexOf',
|
|
41
|
+
'at',
|
|
42
|
+
'join',
|
|
43
|
+
'entries',
|
|
44
|
+
'keys',
|
|
45
|
+
'values',
|
|
46
|
+
]);
|
|
28
47
|
const SERIALIZATION_METHODS = new Set(['json', 'send', 'jsonp']);
|
|
29
48
|
const RESPONSE_RECEIVERS = /^(?:res|response|reply|ctx|c|NextResponse|Response)$/;
|
|
30
49
|
function hasMongooseImport(sourceFile) {
|
|
@@ -187,9 +206,95 @@ function isDirectReadReturnOrSerialize(outer) {
|
|
|
187
206
|
return true;
|
|
188
207
|
return false;
|
|
189
208
|
}
|
|
190
|
-
function
|
|
191
|
-
let
|
|
192
|
-
|
|
209
|
+
function hasSchemaVirtuals(sourceFile) {
|
|
210
|
+
let found = false;
|
|
211
|
+
function visit(node) {
|
|
212
|
+
if (found)
|
|
213
|
+
return;
|
|
214
|
+
if (ts.isCallExpression(node) &&
|
|
215
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
216
|
+
node.expression.name.text === 'virtual') {
|
|
217
|
+
found = true;
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (ts.isPropertyAssignment(node) &&
|
|
221
|
+
staticPropertyName(node.name) === 'virtuals' &&
|
|
222
|
+
unwrapExpression(node.initializer).kind === ts.SyntaxKind.TrueKeyword) {
|
|
223
|
+
found = true;
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
ts.forEachChild(node, visit);
|
|
227
|
+
}
|
|
228
|
+
visit(sourceFile);
|
|
229
|
+
return found;
|
|
230
|
+
}
|
|
231
|
+
function modelUsesVirtuals(callee, sourceFile, checker) {
|
|
232
|
+
if (hasSchemaVirtuals(sourceFile))
|
|
233
|
+
return true;
|
|
234
|
+
const checkedFiles = new Set([sourceFile]);
|
|
235
|
+
const declarations = symbolDeclarations(callee.expression, checker);
|
|
236
|
+
const queue = [...declarations];
|
|
237
|
+
while (queue.length > 0) {
|
|
238
|
+
const declaration = queue.pop();
|
|
239
|
+
if (!declaration)
|
|
240
|
+
continue;
|
|
241
|
+
const file = declaration.getSourceFile();
|
|
242
|
+
if (file.isDeclarationFile)
|
|
243
|
+
continue;
|
|
244
|
+
if (!checkedFiles.has(file)) {
|
|
245
|
+
checkedFiles.add(file);
|
|
246
|
+
if (hasSchemaVirtuals(file))
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
if (ts.isVariableDeclaration(declaration) && declaration.initializer) {
|
|
250
|
+
(function collectIdentifiers(node) {
|
|
251
|
+
if (ts.isIdentifier(node)) {
|
|
252
|
+
for (const target of symbolDeclarations(node, checker)) {
|
|
253
|
+
const targetFile = target.getSourceFile();
|
|
254
|
+
if (!targetFile.isDeclarationFile && !checkedFiles.has(targetFile)) {
|
|
255
|
+
queue.push(target);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
ts.forEachChild(node, collectIdentifiers);
|
|
261
|
+
})(declaration.initializer);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
function isSafeTruthinessCheck(result, parent) {
|
|
267
|
+
if (!parent)
|
|
268
|
+
return false;
|
|
269
|
+
if (ts.isIfStatement(parent) && parent.expression === result)
|
|
270
|
+
return true;
|
|
271
|
+
if (ts.isConditionalExpression(parent) && parent.condition === result)
|
|
272
|
+
return true;
|
|
273
|
+
if (ts.isPrefixUnaryExpression(parent) && parent.operator === ts.SyntaxKind.ExclamationToken)
|
|
274
|
+
return true;
|
|
275
|
+
if (ts.isBinaryExpression(parent)) {
|
|
276
|
+
const op = parent.operatorToken.kind;
|
|
277
|
+
if (op === ts.SyntaxKind.AmpersandAmpersandToken && parent.left === result)
|
|
278
|
+
return true;
|
|
279
|
+
if (op === ts.SyntaxKind.EqualsEqualsToken ||
|
|
280
|
+
op === ts.SyntaxKind.ExclamationEqualsToken ||
|
|
281
|
+
op === ts.SyntaxKind.EqualsEqualsEqualsToken ||
|
|
282
|
+
op === ts.SyntaxKind.ExclamationEqualsEqualsToken) {
|
|
283
|
+
const other = parent.left === result ? parent.right : parent.left;
|
|
284
|
+
const unwrapped = ts.skipOuterExpressions(other);
|
|
285
|
+
return (unwrapped.kind === ts.SyntaxKind.NullKeyword || (ts.isIdentifier(unwrapped) && unwrapped.text === 'undefined'));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
function callbackUsesSafeElementReads(callback, checker) {
|
|
291
|
+
const fn = ts.skipOuterExpressions(callback);
|
|
292
|
+
if (!ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn))
|
|
293
|
+
return false;
|
|
294
|
+
const firstParam = fn.parameters[0];
|
|
295
|
+
if (!firstParam || !ts.isIdentifier(firstParam.name))
|
|
296
|
+
return false;
|
|
297
|
+
for (const use of bindingUses(firstParam, checker)) {
|
|
193
298
|
const result = outsideWrappers(use);
|
|
194
299
|
const parent = result.parent;
|
|
195
300
|
if (ts.isAssignmentTarget(result))
|
|
@@ -198,19 +303,75 @@ function isVariableReturnedOrSerialized(declaration, checker) {
|
|
|
198
303
|
parent.expression === result) {
|
|
199
304
|
const member = outsideWrappers(parent);
|
|
200
305
|
const consumer = member.parent;
|
|
201
|
-
const method = staticMemberName(parent);
|
|
202
306
|
if (ts.isAssignmentTarget(member) ||
|
|
203
307
|
ts.isDeleteExpression(consumer) ||
|
|
204
|
-
(ts.isCallExpression(consumer) &&
|
|
205
|
-
consumer.expression === member &&
|
|
206
|
-
method !== undefined &&
|
|
207
|
-
MONGOOSE_MUTATION_METHODS.has(method))) {
|
|
308
|
+
(ts.isCallExpression(consumer) && consumer.expression === member)) {
|
|
208
309
|
return false;
|
|
209
310
|
}
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (!isSafeTruthinessCheck(result, parent))
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
function isUnsafeArrayCallResult(call) {
|
|
319
|
+
const callResult = outsideWrappers(call);
|
|
320
|
+
const callParent = callResult.parent;
|
|
321
|
+
const isMemberChain = (ts.isPropertyAccessExpression(callParent) || ts.isElementAccessExpression(callParent)) &&
|
|
322
|
+
callParent.expression === callResult;
|
|
323
|
+
if (!isMemberChain) {
|
|
324
|
+
return (ts.isVariableDeclaration(callParent) ||
|
|
325
|
+
ts.isAssignmentTarget(callResult) ||
|
|
326
|
+
(ts.isCallExpression(callParent) && !isJsonSerializationCall(callParent, callResult)));
|
|
327
|
+
}
|
|
328
|
+
const nextMember = outsideWrappers(callParent);
|
|
329
|
+
const nextConsumer = nextMember.parent;
|
|
330
|
+
return (ts.isAssignmentTarget(nextMember) ||
|
|
331
|
+
ts.isDeleteExpression(nextConsumer) ||
|
|
332
|
+
(ts.isCallExpression(nextConsumer) && nextConsumer.expression === nextMember));
|
|
333
|
+
}
|
|
334
|
+
function isMemberAccessOn(node, expression) {
|
|
335
|
+
return (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) && node.expression === expression;
|
|
336
|
+
}
|
|
337
|
+
function isSafeMemberUse(memberAccess, isArrayRead, checker) {
|
|
338
|
+
const member = outsideWrappers(memberAccess);
|
|
339
|
+
const consumer = member.parent;
|
|
340
|
+
const method = staticMemberName(memberAccess);
|
|
341
|
+
if (ts.isAssignmentTarget(member) || ts.isDeleteExpression(consumer))
|
|
342
|
+
return false;
|
|
343
|
+
if (isArrayRead && ts.isElementAccessExpression(memberAccess) && isMemberAccessOn(consumer, member)) {
|
|
344
|
+
// An indexed element is a Document, so follow its member uses (e.g. users[0]?.validate()).
|
|
345
|
+
return isSafeMemberUse(consumer, false, checker);
|
|
346
|
+
}
|
|
347
|
+
if (!ts.isCallExpression(consumer) || consumer.expression !== member)
|
|
348
|
+
return true;
|
|
349
|
+
if (!isArrayRead || method === undefined || !SAFE_ARRAY_METHODS.has(method))
|
|
350
|
+
return false;
|
|
351
|
+
const [callback] = consumer.arguments;
|
|
352
|
+
if (callback && !callbackUsesSafeElementReads(callback, checker))
|
|
353
|
+
return false;
|
|
354
|
+
return !isUnsafeArrayCallResult(consumer);
|
|
355
|
+
}
|
|
356
|
+
function isVariableReturnedOrSerialized(declaration, checker, isArrayRead) {
|
|
357
|
+
let returnedOrSerialized = false;
|
|
358
|
+
for (const use of bindingUses(declaration, checker)) {
|
|
359
|
+
const result = outsideWrappers(use);
|
|
360
|
+
const parent = result.parent;
|
|
361
|
+
if (ts.isAssignmentTarget(result))
|
|
362
|
+
return false;
|
|
363
|
+
if ((ts.isPropertyAccessExpression(parent) || ts.isElementAccessExpression(parent)) &&
|
|
364
|
+
parent.expression === result) {
|
|
365
|
+
if (!isSafeMemberUse(parent, isArrayRead, checker))
|
|
366
|
+
return false;
|
|
367
|
+
continue;
|
|
210
368
|
}
|
|
211
369
|
if ((ts.isReturnStatement(parent) && parent.expression === result) || isJsonSerializationCall(parent, result)) {
|
|
212
370
|
returnedOrSerialized = true;
|
|
371
|
+
continue;
|
|
213
372
|
}
|
|
373
|
+
if (!isSafeTruthinessCheck(result, parent))
|
|
374
|
+
return false;
|
|
214
375
|
}
|
|
215
376
|
return returnedOrSerialized;
|
|
216
377
|
}
|
|
@@ -225,11 +386,15 @@ function checkMongooseMissingLean(call, sourceFile, context) {
|
|
|
225
386
|
const modelRead = isModelRead(call, callee, sourceFile, checker, declarations);
|
|
226
387
|
if (!modelRead && (!hasMongooseImport(sourceFile) || !hasHydratingRepositoryRead(declarations, checker)))
|
|
227
388
|
return;
|
|
389
|
+
if (modelUsesVirtuals(callee, sourceFile, checker))
|
|
390
|
+
return;
|
|
228
391
|
const { outer, hasLean } = unwrapQueryChain(call, checker, modelRead);
|
|
229
392
|
if (hasLean)
|
|
230
393
|
return;
|
|
394
|
+
const isArrayRead = callee.name.text === 'find';
|
|
231
395
|
const declaration = initializedVariable(outer);
|
|
232
|
-
if (isDirectReadReturnOrSerialize(outer) ||
|
|
396
|
+
if (isDirectReadReturnOrSerialize(outer) ||
|
|
397
|
+
(declaration && isVariableReturnedOrSerialized(declaration, checker, isArrayRead))) {
|
|
233
398
|
context.report(call, 'mongoose-missing-lean', 'Mongoose read query is returned or serialized without .lean(), paying full Document hydration overhead.');
|
|
234
399
|
}
|
|
235
400
|
}
|
|
@@ -118,12 +118,20 @@ function isDbOrHttpCall(node, context) {
|
|
|
118
118
|
const firstArg = node.arguments[0];
|
|
119
119
|
if (firstArg && (ts.isArrowFunction(firstArg) || ts.isFunctionExpression(firstArg)))
|
|
120
120
|
return false;
|
|
121
|
+
const receiverSource = ts.isIdentifier(callee.expression)
|
|
122
|
+
? constSource(callee.expression, context.checker)
|
|
123
|
+
: undefined;
|
|
124
|
+
const receiverType = context.checker.getNonNullableType(context.checker.getTypeAtLocation(callee.expression));
|
|
125
|
+
if (ts.isArrayLiteralExpression(receiverSource ?? callee.expression) ||
|
|
126
|
+
(receiverType.getProperty('length') !== undefined && receiverType.getProperty('findIndex') !== undefined)) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
121
129
|
}
|
|
122
|
-
|
|
123
|
-
return true;
|
|
124
|
-
const owner = standardInterface(node, context.checker);
|
|
130
|
+
const owner = standardInterface(node, context.checker) ?? context.checker.getTypeAtLocation(callee.expression).getSymbol()?.name;
|
|
125
131
|
if (owner !== undefined && IN_MEMORY_COLLECTIONS.has(owner))
|
|
126
132
|
return false;
|
|
133
|
+
if (method !== 'get' && method !== 'delete')
|
|
134
|
+
return true;
|
|
127
135
|
if (method === 'delete')
|
|
128
136
|
return true;
|
|
129
137
|
// A generic get can be an in-memory read. Require independent client or return-type evidence.
|
|
@@ -181,12 +189,24 @@ function delegatedResolverQuery(resolver, context) {
|
|
|
181
189
|
function checkGraphqlNPlusOneResolver(node, context) {
|
|
182
190
|
if (!node.body || !isGraphqlFieldResolver(node))
|
|
183
191
|
return;
|
|
184
|
-
if (usesDataLoader(node.body))
|
|
185
|
-
return;
|
|
186
192
|
let queryCall;
|
|
187
193
|
function findQuery(current) {
|
|
188
194
|
if (queryCall)
|
|
189
195
|
return;
|
|
196
|
+
// A named batch callback is only deferred work (e.g. DataLoader's batch function), not a direct resolver query.
|
|
197
|
+
if (ts.isFunctionDeclaration(current))
|
|
198
|
+
return;
|
|
199
|
+
if (ts.isVariableDeclaration(current) &&
|
|
200
|
+
current.initializer &&
|
|
201
|
+
(ts.isArrowFunction(current.initializer) || ts.isFunctionExpression(current.initializer))) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (ts.isNewExpression(current) &&
|
|
205
|
+
(ts.isIdentifier(current.expression)
|
|
206
|
+
? /dataloader/i.test(current.expression.text)
|
|
207
|
+
: ts.isPropertyAccessExpression(current.expression) && /dataloader/i.test(current.expression.name.text))) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
190
210
|
if (isDbOrHttpCall(current, context)) {
|
|
191
211
|
queryCall = current;
|
|
192
212
|
return;
|
|
@@ -200,19 +220,60 @@ function checkGraphqlNPlusOneResolver(node, context) {
|
|
|
200
220
|
}
|
|
201
221
|
}
|
|
202
222
|
// --- Rule 4: react-context-value-recreated -------------------------------------------------------
|
|
223
|
+
function isReactContextExpression(expr, context) {
|
|
224
|
+
const type = context.checker.getTypeAtLocation(expr);
|
|
225
|
+
const typeSymbol = type.getSymbol();
|
|
226
|
+
const rawSymbol = context.checker.getSymbolAtLocation(expr);
|
|
227
|
+
const symbol = rawSymbol && rawSymbol.flags & ts.SymbolFlags.Alias ? context.checker.getAliasedSymbol(rawSymbol) : rawSymbol;
|
|
228
|
+
const decl = symbol?.valueDeclaration;
|
|
229
|
+
const init = decl && ts.isVariableDeclaration(decl) && decl.initializer ? ts.skipOuterExpressions(decl.initializer) : undefined;
|
|
230
|
+
if (init && ts.isObjectLiteralExpression(init))
|
|
231
|
+
return false;
|
|
232
|
+
// An application type merely named `Context` is not React's; React's lives in a declaration file.
|
|
233
|
+
const isReactNamedContext = typeSymbol?.name === 'Context' &&
|
|
234
|
+
(typeSymbol.declarations ?? []).some((declaration) => declaration.getSourceFile().isDeclarationFile);
|
|
235
|
+
if (isReactNamedContext || (type.getProperty('Provider') && type.getProperty('Consumer'))) {
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
if (init && ts.isCallExpression(init)) {
|
|
239
|
+
const callee = ts.skipOuterExpressions(init.expression);
|
|
240
|
+
const name = ts.isIdentifier(callee)
|
|
241
|
+
? callee.text
|
|
242
|
+
: ts.isPropertyAccessExpression(callee)
|
|
243
|
+
? callee.name.text
|
|
244
|
+
: undefined;
|
|
245
|
+
if (name !== 'createContext')
|
|
246
|
+
return false;
|
|
247
|
+
// A local function with a body is the application's own factory, not React's createContext.
|
|
248
|
+
const calleeSymbol = ts.isIdentifier(callee) ? context.checker.getSymbolAtLocation(callee) : undefined;
|
|
249
|
+
return !calleeSymbol?.declarations?.some((declaration) => ts.isFunctionDeclaration(declaration) && declaration.body);
|
|
250
|
+
}
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
203
253
|
function checkReactContextValueRecreated(node, context) {
|
|
204
|
-
|
|
254
|
+
const targetExpr = ts.isPropertyAccessExpression(node.tagName) && node.tagName.name.text === 'Provider'
|
|
255
|
+
? node.tagName.expression
|
|
256
|
+
: node.tagName;
|
|
257
|
+
if (!ts.isExpression(targetExpr))
|
|
205
258
|
return;
|
|
259
|
+
let valueAttr;
|
|
206
260
|
for (const attr of node.attributes.properties) {
|
|
207
261
|
if (!ts.isJsxAttribute(attr) || !ts.isIdentifier(attr.name) || attr.name.text !== 'value')
|
|
208
262
|
continue;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const expr = ts.skipOuterExpressions(attr.initializer.expression);
|
|
212
|
-
if (ts.isObjectLiteralExpression(expr) || ts.isArrayLiteralExpression(expr)) {
|
|
213
|
-
context.report(attr, 'react-context-value-recreated', 'Inline object or array literal in Context.Provider value creates a new reference on every render; wrap it in useMemo.');
|
|
214
|
-
}
|
|
263
|
+
valueAttr = attr;
|
|
264
|
+
break;
|
|
215
265
|
}
|
|
266
|
+
if (!valueAttr?.initializer || !ts.isJsxExpression(valueAttr.initializer) || !valueAttr.initializer.expression)
|
|
267
|
+
return;
|
|
268
|
+
const expr = ts.skipOuterExpressions(valueAttr.initializer.expression);
|
|
269
|
+
if (!ts.isObjectLiteralExpression(expr) && !ts.isArrayLiteralExpression(expr))
|
|
270
|
+
return;
|
|
271
|
+
// Module-level elements are evaluated once, so their literal is not recreated per render.
|
|
272
|
+
if (!ts.findAncestor(node, ts.isFunctionLike))
|
|
273
|
+
return;
|
|
274
|
+
if (!isReactContextExpression(targetExpr, context))
|
|
275
|
+
return;
|
|
276
|
+
context.report(valueAttr, 'react-context-value-recreated', 'Inline object or array literal in Context.Provider value creates a new reference on every render; wrap it in useMemo.');
|
|
216
277
|
}
|
|
217
278
|
// --- Rule 6: json-stringify-in-loop --------------------------------------------------------------
|
|
218
279
|
function bindingIdentifiers(name, into) {
|
|
@@ -412,7 +473,7 @@ function phase5CliReason(sourceFile, context) {
|
|
|
412
473
|
}
|
|
413
474
|
function checkPhase5PerfNode(node, sourceFile, context, cliReason) {
|
|
414
475
|
if (ts.isCallExpression(node)) {
|
|
415
|
-
checkUnboundedPromiseAll(node,
|
|
476
|
+
checkUnboundedPromiseAll(node, context, cliReason);
|
|
416
477
|
checkMongooseMissingLean(node, sourceFile, context);
|
|
417
478
|
checkNodeEventListenerLeak(node, context);
|
|
418
479
|
checkJsonStringifyInLoop(node, context, cliReason);
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// SQL text analysis for sql-select-star-in-query: finds a top-level `SELECT *` outside comments and literals.
|
|
2
|
+
const DOLLAR_QUOTE_TAG_RE = /^\$(?:[A-Za-z_]\w*)?\$/;
|
|
3
|
+
// Index just past the quoted run that starts at `start` and ends at an unescaped `quote`.
|
|
4
|
+
function endOfQuoted(sql, start, quote, backslashEscapes = false) {
|
|
5
|
+
let index = start + 1;
|
|
6
|
+
while (index < sql.length) {
|
|
7
|
+
if (backslashEscapes && sql[index] === '\\') {
|
|
8
|
+
index += 2;
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if (sql[index] === quote) {
|
|
12
|
+
if (sql[index + 1] !== quote)
|
|
13
|
+
return index + 1;
|
|
14
|
+
index++;
|
|
15
|
+
}
|
|
16
|
+
index++;
|
|
17
|
+
}
|
|
18
|
+
return sql.length;
|
|
19
|
+
}
|
|
20
|
+
// PostgreSQL E'...' strings (not preceded by an identifier character) honour backslash escapes.
|
|
21
|
+
function isEscapeStringPrefix(sql, quoteIndex) {
|
|
22
|
+
return /[eE]/.test(sql[quoteIndex - 1] ?? '') && !/[\w$\u0080-]/.test(sql[quoteIndex - 2] ?? '');
|
|
23
|
+
}
|
|
24
|
+
function endOfBlockComment(sql, start) {
|
|
25
|
+
let depth = 0;
|
|
26
|
+
let index = start;
|
|
27
|
+
while (index < sql.length) {
|
|
28
|
+
if (sql.startsWith('/*', index)) {
|
|
29
|
+
depth++;
|
|
30
|
+
index += 2;
|
|
31
|
+
}
|
|
32
|
+
else if (sql.startsWith('*/', index)) {
|
|
33
|
+
depth--;
|
|
34
|
+
index += 2;
|
|
35
|
+
if (depth === 0)
|
|
36
|
+
return index;
|
|
37
|
+
}
|
|
38
|
+
else
|
|
39
|
+
index++;
|
|
40
|
+
}
|
|
41
|
+
return sql.length;
|
|
42
|
+
}
|
|
43
|
+
// Comments become a space; string literals, dollar-quoted bodies and quoted identifiers become empty
|
|
44
|
+
// quotes so their commas, stars and keywords are never read as SQL.
|
|
45
|
+
function stripSqlCommentsAndLiterals(sql) {
|
|
46
|
+
let output = '';
|
|
47
|
+
let index = 0;
|
|
48
|
+
while (index < sql.length) {
|
|
49
|
+
const rest = sql.slice(index);
|
|
50
|
+
const dollarTag = DOLLAR_QUOTE_TAG_RE.exec(rest)?.[0];
|
|
51
|
+
if (rest.startsWith('/*')) {
|
|
52
|
+
index = endOfBlockComment(sql, index);
|
|
53
|
+
output += ' ';
|
|
54
|
+
}
|
|
55
|
+
else if (rest.startsWith('--')) {
|
|
56
|
+
const lineEnd = rest.search(/[\r\n]/);
|
|
57
|
+
index = lineEnd === -1 ? sql.length : index + lineEnd;
|
|
58
|
+
output += ' ';
|
|
59
|
+
}
|
|
60
|
+
else if (rest[0] === "'" || rest[0] === '"') {
|
|
61
|
+
index = endOfQuoted(sql, index, rest[0], rest[0] === "'" && isEscapeStringPrefix(sql, index));
|
|
62
|
+
output += rest[0] + rest[0];
|
|
63
|
+
}
|
|
64
|
+
else if (dollarTag) {
|
|
65
|
+
const closeIndex = sql.indexOf(dollarTag, index + dollarTag.length);
|
|
66
|
+
index = closeIndex === -1 ? sql.length : closeIndex + dollarTag.length;
|
|
67
|
+
output += "''";
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
output += rest[0];
|
|
71
|
+
index++;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return output;
|
|
75
|
+
}
|
|
76
|
+
function skipBalancedParens(sql, openIndex) {
|
|
77
|
+
let depth = 0;
|
|
78
|
+
for (let index = openIndex; index < sql.length; index++) {
|
|
79
|
+
if (sql[index] === '(')
|
|
80
|
+
depth++;
|
|
81
|
+
else if (sql[index] === ')') {
|
|
82
|
+
depth--;
|
|
83
|
+
if (depth === 0)
|
|
84
|
+
return index + 1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return sql.length;
|
|
88
|
+
}
|
|
89
|
+
// Index just past the CTE list of a leading WITH clause, or undefined when a CTE has no body.
|
|
90
|
+
function endOfWithClause(sql) {
|
|
91
|
+
let cursor = /^with\s+recursive\b/i.test(sql) ? sql.search(/\brecursive\b/i) + 'recursive'.length : 'with'.length;
|
|
92
|
+
for (;;) {
|
|
93
|
+
const asMatch = /\bas\s*\(/i.exec(sql.slice(cursor));
|
|
94
|
+
if (!asMatch)
|
|
95
|
+
return undefined;
|
|
96
|
+
cursor = skipBalancedParens(sql, cursor + asMatch.index + asMatch[0].length - 1);
|
|
97
|
+
while (cursor < sql.length && /\s/.test(sql[cursor]))
|
|
98
|
+
cursor++;
|
|
99
|
+
if (sql[cursor] !== ',')
|
|
100
|
+
return cursor;
|
|
101
|
+
cursor++;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function indexOfTopLevelFrom(sql, start) {
|
|
105
|
+
let depth = 0;
|
|
106
|
+
for (let index = start; index < sql.length; index++) {
|
|
107
|
+
const ch = sql[index];
|
|
108
|
+
if (ch === '(')
|
|
109
|
+
depth++;
|
|
110
|
+
else if (ch === ')')
|
|
111
|
+
depth = Math.max(0, depth - 1);
|
|
112
|
+
else if (depth === 0 && /^from\b/i.test(sql.slice(index)) && /\s/.test(sql[index - 1] ?? ' '))
|
|
113
|
+
return index;
|
|
114
|
+
}
|
|
115
|
+
return -1;
|
|
116
|
+
}
|
|
117
|
+
function splitTopLevelCommas(text) {
|
|
118
|
+
const items = [''];
|
|
119
|
+
let depth = 0;
|
|
120
|
+
for (const ch of text) {
|
|
121
|
+
if (ch === '(')
|
|
122
|
+
depth++;
|
|
123
|
+
else if (ch === ')')
|
|
124
|
+
depth = Math.max(0, depth - 1);
|
|
125
|
+
if (ch === ',' && depth === 0)
|
|
126
|
+
items.push('');
|
|
127
|
+
else
|
|
128
|
+
items[items.length - 1] += ch;
|
|
129
|
+
}
|
|
130
|
+
return items;
|
|
131
|
+
}
|
|
132
|
+
export function topLevelSelectStar(rawSql) {
|
|
133
|
+
const sql = stripSqlCommentsAndLiterals(rawSql).trimStart();
|
|
134
|
+
const cursor = /^with\b/i.test(sql) ? endOfWithClause(sql) : 0;
|
|
135
|
+
if (cursor === undefined)
|
|
136
|
+
return undefined;
|
|
137
|
+
const rest = sql.slice(cursor).trimStart();
|
|
138
|
+
const selectMatch = /^select\s+(?:(?:distinct|all)\s+)?/i.exec(rest);
|
|
139
|
+
if (!selectMatch)
|
|
140
|
+
return undefined;
|
|
141
|
+
const fromIndex = indexOfTopLevelFrom(rest, selectMatch[0].length);
|
|
142
|
+
if (fromIndex === -1)
|
|
143
|
+
return undefined;
|
|
144
|
+
const fromClause = rest.slice(fromIndex + 4).trimStart();
|
|
145
|
+
if (/^(?:\(|information_schema\b|pg_)/i.test(fromClause))
|
|
146
|
+
return undefined;
|
|
147
|
+
const projectionItems = splitTopLevelCommas(rest.slice(selectMatch[0].length, fromIndex));
|
|
148
|
+
const hasStar = projectionItems.some((item) => /^(?:[\w$]+\.)?\*$/.test(item.trim()));
|
|
149
|
+
return hasStar ? { isSelectStar: true, fromClause } : undefined;
|
|
150
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ts } from '../engine/compiler.js';
|
|
2
|
+
import { importedFrom } from '../../security/bindings.js';
|
|
2
3
|
import { hasPromiseType } from '../async/awaits.js';
|
|
3
4
|
import { declaredTypeNode, smallLiteralLimit, syncCallback } from '../collections/collection-bindings.js';
|
|
4
5
|
import { hasSmallReadonlyTuple } from '../collections/collection-bounds.js';
|
|
@@ -7,38 +8,53 @@ import { effectiveProperty, isUnshadowedGlobal, staticMemberName, staticProperty
|
|
|
7
8
|
import { MAX_SOURCE_DEPTH, constSource, containsMatchingNode, enclosingLoop, isGlobalMethodCall, isStatementLoop, valueSymbol, } from './phase5-ast.js';
|
|
8
9
|
const COLLECTION_TRANSFORMS = new Set(['map', 'flatMap', 'filter', 'sort', 'toSorted', 'reverse', 'toReversed']);
|
|
9
10
|
const COLLECTION_SOURCES = new Set(['findMany', 'find', 'readdir']);
|
|
10
|
-
const CONCURRENCY_LIMITER_PACKAGES = new Set([
|
|
11
|
-
'p-limit',
|
|
12
|
-
'p-map',
|
|
13
|
-
'@supercharge/promise-pool',
|
|
14
|
-
'bottleneck',
|
|
15
|
-
'p-queue',
|
|
16
|
-
]);
|
|
17
|
-
const CONCURRENCY_LIMITER_NAMES = /^(?:pLimit|limit|limiter|concurrencyLimit|pMap|PromisePool)$/i;
|
|
18
|
-
function hasConcurrencyLimiterImport(sourceFile) {
|
|
19
|
-
for (const stmt of sourceFile.statements) {
|
|
20
|
-
if (ts.isImportDeclaration(stmt) && ts.isStringLiteral(stmt.moduleSpecifier)) {
|
|
21
|
-
if (CONCURRENCY_LIMITER_PACKAGES.has(stmt.moduleSpecifier.text))
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
11
|
function isChunkingLoop(loopNode) {
|
|
28
12
|
if (!isStatementLoop(loopNode))
|
|
29
13
|
return false;
|
|
30
14
|
return containsMatchingNode(loopNode, (node) => (ts.isPropertyAccessExpression(node) && node.name.text === 'slice') ||
|
|
31
15
|
(ts.isIdentifier(node) && /(?:chunk|batch)/i.test(node.text)), false);
|
|
32
16
|
}
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
ts.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (!
|
|
17
|
+
function mappedTask(input, checker) {
|
|
18
|
+
if (!ts.isCallExpression(input) ||
|
|
19
|
+
!ts.isPropertyAccessExpression(input.expression) ||
|
|
20
|
+
input.expression.name.text !== 'map')
|
|
21
|
+
return;
|
|
22
|
+
const mapper = unwrapExpression(input.arguments[0]);
|
|
23
|
+
if (!mapper || (!ts.isArrowFunction(mapper) && !ts.isFunctionExpression(mapper)))
|
|
24
|
+
return;
|
|
25
|
+
let result;
|
|
26
|
+
if (ts.isBlock(mapper.body)) {
|
|
27
|
+
const setup = mapper.body.statements.slice(0, -1);
|
|
28
|
+
if (!setup.every((statement) => ts.isVariableStatement(statement) &&
|
|
29
|
+
!containsMatchingNode(statement, (node) => ts.isCallExpression(node) && hasPromiseType(checker.getTypeAtLocation(node), checker))))
|
|
30
|
+
return;
|
|
31
|
+
const last = mapper.body.statements.at(-1);
|
|
32
|
+
if (last && ts.isReturnStatement(last))
|
|
33
|
+
result = last.expression;
|
|
34
|
+
}
|
|
35
|
+
else
|
|
36
|
+
result = mapper.body;
|
|
37
|
+
let task = unwrapExpression(result);
|
|
38
|
+
if (task && ts.isAwaitExpression(task))
|
|
39
|
+
task = unwrapExpression(task.expression);
|
|
40
|
+
return task && ts.isCallExpression(task) ? task : undefined;
|
|
41
|
+
}
|
|
42
|
+
function schedulesLimitedWork(task, checker) {
|
|
43
|
+
const callee = unwrapExpression(task.expression);
|
|
44
|
+
const member = ts.isPropertyAccessExpression(callee) ? callee : undefined;
|
|
45
|
+
const receiver = member ? unwrapExpression(member.expression) : callee;
|
|
46
|
+
if (!ts.isIdentifier(receiver))
|
|
40
47
|
return false;
|
|
41
|
-
|
|
48
|
+
const origin = constSource(receiver, checker);
|
|
49
|
+
if (!origin || (!ts.isCallExpression(origin) && !ts.isNewExpression(origin)))
|
|
50
|
+
return false;
|
|
51
|
+
const binding = importedFrom(origin.expression, checker);
|
|
52
|
+
const [work] = task.arguments;
|
|
53
|
+
if (!binding || !work || (!ts.isArrowFunction(work) && !ts.isFunctionExpression(work) && !ts.isIdentifier(work)))
|
|
54
|
+
return false;
|
|
55
|
+
return ((binding.module === 'p-limit' && !member) ||
|
|
56
|
+
(binding.module === 'p-queue' && member?.name.text === 'add') ||
|
|
57
|
+
(binding.module === 'bottleneck' && member?.name.text === 'schedule'));
|
|
42
58
|
}
|
|
43
59
|
function isUndefinedSeparator(expression, checker, depth = 0) {
|
|
44
60
|
const value = unwrapExpression(expression);
|
|
@@ -402,8 +418,9 @@ function promiseAllInput(expression) {
|
|
|
402
418
|
const [element] = spread.elements;
|
|
403
419
|
return ts.isOmittedExpression(element) || ts.isSpreadElement(element) ? value : unwrapExpression(element);
|
|
404
420
|
}
|
|
405
|
-
function checkUnboundedPromiseAll(call,
|
|
406
|
-
|
|
421
|
+
function checkUnboundedPromiseAll(call, context, cliReason) {
|
|
422
|
+
const settled = isGlobalMethodCall(call, 'Promise', 'allSettled', context.checker);
|
|
423
|
+
if ((!settled && !isGlobalMethodCall(call, 'Promise', 'all', context.checker)) || call.arguments.length === 0)
|
|
407
424
|
return;
|
|
408
425
|
const arg = promiseAllInput(call.arguments[0]);
|
|
409
426
|
if (ts.isArrayLiteralExpression(arg) || hasDeclaredReadonlyTupleBound(arg, context.checker))
|
|
@@ -414,13 +431,21 @@ function checkUnboundedPromiseAll(call, sourceFile, context, cliReason) {
|
|
|
414
431
|
const loop = enclosingLoop(call);
|
|
415
432
|
if (loop && isChunkingLoop(loop))
|
|
416
433
|
return;
|
|
417
|
-
|
|
434
|
+
const task = mappedTask(arg, context.checker);
|
|
435
|
+
if (settled &&
|
|
436
|
+
(!task ||
|
|
437
|
+
!hasPromiseType(context.checker.getTypeAtLocation(task), context.checker) ||
|
|
438
|
+
task.arguments.some((argument) => hasPromiseType(context.checker.getTypeAtLocation(argument), context.checker))))
|
|
439
|
+
return;
|
|
440
|
+
if (task && schedulesLimitedWork(task, context.checker))
|
|
418
441
|
return;
|
|
419
442
|
if (isDbQueryInMap(arg))
|
|
420
443
|
return;
|
|
421
444
|
if (ts.isCallExpression(arg) && !isUnboundedCollection(arg, context.checker))
|
|
422
445
|
return;
|
|
423
446
|
const reason = cliReason;
|
|
424
|
-
context.report(call, 'unbounded-promise-all',
|
|
447
|
+
context.report(call, 'unbounded-promise-all', settled
|
|
448
|
+
? 'Promise.allSettled runs over an unbounded collection without a concurrency limit, risking memory spikes or downstream saturation.'
|
|
449
|
+
: 'Promise.all runs over an unbounded collection without a concurrency limit, risking memory spikes or downstream saturation.', reason);
|
|
425
450
|
}
|
|
426
451
|
export { checkUnboundedPromiseAll };
|
|
@@ -140,6 +140,10 @@ function check(node, context) {
|
|
|
140
140
|
if (limitStatus(node.arguments[helper.index], context.checker) !== 'missing')
|
|
141
141
|
return;
|
|
142
142
|
const name = ts.isIdentifier(callee) ? callee.text : staticMemberName(callee);
|
|
143
|
-
context.
|
|
143
|
+
const maxBytes = context.ruleOption?.('upload-without-size-limit', 'maxBytes');
|
|
144
|
+
context.report(callee, 'upload-without-size-limit', `\`${name}\` has no local \`limits.fileSize\`. Large files can exhaust memory with memory storage. Check the application's effective upload limits, including any global Multer configuration, and choose a byte limit that supports the files this endpoint accepts.`, undefined, {
|
|
145
|
+
uploadOptionsIndex: helper.index,
|
|
146
|
+
...(typeof maxBytes === 'number' ? { uploadMaxBytes: maxBytes } : {}),
|
|
147
|
+
});
|
|
144
148
|
}
|
|
145
149
|
export { check };
|
|
@@ -157,7 +157,7 @@ function buildFix(finding, load, { comments = true } = {}) {
|
|
|
157
157
|
if (!result)
|
|
158
158
|
return;
|
|
159
159
|
const targets = result.targets ?? (entry && finding.file !== undefined ? [{ file: finding.file, edits: result.edits }] : []);
|
|
160
|
-
|
|
160
|
+
const commentRows = [];
|
|
161
161
|
const changes = [];
|
|
162
162
|
for (const target of targets) {
|
|
163
163
|
if (typeof target?.file !== 'string')
|
|
@@ -169,7 +169,7 @@ function buildFix(finding, load, { comments = true } = {}) {
|
|
|
169
169
|
return;
|
|
170
170
|
changes.push(...targetChanges.changes);
|
|
171
171
|
if (targetChanges.commentRow !== undefined)
|
|
172
|
-
|
|
172
|
+
commentRows.push({ file: target.file, row: targetChanges.commentRow });
|
|
173
173
|
}
|
|
174
174
|
if (!changes.length || changes.every((change) => change.before === change.after))
|
|
175
175
|
return;
|
|
@@ -179,8 +179,8 @@ function buildFix(finding, load, { comments = true } = {}) {
|
|
|
179
179
|
...(result.requiresReview && { requiresReview: true }),
|
|
180
180
|
...(result.comment && { comment: result.comment }),
|
|
181
181
|
};
|
|
182
|
-
|
|
183
|
-
rememberCommentRow(fix,
|
|
182
|
+
for (const { file, row } of commentRows)
|
|
183
|
+
rememberCommentRow(fix, file, row);
|
|
184
184
|
return fix;
|
|
185
185
|
}
|
|
186
186
|
// Returns undefined when the finding does not point at a usable position, and an empty location for
|