loadwise 0.6.2 → 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 +175 -115
- package/dist/bin/loadwise.js +132 -67
- 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/frontend-detect.js +6 -5
- 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/accessibility/usage.js +10 -2
- 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 +63 -0
- 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 +170 -0
- package/dist/lib/editor/fix-edits.js +19 -0
- package/dist/lib/editor/jetbrains-setup.js +53 -0
- package/dist/lib/editor/language-server.js +80 -24
- package/dist/lib/editor/managed-config.js +37 -0
- package/dist/lib/editor/native-setup.js +86 -0
- package/dist/lib/editor/perf-watch.js +8 -6
- package/dist/lib/editor/release-vsix.js +61 -0
- 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 +38 -9
- package/dist/lib/editor/setup-server.js +87 -0
- package/dist/lib/editor/setup-vim.js +63 -0
- package/dist/lib/editor/setup.js +131 -0
- package/dist/lib/editor/stdio-setup.js +6 -0
- 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 +12 -3
- package/dist/lib/maintainability/cli.js +18 -5
- 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/examples.js +4 -0
- 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/rule-ids.js +3 -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/site-fixes/unused-bindings.js +138 -3
- package/dist/lib/maintainability/unused/module-usage.js +43 -21
- package/dist/lib/maintainability/unused/unused-bindings.js +39 -4
- 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/changed-lines.js +8 -1
- package/dist/lib/performance/cli/cli-arguments.js +19 -8
- package/dist/lib/performance/cli/cli-output.js +4 -0
- package/dist/lib/performance/cli/cli-scan.js +21 -2
- package/dist/lib/performance/cli.js +16 -7
- 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 +68 -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 +62 -3
- 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-syntax.js +3 -0
- 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 +149 -74
- 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/bulk-listener-registration.js +111 -0
- package/dist/lib/performance/request/fastify-receivers.js +93 -0
- package/dist/lib/performance/request/fresh-loop-socket.js +103 -0
- package/dist/lib/performance/request/mongoose-lean.js +298 -46
- package/dist/lib/performance/request/node-event-listener-leak.js +99 -5
- package/dist/lib/performance/request/phase5-ast.js +6 -7
- package/dist/lib/performance/request/phase5-rules.js +204 -23
- package/dist/lib/performance/request/request-handlers.js +120 -23
- 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/collection-existence.js +2 -1
- package/dist/lib/performance/site-fixes/collections.js +1 -2
- package/dist/lib/performance/site-fixes/frontend-fixes.js +358 -14
- package/dist/lib/performance/site-fixes/helpers.js +3 -4
- package/dist/lib/performance/site-fixes/integrity.js +2 -4
- 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 +29 -7
- 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/usage.js +16 -5
- 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 +21 -6
- 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 +28 -5
- package/dist/lib/shared/agent/agent-prompt.js +74 -0
- package/dist/lib/shared/agent/agent-session.js +6 -1
- package/dist/lib/shared/agent/agent-verify.js +58 -11
- package/dist/lib/shared/agent/git-hook.js +17 -6
- package/dist/lib/shared/agent/review-delivery.js +1 -1
- 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 +99 -14
- package/dist/lib/shared/check.js +172 -20
- 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 +19 -31
- package/dist/lib/shared/fix/fix-handoff.js +16 -11
- package/dist/lib/shared/fix/fix-imports.js +4 -162
- package/dist/lib/shared/fix/fix-presentation-comments.js +23 -9
- package/dist/lib/shared/fix/fix-presentation-prettier.js +1 -46
- package/dist/lib/shared/fix/fix-presentation-rows.js +45 -1
- package/dist/lib/shared/fix/fix-presentation.js +9 -6
- package/dist/lib/shared/fix/fix-safety.js +32 -1
- package/dist/lib/shared/fix/fix-scope.js +82 -0
- package/dist/lib/shared/fix/fix-terminal.js +28 -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/project-file-access.js +17 -26
- package/dist/lib/shared/fix/read-fix-text.js +20 -0
- package/dist/lib/shared/fix.js +241 -104
- 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 +97 -0
- package/dist/lib/shared/reporting/automatic-fix-signal.js +10 -0
- package/dist/lib/shared/reporting/baseline.js +7 -5
- package/dist/lib/shared/reporting/check-text.js +50 -0
- package/dist/lib/shared/reporting/pillars.js +54 -19
- package/dist/lib/shared/reporting/source-report.js +3 -0
- package/dist/lib/shared/system/atomic-write.js +5 -2
- package/dist/lib/shared/system/glob.js +34 -8
- package/dist/lib/shared/system/sentry.js +222 -0
- package/dist/lib/shared/system/shell-argument.js +5 -1
- package/dist/lib/shared/system/terminal-safe.js +3 -2
- package/dist/lib/shared/system/terminal-style.js +131 -0
- package/dist/lib/shared/workspaces.js +15 -3
- package/docs/assets/cli-workflow.gif +0 -0
- package/integrations/sublime/plugin.py +22 -0
- package/integrations/zed/Cargo.lock +845 -0
- package/integrations/zed/Cargo.toml +11 -0
- package/integrations/zed/extension.toml +11 -0
- package/integrations/zed/src/lib.rs +25 -0
- package/package.json +15 -3
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/commands/loadwise.md +11 -6
- 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 +556 -76
- /package/polyglot/{performance/rules → shared-rules}/input.yml +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Shared by the rules that only matter when the work happens for a request: which function is a
|
|
2
2
|
// request handler, and whether a value ends up in its response.
|
|
3
3
|
import { ts } from '../engine/compiler.js';
|
|
4
|
+
import { isProvenFastifyReceiver } from './fastify-receivers.js';
|
|
4
5
|
const ROUTE_DECORATORS = new Set([
|
|
5
6
|
'Get',
|
|
6
7
|
'Post',
|
|
@@ -30,7 +31,21 @@ const USE_SERVER_DIRECTIVE = 'use server';
|
|
|
30
31
|
const HONO_MODULE = /^@?hono(?:[/-]|$)/;
|
|
31
32
|
const FASTIFY_MODULE = /^(?:fastify|@fastify\/|fastify-)/;
|
|
32
33
|
const ROUTE_METHODS = new Set(['get', 'post', 'put', 'patch', 'delete', 'all', 'head', 'options', 'on', 'route']);
|
|
33
|
-
const
|
|
34
|
+
const LEGACY_FASTIFY_OPTIONS = new Set(['handler', 'preHandler', 'onRequest', 'preValidation', 'preParsing']);
|
|
35
|
+
const FASTIFY_REQUEST_HOOKS = new Set([
|
|
36
|
+
'onRequest',
|
|
37
|
+
'preParsing',
|
|
38
|
+
'preValidation',
|
|
39
|
+
'preHandler',
|
|
40
|
+
'preSerialization',
|
|
41
|
+
'onError',
|
|
42
|
+
'onSend',
|
|
43
|
+
'onResponse',
|
|
44
|
+
'onTimeout',
|
|
45
|
+
'onRequestAbort',
|
|
46
|
+
]);
|
|
47
|
+
const FASTIFY_RESPONSE_TRANSFORMS = new Set(['preSerialization', 'onSend']);
|
|
48
|
+
const FASTIFY_HOOKS_WITHOUT_REPLY = new Set(['onError', 'onResponse', 'onTimeout', 'onRequestAbort']);
|
|
34
49
|
const TYPED_REQUEST_PARAMETERS = new Set(['FastifyRequest', 'NextApiRequest']);
|
|
35
50
|
const HONO_CONTEXT_NAME = 'c';
|
|
36
51
|
const HONO_CONTEXT_MEMBERS = new Set(['req', 'json', 'text', 'html']);
|
|
@@ -72,11 +87,54 @@ function isFunctionLikeDeclaration(node) {
|
|
|
72
87
|
ts.isFunctionExpression(node) ||
|
|
73
88
|
ts.isArrowFunction(node));
|
|
74
89
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
90
|
+
const nestRouteImports = new WeakMap();
|
|
91
|
+
function nestBindings(file) {
|
|
92
|
+
const cached = nestRouteImports.get(file);
|
|
93
|
+
if (cached)
|
|
94
|
+
return cached;
|
|
95
|
+
const aliases = new Set();
|
|
96
|
+
const namespaces = new Set();
|
|
97
|
+
for (const statement of file.statements) {
|
|
98
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteralLike(statement.moduleSpecifier))
|
|
99
|
+
continue;
|
|
100
|
+
const module = statement.moduleSpecifier.text;
|
|
101
|
+
if (module !== '@nestjs/common' && module !== '@nestjs/graphql')
|
|
102
|
+
continue;
|
|
103
|
+
const bindings = statement.importClause?.namedBindings;
|
|
104
|
+
if (statement.importClause?.isTypeOnly || !bindings)
|
|
105
|
+
continue;
|
|
106
|
+
if (ts.isNamespaceImport(bindings)) {
|
|
107
|
+
namespaces.add(bindings.name.text);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
for (const item of bindings.elements) {
|
|
111
|
+
if (item.isTypeOnly)
|
|
112
|
+
continue;
|
|
113
|
+
if (ROUTE_DECORATORS.has((item.propertyName ?? item.name).text))
|
|
114
|
+
aliases.add(item.name.text);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const result = { aliases, namespaces };
|
|
118
|
+
nestRouteImports.set(file, result);
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
function isRouteDecorator(modifier) {
|
|
122
|
+
if (!ts.isDecorator(modifier) || !ts.isCallExpression(modifier.expression))
|
|
123
|
+
return false;
|
|
124
|
+
const callee = modifier.expression.expression;
|
|
125
|
+
if (ts.isIdentifier(callee) && ROUTE_DECORATORS.has(callee.text))
|
|
126
|
+
return true;
|
|
127
|
+
// File-level classes can use renamed or namespaced Nest imports without the packages being installed.
|
|
128
|
+
const declaration = modifier.parent.parent;
|
|
129
|
+
if (!ts.isClassDeclaration(declaration) || !ts.isSourceFile(declaration.parent))
|
|
130
|
+
return false;
|
|
131
|
+
const { aliases, namespaces } = nestBindings(declaration.parent);
|
|
132
|
+
if (ts.isIdentifier(callee))
|
|
133
|
+
return aliases.has(callee.text);
|
|
134
|
+
return (ts.isPropertyAccessExpression(callee) &&
|
|
135
|
+
ts.isIdentifier(callee.expression) &&
|
|
136
|
+
namespaces.has(callee.expression.text) &&
|
|
137
|
+
ROUTE_DECORATORS.has(callee.name.text));
|
|
80
138
|
}
|
|
81
139
|
function parameterName(parameter) {
|
|
82
140
|
return parameter && ts.isIdentifier(parameter.name) ? parameter.name.text : undefined;
|
|
@@ -224,26 +282,52 @@ function isHonoHandler(node) {
|
|
|
224
282
|
const looksLikeHono = importsModule(node, HONO_MODULE) || contextName === HONO_CONTEXT_NAME;
|
|
225
283
|
return looksLikeHono && usesHonoContext(node, contextName);
|
|
226
284
|
}
|
|
227
|
-
function
|
|
228
|
-
|
|
285
|
+
function fastifyRouteOption(node) {
|
|
286
|
+
let value = ts.isMethodDeclaration(node) ? node : node.parent;
|
|
287
|
+
const array = ts.isArrayLiteralExpression(value);
|
|
288
|
+
if (array)
|
|
289
|
+
value = value.parent;
|
|
290
|
+
const property = value;
|
|
229
291
|
if (!ts.isPropertyAssignment(property) && !ts.isMethodDeclaration(property))
|
|
230
|
-
return
|
|
231
|
-
if (!ts.isIdentifier(property.name)
|
|
232
|
-
return
|
|
292
|
+
return;
|
|
293
|
+
if (!ts.isIdentifier(property.name) && !ts.isStringLiteralLike(property.name))
|
|
294
|
+
return;
|
|
295
|
+
if (!FASTIFY_REQUEST_HOOKS.has(property.name.text) && (array || property.name.text !== 'handler'))
|
|
296
|
+
return;
|
|
233
297
|
const options = property.parent;
|
|
234
298
|
const call = ts.isObjectLiteralExpression(options) && options.parent;
|
|
235
299
|
if (!call || !isMemberCall(call))
|
|
236
|
-
return
|
|
237
|
-
|
|
300
|
+
return;
|
|
301
|
+
if (!ROUTE_METHODS.has(call.expression.name.text))
|
|
302
|
+
return;
|
|
303
|
+
const name = property.name.text;
|
|
304
|
+
// New hook shapes need actual receiver evidence. The old route shapes keep their existing coverage.
|
|
305
|
+
const fastify = array || !LEGACY_FASTIFY_OPTIONS.has(name)
|
|
306
|
+
? isProvenFastifyReceiver(call.expression.expression)
|
|
307
|
+
: isFastifyReceiver(call);
|
|
308
|
+
return fastify ? name : undefined;
|
|
238
309
|
}
|
|
239
310
|
function isFastifyReceiver(call) {
|
|
240
311
|
const receiver = call.expression.expression;
|
|
241
312
|
return importsModule(call, FASTIFY_MODULE) || (ts.isIdentifier(receiver) && receiver.text === 'fastify');
|
|
242
313
|
}
|
|
314
|
+
function fastifyHook(node) {
|
|
315
|
+
const call = node.parent;
|
|
316
|
+
if (!isMemberCall(call) || call.expression.name.text !== 'addHook')
|
|
317
|
+
return;
|
|
318
|
+
const [name, callback] = call.arguments;
|
|
319
|
+
return !!name &&
|
|
320
|
+
ts.isStringLiteralLike(name) &&
|
|
321
|
+
FASTIFY_REQUEST_HOOKS.has(name.text) &&
|
|
322
|
+
callback === node &&
|
|
323
|
+
isProvenFastifyReceiver(call.expression.expression)
|
|
324
|
+
? name.text
|
|
325
|
+
: undefined;
|
|
326
|
+
}
|
|
243
327
|
function isFastifyHandler(node) {
|
|
244
328
|
if (!isFunctionLikeDeclaration(node))
|
|
245
329
|
return false;
|
|
246
|
-
if (
|
|
330
|
+
if (fastifyRouteOption(node) || fastifyHook(node))
|
|
247
331
|
return true;
|
|
248
332
|
const call = routeCall(node);
|
|
249
333
|
if (!call || !node.parameters.length || call.expression.name.text === 'use')
|
|
@@ -301,7 +385,7 @@ function computeIsRequestHandler(node) {
|
|
|
301
385
|
if (!node.body)
|
|
302
386
|
return false;
|
|
303
387
|
if (ts.isMethodDeclaration(node))
|
|
304
|
-
return
|
|
388
|
+
return node.modifiers?.some(isRouteDecorator) === true || fastifyRouteOption(node) !== undefined;
|
|
305
389
|
const [first, second] = node.parameters.map(parameterName);
|
|
306
390
|
if (first && REQUEST_PARAMETER.test(first)) {
|
|
307
391
|
if (second && RESPONSE_PARAMETER.test(second))
|
|
@@ -354,16 +438,27 @@ function identifiersNamed(root, name, declaration) {
|
|
|
354
438
|
function isTransparent(node) {
|
|
355
439
|
return TRANSPARENT_KINDS.some((kind) => ts[kind](node));
|
|
356
440
|
}
|
|
441
|
+
function returnsFromHandler(parent, value, handler) {
|
|
442
|
+
if (ts.isReturnStatement(parent))
|
|
443
|
+
return ts.findAncestor(parent, ts.isFunctionLike) === handler;
|
|
444
|
+
return ts.isArrowFunction(parent) && parent.body === value && parent === handler;
|
|
445
|
+
}
|
|
446
|
+
function reachesResponse(value, handler) {
|
|
447
|
+
const fastify = fastifyRouteOption(handler) ?? fastifyHook(handler);
|
|
448
|
+
if (fastify && FASTIFY_HOOKS_WITHOUT_REPLY.has(fastify))
|
|
449
|
+
return false;
|
|
450
|
+
// Ordinary hooks continue the lifecycle on return. Only payload hooks forward a returned value.
|
|
451
|
+
const sendsReturnValue = !fastify || fastify === 'handler' || FASTIFY_RESPONSE_TRANSFORMS.has(fastify);
|
|
452
|
+
return followsResponse(value, handler, sendsReturnValue, 0);
|
|
453
|
+
}
|
|
357
454
|
// True when `value` is returned from `handler` or passed to a response call, possibly after being
|
|
358
455
|
// wrapped in an object or array, mapped, or stored in a local that is then returned. Stops at
|
|
359
456
|
// nested callbacks.
|
|
360
|
-
function
|
|
457
|
+
function followsResponse(value, handler, sendsReturnValue, depth) {
|
|
361
458
|
let current = value;
|
|
362
459
|
for (let parent = current.parent; parent; current = parent, parent = parent.parent) {
|
|
363
|
-
if (
|
|
364
|
-
return
|
|
365
|
-
if (ts.isArrowFunction(parent) && parent.body === current)
|
|
366
|
-
return parent === handler;
|
|
460
|
+
if (returnsFromHandler(parent, current, handler))
|
|
461
|
+
return sendsReturnValue;
|
|
367
462
|
if (ts.isFunctionLike(parent))
|
|
368
463
|
return false;
|
|
369
464
|
if (isTransparent(parent))
|
|
@@ -390,14 +485,16 @@ function reachesResponse(value, handler, depth = 0) {
|
|
|
390
485
|
continue;
|
|
391
486
|
}
|
|
392
487
|
if (ts.isVariableDeclaration(parent) && parent.initializer === current) {
|
|
393
|
-
return ts.isIdentifier(parent.name) &&
|
|
488
|
+
return (ts.isIdentifier(parent.name) &&
|
|
489
|
+
depth < MAX_ALIAS_DEPTH &&
|
|
490
|
+
usesReachResponse(parent.name, handler, sendsReturnValue, depth));
|
|
394
491
|
}
|
|
395
492
|
return false;
|
|
396
493
|
}
|
|
397
494
|
return false;
|
|
398
495
|
}
|
|
399
|
-
function usesReachResponse(declaredName, handler, depth) {
|
|
400
|
-
return identifiersNamed(handler.body, declaredName.text, declaredName).some((use) =>
|
|
496
|
+
function usesReachResponse(declaredName, handler, sendsReturnValue, depth) {
|
|
497
|
+
return identifiersNamed(handler.body, declaredName.text, declaredName).some((use) => followsResponse(use, handler, sendsReturnValue, depth + 1));
|
|
401
498
|
}
|
|
402
499
|
const USER_SCOPED_FIELDS = new Set([
|
|
403
500
|
'userId',
|
|
@@ -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
|