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.
Files changed (228) hide show
  1. package/README.md +23 -15
  2. package/dist/bin/loadwise.js +12 -24
  3. package/dist/lib/accessibility/analyze.js +5 -3
  4. package/dist/lib/accessibility/angular-inline.js +9 -11
  5. package/dist/lib/accessibility/angular-literal.js +39 -0
  6. package/dist/lib/accessibility/form-context.js +36 -0
  7. package/dist/lib/accessibility/frame-head.js +92 -0
  8. package/dist/lib/accessibility/frame-viewport.js +149 -0
  9. package/dist/lib/accessibility/jsx-elements.js +13 -3
  10. package/dist/lib/accessibility/markup-files.js +7 -2
  11. package/dist/lib/accessibility/rule-ids.js +3 -0
  12. package/dist/lib/accessibility/rules.js +128 -41
  13. package/dist/lib/accessibility/site-fixes/buttons.js +5 -1
  14. package/dist/lib/accessibility/template-attributes.js +5 -3
  15. package/dist/lib/accessibility/template-elements.js +25 -6
  16. package/dist/lib/accessibility/template-file.js +40 -25
  17. package/dist/lib/editor/accessibility-examples.js +6 -1
  18. package/dist/lib/editor/actions.js +46 -7
  19. package/dist/lib/editor/apply-fix.js +69 -4
  20. package/dist/lib/editor/configured-setup.js +5 -3
  21. package/dist/lib/editor/diagnostics.js +206 -17
  22. package/dist/lib/editor/dismissals.js +85 -26
  23. package/dist/lib/editor/editor-document.js +5 -2
  24. package/dist/lib/editor/editor-launcher.js +7 -2
  25. package/dist/lib/editor/language-server.js +64 -25
  26. package/dist/lib/editor/native-setup.js +3 -2
  27. package/dist/lib/editor/perf-watch.js +8 -6
  28. package/dist/lib/editor/reliability-examples.js +15 -0
  29. package/dist/lib/editor/scan-session.js +29 -8
  30. package/dist/lib/editor/server-commands.js +36 -9
  31. package/dist/lib/editor/setup-server.js +1 -1
  32. package/dist/lib/editor/setup-vim.js +6 -4
  33. package/dist/lib/editor/workspace-files.js +61 -7
  34. package/dist/lib/editor/workspace-paths.js +41 -1
  35. package/dist/lib/maintainability/analysis/analyze-source.js +1 -1
  36. package/dist/lib/maintainability/architecture/architecture.js +4 -4
  37. package/dist/lib/maintainability/cli/changed-lines.js +20 -2
  38. package/dist/lib/maintainability/cli/inputs.js +9 -1
  39. package/dist/lib/maintainability/cli.js +4 -0
  40. package/dist/lib/maintainability/entry-points/entry-points.js +44 -15
  41. package/dist/lib/maintainability/entry-points/html-entry-points.js +5 -1
  42. package/dist/lib/maintainability/quality/functions.js +9 -6
  43. package/dist/lib/maintainability/quality/limits.js +19 -0
  44. package/dist/lib/maintainability/quality/size-limits.js +8 -2
  45. package/dist/lib/maintainability/quality/stray-console.js +62 -1
  46. package/dist/lib/maintainability/quality/tsconfig-strict.js +2 -0
  47. package/dist/lib/maintainability/scan-changed.js +4 -1
  48. package/dist/lib/maintainability/scan-worker.js +6 -2
  49. package/dist/lib/maintainability/scan.js +21 -8
  50. package/dist/lib/maintainability/unused/module-usage.js +43 -21
  51. package/dist/lib/maintainability/unused/unused-modules.js +5 -10
  52. package/dist/lib/performance/analysis/source-inputs.js +7 -2
  53. package/dist/lib/performance/analysis/source-options.js +7 -6
  54. package/dist/lib/performance/analyze.js +16 -3
  55. package/dist/lib/performance/cli/cli-output.js +1 -0
  56. package/dist/lib/performance/cli/cli-scan.js +21 -2
  57. package/dist/lib/performance/cli.js +8 -3
  58. package/dist/lib/performance/collections/memory-growth.js +55 -12
  59. package/dist/lib/performance/contracts/openapi.js +13 -4
  60. package/dist/lib/performance/datastores/pg-integrity.js +61 -22
  61. package/dist/lib/performance/datastores/pg-session-release.js +114 -0
  62. package/dist/lib/performance/datastores/pg-session-sql.js +144 -0
  63. package/dist/lib/performance/datastores/pooling.js +56 -2
  64. package/dist/lib/performance/datastores/redis.js +94 -18
  65. package/dist/lib/performance/datastores/session-store.js +2 -1
  66. package/dist/lib/performance/db/checks.js +19 -8
  67. package/dist/lib/performance/db/gateway.js +3 -1
  68. package/dist/lib/performance/db/plan-estimates.js +4 -4
  69. package/dist/lib/performance/engine/native.js +11 -7
  70. package/dist/lib/performance/evidence/plans.js +7 -5
  71. package/dist/lib/performance/evidence/traces.js +21 -1
  72. package/dist/lib/performance/frontend/angular-teardown.js +96 -0
  73. package/dist/lib/performance/frontend/effect-cleanup.js +148 -0
  74. package/dist/lib/performance/frontend/frontend-dom-perf.js +14 -2
  75. package/dist/lib/performance/frontend/frontend-helpers.js +1 -9
  76. package/dist/lib/performance/frontend/frontend-perf.js +72 -57
  77. package/dist/lib/performance/migrations/extract-code-sql.js +16 -4
  78. package/dist/lib/performance/migrations/extract-code.js +13 -5
  79. package/dist/lib/performance/migrations/extract-sql.js +82 -38
  80. package/dist/lib/performance/migrations/operations.js +56 -13
  81. package/dist/lib/performance/migrations/postgres-lock-timeout.js +52 -0
  82. package/dist/lib/performance/migrations/postgres-registry.js +127 -26
  83. package/dist/lib/performance/migrations/postgres-settings.js +78 -0
  84. package/dist/lib/performance/migrations/rules-postgres-add-column.js +3 -3
  85. package/dist/lib/performance/migrations/rules-postgres-shared.js +9 -0
  86. package/dist/lib/performance/migrations/rules-postgres.js +88 -39
  87. package/dist/lib/performance/orm/offset-pagination.js +6 -4
  88. package/dist/lib/performance/orm/prisma-aggregates.js +69 -18
  89. package/dist/lib/performance/orm/unbounded-list-chain.js +29 -0
  90. package/dist/lib/performance/orm/unbounded-list-queries.js +18 -13
  91. package/dist/lib/performance/polyglot.js +111 -14
  92. package/dist/lib/performance/projects.js +3 -3
  93. package/dist/lib/performance/query-loops/sequential-loops.js +1 -0
  94. package/dist/lib/performance/request/backend-mastery.js +151 -42
  95. package/dist/lib/performance/request/mongoose-lean.js +175 -10
  96. package/dist/lib/performance/request/phase5-rules.js +74 -13
  97. package/dist/lib/performance/request/sql-select-star.js +150 -0
  98. package/dist/lib/performance/request/unbounded-promise-all.js +54 -29
  99. package/dist/lib/performance/request/upload-limits.js +5 -1
  100. package/dist/lib/performance/site-fix.js +4 -4
  101. package/dist/lib/performance/site-fixes/backend-mastery-fixes.js +298 -16
  102. package/dist/lib/performance/site-fixes/frontend-fixes.js +350 -10
  103. package/dist/lib/performance/site-fixes/migration-context.js +8 -1
  104. package/dist/lib/performance/site-fixes/migration-lock-rules.js +66 -30
  105. package/dist/lib/performance/site-fixes/prisma-aggregates.js +29 -9
  106. package/dist/lib/performance/site-fixes/small-rewrites.js +168 -10
  107. package/dist/lib/performance/site-fixes/sync-calls.js +14 -12
  108. package/dist/lib/performance/site-fixes/upload-limits.js +13 -7
  109. package/dist/lib/performance/sql/mysql-tokens.js +38 -12
  110. package/dist/lib/reliability/boundary-access.js +114 -57
  111. package/dist/lib/reliability/react-bugs.js +18 -4
  112. package/dist/lib/reliability/resource-leak-intervals.js +258 -0
  113. package/dist/lib/reliability/resource-leaks.js +209 -195
  114. package/dist/lib/reliability/rule-ids.js +10 -1
  115. package/dist/lib/reliability/site-fixes/resource-leaks.js +16 -1
  116. package/dist/lib/reliability/swallowed-errors.js +107 -21
  117. package/dist/lib/reliability/test-cleanup-after-await.js +92 -18
  118. package/dist/lib/reliability/walk.js +3 -2
  119. package/dist/lib/security/auth-crypto/hashing.js +24 -8
  120. package/dist/lib/security/auth-crypto/jwt.js +21 -6
  121. package/dist/lib/security/auth-crypto/secrets.js +44 -1
  122. package/dist/lib/security/auth-crypto/shared.js +3 -1
  123. package/dist/lib/security/auth-crypto/signing-algorithm.js +79 -0
  124. package/dist/lib/security/auth-crypto/transport-and-ciphers.js +85 -1
  125. package/dist/lib/security/cli.js +6 -2
  126. package/dist/lib/security/cookie-credentials.js +115 -0
  127. package/dist/lib/security/cookie-csrf.js +241 -0
  128. package/dist/lib/security/deps/advisory.js +50 -109
  129. package/dist/lib/security/deps/cli.js +1 -1
  130. package/dist/lib/security/deps/cvss-score.js +14 -0
  131. package/dist/lib/security/deps/fixed-version.js +97 -0
  132. package/dist/lib/security/deps/lockfiles.js +135 -74
  133. package/dist/lib/security/deps/osv.js +11 -3
  134. package/dist/lib/security/deps/scan.js +47 -20
  135. package/dist/lib/security/deps/yarn-lock.js +158 -0
  136. package/dist/lib/security/examples/injection.cjs +4 -0
  137. package/dist/lib/security/exposure/cookies.js +17 -2
  138. package/dist/lib/security/exposure/cors-origin-regex.js +2 -3
  139. package/dist/lib/security/exposure/frontend-security.js +21 -14
  140. package/dist/lib/security/exposure/jsx-url.js +18 -33
  141. package/dist/lib/security/exposure/logging.js +49 -10
  142. package/dist/lib/security/exposure/prototype-pollution.js +126 -56
  143. package/dist/lib/security/exposure/react-html.js +26 -0
  144. package/dist/lib/security/exposure/reflected-xss.js +34 -5
  145. package/dist/lib/security/files/compose.js +126 -1
  146. package/dist/lib/security/files/dockerfile.js +62 -4
  147. package/dist/lib/security/files/index.js +1 -1
  148. package/dist/lib/security/injection/command.js +46 -18
  149. package/dist/lib/security/injection/index.js +2 -0
  150. package/dist/lib/security/injection/ldap.js +86 -0
  151. package/dist/lib/security/injection/nosql.js +28 -4
  152. package/dist/lib/security/injection/redos.js +1 -1
  153. package/dist/lib/security/injection/rule-ids.js +1 -0
  154. package/dist/lib/security/injection/shared.js +5 -1
  155. package/dist/lib/security/injection/sql.js +28 -13
  156. package/dist/lib/security/lexical-declaration.js +113 -0
  157. package/dist/lib/security/pg-dynamic-query.js +28 -1
  158. package/dist/lib/security/pg-identifier-guards.js +107 -3
  159. package/dist/lib/security/phase5-rules.js +26 -135
  160. package/dist/lib/security/polyglot.js +2 -2
  161. package/dist/lib/security/redirect-settings.js +98 -0
  162. package/dist/lib/security/request-forgery/open-redirect.js +18 -5
  163. package/dist/lib/security/request-forgery/path-traversal.js +84 -6
  164. package/dist/lib/security/request-forgery/shared.js +1 -7
  165. package/dist/lib/security/request-forgery/ssrf.js +176 -14
  166. package/dist/lib/security/rule-descriptions.js +5 -1
  167. package/dist/lib/security/rule-ids.js +7 -0
  168. package/dist/lib/security/site-fixes/auth-crypto.js +5 -78
  169. package/dist/lib/security/site-fixes/exposure.js +21 -3
  170. package/dist/lib/security/site-fixes/files.js +11 -13
  171. package/dist/lib/security/site-fixes/frontend-security-fixes.js +2 -2
  172. package/dist/lib/security/site-fixes/injection.js +17 -4
  173. package/dist/lib/security/site-fixes/jwt.js +1 -20
  174. package/dist/lib/security/site-fixes/request-forgery.js +37 -29
  175. package/dist/lib/security/taint/binding-inputs.js +236 -0
  176. package/dist/lib/security/taint/filename-guard.js +45 -45
  177. package/dist/lib/security/taint/guards.js +14 -8
  178. package/dist/lib/security/taint/index.js +126 -154
  179. package/dist/lib/security/taint/propagate.js +43 -9
  180. package/dist/lib/security/taint/record-writes.js +161 -0
  181. package/dist/lib/security/taint/resolution-cache.js +13 -7
  182. package/dist/lib/security/taint/sanitizers.js +89 -5
  183. package/dist/lib/security/taint/trace-nodes.js +61 -0
  184. package/dist/lib/security/taint/validators.js +89 -9
  185. package/dist/lib/shared/agent/agent-init.js +2 -1
  186. package/dist/lib/shared/agent/agent-verify.js +4 -1
  187. package/dist/lib/shared/agent/git-hook.js +17 -6
  188. package/dist/lib/shared/agent/review-mcp.js +8 -2
  189. package/dist/lib/shared/analysis/ast-semantics.js +2 -2
  190. package/dist/lib/shared/analysis/scan-cache.js +96 -12
  191. package/dist/lib/shared/cli-dispatch.js +17 -0
  192. package/dist/lib/shared/config.js +27 -10
  193. package/dist/lib/shared/explain.js +1 -1
  194. package/dist/lib/shared/fix/fix-convergence.js +5 -3
  195. package/dist/lib/shared/fix/fix-imports.js +4 -171
  196. package/dist/lib/shared/fix/fix-presentation-comments.js +23 -9
  197. package/dist/lib/shared/fix/fix-presentation.js +5 -3
  198. package/dist/lib/shared/fix/fix-safety.js +7 -1
  199. package/dist/lib/shared/fix/fix-typecheck.js +8 -4
  200. package/dist/lib/shared/fix/import-text-edits.js +148 -0
  201. package/dist/lib/shared/fix.js +31 -7
  202. package/dist/lib/shared/formats/finding-location.js +4 -1
  203. package/dist/lib/shared/formats/github.js +3 -3
  204. package/dist/lib/shared/formats/sarif.js +9 -3
  205. package/dist/lib/shared/report-fp.js +6 -2
  206. package/dist/lib/shared/reporting/baseline.js +7 -5
  207. package/dist/lib/shared/reporting/pillars.js +9 -3
  208. package/dist/lib/shared/reporting/source-report.js +1 -0
  209. package/dist/lib/shared/system/glob.js +34 -8
  210. package/dist/lib/shared/system/sentry.js +26 -7
  211. package/dist/lib/shared/workspaces.js +15 -3
  212. package/package.json +5 -1
  213. package/plugin/.claude-plugin/plugin.json +1 -1
  214. package/plugin/hooks/check-edited-file.mjs +27 -5
  215. package/polyglot/performance/rules/csharp.yml +34 -5
  216. package/polyglot/performance/rules/java.yml +24 -1
  217. package/polyglot/performance/rules/python.yml +74 -2
  218. package/polyglot/performance/sgconfig.yml +1 -0
  219. package/polyglot/reliability/rules/csharp.yml +12 -6
  220. package/polyglot/reliability/rules/go.yml +86 -6
  221. package/polyglot/reliability/rules/java.yml +22 -1
  222. package/polyglot/reliability/sgconfig.yml +1 -0
  223. package/polyglot/security/rules/go.yml +100 -22
  224. package/polyglot/security/rules/python.yml +74 -6
  225. package/polyglot/security/rules/rust.yml +65 -0
  226. package/polyglot/security/sgconfig.yml +1 -0
  227. package/schema/loadwise.config.schema.json +554 -76
  228. /package/polyglot/{performance/rules → shared-rules}/input.yml +0 -0
@@ -0,0 +1,96 @@
1
+ import { ts } from '../engine/compiler.js';
2
+ import { propertyName } from '../schema/ts-helpers.js';
3
+ import { importedName, walkSkippingFunctions } from './frontend-helpers.js';
4
+ import { mayExit } from './effect-cleanup.js';
5
+ export function thisField(expression) {
6
+ return expression &&
7
+ ts.isPropertyAccessExpression(expression) &&
8
+ expression.expression.kind === ts.SyntaxKind.ThisKeyword
9
+ ? expression.name.text
10
+ : undefined;
11
+ }
12
+ export function subscriptionField(call, teardown) {
13
+ const parent = call.parent;
14
+ if (ts.isCallExpression(parent) &&
15
+ parent.arguments[0] === call &&
16
+ ts.isPropertyAccessExpression(parent.expression) &&
17
+ parent.expression.name.text === 'add') {
18
+ const composite = thisField(parent.expression.expression);
19
+ if (composite && teardown.composites.has(composite))
20
+ return composite;
21
+ }
22
+ if (ts.isPropertyDeclaration(parent) && parent.initializer === call)
23
+ return propertyName(parent);
24
+ if (ts.isBinaryExpression(parent) && parent.right === call && parent.operatorToken.kind === ts.SyntaxKind.EqualsToken)
25
+ return thisField(parent.left);
26
+ }
27
+ function releasedOnPath(statement, field, method, continuation) {
28
+ if (ts.isBlock(statement))
29
+ return statement.statements.reduceRight((next, child) => releasedOnPath(child, field, method, next), continuation);
30
+ if (ts.isIfStatement(statement)) {
31
+ const condition = ts.skipOuterExpressions(statement.expression);
32
+ if (thisField(condition) === field)
33
+ return releasedOnPath(statement.thenStatement, field, method, continuation);
34
+ const otherwise = !statement.elseStatement
35
+ ? continuation
36
+ : releasedOnPath(statement.elseStatement, field, method, continuation);
37
+ if (ts.isPrefixUnaryExpression(condition) &&
38
+ condition.operator === ts.SyntaxKind.ExclamationToken &&
39
+ thisField(condition.operand) === field)
40
+ return otherwise;
41
+ return otherwise && releasedOnPath(statement.thenStatement, field, method, continuation);
42
+ }
43
+ const expression = ts.isExpressionStatement(statement) || ts.isReturnStatement(statement) ? statement.expression : undefined;
44
+ return ((expression !== undefined && releasesField(expression, field, method)) || (continuation && !mayExit(statement)));
45
+ }
46
+ function releasesField(expression, field, method) {
47
+ const value = ts.skipOuterExpressions(expression);
48
+ if (ts.isBinaryExpression(value) && value.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken)
49
+ return thisField(ts.skipOuterExpressions(value.left)) === field && releasesField(value.right, field, method);
50
+ if (!ts.isCallExpression(value) || !ts.isPropertyAccessExpression(value.expression))
51
+ return false;
52
+ return value.expression.name.text === method && thisField(value.expression.expression) === field;
53
+ }
54
+ function collectReleases(body, teardown) {
55
+ const candidates = new Map();
56
+ walkSkippingFunctions(body, (node) => {
57
+ if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression))
58
+ return;
59
+ const method = node.expression.name.text;
60
+ const field = thisField(node.expression.expression);
61
+ if (!field || (method !== 'unsubscribe' && method !== 'next'))
62
+ return;
63
+ const fields = candidates.get(method) ?? new Set();
64
+ fields.add(field);
65
+ candidates.set(method, fields);
66
+ });
67
+ for (const [method, fields] of candidates) {
68
+ const released = method === 'unsubscribe' ? teardown.subscriptions : teardown.notifiers;
69
+ for (const field of fields)
70
+ if (releasedOnPath(body, field, method, false))
71
+ released.add(field);
72
+ }
73
+ }
74
+ export function angularTeardown(classNode, checker) {
75
+ const teardown = {
76
+ subscriptions: new Set(),
77
+ composites: new Set(),
78
+ notifiers: new Set(),
79
+ ownedNotifiers: new Set(),
80
+ };
81
+ for (const member of classNode.members) {
82
+ if (ts.isMethodDeclaration(member) && propertyName(member) === 'ngOnDestroy' && member.body)
83
+ collectReleases(member.body, teardown);
84
+ if (!ts.isPropertyDeclaration(member) || !member.initializer || !ts.isNewExpression(member.initializer))
85
+ continue;
86
+ const field = propertyName(member);
87
+ if (!field)
88
+ continue;
89
+ const type = importedName(member.initializer.expression, checker, ['rxjs']);
90
+ if (type === 'Subscription')
91
+ teardown.composites.add(field);
92
+ if (type === 'Subject' || type === 'ReplaySubject' || type === 'AsyncSubject')
93
+ teardown.ownedNotifiers.add(field);
94
+ }
95
+ return teardown;
96
+ }
@@ -0,0 +1,148 @@
1
+ import { ts } from '../engine/compiler.js';
2
+ import { isBrowserGlobal, walkSkippingFunctions } from './frontend-helpers.js';
3
+ // Unknown options can run getters or change between registration and removal.
4
+ export function listenerCapture(options) {
5
+ if (!options || options.kind === ts.SyntaxKind.FalseKeyword)
6
+ return false;
7
+ if (options.kind === ts.SyntaxKind.TrueKeyword)
8
+ return true;
9
+ if (!ts.isObjectLiteralExpression(options))
10
+ return;
11
+ let capture = false;
12
+ for (const property of options.properties) {
13
+ if (!ts.isPropertyAssignment(property) || ts.isComputedPropertyName(property.name))
14
+ return;
15
+ if (property.name.text !== 'capture')
16
+ continue;
17
+ if (property.initializer.kind === ts.SyntaxKind.TrueKeyword)
18
+ capture = true;
19
+ else if (property.initializer.kind === ts.SyntaxKind.FalseKeyword)
20
+ capture = false;
21
+ else
22
+ return;
23
+ }
24
+ return capture;
25
+ }
26
+ function sameValue(left, right, checker) {
27
+ if (!left || !right)
28
+ return false;
29
+ if (ts.isStringLiteralLike(left) && ts.isStringLiteralLike(right))
30
+ return left.text === right.text;
31
+ if (ts.isIdentifier(left) && ts.isIdentifier(right)) {
32
+ const symbol = checker.getSymbolAtLocation(left);
33
+ return !!symbol && symbol === checker.getSymbolAtLocation(right);
34
+ }
35
+ return (ts.isPropertyAccessExpression(left) &&
36
+ ts.isPropertyAccessExpression(right) &&
37
+ left.name.text === right.name.text &&
38
+ sameValue(left.expression, right.expression, checker));
39
+ }
40
+ export function releases(acquisition, method, release, checker) {
41
+ if (!ts.isCallExpression(release))
42
+ return false;
43
+ if (method === 'removeEventListener') {
44
+ if (!ts.isCallExpression(acquisition) ||
45
+ !ts.isPropertyAccessExpression(acquisition.expression) ||
46
+ !ts.isPropertyAccessExpression(release.expression) ||
47
+ release.expression.name.text !== method)
48
+ return false;
49
+ const capture = listenerCapture(acquisition.arguments[2]);
50
+ return (capture !== undefined &&
51
+ capture === listenerCapture(release.arguments[2]) &&
52
+ sameValue(acquisition.expression.expression, release.expression.expression, checker) &&
53
+ sameValue(acquisition.arguments[0], release.arguments[0], checker) &&
54
+ sameValue(acquisition.arguments[1], release.arguments[1], checker));
55
+ }
56
+ const owner = acquisition.parent;
57
+ if (!ts.isVariableDeclaration(owner) || !ts.isIdentifier(owner.name))
58
+ return false;
59
+ if (method === 'clearInterval')
60
+ return (((ts.isIdentifier(release.expression) && release.expression.text === method) ||
61
+ (ts.isPropertyAccessExpression(release.expression) && release.expression.name.text === method)) &&
62
+ isBrowserGlobal(release.expression, checker) &&
63
+ sameValue(owner.name, release.arguments[0], checker));
64
+ return (ts.isPropertyAccessExpression(release.expression) &&
65
+ release.expression.name.text === method &&
66
+ sameValue(owner.name, release.expression.expression, checker));
67
+ }
68
+ export function mayExit(node) {
69
+ if (ts.isFunctionLike(node))
70
+ return false;
71
+ return (ts.isReturnStatement(node) ||
72
+ ts.isThrowStatement(node) ||
73
+ (ts.forEachChild(node, (child) => mayExit(child) || undefined) ?? false));
74
+ }
75
+ function alwaysReturns(node) {
76
+ if (ts.isReturnStatement(node))
77
+ return true;
78
+ if (ts.isIfStatement(node))
79
+ return !!node.elseStatement && alwaysReturns(node.thenStatement) && alwaysReturns(node.elseStatement);
80
+ return ts.isBlock(node) && node.statements.some(alwaysReturns);
81
+ }
82
+ // Work backwards so both arms of an if share the same continuation without enumerating paths.
83
+ function disposesOnEveryPath(statement, continuation, matches) {
84
+ if (ts.isBlock(statement))
85
+ return statement.statements.reduceRight((next, child) => disposesOnEveryPath(child, next, matches), continuation);
86
+ if (ts.isIfStatement(statement))
87
+ return (disposesOnEveryPath(statement.thenStatement, continuation, matches) &&
88
+ (statement.elseStatement ? disposesOnEveryPath(statement.elseStatement, continuation, matches) : continuation));
89
+ if (ts.isReturnStatement(statement))
90
+ return !!statement.expression && matches(statement.expression);
91
+ if (ts.isExpressionStatement(statement))
92
+ return continuation || matches(statement.expression);
93
+ return continuation && !mayExit(statement);
94
+ }
95
+ function returnedDisposes(expression, matches) {
96
+ if (!expression)
97
+ return false;
98
+ const disposer = ts.skipOuterExpressions(expression);
99
+ if (ts.isConditionalExpression(disposer))
100
+ return returnedDisposes(disposer.whenTrue, matches) && returnedDisposes(disposer.whenFalse, matches);
101
+ if (!ts.isArrowFunction(disposer) && !ts.isFunctionExpression(disposer)) {
102
+ // A helper can own the resource even if its implementation is outside this callback.
103
+ return ((ts.isIdentifier(disposer) && disposer.text !== 'undefined') ||
104
+ ts.isCallExpression(disposer) ||
105
+ ts.isPropertyAccessExpression(disposer));
106
+ }
107
+ return ts.isBlock(disposer.body) ? disposesOnEveryPath(disposer.body, false, matches) : matches(disposer.body);
108
+ }
109
+ export function effectCleanup(body) {
110
+ const cleanup = { alwaysReturns: alwaysReturns(body), returns: [] };
111
+ if (cleanup.alwaysReturns)
112
+ walkSkippingFunctions(body, (node) => {
113
+ if (ts.isReturnStatement(node))
114
+ cleanup.returns.push(node);
115
+ });
116
+ return cleanup;
117
+ }
118
+ export function effectDisposes(cleanup, site, checker, matches) {
119
+ if (!cleanup.alwaysReturns)
120
+ return false;
121
+ const activeHelpers = new Set();
122
+ function matchesCleanup(expression) {
123
+ if (matches(expression))
124
+ return true;
125
+ if (!ts.isCallExpression(expression) || expression.arguments.length || !ts.isIdentifier(expression.expression))
126
+ return false;
127
+ const declaration = checker.getSymbolAtLocation(expression.expression)?.valueDeclaration;
128
+ if (!declaration || declaration.getSourceFile() !== site.getSourceFile())
129
+ return false;
130
+ const helper = ts.isVariableDeclaration(declaration) && declaration.parent.flags & ts.NodeFlags.Const && declaration.initializer
131
+ ? ts.skipOuterExpressions(declaration.initializer)
132
+ : declaration;
133
+ if ((!ts.isArrowFunction(helper) && !ts.isFunctionExpression(helper) && !ts.isFunctionDeclaration(helper)) ||
134
+ !helper.body ||
135
+ helper.asteriskToken ||
136
+ helper.parameters.length ||
137
+ activeHelpers.has(helper))
138
+ return false;
139
+ activeHelpers.add(helper);
140
+ const result = ts.isBlock(helper.body)
141
+ ? disposesOnEveryPath(helper.body, false, matchesCleanup)
142
+ : matchesCleanup(helper.body);
143
+ activeHelpers.delete(helper);
144
+ return result;
145
+ }
146
+ const exits = cleanup.returns.filter((exit) => exit.end > site.end);
147
+ return exits.length > 0 && exits.every((exit) => returnedDisposes(exit.expression, matchesCleanup));
148
+ }
@@ -293,15 +293,27 @@ function heavyBarrelOf(moduleName, clause) {
293
293
  return isNamespace ? { advice: FONTAWESOME_NAMESPACE_ADVICE } : undefined;
294
294
  }
295
295
  if (moduleName === MUI_ICONS_ROOT) {
296
- return isNamedOnly ? { advice: MUI_ICONS_ADVICE, reason: MUI_ICONS_NAMED_REASON } : undefined;
296
+ if (isNamedOnly)
297
+ return { advice: MUI_ICONS_ADVICE, reason: MUI_ICONS_NAMED_REASON };
298
+ return clause.namedBindings && ts.isNamespaceImport(clause.namedBindings)
299
+ ? { advice: MUI_ICONS_ADVICE }
300
+ : undefined;
297
301
  }
298
302
  const advice = HEAVY_CLIENT_BARRELS.get(moduleName);
299
- return advice === undefined ? undefined : { advice, reason: isNamedOnly ? LODASH_NAMED_REASON : undefined };
303
+ return advice === undefined
304
+ ? undefined
305
+ : { advice, reason: moduleName === 'lodash' && isNamedOnly ? LODASH_NAMED_REASON : undefined };
300
306
  }
301
307
  function checkHeavyBarrelImport(node, context) {
302
308
  const clause = node.importClause;
303
309
  if (!clause || clause.isTypeOnly || !ts.isStringLiteralLike(node.moduleSpecifier))
304
310
  return;
311
+ if (clause.namedBindings &&
312
+ ts.isNamedImports(clause.namedBindings) &&
313
+ clause.namedBindings.elements.length &&
314
+ !clause.name &&
315
+ clause.namedBindings.elements.every((specifier) => specifier.isTypeOnly))
316
+ return;
305
317
  const barrel = heavyBarrelOf(node.moduleSpecifier.text, clause);
306
318
  if (!barrel || !isClientModule(node.getSourceFile()))
307
319
  return;
@@ -69,14 +69,6 @@ function walkAll(root, visit) {
69
69
  ts.forEachChild(node, walk);
70
70
  })(root);
71
71
  }
72
- function containsReturnValue(body) {
73
- let found = false;
74
- walkSkippingFunctions(body, (node) => {
75
- if (ts.isReturnStatement(node) && node.expression)
76
- found = true;
77
- });
78
- return found;
79
- }
80
72
  function effectCallback(call, checker) {
81
73
  const callback = call.arguments[0] && ts.skipOuterExpressions(call.arguments[0]);
82
74
  const isFunction = callback && (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback));
@@ -90,4 +82,4 @@ function effectCallback(call, checker) {
90
82
  function isVueImport(expression, checker, exportName) {
91
83
  return importedName(expression, checker, VUE_MODULES) === exportName;
92
84
  }
93
- export { ANGULAR_MODULES, REACT_EFFECTS, REACT_MODULES, VUE_MODULES, calleeName, containsReturnValue, declaredInDomLibrary, domSymbolOf, effectCallback, importedName, isBrowserGlobal, isGlobalEventTarget, isVueImport, ownerNameOf, walkAll, walkSkippingFunctions, };
85
+ export { ANGULAR_MODULES, REACT_EFFECTS, REACT_MODULES, VUE_MODULES, calleeName, declaredInDomLibrary, domSymbolOf, effectCallback, importedName, isBrowserGlobal, isGlobalEventTarget, isVueImport, ownerNameOf, walkAll, walkSkippingFunctions, };
@@ -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, containsReturnValue, effectCallback, importedName, isBrowserGlobal, isGlobalEventTarget, isVueImport, walkAll, walkSkippingFunctions, } from './frontend-helpers.js';
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']);
@@ -54,20 +56,20 @@ const ON_PUSH_REASON = 'OnPush skips checks for @Input objects that are mutated
54
56
  // --- RxJS subscriptions
55
57
  // -------------------------------------------------------------------------------------
56
58
  // Keep the lifetime effects in pipeline order, including across separate pipe() calls.
57
- function unwrapPipes(expression, checker) {
59
+ function unwrapPipes(expression, checker, teardown) {
58
60
  const effects = [];
59
61
  let source = ts.skipOuterExpressions(expression);
60
62
  while (ts.isCallExpression(source) && ts.isPropertyAccessExpression(source.expression)) {
61
63
  const method = source.expression.name.text;
62
64
  if (method === 'pipe')
63
- effects.unshift(...operatorEffects(source.arguments, checker));
65
+ effects.unshift(...operatorEffects(source.arguments, checker, teardown));
64
66
  else if (method !== 'asObservable')
65
67
  break;
66
68
  source = ts.skipOuterExpressions(source.expression.expression);
67
69
  }
68
70
  return { source, effects };
69
71
  }
70
- function operatorEffects(pipeArguments, checker) {
72
+ function operatorEffects(pipeArguments, checker, teardown) {
71
73
  const effects = [];
72
74
  for (const argument of pipeArguments) {
73
75
  const operator = ts.skipOuterExpressions(argument);
@@ -76,6 +78,11 @@ function operatorEffects(pipeArguments, checker) {
76
78
  const name = importedName(operator.expression, checker, RXJS_OPERATOR_MODULES);
77
79
  if (!name)
78
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
+ }
79
86
  // RxJS implements a nonpositive takeLast count as an immediately completing stream.
80
87
  if (COMPLETING_OPERATORS.has(name) || (name === 'takeLast' && isNonpositiveCount(operator.arguments[0]))) {
81
88
  effects.push('complete');
@@ -141,13 +148,13 @@ function classifySource(source, checker) {
141
148
  }
142
149
  // undefined: not an RxJS subscription, or one that ends on its own. Otherwise 'endless' or
143
150
  // 'unknown'.
144
- function unmanagedSubscription(call, checker) {
151
+ function unmanagedSubscription(call, checker, teardown) {
145
152
  const callee = ts.skipOuterExpressions(call.expression);
146
153
  if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== 'subscribe')
147
154
  return;
148
155
  if (!declaredInPackage(callee, checker, ['rxjs']))
149
156
  return;
150
- const { source, effects } = unwrapPipes(callee.expression, checker);
157
+ const { source, effects } = unwrapPipes(callee.expression, checker, teardown);
151
158
  let kind = classifySource(source, checker);
152
159
  for (const effect of effects) {
153
160
  if (effect === 'complete')
@@ -160,13 +167,6 @@ function unmanagedSubscription(call, checker) {
160
167
  }
161
168
  // --- React
162
169
  // ---------------------------------------------------------------------------------------------------
163
- function leakedEffectResource(body, checker) {
164
- let leak;
165
- walkSkippingFunctions(body, (node) => {
166
- leak ??= leakOfNode(node, checker);
167
- });
168
- return leak;
169
- }
170
170
  function leakOfNode(node, checker) {
171
171
  if (ts.isNewExpression(node))
172
172
  return leakOfConstructor(node, checker);
@@ -174,39 +174,53 @@ function leakOfNode(node, checker) {
174
174
  return;
175
175
  const name = calleeName(node);
176
176
  if (name === 'setInterval' && isBrowserGlobal(node.expression, checker))
177
- return { label: 'setInterval()' };
177
+ return { label: 'setInterval()', release: 'clearInterval' };
178
178
  const callee = ts.skipOuterExpressions(node.expression);
179
179
  if (name === 'addEventListener' &&
180
180
  ts.isPropertyAccessExpression(callee) &&
181
181
  isGlobalEventTarget(callee.expression, checker)) {
182
- return { label: 'addEventListener()' };
182
+ return { label: 'addEventListener()', release: 'removeEventListener' };
183
183
  }
184
184
  const kind = unmanagedSubscription(node, checker);
185
185
  if (kind)
186
- return { label: 'subscribe()', reason: kind === 'unknown' ? SUBSCRIBE_MAY_COMPLETE_REASON : undefined };
186
+ return {
187
+ label: 'subscribe()',
188
+ release: 'unsubscribe',
189
+ reason: kind === 'unknown' ? SUBSCRIBE_MAY_COMPLETE_REASON : undefined,
190
+ };
187
191
  }
188
192
  function leakOfConstructor(node, checker) {
189
193
  if (!ts.isIdentifier(node.expression) || !isBrowserGlobal(node.expression, checker))
190
194
  return;
191
195
  const name = node.expression.text;
192
196
  if (DEFINITE_LEAK_CONSTRUCTORS.has(name))
193
- return { label: `new ${name}()` };
197
+ return { label: `new ${name}()`, release: 'close' };
194
198
  if (OBSERVER_CONSTRUCTORS.has(name))
195
- return { label: `new ${name}()`, reason: OBSERVER_REASON };
196
- }
197
- function findFetchWithoutAbort(body, checker) {
198
- let fetchCall;
199
- let hasAbort = false;
200
- walkAll(body, (node) => {
201
- if (ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'AbortController') {
202
- hasAbort = true;
203
- }
204
- else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'fetch') {
205
- if (isBrowserGlobal(node.expression, checker) && !passesSignal(node))
206
- fetchCall ??= node;
207
- }
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;
208
223
  });
209
- return hasAbort ? undefined : fetchCall;
210
224
  }
211
225
  function passesSignal(fetchCall) {
212
226
  const options = fetchCall.arguments[1] && ts.skipOuterExpressions(fetchCall.arguments[1]);
@@ -241,21 +255,34 @@ function isFireAndForgetMutation(fetchCall) {
241
255
  }
242
256
  function checkReactEffect(call, context) {
243
257
  const effect = effectCallback(call, context.checker);
244
- if (!effect || containsReturnValue(effect.body))
245
- return;
246
- const leak = leakedEffectResource(effect.body, context.checker);
247
- if (leak) {
248
- 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);
249
- }
250
- const fetchCall = findFetchWithoutAbort(effect.body, context.checker);
251
- if (!fetchCall)
258
+ if (!effect)
252
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) {
253
280
  const reason = isFireAndForgetMutation(fetchCall)
254
281
  ? 'Fire-and-forget mutating request whose response is unused.'
255
282
  : hasNonEmptyDependencies(call)
256
283
  ? undefined
257
284
  : FETCH_STATIC_DEPS_REASON;
258
- context.report(fetchCall, 'react-fetch-in-effect-no-abort', `\`fetch()\` inside \`${effect.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);
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);
259
286
  }
260
287
  function isArrayExpression(expression, checker) {
261
288
  const type = checker.getNonNullableType(checker.getTypeAtLocation(expression));
@@ -382,20 +409,6 @@ function checkAngularChangeDetection(classNode, context) {
382
409
  return;
383
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);
384
411
  }
385
- function destroyHookReleases(classNode) {
386
- const hook = classNode.members.find((member) => ts.isMethodDeclaration(member) && ts.isIdentifier(member.name) && member.name.text === 'ngOnDestroy');
387
- if (!hook?.body)
388
- return false;
389
- let releases = false;
390
- walkAll(hook.body, (node) => {
391
- if (ts.isCallExpression(node)) {
392
- const name = calleeName(node);
393
- if (name !== undefined && ['unsubscribe', 'next', 'complete'].includes(name))
394
- releases = true;
395
- }
396
- });
397
- return releases;
398
- }
399
412
  function checkAngularClass(classNode, context) {
400
413
  if (!ts.canHaveDecorators(classNode) || !ts.getDecorators(classNode)?.length)
401
414
  return;
@@ -405,12 +418,14 @@ function checkAngularClass(classNode, context) {
405
418
  checkNgForTrackBy(component.metadata, context);
406
419
  if (!isAngularComponentOrDirective(classNode, context.checker))
407
420
  return;
408
- if (destroyHookReleases(classNode))
409
- return;
421
+ const teardown = angularTeardown(classNode, context.checker);
410
422
  walkAll(classNode, (node) => {
411
423
  if (!ts.isCallExpression(node))
412
424
  return;
413
- const kind = unmanagedSubscription(node, context.checker);
425
+ const field = subscriptionField(node, teardown);
426
+ if (field && teardown.subscriptions.has(field))
427
+ return;
428
+ const kind = unmanagedSubscription(node, context.checker, teardown);
414
429
  if (!kind)
415
430
  return;
416
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);
@@ -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 isInsideTransactionCallback(node, upFunction) {
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 === 'transaction')
147
- return true;
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 false;
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, isInsideTransactionCallback, positionOf, receiverName, } from './extract-code-sql.js';
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({ file: context.file, ...fields, explicitTransaction }));
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
- explicitTransaction: scope.explicitTransaction || isInsideTransactionCallback(node, fn),
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], explicitTransaction: false });
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));