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.
Files changed (278) hide show
  1. package/README.md +175 -115
  2. package/dist/bin/loadwise.js +132 -67
  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/frontend-detect.js +6 -5
  10. package/dist/lib/accessibility/jsx-elements.js +13 -3
  11. package/dist/lib/accessibility/markup-files.js +7 -2
  12. package/dist/lib/accessibility/rule-ids.js +3 -0
  13. package/dist/lib/accessibility/rules.js +128 -41
  14. package/dist/lib/accessibility/site-fixes/buttons.js +5 -1
  15. package/dist/lib/accessibility/template-attributes.js +5 -3
  16. package/dist/lib/accessibility/template-elements.js +25 -6
  17. package/dist/lib/accessibility/template-file.js +40 -25
  18. package/dist/lib/accessibility/usage.js +10 -2
  19. package/dist/lib/editor/accessibility-examples.js +6 -1
  20. package/dist/lib/editor/actions.js +46 -7
  21. package/dist/lib/editor/apply-fix.js +69 -4
  22. package/dist/lib/editor/configured-setup.js +63 -0
  23. package/dist/lib/editor/diagnostics.js +206 -17
  24. package/dist/lib/editor/dismissals.js +85 -26
  25. package/dist/lib/editor/editor-document.js +5 -2
  26. package/dist/lib/editor/editor-launcher.js +170 -0
  27. package/dist/lib/editor/fix-edits.js +19 -0
  28. package/dist/lib/editor/jetbrains-setup.js +53 -0
  29. package/dist/lib/editor/language-server.js +80 -24
  30. package/dist/lib/editor/managed-config.js +37 -0
  31. package/dist/lib/editor/native-setup.js +86 -0
  32. package/dist/lib/editor/perf-watch.js +8 -6
  33. package/dist/lib/editor/release-vsix.js +61 -0
  34. package/dist/lib/editor/reliability-examples.js +15 -0
  35. package/dist/lib/editor/scan-session.js +29 -8
  36. package/dist/lib/editor/server-commands.js +38 -9
  37. package/dist/lib/editor/setup-server.js +87 -0
  38. package/dist/lib/editor/setup-vim.js +63 -0
  39. package/dist/lib/editor/setup.js +131 -0
  40. package/dist/lib/editor/stdio-setup.js +6 -0
  41. package/dist/lib/editor/workspace-files.js +61 -7
  42. package/dist/lib/editor/workspace-paths.js +41 -1
  43. package/dist/lib/maintainability/analysis/analyze-source.js +1 -1
  44. package/dist/lib/maintainability/architecture/architecture.js +4 -4
  45. package/dist/lib/maintainability/cli/changed-lines.js +20 -2
  46. package/dist/lib/maintainability/cli/inputs.js +12 -3
  47. package/dist/lib/maintainability/cli.js +18 -5
  48. package/dist/lib/maintainability/entry-points/entry-points.js +44 -15
  49. package/dist/lib/maintainability/entry-points/html-entry-points.js +5 -1
  50. package/dist/lib/maintainability/examples.js +4 -0
  51. package/dist/lib/maintainability/quality/functions.js +9 -6
  52. package/dist/lib/maintainability/quality/limits.js +19 -0
  53. package/dist/lib/maintainability/quality/size-limits.js +8 -2
  54. package/dist/lib/maintainability/quality/stray-console.js +62 -1
  55. package/dist/lib/maintainability/quality/tsconfig-strict.js +2 -0
  56. package/dist/lib/maintainability/rule-ids.js +3 -0
  57. package/dist/lib/maintainability/scan-changed.js +4 -1
  58. package/dist/lib/maintainability/scan-worker.js +6 -2
  59. package/dist/lib/maintainability/scan.js +21 -8
  60. package/dist/lib/maintainability/site-fixes/unused-bindings.js +138 -3
  61. package/dist/lib/maintainability/unused/module-usage.js +43 -21
  62. package/dist/lib/maintainability/unused/unused-bindings.js +39 -4
  63. package/dist/lib/maintainability/unused/unused-modules.js +5 -10
  64. package/dist/lib/performance/analysis/source-inputs.js +7 -2
  65. package/dist/lib/performance/analysis/source-options.js +7 -6
  66. package/dist/lib/performance/analyze.js +16 -3
  67. package/dist/lib/performance/cli/changed-lines.js +8 -1
  68. package/dist/lib/performance/cli/cli-arguments.js +19 -8
  69. package/dist/lib/performance/cli/cli-output.js +4 -0
  70. package/dist/lib/performance/cli/cli-scan.js +21 -2
  71. package/dist/lib/performance/cli.js +16 -7
  72. package/dist/lib/performance/collections/memory-growth.js +55 -12
  73. package/dist/lib/performance/contracts/openapi.js +13 -4
  74. package/dist/lib/performance/datastores/pg-integrity.js +68 -22
  75. package/dist/lib/performance/datastores/pg-session-release.js +114 -0
  76. package/dist/lib/performance/datastores/pg-session-sql.js +144 -0
  77. package/dist/lib/performance/datastores/pooling.js +62 -3
  78. package/dist/lib/performance/datastores/redis.js +94 -18
  79. package/dist/lib/performance/datastores/session-store.js +2 -1
  80. package/dist/lib/performance/db/checks.js +19 -8
  81. package/dist/lib/performance/db/gateway.js +3 -1
  82. package/dist/lib/performance/db/plan-estimates.js +4 -4
  83. package/dist/lib/performance/engine/native-syntax.js +3 -0
  84. package/dist/lib/performance/engine/native.js +11 -7
  85. package/dist/lib/performance/evidence/plans.js +7 -5
  86. package/dist/lib/performance/evidence/traces.js +21 -1
  87. package/dist/lib/performance/frontend/angular-teardown.js +96 -0
  88. package/dist/lib/performance/frontend/effect-cleanup.js +148 -0
  89. package/dist/lib/performance/frontend/frontend-dom-perf.js +14 -2
  90. package/dist/lib/performance/frontend/frontend-helpers.js +1 -9
  91. package/dist/lib/performance/frontend/frontend-perf.js +149 -74
  92. package/dist/lib/performance/migrations/extract-code-sql.js +16 -4
  93. package/dist/lib/performance/migrations/extract-code.js +13 -5
  94. package/dist/lib/performance/migrations/extract-sql.js +82 -38
  95. package/dist/lib/performance/migrations/operations.js +56 -13
  96. package/dist/lib/performance/migrations/postgres-lock-timeout.js +52 -0
  97. package/dist/lib/performance/migrations/postgres-registry.js +127 -26
  98. package/dist/lib/performance/migrations/postgres-settings.js +78 -0
  99. package/dist/lib/performance/migrations/rules-postgres-add-column.js +3 -3
  100. package/dist/lib/performance/migrations/rules-postgres-shared.js +9 -0
  101. package/dist/lib/performance/migrations/rules-postgres.js +88 -39
  102. package/dist/lib/performance/orm/offset-pagination.js +6 -4
  103. package/dist/lib/performance/orm/prisma-aggregates.js +69 -18
  104. package/dist/lib/performance/orm/unbounded-list-chain.js +29 -0
  105. package/dist/lib/performance/orm/unbounded-list-queries.js +18 -13
  106. package/dist/lib/performance/polyglot.js +111 -14
  107. package/dist/lib/performance/projects.js +3 -3
  108. package/dist/lib/performance/query-loops/sequential-loops.js +1 -0
  109. package/dist/lib/performance/request/backend-mastery.js +151 -42
  110. package/dist/lib/performance/request/bulk-listener-registration.js +111 -0
  111. package/dist/lib/performance/request/fastify-receivers.js +93 -0
  112. package/dist/lib/performance/request/fresh-loop-socket.js +103 -0
  113. package/dist/lib/performance/request/mongoose-lean.js +298 -46
  114. package/dist/lib/performance/request/node-event-listener-leak.js +99 -5
  115. package/dist/lib/performance/request/phase5-ast.js +6 -7
  116. package/dist/lib/performance/request/phase5-rules.js +204 -23
  117. package/dist/lib/performance/request/request-handlers.js +120 -23
  118. package/dist/lib/performance/request/sql-select-star.js +150 -0
  119. package/dist/lib/performance/request/unbounded-promise-all.js +54 -29
  120. package/dist/lib/performance/request/upload-limits.js +5 -1
  121. package/dist/lib/performance/site-fix.js +4 -4
  122. package/dist/lib/performance/site-fixes/backend-mastery-fixes.js +298 -16
  123. package/dist/lib/performance/site-fixes/collection-existence.js +2 -1
  124. package/dist/lib/performance/site-fixes/collections.js +1 -2
  125. package/dist/lib/performance/site-fixes/frontend-fixes.js +358 -14
  126. package/dist/lib/performance/site-fixes/helpers.js +3 -4
  127. package/dist/lib/performance/site-fixes/integrity.js +2 -4
  128. package/dist/lib/performance/site-fixes/migration-context.js +8 -1
  129. package/dist/lib/performance/site-fixes/migration-lock-rules.js +66 -30
  130. package/dist/lib/performance/site-fixes/prisma-aggregates.js +29 -9
  131. package/dist/lib/performance/site-fixes/small-rewrites.js +168 -10
  132. package/dist/lib/performance/site-fixes/sync-calls.js +14 -12
  133. package/dist/lib/performance/site-fixes/upload-limits.js +13 -7
  134. package/dist/lib/performance/sql/mysql-tokens.js +38 -12
  135. package/dist/lib/reliability/boundary-access.js +114 -57
  136. package/dist/lib/reliability/react-bugs.js +29 -7
  137. package/dist/lib/reliability/resource-leak-intervals.js +258 -0
  138. package/dist/lib/reliability/resource-leaks.js +209 -195
  139. package/dist/lib/reliability/rule-ids.js +10 -1
  140. package/dist/lib/reliability/site-fixes/resource-leaks.js +16 -1
  141. package/dist/lib/reliability/swallowed-errors.js +107 -21
  142. package/dist/lib/reliability/test-cleanup-after-await.js +92 -18
  143. package/dist/lib/reliability/usage.js +16 -5
  144. package/dist/lib/reliability/walk.js +3 -2
  145. package/dist/lib/security/auth-crypto/hashing.js +24 -8
  146. package/dist/lib/security/auth-crypto/jwt.js +21 -6
  147. package/dist/lib/security/auth-crypto/secrets.js +44 -1
  148. package/dist/lib/security/auth-crypto/shared.js +3 -1
  149. package/dist/lib/security/auth-crypto/signing-algorithm.js +79 -0
  150. package/dist/lib/security/auth-crypto/transport-and-ciphers.js +85 -1
  151. package/dist/lib/security/cli.js +21 -6
  152. package/dist/lib/security/cookie-credentials.js +115 -0
  153. package/dist/lib/security/cookie-csrf.js +241 -0
  154. package/dist/lib/security/deps/advisory.js +50 -109
  155. package/dist/lib/security/deps/cli.js +1 -1
  156. package/dist/lib/security/deps/cvss-score.js +14 -0
  157. package/dist/lib/security/deps/fixed-version.js +97 -0
  158. package/dist/lib/security/deps/lockfiles.js +135 -74
  159. package/dist/lib/security/deps/osv.js +11 -3
  160. package/dist/lib/security/deps/scan.js +47 -20
  161. package/dist/lib/security/deps/yarn-lock.js +158 -0
  162. package/dist/lib/security/examples/injection.cjs +4 -0
  163. package/dist/lib/security/exposure/cookies.js +17 -2
  164. package/dist/lib/security/exposure/cors-origin-regex.js +2 -3
  165. package/dist/lib/security/exposure/frontend-security.js +21 -14
  166. package/dist/lib/security/exposure/jsx-url.js +18 -33
  167. package/dist/lib/security/exposure/logging.js +49 -10
  168. package/dist/lib/security/exposure/prototype-pollution.js +126 -56
  169. package/dist/lib/security/exposure/react-html.js +26 -0
  170. package/dist/lib/security/exposure/reflected-xss.js +34 -5
  171. package/dist/lib/security/files/compose.js +126 -1
  172. package/dist/lib/security/files/dockerfile.js +62 -4
  173. package/dist/lib/security/files/index.js +1 -1
  174. package/dist/lib/security/injection/command.js +46 -18
  175. package/dist/lib/security/injection/index.js +2 -0
  176. package/dist/lib/security/injection/ldap.js +86 -0
  177. package/dist/lib/security/injection/nosql.js +28 -4
  178. package/dist/lib/security/injection/redos.js +1 -1
  179. package/dist/lib/security/injection/rule-ids.js +1 -0
  180. package/dist/lib/security/injection/shared.js +5 -1
  181. package/dist/lib/security/injection/sql.js +28 -13
  182. package/dist/lib/security/lexical-declaration.js +113 -0
  183. package/dist/lib/security/pg-dynamic-query.js +28 -1
  184. package/dist/lib/security/pg-identifier-guards.js +107 -3
  185. package/dist/lib/security/phase5-rules.js +26 -135
  186. package/dist/lib/security/polyglot.js +2 -2
  187. package/dist/lib/security/redirect-settings.js +98 -0
  188. package/dist/lib/security/request-forgery/open-redirect.js +18 -5
  189. package/dist/lib/security/request-forgery/path-traversal.js +84 -6
  190. package/dist/lib/security/request-forgery/shared.js +1 -7
  191. package/dist/lib/security/request-forgery/ssrf.js +176 -14
  192. package/dist/lib/security/rule-descriptions.js +5 -1
  193. package/dist/lib/security/rule-ids.js +7 -0
  194. package/dist/lib/security/site-fixes/auth-crypto.js +5 -78
  195. package/dist/lib/security/site-fixes/exposure.js +21 -3
  196. package/dist/lib/security/site-fixes/files.js +11 -13
  197. package/dist/lib/security/site-fixes/frontend-security-fixes.js +2 -2
  198. package/dist/lib/security/site-fixes/injection.js +17 -4
  199. package/dist/lib/security/site-fixes/jwt.js +1 -20
  200. package/dist/lib/security/site-fixes/request-forgery.js +37 -29
  201. package/dist/lib/security/taint/binding-inputs.js +236 -0
  202. package/dist/lib/security/taint/filename-guard.js +45 -45
  203. package/dist/lib/security/taint/guards.js +14 -8
  204. package/dist/lib/security/taint/index.js +126 -154
  205. package/dist/lib/security/taint/propagate.js +43 -9
  206. package/dist/lib/security/taint/record-writes.js +161 -0
  207. package/dist/lib/security/taint/resolution-cache.js +13 -7
  208. package/dist/lib/security/taint/sanitizers.js +89 -5
  209. package/dist/lib/security/taint/trace-nodes.js +61 -0
  210. package/dist/lib/security/taint/validators.js +89 -9
  211. package/dist/lib/shared/agent/agent-init.js +28 -5
  212. package/dist/lib/shared/agent/agent-prompt.js +74 -0
  213. package/dist/lib/shared/agent/agent-session.js +6 -1
  214. package/dist/lib/shared/agent/agent-verify.js +58 -11
  215. package/dist/lib/shared/agent/git-hook.js +17 -6
  216. package/dist/lib/shared/agent/review-delivery.js +1 -1
  217. package/dist/lib/shared/agent/review-mcp.js +8 -2
  218. package/dist/lib/shared/analysis/ast-semantics.js +2 -2
  219. package/dist/lib/shared/analysis/scan-cache.js +99 -14
  220. package/dist/lib/shared/check.js +172 -20
  221. package/dist/lib/shared/cli-dispatch.js +17 -0
  222. package/dist/lib/shared/config.js +27 -10
  223. package/dist/lib/shared/explain.js +1 -1
  224. package/dist/lib/shared/fix/fix-convergence.js +19 -31
  225. package/dist/lib/shared/fix/fix-handoff.js +16 -11
  226. package/dist/lib/shared/fix/fix-imports.js +4 -162
  227. package/dist/lib/shared/fix/fix-presentation-comments.js +23 -9
  228. package/dist/lib/shared/fix/fix-presentation-prettier.js +1 -46
  229. package/dist/lib/shared/fix/fix-presentation-rows.js +45 -1
  230. package/dist/lib/shared/fix/fix-presentation.js +9 -6
  231. package/dist/lib/shared/fix/fix-safety.js +32 -1
  232. package/dist/lib/shared/fix/fix-scope.js +82 -0
  233. package/dist/lib/shared/fix/fix-terminal.js +28 -1
  234. package/dist/lib/shared/fix/fix-typecheck.js +8 -4
  235. package/dist/lib/shared/fix/import-text-edits.js +148 -0
  236. package/dist/lib/shared/fix/project-file-access.js +17 -26
  237. package/dist/lib/shared/fix/read-fix-text.js +20 -0
  238. package/dist/lib/shared/fix.js +241 -104
  239. package/dist/lib/shared/formats/finding-location.js +4 -1
  240. package/dist/lib/shared/formats/github.js +3 -3
  241. package/dist/lib/shared/formats/sarif.js +9 -3
  242. package/dist/lib/shared/report-fp.js +97 -0
  243. package/dist/lib/shared/reporting/automatic-fix-signal.js +10 -0
  244. package/dist/lib/shared/reporting/baseline.js +7 -5
  245. package/dist/lib/shared/reporting/check-text.js +50 -0
  246. package/dist/lib/shared/reporting/pillars.js +54 -19
  247. package/dist/lib/shared/reporting/source-report.js +3 -0
  248. package/dist/lib/shared/system/atomic-write.js +5 -2
  249. package/dist/lib/shared/system/glob.js +34 -8
  250. package/dist/lib/shared/system/sentry.js +222 -0
  251. package/dist/lib/shared/system/shell-argument.js +5 -1
  252. package/dist/lib/shared/system/terminal-safe.js +3 -2
  253. package/dist/lib/shared/system/terminal-style.js +131 -0
  254. package/dist/lib/shared/workspaces.js +15 -3
  255. package/docs/assets/cli-workflow.gif +0 -0
  256. package/integrations/sublime/plugin.py +22 -0
  257. package/integrations/zed/Cargo.lock +845 -0
  258. package/integrations/zed/Cargo.toml +11 -0
  259. package/integrations/zed/extension.toml +11 -0
  260. package/integrations/zed/src/lib.rs +25 -0
  261. package/package.json +15 -3
  262. package/plugin/.claude-plugin/plugin.json +1 -1
  263. package/plugin/commands/loadwise.md +11 -6
  264. package/plugin/hooks/check-edited-file.mjs +27 -5
  265. package/polyglot/performance/rules/csharp.yml +34 -5
  266. package/polyglot/performance/rules/java.yml +24 -1
  267. package/polyglot/performance/rules/python.yml +74 -2
  268. package/polyglot/performance/sgconfig.yml +1 -0
  269. package/polyglot/reliability/rules/csharp.yml +12 -6
  270. package/polyglot/reliability/rules/go.yml +86 -6
  271. package/polyglot/reliability/rules/java.yml +22 -1
  272. package/polyglot/reliability/sgconfig.yml +1 -0
  273. package/polyglot/security/rules/go.yml +100 -22
  274. package/polyglot/security/rules/python.yml +74 -6
  275. package/polyglot/security/rules/rust.yml +65 -0
  276. package/polyglot/security/sgconfig.yml +1 -0
  277. package/schema/loadwise.config.schema.json +556 -76
  278. /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 FASTIFY_HANDLER_OPTIONS = new Set(['handler', 'preHandler', 'onRequest', 'preValidation', 'preParsing']);
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
- function hasDecoratorNamed(node, names) {
76
- return !!node.modifiers?.some((modifier) => ts.isDecorator(modifier) &&
77
- ts.isCallExpression(modifier.expression) &&
78
- ts.isIdentifier(modifier.expression.expression) &&
79
- names.has(modifier.expression.expression.text));
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 isFastifyRouteOption(node) {
228
- const property = ts.isMethodDeclaration(node) ? node : node.parent;
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 false;
231
- if (!ts.isIdentifier(property.name) || !FASTIFY_HANDLER_OPTIONS.has(property.name.text))
232
- return false;
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 false;
237
- return ROUTE_METHODS.has(call.expression.name.text) && isFastifyReceiver(call);
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 (isFastifyRouteOption(node))
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 hasDecoratorNamed(node, ROUTE_DECORATORS) || isFastifyRouteOption(node);
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 reachesResponse(value, handler, depth = 0) {
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 (ts.isReturnStatement(parent))
364
- return ts.findAncestor(parent, ts.isFunctionLike) === handler;
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) && depth < MAX_ALIAS_DEPTH && usesReachResponse(parent.name, handler, depth);
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) => reachesResponse(use, handler, depth + 1));
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 usesConcurrencyLimiter(arg, sourceFile) {
34
- const hasLimiterCall = containsMatchingNode(arg, (node) => ts.isCallExpression(node) &&
35
- ts.isIdentifier(node.expression) &&
36
- CONCURRENCY_LIMITER_NAMES.test(node.expression.text), false);
37
- if (hasLimiterCall)
38
- return true;
39
- if (!hasConcurrencyLimiterImport(sourceFile))
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
- return containsMatchingNode(arg, (node) => ts.isCallExpression(node) && ts.isIdentifier(node.expression), false);
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, sourceFile, context, cliReason) {
406
- if (!isGlobalMethodCall(call, 'Promise', 'all', context.checker) || call.arguments.length === 0)
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
- if (usesConcurrencyLimiter(arg, sourceFile))
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', 'Promise.all runs over an unbounded collection without a concurrency limit, risking memory spikes or downstream saturation.', reason);
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.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, { uploadOptionsIndex: helper.index });
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
- let commentRow;
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
- commentRow = targetChanges.commentRow;
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
- if (commentRow !== undefined && finding.file !== undefined)
183
- rememberCommentRow(fix, finding.file, commentRow);
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