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
|
@@ -11,11 +11,13 @@
|
|
|
11
11
|
// frontend-render-perf.ts adds react-component-defined-in-component and angular-ngfor-missing-trackby.
|
|
12
12
|
// Every rule rests on where a name comes from (its import), never on the name alone.
|
|
13
13
|
import { ts } from '../engine/compiler.js';
|
|
14
|
+
import { effectCleanup, effectDisposes, releases } from './effect-cleanup.js';
|
|
15
|
+
import { angularTeardown, subscriptionField, thisField } from './angular-teardown.js';
|
|
14
16
|
import { isTestSource } from '../analysis/review-context.js';
|
|
15
17
|
import { declaredInPackage, initializerOf, packageOf, propertyName } from '../schema/ts-helpers.js';
|
|
16
18
|
import { checkComponentInComponent, checkNgForTrackBy, isFunctionNode } from './frontend-render-perf.js';
|
|
17
19
|
import { checkAddEventListener, checkHeavyBarrelImport, checkLayoutThrashing, isLoop } from './frontend-dom-perf.js';
|
|
18
|
-
import { ANGULAR_MODULES, REACT_MODULES, VUE_MODULES, calleeName,
|
|
20
|
+
import { ANGULAR_MODULES, REACT_MODULES, VUE_MODULES, calleeName, effectCallback, importedName, isBrowserGlobal, isGlobalEventTarget, isVueImport, walkAll, walkSkippingFunctions, } from './frontend-helpers.js';
|
|
19
21
|
const RXJS_OPERATOR_MODULES = ['rxjs', 'rxjs/operators', '@angular/core/rxjs-interop'];
|
|
20
22
|
const DEFINITE_LEAK_CONSTRUCTORS = new Set(['WebSocket', 'EventSource']);
|
|
21
23
|
const OBSERVER_CONSTRUCTORS = new Set(['ResizeObserver', 'IntersectionObserver', 'MutationObserver']);
|
|
@@ -25,12 +27,24 @@ const COMPLETING_OPERATORS = new Set([
|
|
|
25
27
|
'takeUntilDestroyed',
|
|
26
28
|
'take',
|
|
27
29
|
'takeWhile',
|
|
28
|
-
'takeLast',
|
|
29
30
|
'first',
|
|
30
|
-
'last',
|
|
31
31
|
'single',
|
|
32
32
|
'elementAt',
|
|
33
33
|
]);
|
|
34
|
+
const FLATTENING_OPERATORS = new Set([
|
|
35
|
+
'concatAll',
|
|
36
|
+
'concatMap',
|
|
37
|
+
'concatMapTo',
|
|
38
|
+
'exhaust',
|
|
39
|
+
'exhaustAll',
|
|
40
|
+
'exhaustMap',
|
|
41
|
+
'mergeAll',
|
|
42
|
+
'mergeMap',
|
|
43
|
+
'mergeMapTo',
|
|
44
|
+
'switchAll',
|
|
45
|
+
'switchMap',
|
|
46
|
+
'switchMapTo',
|
|
47
|
+
]);
|
|
34
48
|
const ENDLESS_PACKAGES = ['@ngrx/store', '@angular/forms'];
|
|
35
49
|
const COMPLETING_PACKAGES = ['@angular/common'];
|
|
36
50
|
const SUBSCRIBE_MAY_COMPLETE_REASON = 'The source may complete on its own (route params, single-emission or finite observables); dismiss if it does.';
|
|
@@ -41,30 +55,70 @@ const OBSERVER_REASON = 'An observer attached to an element the component owns i
|
|
|
41
55
|
const ON_PUSH_REASON = 'OnPush skips checks for @Input objects that are mutated in place, so confirm the inputs are immutable or signal-driven first; zoneless apps do not need it.';
|
|
42
56
|
// --- RxJS subscriptions
|
|
43
57
|
// -------------------------------------------------------------------------------------
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const operatorNames = [];
|
|
58
|
+
// Keep the lifetime effects in pipeline order, including across separate pipe() calls.
|
|
59
|
+
function unwrapPipes(expression, checker, teardown) {
|
|
60
|
+
const effects = [];
|
|
48
61
|
let source = ts.skipOuterExpressions(expression);
|
|
49
62
|
while (ts.isCallExpression(source) && ts.isPropertyAccessExpression(source.expression)) {
|
|
50
63
|
const method = source.expression.name.text;
|
|
51
64
|
if (method === 'pipe')
|
|
52
|
-
|
|
65
|
+
effects.unshift(...operatorEffects(source.arguments, checker, teardown));
|
|
53
66
|
else if (method !== 'asObservable')
|
|
54
67
|
break;
|
|
55
68
|
source = ts.skipOuterExpressions(source.expression.expression);
|
|
56
69
|
}
|
|
57
|
-
return { source,
|
|
70
|
+
return { source, effects };
|
|
58
71
|
}
|
|
59
|
-
function
|
|
60
|
-
const
|
|
72
|
+
function operatorEffects(pipeArguments, checker, teardown) {
|
|
73
|
+
const effects = [];
|
|
61
74
|
for (const argument of pipeArguments) {
|
|
62
75
|
const operator = ts.skipOuterExpressions(argument);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
if (!ts.isCallExpression(operator))
|
|
77
|
+
continue;
|
|
78
|
+
const name = importedName(operator.expression, checker, RXJS_OPERATOR_MODULES);
|
|
79
|
+
if (!name)
|
|
80
|
+
continue;
|
|
81
|
+
if (name === 'takeUntil' && teardown) {
|
|
82
|
+
const notifier = thisField(operator.arguments[0]);
|
|
83
|
+
if (notifier && teardown.ownedNotifiers.has(notifier) && !teardown.notifiers.has(notifier))
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
// RxJS implements a nonpositive takeLast count as an immediately completing stream.
|
|
87
|
+
if (COMPLETING_OPERATORS.has(name) || (name === 'takeLast' && isNonpositiveCount(operator.arguments[0]))) {
|
|
88
|
+
effects.push('complete');
|
|
89
|
+
}
|
|
90
|
+
else if (FLATTENING_OPERATORS.has(name) && !hasFiniteInnerStream(name, operator, checker)) {
|
|
91
|
+
effects.push('flatten');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return effects;
|
|
95
|
+
}
|
|
96
|
+
function hasFiniteInnerStream(name, operator, checker) {
|
|
97
|
+
const argument = operator.arguments[0] && ts.skipOuterExpressions(operator.arguments[0]);
|
|
98
|
+
if (!argument)
|
|
99
|
+
return false;
|
|
100
|
+
if (name.endsWith('MapTo'))
|
|
101
|
+
return isFiniteRxjsSource(argument, checker);
|
|
102
|
+
if (!name.endsWith('Map') || (!ts.isArrowFunction(argument) && !ts.isFunctionExpression(argument))) {
|
|
103
|
+
return false;
|
|
66
104
|
}
|
|
67
|
-
|
|
105
|
+
const returned = returnedExpressions(argument);
|
|
106
|
+
return returned.length > 0 && returned.every((value) => isFiniteRxjsSource(value, checker));
|
|
107
|
+
}
|
|
108
|
+
function isFiniteRxjsSource(value, checker) {
|
|
109
|
+
if (ts.isCallExpression(value))
|
|
110
|
+
return importedName(value.expression, checker, ['rxjs']) === 'of';
|
|
111
|
+
return importedName(value, checker, ['rxjs']) === 'EMPTY';
|
|
112
|
+
}
|
|
113
|
+
function isNonpositiveCount(argument) {
|
|
114
|
+
if (!argument)
|
|
115
|
+
return false;
|
|
116
|
+
const count = ts.skipOuterExpressions(argument);
|
|
117
|
+
if (ts.isNumericLiteral(count))
|
|
118
|
+
return Number(count.text) === 0;
|
|
119
|
+
return (ts.isPrefixUnaryExpression(count) &&
|
|
120
|
+
count.operator === ts.SyntaxKind.MinusToken &&
|
|
121
|
+
ts.isNumericLiteral(count.operand));
|
|
68
122
|
}
|
|
69
123
|
function isRxjsSubject(source, checker) {
|
|
70
124
|
const symbol = checker.getTypeAtLocation(source).getSymbol();
|
|
@@ -94,27 +148,25 @@ function classifySource(source, checker) {
|
|
|
94
148
|
}
|
|
95
149
|
// undefined: not an RxJS subscription, or one that ends on its own. Otherwise 'endless' or
|
|
96
150
|
// 'unknown'.
|
|
97
|
-
function unmanagedSubscription(call, checker) {
|
|
151
|
+
function unmanagedSubscription(call, checker, teardown) {
|
|
98
152
|
const callee = ts.skipOuterExpressions(call.expression);
|
|
99
153
|
if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== 'subscribe')
|
|
100
154
|
return;
|
|
101
155
|
if (!declaredInPackage(callee, checker, ['rxjs']))
|
|
102
156
|
return;
|
|
103
|
-
const { source,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
157
|
+
const { source, effects } = unwrapPipes(callee.expression, checker, teardown);
|
|
158
|
+
let kind = classifySource(source, checker);
|
|
159
|
+
for (const effect of effects) {
|
|
160
|
+
if (effect === 'complete')
|
|
161
|
+
kind = 'completing';
|
|
162
|
+
// Completing the outer stream can leave an active inner subscription.
|
|
163
|
+
else if (kind === 'completing')
|
|
164
|
+
kind = 'unknown';
|
|
165
|
+
}
|
|
107
166
|
return kind === 'completing' ? undefined : kind;
|
|
108
167
|
}
|
|
109
168
|
// --- React
|
|
110
169
|
// ---------------------------------------------------------------------------------------------------
|
|
111
|
-
function leakedEffectResource(body, checker) {
|
|
112
|
-
let leak;
|
|
113
|
-
walkSkippingFunctions(body, (node) => {
|
|
114
|
-
leak ??= leakOfNode(node, checker);
|
|
115
|
-
});
|
|
116
|
-
return leak;
|
|
117
|
-
}
|
|
118
170
|
function leakOfNode(node, checker) {
|
|
119
171
|
if (ts.isNewExpression(node))
|
|
120
172
|
return leakOfConstructor(node, checker);
|
|
@@ -122,39 +174,53 @@ function leakOfNode(node, checker) {
|
|
|
122
174
|
return;
|
|
123
175
|
const name = calleeName(node);
|
|
124
176
|
if (name === 'setInterval' && isBrowserGlobal(node.expression, checker))
|
|
125
|
-
return { label: 'setInterval()' };
|
|
177
|
+
return { label: 'setInterval()', release: 'clearInterval' };
|
|
126
178
|
const callee = ts.skipOuterExpressions(node.expression);
|
|
127
179
|
if (name === 'addEventListener' &&
|
|
128
180
|
ts.isPropertyAccessExpression(callee) &&
|
|
129
181
|
isGlobalEventTarget(callee.expression, checker)) {
|
|
130
|
-
return { label: 'addEventListener()' };
|
|
182
|
+
return { label: 'addEventListener()', release: 'removeEventListener' };
|
|
131
183
|
}
|
|
132
184
|
const kind = unmanagedSubscription(node, checker);
|
|
133
185
|
if (kind)
|
|
134
|
-
return {
|
|
186
|
+
return {
|
|
187
|
+
label: 'subscribe()',
|
|
188
|
+
release: 'unsubscribe',
|
|
189
|
+
reason: kind === 'unknown' ? SUBSCRIBE_MAY_COMPLETE_REASON : undefined,
|
|
190
|
+
};
|
|
135
191
|
}
|
|
136
192
|
function leakOfConstructor(node, checker) {
|
|
137
193
|
if (!ts.isIdentifier(node.expression) || !isBrowserGlobal(node.expression, checker))
|
|
138
194
|
return;
|
|
139
195
|
const name = node.expression.text;
|
|
140
196
|
if (DEFINITE_LEAK_CONSTRUCTORS.has(name))
|
|
141
|
-
return { label: `new ${name}()
|
|
197
|
+
return { label: `new ${name}()`, release: 'close' };
|
|
142
198
|
if (OBSERVER_CONSTRUCTORS.has(name))
|
|
143
|
-
return { label: `new ${name}()`, reason: OBSERVER_REASON };
|
|
144
|
-
}
|
|
145
|
-
function
|
|
146
|
-
|
|
147
|
-
let
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
199
|
+
return { label: `new ${name}()`, release: 'disconnect', reason: OBSERVER_REASON };
|
|
200
|
+
}
|
|
201
|
+
function cleanupInvalidatesFetch(cleanup, call, checker) {
|
|
202
|
+
// The stale-response flag belongs to this request only if its promise chain reads that flag.
|
|
203
|
+
let chain = call;
|
|
204
|
+
while (ts.isPropertyAccessExpression(chain.parent) &&
|
|
205
|
+
chain.parent.expression === chain &&
|
|
206
|
+
ts.isCallExpression(chain.parent.parent))
|
|
207
|
+
chain = chain.parent.parent;
|
|
208
|
+
return effectDisposes(cleanup, call, checker, (expression) => {
|
|
209
|
+
if (!ts.isBinaryExpression(expression) ||
|
|
210
|
+
expression.operatorToken.kind !== ts.SyntaxKind.EqualsToken ||
|
|
211
|
+
!ts.isIdentifier(expression.left) ||
|
|
212
|
+
![ts.SyntaxKind.FalseKeyword, ts.SyntaxKind.TrueKeyword].includes(expression.right.kind))
|
|
213
|
+
return false;
|
|
214
|
+
const symbol = checker.getSymbolAtLocation(expression.left);
|
|
215
|
+
if (!symbol)
|
|
216
|
+
return false;
|
|
217
|
+
let read = false;
|
|
218
|
+
walkAll(chain, (node) => {
|
|
219
|
+
if (ts.isIdentifier(node) && checker.getSymbolAtLocation(node) === symbol)
|
|
220
|
+
read = true;
|
|
221
|
+
});
|
|
222
|
+
return read;
|
|
156
223
|
});
|
|
157
|
-
return hasAbort ? undefined : fetchCall;
|
|
158
224
|
}
|
|
159
225
|
function passesSignal(fetchCall) {
|
|
160
226
|
const options = fetchCall.arguments[1] && ts.skipOuterExpressions(fetchCall.arguments[1]);
|
|
@@ -189,21 +255,34 @@ function isFireAndForgetMutation(fetchCall) {
|
|
|
189
255
|
}
|
|
190
256
|
function checkReactEffect(call, context) {
|
|
191
257
|
const effect = effectCallback(call, context.checker);
|
|
192
|
-
if (!effect
|
|
193
|
-
return;
|
|
194
|
-
const leak = leakedEffectResource(effect.body, context.checker);
|
|
195
|
-
if (leak) {
|
|
196
|
-
context.report(call, 'react-missing-cleanup', `\`${effect.hook}\` allocates \`${leak.label}\` without returning a cleanup function, leaking listeners, timers, or subscriptions across remounts. Return a cleanup callback that disposes it.`, leak.reason);
|
|
197
|
-
}
|
|
198
|
-
const fetchCall = findFetchWithoutAbort(effect.body, context.checker);
|
|
199
|
-
if (!fetchCall)
|
|
258
|
+
if (!effect)
|
|
200
259
|
return;
|
|
260
|
+
const cleanup = effectCleanup(effect.body);
|
|
261
|
+
walkSkippingFunctions(effect.body, (node) => {
|
|
262
|
+
const leak = leakOfNode(node, context.checker);
|
|
263
|
+
if (!leak ||
|
|
264
|
+
effectDisposes(cleanup, node, context.checker, (release) => releases(node, leak.release, release, context.checker)))
|
|
265
|
+
return;
|
|
266
|
+
context.report(node, 'react-missing-cleanup', `\`${effect.hook}\` allocates \`${leak.label}\` without matching teardown. Return a cleanup callback that disposes this resource.`, leak.reason);
|
|
267
|
+
});
|
|
268
|
+
walkAll(effect.body, (node) => {
|
|
269
|
+
if (!ts.isCallExpression(node) ||
|
|
270
|
+
!ts.isIdentifier(node.expression) ||
|
|
271
|
+
node.expression.text !== 'fetch' ||
|
|
272
|
+
!isBrowserGlobal(node.expression, context.checker) ||
|
|
273
|
+
passesSignal(node) ||
|
|
274
|
+
cleanupInvalidatesFetch(cleanup, node, context.checker))
|
|
275
|
+
return;
|
|
276
|
+
reportFetch(node, call, effect.hook, context);
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
function reportFetch(fetchCall, call, hook, context) {
|
|
201
280
|
const reason = isFireAndForgetMutation(fetchCall)
|
|
202
281
|
? 'Fire-and-forget mutating request whose response is unused.'
|
|
203
282
|
: hasNonEmptyDependencies(call)
|
|
204
283
|
? undefined
|
|
205
284
|
: FETCH_STATIC_DEPS_REASON;
|
|
206
|
-
context.report(fetchCall, 'react-fetch-in-effect-no-abort', `\`fetch()\` inside \`${
|
|
285
|
+
context.report(fetchCall, 'react-fetch-in-effect-no-abort', `\`fetch()\` inside \`${hook}\` has no \`AbortController\` cleanup, so fast navigation or dependency changes can trigger race conditions and stale state updates. Pass \`signal: controller.signal\` and call \`controller.abort()\` in the cleanup function.`, reason);
|
|
207
286
|
}
|
|
208
287
|
function isArrayExpression(expression, checker) {
|
|
209
288
|
const type = checker.getNonNullableType(checker.getTypeAtLocation(expression));
|
|
@@ -330,20 +409,6 @@ function checkAngularChangeDetection(classNode, context) {
|
|
|
330
409
|
return;
|
|
331
410
|
context.report(component.decorator, 'angular-default-change-detection', 'This Angular `@Component` uses the default change detection strategy, re-checking the entire component subtree on every browser event. Set `changeDetection: ChangeDetectionStrategy.OnPush` where inputs are immutable or driven by observables/signals.', ON_PUSH_REASON);
|
|
332
411
|
}
|
|
333
|
-
function destroyHookReleases(classNode) {
|
|
334
|
-
const hook = classNode.members.find((member) => ts.isMethodDeclaration(member) && ts.isIdentifier(member.name) && member.name.text === 'ngOnDestroy');
|
|
335
|
-
if (!hook?.body)
|
|
336
|
-
return false;
|
|
337
|
-
let releases = false;
|
|
338
|
-
walkAll(hook.body, (node) => {
|
|
339
|
-
if (ts.isCallExpression(node)) {
|
|
340
|
-
const name = calleeName(node);
|
|
341
|
-
if (name !== undefined && ['unsubscribe', 'next', 'complete'].includes(name))
|
|
342
|
-
releases = true;
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
return releases;
|
|
346
|
-
}
|
|
347
412
|
function checkAngularClass(classNode, context) {
|
|
348
413
|
if (!ts.canHaveDecorators(classNode) || !ts.getDecorators(classNode)?.length)
|
|
349
414
|
return;
|
|
@@ -353,15 +418,17 @@ function checkAngularClass(classNode, context) {
|
|
|
353
418
|
checkNgForTrackBy(component.metadata, context);
|
|
354
419
|
if (!isAngularComponentOrDirective(classNode, context.checker))
|
|
355
420
|
return;
|
|
356
|
-
|
|
357
|
-
return;
|
|
421
|
+
const teardown = angularTeardown(classNode, context.checker);
|
|
358
422
|
walkAll(classNode, (node) => {
|
|
359
423
|
if (!ts.isCallExpression(node))
|
|
360
424
|
return;
|
|
361
|
-
const
|
|
425
|
+
const field = subscriptionField(node, teardown);
|
|
426
|
+
if (field && teardown.subscriptions.has(field))
|
|
427
|
+
return;
|
|
428
|
+
const kind = unmanagedSubscription(node, context.checker, teardown);
|
|
362
429
|
if (!kind)
|
|
363
430
|
return;
|
|
364
|
-
context.report(node, 'angular-subscribe-without-cleanup', 'This RxJS `.subscribe()` inside an Angular component/directive
|
|
431
|
+
context.report(node, 'angular-subscribe-without-cleanup', 'This RxJS `.subscribe()` inside an Angular component/directive can outlive the component. Prefer the `async` pipe, `toSignal()`, or place `takeUntilDestroyed()` after operators that create inner subscriptions.', kind === 'unknown' ? SUBSCRIBE_MAY_COMPLETE_REASON : undefined);
|
|
365
432
|
});
|
|
366
433
|
}
|
|
367
434
|
// --- Vue
|
|
@@ -380,7 +447,15 @@ function scopeRegistersUnmount(scope, checker) {
|
|
|
380
447
|
if (!ts.isCallExpression(node))
|
|
381
448
|
return;
|
|
382
449
|
const name = importedName(node.expression, checker, VUE_MODULES);
|
|
383
|
-
if (name
|
|
450
|
+
if (name !== 'onUnmounted' && name !== 'onBeforeUnmount' && name !== 'onScopeDispose')
|
|
451
|
+
return;
|
|
452
|
+
const cleanup = node.arguments[0] && ts.skipOuterExpressions(node.arguments[0]);
|
|
453
|
+
if (cleanup &&
|
|
454
|
+
(ts.isArrowFunction(cleanup) || ts.isFunctionExpression(cleanup)) &&
|
|
455
|
+
ts.isBlock(cleanup.body) &&
|
|
456
|
+
cleanup.body.statements.every(ts.isEmptyStatement))
|
|
457
|
+
return;
|
|
458
|
+
if (cleanup)
|
|
384
459
|
registers = true;
|
|
385
460
|
});
|
|
386
461
|
return registers;
|
|
@@ -403,7 +478,7 @@ function checkVueMounted(call, context) {
|
|
|
403
478
|
const leak = vueLeakInCallback(callback, context.checker);
|
|
404
479
|
if (!leak)
|
|
405
480
|
return;
|
|
406
|
-
context.report(call, 'vue-watch-missing-cleanup', `\`onMounted\` registers \`${leak.label}\` without
|
|
481
|
+
context.report(call, 'vue-watch-missing-cleanup', `\`onMounted\` registers \`${leak.label}\` without an apparent unmount cleanup, leaking resources when the Vue component unmounts. Release it with \`onUnmounted\` or \`onScopeDispose\`.`, leak.reason);
|
|
407
482
|
}
|
|
408
483
|
function hasKeyProperty(propsArgument) {
|
|
409
484
|
const props = ts.skipOuterExpressions(propsArgument);
|
|
@@ -138,15 +138,27 @@ export function tableArgument(node) {
|
|
|
138
138
|
return stringArgument(objectProperty(value.arguments?.[0], 'name')?.initializer);
|
|
139
139
|
return stringArgument(value);
|
|
140
140
|
}
|
|
141
|
-
export function
|
|
141
|
+
export function transactionCallbackScope(node, upFunction, framework) {
|
|
142
|
+
let transactionScope;
|
|
143
|
+
let transactionConnectionScope;
|
|
144
|
+
let nestedReceiver;
|
|
142
145
|
for (let current = node.parent; current && current !== upFunction; current = current.parent) {
|
|
143
146
|
if (!isFunctionLike(current) || !ts.isCallExpression(current.parent))
|
|
144
147
|
continue;
|
|
145
148
|
const parts = calleeParts(current.parent);
|
|
146
|
-
if (parts?.method
|
|
147
|
-
|
|
149
|
+
if (parts?.method !== 'transaction')
|
|
150
|
+
continue;
|
|
151
|
+
const parameter = current.parameters[0]?.name;
|
|
152
|
+
if (transactionScope !== undefined &&
|
|
153
|
+
(!parameter || !ts.isIdentifier(parameter) || parameter.text !== nestedReceiver))
|
|
154
|
+
break;
|
|
155
|
+
transactionScope ??= current.getStart();
|
|
156
|
+
transactionConnectionScope = current.getStart();
|
|
157
|
+
if (framework !== 'knex' || !ts.isIdentifier(parts.receiver))
|
|
158
|
+
break;
|
|
159
|
+
nestedReceiver = parts.receiver.text;
|
|
148
160
|
}
|
|
149
|
-
return
|
|
161
|
+
return transactionScope === undefined ? undefined : { transactionScope, transactionConnectionScope };
|
|
150
162
|
}
|
|
151
163
|
// Parses a raw SQL default (TypeORM `default`, `Sequelize.literal`, `knex.raw`) into an expression
|
|
152
164
|
// node.
|
|
@@ -5,7 +5,7 @@ import ts from 'typescript';
|
|
|
5
5
|
import { createOperation } from './operations.js';
|
|
6
6
|
import { builderOperations, isRawSqlCall, rawSqlOperations } from './extract-code-builders.js';
|
|
7
7
|
import { defaultTransaction, detectFramework, findDeclaration, findUpFunctions, isFunctionLike, propertyName, scriptKindFor, unwrapExpression, } from './extract-code-discovery.js';
|
|
8
|
-
import { EMPTY_BINDINGS, calleeParts,
|
|
8
|
+
import { EMPTY_BINDINGS, calleeParts, transactionCallbackScope, positionOf, receiverName } from './extract-code-sql.js';
|
|
9
9
|
const MAX_HELPER_DEPTH = 3;
|
|
10
10
|
// `this.helper(...)` resolves to a method of the migration class; `helper(...)` to a function
|
|
11
11
|
// declared in the file.
|
|
@@ -66,6 +66,10 @@ function functionOperations(fn, context, scope) {
|
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
68
|
const parts = calleeParts(node);
|
|
69
|
+
const transaction = transactionCallbackScope(node, fn, context.framework) ?? {
|
|
70
|
+
transactionScope: scope.transactionScope,
|
|
71
|
+
transactionConnectionScope: scope.transactionConnectionScope,
|
|
72
|
+
};
|
|
69
73
|
if (parts) {
|
|
70
74
|
const receiverText = receiverName(parts.receiver, context.sourceFile);
|
|
71
75
|
const found = isRawSqlCall(parts.method, receiverText, context)
|
|
@@ -75,16 +79,20 @@ function functionOperations(fn, context, scope) {
|
|
|
75
79
|
// The receiver of a chained builder call (`schema.createTable(...).alterTable(...)`) runs
|
|
76
80
|
// first. Arguments, including Knex alterTable callbacks, were already read with their call.
|
|
77
81
|
visit(parts.receiver);
|
|
78
|
-
const explicitTransaction = scope.explicitTransaction || isInsideTransactionCallback(node, fn);
|
|
79
82
|
for (const fields of found) {
|
|
80
|
-
operations.push(createOperation({
|
|
83
|
+
operations.push(createOperation({
|
|
84
|
+
file: context.file,
|
|
85
|
+
...fields,
|
|
86
|
+
explicitTransaction: transaction.transactionScope !== undefined,
|
|
87
|
+
...transaction,
|
|
88
|
+
}));
|
|
81
89
|
}
|
|
82
90
|
return;
|
|
83
91
|
}
|
|
84
92
|
}
|
|
85
93
|
const helperOperations = helperCallOperations(node, context, {
|
|
86
94
|
...scope,
|
|
87
|
-
|
|
95
|
+
...transaction,
|
|
88
96
|
});
|
|
89
97
|
if (helperOperations.length > 0) {
|
|
90
98
|
ts.forEachChild(node, visit);
|
|
@@ -102,7 +110,7 @@ function upFunctionOperations(upFunction, owner, context) {
|
|
|
102
110
|
return [];
|
|
103
111
|
const firstParameter = upFunction.parameters[0]?.name.getText(context.sourceFile);
|
|
104
112
|
const unitContext = { ...context, firstParameter, bindings: EMPTY_BINDINGS };
|
|
105
|
-
return functionOperations(upFunction, unitContext, { owner, helpers: [upFunction]
|
|
113
|
+
return functionOperations(upFunction, unitContext, { owner, helpers: [upFunction] });
|
|
106
114
|
}
|
|
107
115
|
function extractCodeFile(text, { file, dialect }) {
|
|
108
116
|
const sourceFile = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, scriptKindFor(file));
|