loadwise 0.8.0 → 0.9.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 (584) hide show
  1. package/PERFORMANCE.md +17 -0
  2. package/README.md +238 -713
  3. package/agent/hooks/check-edited-file.mjs +682 -0
  4. package/dist/bin/github-action.js +143 -18
  5. package/dist/bin/loadwise.js +15 -28
  6. package/dist/lib/accessibility/angular-literal.js +1 -1
  7. package/dist/lib/accessibility/astro-template.js +111 -0
  8. package/dist/lib/accessibility/autofocus.js +94 -0
  9. package/dist/lib/accessibility/document-reference-rules.js +133 -0
  10. package/dist/lib/accessibility/form-context.js +7 -2
  11. package/dist/lib/accessibility/frontend-detect.js +18 -8
  12. package/dist/lib/accessibility/heading-order.js +59 -0
  13. package/dist/lib/accessibility/interaction-semantics.js +90 -0
  14. package/dist/lib/accessibility/jinja-template.js +150 -0
  15. package/dist/lib/accessibility/jsx-elements.js +134 -9
  16. package/dist/lib/accessibility/language-tags.js +18 -0
  17. package/dist/lib/accessibility/markup-files.js +44 -17
  18. package/dist/lib/accessibility/markup.js +4 -1
  19. package/dist/lib/accessibility/media-rules.js +81 -0
  20. package/dist/lib/accessibility/native-interactive.js +107 -0
  21. package/dist/lib/accessibility/rule-ids.js +30 -0
  22. package/dist/lib/accessibility/rule-utilities.js +92 -0
  23. package/dist/lib/accessibility/rules.js +74 -139
  24. package/dist/lib/accessibility/site-fixes/buttons.js +4 -11
  25. package/dist/lib/accessibility/site-fixes/email-autocomplete.js +103 -0
  26. package/dist/lib/accessibility/site-fixes/html-language.js +48 -0
  27. package/dist/lib/accessibility/site-fixes/media-autoplay.js +87 -0
  28. package/dist/lib/accessibility/site-fixes/positive-tabindex.js +102 -0
  29. package/dist/lib/accessibility/site-fixes/source-position.js +11 -0
  30. package/dist/lib/accessibility/site-fixes/viewport.js +107 -0
  31. package/dist/lib/accessibility/table-headers.js +70 -0
  32. package/dist/lib/accessibility/template-attributes.js +13 -2
  33. package/dist/lib/accessibility/template-binding-scope.js +122 -0
  34. package/dist/lib/accessibility/template-elements.js +257 -109
  35. package/dist/lib/accessibility/template-file.js +111 -22
  36. package/dist/lib/accessibility/template-tag-tables.js +86 -0
  37. package/dist/lib/accessibility/usage.js +1 -1
  38. package/dist/lib/editor/accessibility-examples.js +5 -0
  39. package/dist/lib/editor/actions.js +11 -5
  40. package/dist/lib/editor/apply-fix.js +30 -2
  41. package/dist/lib/editor/configured-setup.js +9 -14
  42. package/dist/lib/editor/diagnostics.js +9 -26
  43. package/dist/lib/editor/dismissals.js +21 -10
  44. package/dist/lib/editor/doctor.js +167 -0
  45. package/dist/lib/editor/editor-document.js +17 -1
  46. package/dist/lib/editor/editor-launcher.js +60 -26
  47. package/dist/lib/editor/fix-edits.js +87 -8
  48. package/dist/lib/editor/jetbrains-setup.js +2 -1
  49. package/dist/lib/editor/language-server.js +220 -47
  50. package/dist/lib/editor/native-setup.js +7 -2
  51. package/dist/lib/editor/perf-watch.js +7 -5
  52. package/dist/lib/editor/performance-examples.js +31 -0
  53. package/dist/lib/editor/polyglot-selection.js +193 -0
  54. package/dist/lib/editor/project-policy.js +146 -0
  55. package/dist/lib/editor/project-watches.js +86 -0
  56. package/dist/lib/editor/release-vsix.js +23 -1
  57. package/dist/lib/editor/reliability-examples.js +36 -0
  58. package/dist/lib/editor/scan-session.js +210 -61
  59. package/dist/lib/editor/security-examples.js +24 -14
  60. package/dist/lib/editor/server-commands.js +24 -11
  61. package/dist/lib/editor/setup.js +7 -12
  62. package/dist/lib/editor/standalone-performance-examples.js +3 -0
  63. package/dist/lib/editor/workspace-files.js +32 -8
  64. package/dist/lib/editor/workspace-paths.js +29 -7
  65. package/dist/lib/editor/zed-settings.js +118 -0
  66. package/dist/lib/editor/zed-setup.js +88 -0
  67. package/dist/lib/maintainability/analysis/analyze-source.js +6 -3
  68. package/dist/lib/maintainability/analysis/source-exclusions.js +2 -1
  69. package/dist/lib/maintainability/analysis/source-facts.js +2 -2
  70. package/dist/lib/maintainability/architecture/graph.js +2 -1
  71. package/dist/lib/maintainability/architecture/layout.js +2 -1
  72. package/dist/lib/maintainability/cli/apply-fix.js +32 -7
  73. package/dist/lib/maintainability/cli/changed-lines.js +7 -113
  74. package/dist/lib/maintainability/cli/finding-ids.js +3 -6
  75. package/dist/lib/maintainability/cli/fix-cli.js +1 -9
  76. package/dist/lib/maintainability/cli/git-inventory.js +5 -6
  77. package/dist/lib/maintainability/cli/inputs.js +12 -11
  78. package/dist/lib/maintainability/cli/scan-arguments.js +33 -0
  79. package/dist/lib/maintainability/cli/site-fix.js +28 -13
  80. package/dist/lib/maintainability/cli.js +25 -35
  81. package/dist/lib/maintainability/entry-points/entry-points.js +27 -68
  82. package/dist/lib/maintainability/examples.js +12 -0
  83. package/dist/lib/maintainability/polyglot-duplicates.js +1 -0
  84. package/dist/lib/maintainability/polyglot.js +337 -12
  85. package/dist/lib/maintainability/project.js +4 -4
  86. package/dist/lib/maintainability/quality/console-tooling.js +114 -0
  87. package/dist/lib/maintainability/quality/declarative-imports.js +18 -0
  88. package/dist/lib/maintainability/quality/deprecated-apis.js +227 -40
  89. package/dist/lib/maintainability/quality/duplicates.js +5 -11
  90. package/dist/lib/maintainability/quality/generic-assertion-target.js +75 -0
  91. package/dist/lib/maintainability/quality/limits.js +5 -1
  92. package/dist/lib/maintainability/quality/size-limits.js +2 -1
  93. package/dist/lib/maintainability/quality/stray-console.js +31 -7
  94. package/dist/lib/maintainability/quality/tsconfig-strict.js +125 -6
  95. package/dist/lib/maintainability/quality/type-escape-hatches.js +411 -0
  96. package/dist/lib/maintainability/quality/type-safety-hygiene.js +132 -42
  97. package/dist/lib/maintainability/quality/unowned-source.js +15 -0
  98. package/dist/lib/maintainability/rule-ids.js +9 -0
  99. package/dist/lib/maintainability/scan-changed.js +6 -1
  100. package/dist/lib/maintainability/scan-worker.js +3 -5
  101. package/dist/lib/maintainability/scan.js +16 -3
  102. package/dist/lib/maintainability/site-fixes/duplicate-edits.js +3 -2
  103. package/dist/lib/maintainability/site-fixes/duplicate-methods.js +7 -2
  104. package/dist/lib/maintainability/site-fixes/duplicates.js +3 -2
  105. package/dist/lib/maintainability/site-fixes/focused-test.js +230 -0
  106. package/dist/lib/maintainability/site-fixes/helpers.js +2 -6
  107. package/dist/lib/maintainability/site-fixes/if-rewrites.js +1 -7
  108. package/dist/lib/maintainability/site-fixes/large-module.js +2 -1
  109. package/dist/lib/maintainability/unused/ancestor-aliases.js +2 -2
  110. package/dist/lib/maintainability/unused/module-usage-dynamic.js +2 -1
  111. package/dist/lib/maintainability/unused/module-usage-named-exports.js +125 -0
  112. package/dist/lib/maintainability/unused/module-usage.js +8 -3
  113. package/dist/lib/maintainability/unused/unused-modules.js +35 -1
  114. package/dist/lib/performance/analysis/call-syntax.js +2 -1
  115. package/dist/lib/performance/analysis/function-kinds.js +1 -5
  116. package/dist/lib/performance/analysis/missing-packages.js +10 -7
  117. package/dist/lib/performance/analysis/package-types.js +10 -2
  118. package/dist/lib/performance/analysis/schema-tooling.js +157 -8
  119. package/dist/lib/performance/analysis/source-inputs.js +17 -12
  120. package/dist/lib/performance/analysis/unscanned-javascript.js +6 -5
  121. package/dist/lib/performance/analyze.js +22 -6
  122. package/dist/lib/performance/async/async-errors.js +162 -14
  123. package/dist/lib/performance/async/await-before-early-exit.js +1 -6
  124. package/dist/lib/performance/async/floating-promises.js +2 -2
  125. package/dist/lib/performance/async/promise-return-escapes-catch.js +35 -2
  126. package/dist/lib/performance/async/stream-errors.js +1 -3
  127. package/dist/lib/performance/cli/changed-lines.js +14 -111
  128. package/dist/lib/performance/cli/cli-arguments.js +11 -9
  129. package/dist/lib/performance/cli/cli-markup.js +42 -0
  130. package/dist/lib/performance/cli/cli-policy.js +150 -16
  131. package/dist/lib/performance/cli/cli-scan.js +148 -118
  132. package/dist/lib/performance/cli/finding-ids.js +7 -7
  133. package/dist/lib/performance/cli/fix-cli.js +83 -34
  134. package/dist/lib/performance/cli/prisma-schema-findings.js +23 -0
  135. package/dist/lib/performance/cli/watch-security.js +33 -0
  136. package/dist/lib/performance/cli/watch.js +17 -9
  137. package/dist/lib/performance/cli.js +8 -7
  138. package/dist/lib/performance/collections/array-drains.js +354 -0
  139. package/dist/lib/performance/collections/collection-bindings.js +1 -2
  140. package/dist/lib/performance/collections/collection-bounds.js +3 -2
  141. package/dist/lib/performance/collections/collection-copy.js +51 -1
  142. package/dist/lib/performance/collections/collection-lookups.js +47 -3
  143. package/dist/lib/performance/collections/collection-reduce.js +0 -4
  144. package/dist/lib/performance/collections/collections.js +6 -2
  145. package/dist/lib/performance/collections/json-clone.js +137 -17
  146. package/dist/lib/performance/collections/regex-allocation.js +156 -0
  147. package/dist/lib/performance/collections/repeated.js +2 -8
  148. package/dist/lib/performance/collections/sort-extreme.js +18 -1
  149. package/dist/lib/performance/collections/workbook-decodes.js +3 -2
  150. package/dist/lib/performance/contracts/cli.js +329 -21
  151. package/dist/lib/performance/contracts/git-files.js +57 -5
  152. package/dist/lib/performance/contracts/openapi-schema.js +187 -0
  153. package/dist/lib/performance/contracts/openapi-sources.js +260 -0
  154. package/dist/lib/performance/contracts/openapi.js +172 -233
  155. package/dist/lib/performance/contracts/protobuf.js +301 -0
  156. package/dist/lib/performance/contracts/trpc-moves.js +46 -0
  157. package/dist/lib/performance/contracts/trpc.js +477 -0
  158. package/dist/lib/performance/datastores/pg-integrity.js +2 -1
  159. package/dist/lib/performance/datastores/pooling.js +2 -1
  160. package/dist/lib/performance/datastores/redis-keys.js +4 -3
  161. package/dist/lib/performance/datastores/redis.js +8 -1
  162. package/dist/lib/performance/datastores/repeated-reads.js +104 -0
  163. package/dist/lib/performance/datastores/search-clients.js +9 -0
  164. package/dist/lib/performance/datastores/session-store.js +166 -7
  165. package/dist/lib/performance/datastores/supabase.js +73 -0
  166. package/dist/lib/performance/db/checks.js +1 -1
  167. package/dist/lib/performance/db/cli-mysql.js +12 -2
  168. package/dist/lib/performance/db/cli.js +38 -5
  169. package/dist/lib/performance/db/drivers.js +20 -4
  170. package/dist/lib/performance/db/measure.js +1 -1
  171. package/dist/lib/performance/db/mysql-catalog.js +1 -1
  172. package/dist/lib/performance/db/plan-estimates.js +46 -7
  173. package/dist/lib/performance/db/redact.js +1 -3
  174. package/dist/lib/performance/db/snapshot.js +1 -1
  175. package/dist/lib/performance/db/sqlite-plan.js +95 -0
  176. package/dist/lib/performance/engine/compiler.js +3 -2
  177. package/dist/lib/performance/engine/native-checker.js +85 -10
  178. package/dist/lib/performance/engine/native-syntax.js +17 -0
  179. package/dist/lib/performance/engine/native-workspaces.js +36 -8
  180. package/dist/lib/performance/engine/native.js +38 -16
  181. package/dist/lib/performance/engine/review-config-inputs.js +57 -0
  182. package/dist/lib/performance/evidence/plans.js +14 -16
  183. package/dist/lib/performance/evidence/trace-formats.js +182 -0
  184. package/dist/lib/performance/evidence/traces.js +6 -6
  185. package/dist/lib/performance/frontend/angular-bootstrap.js +309 -0
  186. package/dist/lib/performance/frontend/barrel-subpaths.js +204 -0
  187. package/dist/lib/performance/frontend/effect-cleanup.js +30 -4
  188. package/dist/lib/performance/frontend/frontend-dom-perf.js +11 -7
  189. package/dist/lib/performance/frontend/frontend-perf.js +4 -5
  190. package/dist/lib/performance/frontend/frontend-render-perf.js +10 -10
  191. package/dist/lib/performance/frontend/layout-binary-probe.js +186 -0
  192. package/dist/lib/performance/frontend/next-fetch-waterfall.js +88 -0
  193. package/dist/lib/performance/frontend/template-tracking.js +131 -0
  194. package/dist/lib/performance/index-rules/index-rules-table.js +3 -3
  195. package/dist/lib/performance/index-rules/redundant-indexes.js +6 -13
  196. package/dist/lib/performance/migrations/cli.js +65 -14
  197. package/dist/lib/performance/migrations/discover.js +63 -32
  198. package/dist/lib/performance/migrations/enforce.js +5 -12
  199. package/dist/lib/performance/migrations/extract-code-sql.js +10 -7
  200. package/dist/lib/performance/migrations/extract-code.js +1 -0
  201. package/dist/lib/performance/migrations/extract-sql.js +45 -4
  202. package/dist/lib/performance/migrations/extract-sqlite.js +302 -0
  203. package/dist/lib/performance/migrations/operations.js +122 -8
  204. package/dist/lib/performance/migrations/postgres-registry.js +6 -6
  205. package/dist/lib/performance/migrations/postgres-table-history.js +147 -0
  206. package/dist/lib/performance/migrations/rules-postgres-shared.js +4 -6
  207. package/dist/lib/performance/migrations/rules-postgres.js +67 -13
  208. package/dist/lib/performance/migrations/rules-sqlite.js +118 -0
  209. package/dist/lib/performance/migrations/sqlserver-creation.js +131 -0
  210. package/dist/lib/performance/migrations/sqlserver.js +81 -0
  211. package/dist/lib/performance/models/client-imports.js +286 -0
  212. package/dist/lib/performance/models/index.js +46 -8
  213. package/dist/lib/performance/orm/cartesian-includes.js +49 -22
  214. package/dist/lib/performance/orm/drizzle.js +86 -27
  215. package/dist/lib/performance/orm/knex-loop-operations.js +96 -0
  216. package/dist/lib/performance/orm/orm-owners.js +3 -5
  217. package/dist/lib/performance/orm/orm-queries.js +50 -152
  218. package/dist/lib/performance/orm/orm-result-uses.js +116 -0
  219. package/dist/lib/performance/orm/prisma-integrity.js +24 -3
  220. package/dist/lib/performance/orm/prisma.js +31 -8
  221. package/dist/lib/performance/orm/typeorm-batch-filter.js +43 -0
  222. package/dist/lib/performance/orm/typeorm-projection.js +2 -2
  223. package/dist/lib/performance/orm/typeorm-transaction-loops.js +3 -4
  224. package/dist/lib/performance/orm/typeorm-updates.js +1 -3
  225. package/dist/lib/performance/orm/unbounded-list-page-size.js +179 -0
  226. package/dist/lib/performance/orm/unbounded-list-queries.js +63 -146
  227. package/dist/lib/performance/polyglot.js +173 -61
  228. package/dist/lib/performance/probe-caches.js +42 -0
  229. package/dist/lib/performance/program-batches.js +138 -0
  230. package/dist/lib/performance/projects.js +85 -89
  231. package/dist/lib/performance/query-loops/guard-queries.js +2 -1
  232. package/dist/lib/performance/query-loops/parallel-reads-policy.js +1 -3
  233. package/dist/lib/performance/query-loops/query-loop-batch.js +81 -7
  234. package/dist/lib/performance/query-loops/query-loop-bounds.js +1 -13
  235. package/dist/lib/performance/query-loops/query-policy.js +19 -20
  236. package/dist/lib/performance/query-loops/query-results.js +1 -6
  237. package/dist/lib/performance/query-loops/query-write-context.js +89 -0
  238. package/dist/lib/performance/query-loops/sequential-loops.js +6 -24
  239. package/dist/lib/performance/query-loops/service-call-resolution.js +17 -2
  240. package/dist/lib/performance/query-loops/service-loop-source.js +124 -0
  241. package/dist/lib/performance/query-loops/service-loops.js +48 -17
  242. package/dist/lib/performance/query-loops/throw-on-miss-loops.js +141 -0
  243. package/dist/lib/performance/request/backend-mastery.js +18 -30
  244. package/dist/lib/performance/request/fixed-emitter-loop.js +98 -0
  245. package/dist/lib/performance/request/fresh-mapped-elements.js +137 -0
  246. package/dist/lib/performance/request/graphql-list-lookups.js +258 -0
  247. package/dist/lib/performance/request/http-options-writes.js +2 -8
  248. package/dist/lib/performance/request/http-timeouts.js +3 -2
  249. package/dist/lib/performance/request/json-stringify-output.js +139 -0
  250. package/dist/lib/performance/request/llm-max-tokens.js +27 -8
  251. package/dist/lib/performance/request/mongoose-lean.js +15 -10
  252. package/dist/lib/performance/request/node-event-listener-leak.js +190 -35
  253. package/dist/lib/performance/request/node-fs-context.js +6 -8
  254. package/dist/lib/performance/request/node-fs.js +4 -6
  255. package/dist/lib/performance/request/password-hashing.js +4 -3
  256. package/dist/lib/performance/request/phase5-ast.js +3 -9
  257. package/dist/lib/performance/request/phase5-rules.js +50 -102
  258. package/dist/lib/performance/request/pure-js-hashing.js +2 -1
  259. package/dist/lib/performance/request/request-handlers.js +1 -3
  260. package/dist/lib/performance/request/request-inputs.js +121 -26
  261. package/dist/lib/performance/request/unbounded-promise-all.js +132 -3
  262. package/dist/lib/performance/rule-ids.js +47 -4
  263. package/dist/lib/performance/schema/context.js +7 -16
  264. package/dist/lib/performance/schema/model.js +1 -9
  265. package/dist/lib/performance/schema/prisma-owners.js +15 -1
  266. package/dist/lib/performance/schema/prisma-schema.js +5 -6
  267. package/dist/lib/performance/schema/project-indexes-events.js +8 -2
  268. package/dist/lib/performance/schema/project-indexes.js +4 -2
  269. package/dist/lib/performance/schema/query-site-support.js +1 -1
  270. package/dist/lib/performance/schema/sequelize-schema.js +1 -3
  271. package/dist/lib/performance/schema/ts-helpers.js +3 -7
  272. package/dist/lib/performance/shared-libs.js +48 -0
  273. package/dist/lib/performance/site-fix.js +32 -7
  274. package/dist/lib/performance/site-fixes/collection-copy.js +2 -1
  275. package/dist/lib/performance/site-fixes/collection-existence.js +2 -1
  276. package/dist/lib/performance/site-fixes/collection-find.js +2 -1
  277. package/dist/lib/performance/site-fixes/collection-helpers.js +0 -6
  278. package/dist/lib/performance/site-fixes/collection-lookups.js +2 -1
  279. package/dist/lib/performance/site-fixes/database.js +7 -16
  280. package/dist/lib/performance/site-fixes/drizzle-index.js +2 -9
  281. package/dist/lib/performance/site-fixes/frontend-fixes.js +47 -15
  282. package/dist/lib/performance/site-fixes/helpers.js +19 -18
  283. package/dist/lib/performance/site-fixes/last-insert-id.js +2 -1
  284. package/dist/lib/performance/site-fixes/llm-max-tokens.js +56 -0
  285. package/dist/lib/performance/site-fixes/migration-column-rules.js +11 -7
  286. package/dist/lib/performance/site-fixes/migration-lock-rules.js +6 -3
  287. package/dist/lib/performance/site-fixes/migrations.js +4 -0
  288. package/dist/lib/performance/site-fixes/pure-js-hashing.js +2 -2
  289. package/dist/lib/performance/site-fixes/query-shapes.js +1 -4
  290. package/dist/lib/performance/site-fixes/service-loop-ast.js +1 -9
  291. package/dist/lib/performance/site-fixes/small-rewrites.js +28 -2
  292. package/dist/lib/performance/site-fixes/template-tracking-fixes.js +82 -0
  293. package/dist/lib/performance/site-fixes/writes.js +1 -6
  294. package/dist/lib/performance/sql/local-statements.js +108 -0
  295. package/dist/lib/performance/sql/mysql-tokens.js +1 -4
  296. package/dist/lib/performance/sql/pg-parser.js +3 -5
  297. package/dist/lib/performance/sql/sqlserver-control.js +43 -0
  298. package/dist/lib/reliability/analyze.js +48 -5
  299. package/dist/lib/reliability/boundary-access.js +34 -27
  300. package/dist/lib/reliability/callback-completion.js +10 -2
  301. package/dist/lib/reliability/child-process.js +2 -2
  302. package/dist/lib/reliability/crlf-line-split.js +124 -73
  303. package/dist/lib/reliability/crlf-references.js +78 -0
  304. package/dist/lib/reliability/default-numeric-sort.js +25 -0
  305. package/dist/lib/reliability/error-cause-plan.js +29 -0
  306. package/dist/lib/reliability/error-values.js +68 -27
  307. package/dist/lib/reliability/json-cast.js +368 -0
  308. package/dist/lib/reliability/key-test-callee.js +50 -0
  309. package/dist/lib/reliability/lossy-text-rewrite.js +94 -0
  310. package/dist/lib/reliability/manifest-boundary.js +466 -0
  311. package/dist/lib/reliability/manifest-snapshot.js +40 -0
  312. package/dist/lib/reliability/parse-failure-flow.js +5 -2
  313. package/dist/lib/reliability/parse-failure-paths.js +39 -8
  314. package/dist/lib/reliability/parse-failure-reset.js +5 -17
  315. package/dist/lib/reliability/pool-timeout.js +31 -7
  316. package/dist/lib/reliability/promise-usage.js +281 -0
  317. package/dist/lib/reliability/react-bugs.js +7 -6
  318. package/dist/lib/reliability/react-state-order.js +2 -2
  319. package/dist/lib/reliability/react-state-paths.js +2 -2
  320. package/dist/lib/reliability/react-state-setter.js +5 -11
  321. package/dist/lib/reliability/react-state-walker.js +3 -3
  322. package/dist/lib/reliability/required-member.js +19 -0
  323. package/dist/lib/reliability/resource-leak-intervals.js +4 -7
  324. package/dist/lib/reliability/resource-leaks.js +4 -7
  325. package/dist/lib/reliability/rule-ids.js +70 -1
  326. package/dist/lib/reliability/same-file-io.js +135 -0
  327. package/dist/lib/reliability/short-write.js +220 -0
  328. package/dist/lib/reliability/site-fixes/crlf-line-split.js +71 -0
  329. package/dist/lib/reliability/site-fixes/error-values.js +40 -0
  330. package/dist/lib/reliability/site-fixes/pool-timeout.js +51 -0
  331. package/dist/lib/reliability/source-helpers.js +18 -8
  332. package/dist/lib/reliability/standalone-sources.js +8 -6
  333. package/dist/lib/reliability/suspicious-logic.js +6 -8
  334. package/dist/lib/reliability/swallowed-errors.js +3 -7
  335. package/dist/lib/reliability/switch-exhaustive.js +195 -5
  336. package/dist/lib/reliability/test-cleanup-after-await.js +2 -2
  337. package/dist/lib/reliability/throw-string-plan.js +121 -0
  338. package/dist/lib/reliability/uncaught-exception.js +2 -7
  339. package/dist/lib/reliability/usage.js +1 -1
  340. package/dist/lib/reliability/working-directory.js +101 -0
  341. package/dist/lib/security/analyze.js +2 -0
  342. package/dist/lib/security/auth-crypto/hashing.js +21 -4
  343. package/dist/lib/security/auth-crypto/index.js +6 -1
  344. package/dist/lib/security/auth-crypto/jwt-decode-helpers.js +163 -0
  345. package/dist/lib/security/auth-crypto/jwt.js +52 -36
  346. package/dist/lib/security/auth-crypto/plaintext-password.js +2 -1
  347. package/dist/lib/security/auth-crypto/random.js +2 -1
  348. package/dist/lib/security/auth-crypto/rate-limits.js +79 -8
  349. package/dist/lib/security/auth-crypto/rule-ids.js +2 -0
  350. package/dist/lib/security/auth-crypto/secrets.js +11 -3
  351. package/dist/lib/security/auth-crypto/shared.js +1 -4
  352. package/dist/lib/security/auth-crypto/signature-verification.js +29 -0
  353. package/dist/lib/security/auth-crypto/transport-and-ciphers.js +43 -3
  354. package/dist/lib/security/auth-crypto/weak-hash.js +183 -0
  355. package/dist/lib/security/bindings.js +41 -9
  356. package/dist/lib/security/cli.js +83 -26
  357. package/dist/lib/security/cookie-csrf.js +316 -7
  358. package/dist/lib/security/deps/cargo-lock.js +78 -0
  359. package/dist/lib/security/deps/cli.js +4 -4
  360. package/dist/lib/security/deps/fixed-version.js +2 -2
  361. package/dist/lib/security/deps/lockfiles.js +204 -16
  362. package/dist/lib/security/deps/osv.js +190 -59
  363. package/dist/lib/security/deps/scan.js +87 -19
  364. package/dist/lib/security/examples/{auth-crypto.cjs → auth-crypto.js} +11 -5
  365. package/dist/lib/security/examples/{deps.cjs → deps.js} +1 -3
  366. package/dist/lib/security/examples/{exposure.cjs → exposure.js} +17 -3
  367. package/dist/lib/security/examples/{files.cjs → files.js} +9 -3
  368. package/dist/lib/security/examples/{injection.cjs → injection.js} +13 -3
  369. package/dist/lib/security/examples/{moved.cjs → moved.js} +1 -3
  370. package/dist/lib/security/examples/{request-forgery.cjs → request-forgery.js} +1 -3
  371. package/dist/lib/security/exposure/backend-security-mastery.js +2 -1
  372. package/dist/lib/security/exposure/client-env.js +2 -1
  373. package/dist/lib/security/exposure/content-disposition.js +71 -0
  374. package/dist/lib/security/exposure/cookies.js +200 -1
  375. package/dist/lib/security/exposure/cors.js +63 -4
  376. package/dist/lib/security/exposure/frontend-security.js +7 -60
  377. package/dist/lib/security/exposure/index.js +9 -0
  378. package/dist/lib/security/exposure/js-yaml.js +203 -0
  379. package/dist/lib/security/exposure/message-effects.js +266 -0
  380. package/dist/lib/security/exposure/package-manifest.js +2 -2
  381. package/dist/lib/security/exposure/prototype-pollution.js +26 -1
  382. package/dist/lib/security/exposure/reflected-xss.js +47 -12
  383. package/dist/lib/security/exposure/response-content-type.js +181 -0
  384. package/dist/lib/security/exposure/rule-ids.js +4 -0
  385. package/dist/lib/security/exposure/trust-boundary.js +142 -0
  386. package/dist/lib/security/exposure/url-secrets.js +38 -2
  387. package/dist/lib/security/exposure/webhook-verification.js +231 -0
  388. package/dist/lib/security/express-registration.js +45 -0
  389. package/dist/lib/security/express-router-factories.js +118 -0
  390. package/dist/lib/security/files/component-markup.js +66 -0
  391. package/dist/lib/security/files/compose.js +2 -1
  392. package/dist/lib/security/files/index.js +121 -27
  393. package/dist/lib/security/files/kubernetes.js +136 -0
  394. package/dist/lib/security/files/project-files.js +98 -31
  395. package/dist/lib/security/files/rule-ids.js +2 -0
  396. package/dist/lib/security/files/secrets.js +9 -5
  397. package/dist/lib/security/injection/code.js +33 -5
  398. package/dist/lib/security/injection/command.js +51 -4
  399. package/dist/lib/security/injection/escape-preserving.js +219 -0
  400. package/dist/lib/security/injection/escape-replace.js +174 -2
  401. package/dist/lib/security/injection/index.js +5 -1
  402. package/dist/lib/security/injection/nosql.js +1 -1
  403. package/dist/lib/security/injection/redos.js +25 -4
  404. package/dist/lib/security/injection/rule-ids.js +3 -0
  405. package/dist/lib/security/injection/shell-output-guard.js +97 -0
  406. package/dist/lib/security/injection/sql.js +51 -0
  407. package/dist/lib/security/injection/xpath.js +35 -0
  408. package/dist/lib/security/pg-identifier-guards.js +58 -6
  409. package/dist/lib/security/phase5-rules.js +1 -0
  410. package/dist/lib/security/polyglot.js +35 -3
  411. package/dist/lib/security/provider-credentials.js +29 -0
  412. package/dist/lib/security/redirect-settings.js +131 -6
  413. package/dist/lib/security/request-forgery/contained-helper.js +75 -0
  414. package/dist/lib/security/request-forgery/open-redirect-query.js +2 -1
  415. package/dist/lib/security/request-forgery/open-redirect.js +25 -2
  416. package/dist/lib/security/request-forgery/parsed-host-guard.js +213 -0
  417. package/dist/lib/security/request-forgery/path-traversal.js +36 -1
  418. package/dist/lib/security/request-forgery/shared.js +187 -27
  419. package/dist/lib/security/request-forgery/ssrf.js +145 -1
  420. package/dist/lib/security/rule-descriptions.js +17 -1
  421. package/dist/lib/security/rule-ids.js +21 -0
  422. package/dist/lib/security/scope/drizzle-policy.js +2 -1
  423. package/dist/lib/security/scope/kysely-policy.js +173 -0
  424. package/dist/lib/security/site-fixes/auth-crypto.js +3 -1
  425. package/dist/lib/security/taint/accessors.js +364 -0
  426. package/dist/lib/security/taint/array-writes.js +139 -0
  427. package/dist/lib/security/taint/binding-inputs.js +4 -3
  428. package/dist/lib/security/taint/field-access.js +80 -0
  429. package/dist/lib/security/taint/filename-guard.js +81 -6
  430. package/dist/lib/security/taint/guards.js +150 -17
  431. package/dist/lib/security/taint/index.js +41 -116
  432. package/dist/lib/security/taint/propagate.js +5 -6
  433. package/dist/lib/security/taint/resolution-cache.js +10 -1
  434. package/dist/lib/security/taint/sanitizers.js +5 -5
  435. package/dist/lib/security/taint/shape-flows.js +128 -0
  436. package/dist/lib/security/taint/sink-alphabets.js +237 -0
  437. package/dist/lib/security/taint/sources.js +151 -8
  438. package/dist/lib/security/taint/trace-nodes.js +35 -2
  439. package/dist/lib/security/taint/validators.js +58 -19
  440. package/dist/lib/security/trusted-bindings.js +44 -0
  441. package/dist/lib/shared/agent/agent-init.js +84 -9
  442. package/dist/lib/shared/agent/agent-integrations.js +626 -0
  443. package/dist/lib/shared/agent/agent-prompt.js +2 -1
  444. package/dist/lib/shared/agent/agent-session.js +1 -1
  445. package/dist/lib/shared/agent/agent-toml.js +98 -0
  446. package/dist/lib/shared/agent/agent-verify.js +21 -3
  447. package/dist/lib/shared/agent/git-hook.js +31 -4
  448. package/dist/lib/shared/agent/notify-editor.js +2 -1
  449. package/dist/lib/shared/agent/review-mcp.js +67 -13
  450. package/dist/lib/shared/agent/review-request.js +4 -0
  451. package/dist/lib/shared/analysis/ast-helpers.js +50 -0
  452. package/dist/lib/shared/analysis/ast-semantics.js +7 -1
  453. package/dist/lib/shared/analysis/binding-names.js +13 -0
  454. package/dist/lib/shared/analysis/execution-context.js +49 -9
  455. package/dist/lib/shared/analysis/polyglot-compatibility.js +102 -23
  456. package/dist/lib/shared/analysis/scan-cache-storage.js +180 -0
  457. package/dist/lib/shared/analysis/scan-cache.js +342 -119
  458. package/dist/lib/shared/analysis/valid-javascript.js +118 -0
  459. package/dist/lib/shared/changed-lines.js +129 -0
  460. package/dist/lib/shared/check-options.js +63 -0
  461. package/dist/lib/shared/check-watch-inputs.js +152 -0
  462. package/dist/lib/shared/check-watch-process.js +57 -0
  463. package/dist/lib/shared/check-watch.js +136 -0
  464. package/dist/lib/shared/check.js +73 -37
  465. package/dist/lib/shared/completion-shells.js +127 -0
  466. package/dist/lib/shared/completion.js +124 -0
  467. package/dist/lib/shared/config-rule-validation.js +135 -0
  468. package/dist/lib/shared/config.js +330 -163
  469. package/dist/lib/shared/declarative-rule-packs.js +173 -0
  470. package/dist/lib/shared/explain.js +47 -9
  471. package/dist/lib/shared/fix/fix-convergence.js +45 -128
  472. package/dist/lib/shared/fix/fix-history.js +130 -26
  473. package/dist/lib/shared/fix/fix-interactive.js +78 -0
  474. package/dist/lib/shared/fix/fix-patch.js +89 -0
  475. package/dist/lib/shared/fix/fix-polyglot-preview.js +166 -0
  476. package/dist/lib/shared/fix/fix-presentation-biome.js +120 -0
  477. package/dist/lib/shared/fix/fix-presentation-prettier.js +27 -10
  478. package/dist/lib/shared/fix/fix-presentation-rows.js +5 -1
  479. package/dist/lib/shared/fix/fix-presentation.js +22 -15
  480. package/dist/lib/shared/fix/fix-project-membership.js +79 -0
  481. package/dist/lib/shared/fix/fix-reversal-proof.js +107 -0
  482. package/dist/lib/shared/fix/fix-reverse.js +37 -0
  483. package/dist/lib/shared/fix/fix-safety.js +4 -4
  484. package/dist/lib/shared/fix/fix-scope.js +13 -9
  485. package/dist/lib/shared/fix/fix-source-snapshot.js +92 -0
  486. package/dist/lib/shared/fix/fix-staging.js +129 -0
  487. package/dist/lib/shared/fix/fix-terminal.js +34 -9
  488. package/dist/lib/shared/fix/fix-typecheck.js +21 -8
  489. package/dist/lib/shared/fix/project-file-access.js +44 -11
  490. package/dist/lib/shared/fix/read-fix-text.js +23 -0
  491. package/dist/lib/shared/fix/reversal-lock.js +37 -0
  492. package/dist/lib/shared/fix/review-fix-mode.js +9 -0
  493. package/dist/lib/shared/fix.js +162 -26
  494. package/dist/lib/shared/formats/ci-consumers.js +84 -0
  495. package/dist/lib/shared/formats/finding-location.js +52 -3
  496. package/dist/lib/shared/formats/github.js +22 -7
  497. package/dist/lib/shared/formats/index.js +21 -5
  498. package/dist/lib/shared/formats/readable.js +63 -0
  499. package/dist/lib/shared/formats/report-rows.js +38 -0
  500. package/dist/lib/shared/formats/sarif-fixes.js +261 -0
  501. package/dist/lib/shared/formats/sarif.js +175 -33
  502. package/dist/lib/shared/formats/security-cwe.js +113 -0
  503. package/dist/lib/shared/node-scan.js +64 -0
  504. package/dist/lib/shared/package-root.js +2 -0
  505. package/dist/lib/shared/project-root.js +27 -1
  506. package/dist/lib/shared/reporting/action-summary.js +31 -0
  507. package/dist/lib/shared/reporting/baseline.js +12 -12
  508. package/dist/lib/shared/reporting/finding-id-hash.js +7 -0
  509. package/dist/lib/shared/reporting/impact-levels.js +1 -1
  510. package/dist/lib/shared/reporting/pillar-rules.js +13 -1
  511. package/dist/lib/shared/reporting/pillars.js +37 -19
  512. package/dist/lib/shared/reporting/rule-docs.js +2 -2
  513. package/dist/lib/shared/reporting/rule-pack-fingerprint.js +21 -0
  514. package/dist/lib/shared/reporting/source-report.js +16 -2
  515. package/dist/lib/shared/reporting/stray-console-methods.js +1 -0
  516. package/dist/lib/shared/rule-registry.js +6 -1
  517. package/dist/lib/shared/system/atomic-write.js +12 -6
  518. package/dist/lib/shared/system/component-source.js +28 -0
  519. package/dist/lib/shared/system/environment.js +12 -0
  520. package/dist/lib/shared/system/file-key.js +8 -0
  521. package/dist/lib/shared/system/git.js +47 -0
  522. package/dist/lib/shared/system/glob.js +92 -14
  523. package/dist/lib/shared/system/jsonc-config.js +63 -0
  524. package/dist/lib/shared/system/path-inside.js +19 -0
  525. package/dist/lib/shared/system/posix-path.js +22 -0
  526. package/dist/lib/shared/system/read-json.js +10 -0
  527. package/dist/lib/shared/system/sentry.js +6 -3
  528. package/dist/lib/shared/system/text-helpers.js +40 -0
  529. package/dist/lib/shared/system/windows-orphans-script.js +75 -0
  530. package/dist/lib/shared/system/windows-orphans.js +28 -0
  531. package/dist/lib/shared/types/changed-lines.js +1 -0
  532. package/dist/lib/shared/types/completion.js +1 -0
  533. package/dist/lib/shared/workspace-selection.js +67 -0
  534. package/dist/lib/shared/workspaces.js +210 -68
  535. package/dist/polyglot/maintainability/rules.js +119 -3
  536. package/examples/README.md +45 -0
  537. package/examples/clean/avatar.html +1 -0
  538. package/examples/clean/source.ts +10 -0
  539. package/examples/clean/tsconfig.json +4 -0
  540. package/examples/findings/avatar.html +1 -0
  541. package/examples/findings/source.ts +11 -0
  542. package/examples/findings/tsconfig.json +4 -0
  543. package/examples/labels-clean.py +5 -0
  544. package/integrations/zed/Cargo.lock +1 -1
  545. package/integrations/zed/Cargo.toml +1 -1
  546. package/integrations/zed/LICENSE +201 -0
  547. package/integrations/zed/extension.toml +3 -3
  548. package/integrations/zed/extension.wasm +0 -0
  549. package/integrations/zed/src/lib.rs +108 -8
  550. package/package.json +25 -14
  551. package/polyglot/performance/rules/csharp.yml +173 -10
  552. package/polyglot/performance/rules/go.yml +15 -7
  553. package/polyglot/performance/rules/input.yml +12 -0
  554. package/polyglot/performance/rules/java.yml +52 -1
  555. package/polyglot/performance/rules/php.yml +146 -0
  556. package/polyglot/performance/rules/python.yml +7 -3
  557. package/polyglot/performance/rules/ruby.yml +81 -0
  558. package/polyglot/performance/sgconfig.yml +2 -0
  559. package/polyglot/reliability/rules/csharp.yml +105 -0
  560. package/polyglot/reliability/rules/go.yml +339 -0
  561. package/polyglot/reliability/rules/input.yml +6 -0
  562. package/polyglot/reliability/rules/java.yml +218 -0
  563. package/polyglot/reliability/rules/kotlin.yml +49 -0
  564. package/polyglot/reliability/rules/python.yml +288 -0
  565. package/polyglot/reliability/rules/rust.yml +83 -0
  566. package/polyglot/reliability/sgconfig.yml +1 -0
  567. package/polyglot/security/rules/csharp.yml +143 -3
  568. package/polyglot/security/rules/go.yml +59 -4
  569. package/polyglot/security/rules/java.yml +103 -0
  570. package/polyglot/security/rules/python.yml +413 -21
  571. package/polyglot/security/rules/rust.yml +176 -3
  572. package/polyglot/security/sgconfig.yml +2 -0
  573. package/polyglot/security/utils/java-imported-jca-cipher.yml +32 -0
  574. package/polyglot/security/utils/java-unshadowed-javax.yml +29 -0
  575. package/schema/loadwise.config.schema.json +1051 -600
  576. package/schema/loadwise.outcomes.schema.json +43 -0
  577. package/types/scan.d.ts +53 -0
  578. package/dist/lib/maintainability/site-fixes/exports.js +0 -25
  579. package/docs/assets/cli-workflow.gif +0 -0
  580. package/plugin/.claude-plugin/plugin.json +0 -9
  581. package/plugin/commands/loadwise.md +0 -29
  582. package/plugin/hooks/check-edited-file.mjs +0 -173
  583. package/plugin/hooks/hooks.json +0 -17
  584. /package/dist/lib/{maintainability/types/changed-lines.js → editor/types/workspace-fix.js} +0 -0
@@ -1,17 +1,20 @@
1
1
  import ts from 'typescript';
2
2
  import { walkNodes } from '../analysis/walk.js';
3
- import { generatedSource } from './duplicates.js';
4
- import { hasTestCaseFileName, isVendoredMinified, testPathKindInProject, } from '../../shared/analysis/execution-context.js';
5
- import { isVendoredOrSamplePath } from '../analysis/source-exclusions.js';
3
+ import { targetsEnclosingTypeParameter } from './generic-assertion-target.js';
4
+ import { checkTypeEscapeHatches } from './type-escape-hatches.js';
5
+ import { isExcludedSource } from './unowned-source.js';
6
+ import { hasTestCaseFileName, testPathKindInProject } from '../../shared/analysis/execution-context.js';
6
7
  import { originalProgram } from '../site-fixes/isolated-program.js';
7
- // Code generators (GraphQL codegen, Prisma, OpenAPI clients) write casts and directives the team cannot edit.
8
- const GENERATED_PATH = /(?:^|\/)(?:__generated__|generated[\w-]*|gen)\/|\.(?:generated|gen)\.[cm]?[jt]sx?$/i;
9
8
  const TYPESCRIPT_FILE = /\.[cm]?tsx?$/i;
10
9
  const FOCUSABLE_RUNNERS = new Set(['describe', 'it', 'test', 'suite']);
10
+ const BENCHMARK_FILE = /\.bench\.[cm]?[jt]sx?$/i;
11
11
  // Jasmine's focused forms, which are plain functions rather than `.only` members.
12
12
  const JASMINE_FOCUSED = new Set(['fit', 'fdescribe']);
13
- // The compiler reads a directive from the last line of a comment, where a block comment's `*` gutter may precede it.
14
- const SUPPRESSION_DIRECTIVE = /^\s*(?:[/*]\s*)*@ts-(ignore|expect-error|nocheck)\b(.*)$/s;
13
+ // The compiler accepts two or three contiguous slashes in a line comment, not a directive nested in commented-out code.
14
+ const LINE_SUPPRESSION_DIRECTIVE = /^\/\/\/?\s*@ts-(ignore|expect-error|nocheck)\b(.*)$/s;
15
+ // The last line of a block comment can put a `*` gutter before the directive.
16
+ const BLOCK_SUPPRESSION_DIRECTIVE = /^\s*[/*]*\s*@ts-(ignore|expect-error|nocheck)\b(.*)$/s;
17
+ const INVALID_TEST_CASE_REASON = /^\s*\/\/\s*invalid:\s*(.*)$/i;
15
18
  const WORD_CHARACTER = /[\p{L}\p{N}]/u;
16
19
  const WATCHED_DIRECTIVE = /@ts-(?:ignore|expect-error|nocheck)/;
17
20
  const CANONICAL_INTEGER = /^(?:0|[1-9]\d*)$/;
@@ -76,7 +79,8 @@ function isFocusableRunner(expression, runnerNames) {
76
79
  const node = unwrapTestExpression(expression);
77
80
  if (ts.isIdentifier(node)) {
78
81
  // An imported alias is an ordinary name wherever a parameter or local shadows the import.
79
- return runnerNames.has(node.text) && (FOCUSABLE_RUNNERS.has(node.text) || refersToImport(node));
82
+ return ((runnerNames.has(node.text) && (FOCUSABLE_RUNNERS.has(node.text) || refersToImport(node))) ||
83
+ isExplicitFocusRunner(node));
80
84
  }
81
85
  if (ts.isCallExpression(node)) {
82
86
  // `it.each(cases).only(...)`
@@ -86,8 +90,27 @@ function isFocusableRunner(expression, runnerNames) {
86
90
  isFocusableRunner(callee.expression, runnerNames));
87
91
  }
88
92
  return (isMemberAccess(node) &&
89
- RUNNER_MODIFIERS.has(focusedMemberName(node) ?? '') &&
90
- isFocusableRunner(node.expression, runnerNames));
93
+ (isExplicitFocusRunner(node) ||
94
+ (RUNNER_MODIFIERS.has(focusedMemberName(node) ?? '') && isFocusableRunner(node.expression, runnerNames))));
95
+ }
96
+ function isExplicitFocusRunner(node) {
97
+ // Only a binding from vitest or mocha can be `bench` or `context`, so a file that never names either module is
98
+ // settled without building a type checker.
99
+ if (!ts.isIdentifier(node) && !['bench', 'context'].includes(focusedMemberName(node) ?? ''))
100
+ return false;
101
+ if (!/(["'`])(?:vitest|mocha)\1/.test(node.getSourceFile().text))
102
+ return false;
103
+ const checker = originalProgram(node.getSourceFile()).getTypeChecker();
104
+ if (ts.isIdentifier(node)) {
105
+ const declaration = checker.getSymbolAtLocation(node)?.declarations?.[0];
106
+ const imported = declaration && optionRunnerImport(declaration, checker);
107
+ return ((imported?.moduleName === 'vitest' && imported.exportName === 'bench') ||
108
+ (imported?.moduleName === 'mocha' && imported.exportName === 'context'));
109
+ }
110
+ const member = focusedMemberName(node);
111
+ if (member === 'bench')
112
+ return namespaceRunnerModule(node.expression, checker) === 'vitest';
113
+ return member === 'context' && namespaceRunnerModule(node.expression, checker) === 'mocha';
91
114
  }
92
115
  function focusedMemberName(node) {
93
116
  if (ts.isPropertyAccessExpression(node))
@@ -286,18 +309,21 @@ function isVitestTestUnfocused(member, registration) {
286
309
  const imported = declaration && optionRunnerImport(declaration, checker);
287
310
  return imported?.moduleName === 'vitest' && (imported.exportName === 'test' || imported.exportName === 'it');
288
311
  }
289
- function requiresNodeTest(declaration, checker) {
290
- if (!ts.isVariableDeclarationList(declaration.parent) || !(declaration.parent.flags & ts.NodeFlags.Const))
291
- return false;
292
- const initializer = unwrapTestExpression(declaration.initializer);
312
+ function requiredRunnerModuleCall(node, checker) {
313
+ const initializer = unwrapTestExpression(node);
293
314
  if (!initializer || !ts.isCallExpression(initializer) || initializer.arguments.length !== 1)
294
- return false;
315
+ return undefined;
295
316
  const { expression, arguments: [module], } = initializer;
296
- return (ts.isIdentifier(expression) &&
317
+ if (ts.isIdentifier(expression) &&
297
318
  expression.text === 'require' &&
298
319
  !checker.getSymbolAtLocation(expression)?.declarations?.length &&
299
- ts.isStringLiteralLike(module) &&
300
- module.text === 'node:test');
320
+ ts.isStringLiteralLike(module))
321
+ return module.text;
322
+ }
323
+ function requiredRunnerModule(declaration, checker) {
324
+ if (!ts.isVariableDeclarationList(declaration.parent) || !(declaration.parent.flags & ts.NodeFlags.Const))
325
+ return;
326
+ return requiredRunnerModuleCall(declaration.initializer, checker);
301
327
  }
302
328
  function writesTestContext(identifier) {
303
329
  const reference = outerTestExpression(identifier);
@@ -358,16 +384,20 @@ function optionRunnerExport(moduleName, exportName) {
358
384
  if (moduleName === 'vitest' && FOCUSABLE_RUNNERS.has(exportName))
359
385
  return 'vitest';
360
386
  }
361
- function namespaceOptionRunner(receiver, exportName, checker) {
387
+ function namespaceRunnerModule(receiver, checker) {
362
388
  const identifier = unwrapTestExpression(receiver);
363
389
  if (!ts.isIdentifier(identifier))
364
390
  return;
365
391
  const declaration = checker.getSymbolAtLocation(identifier)?.declarations?.[0];
366
- if (!declaration || !ts.isNamespaceImport(declaration) || declaration.parent.isTypeOnly)
392
+ if (!declaration)
393
+ return;
394
+ if (ts.isVariableDeclaration(declaration))
395
+ return requiredRunnerModule(declaration, checker);
396
+ if (!ts.isNamespaceImport(declaration) || declaration.parent.isTypeOnly)
367
397
  return;
368
398
  const module = declaration.parent.parent.moduleSpecifier;
369
399
  if (ts.isStringLiteral(module))
370
- return optionRunnerExport(module.text, exportName);
400
+ return module.text;
371
401
  }
372
402
  function optionRunnerKind(expression, checker) {
373
403
  const callee = unwrapTestExpression(expression);
@@ -380,7 +410,8 @@ function optionRunnerKind(expression, checker) {
380
410
  return 'vitest';
381
411
  return;
382
412
  }
383
- const namespaceRunner = namespaceOptionRunner(callee.expression, member, checker);
413
+ const module = namespaceRunnerModule(callee.expression, checker);
414
+ const namespaceRunner = module && optionRunnerExport(module, member);
384
415
  if (namespaceRunner)
385
416
  return namespaceRunner;
386
417
  if (member !== 'test')
@@ -395,7 +426,7 @@ function optionRunnerKind(expression, checker) {
395
426
  const declaration = checker.getSymbolAtLocation(callee)?.declarations?.[0];
396
427
  if (!declaration)
397
428
  return;
398
- if (ts.isVariableDeclaration(declaration) && requiresNodeTest(declaration, checker))
429
+ if (ts.isVariableDeclaration(declaration) && requiredRunnerModule(declaration, checker) === 'node:test')
399
430
  return 'node-test';
400
431
  const imported = optionRunnerImport(declaration, checker);
401
432
  if (imported)
@@ -403,12 +434,11 @@ function optionRunnerKind(expression, checker) {
403
434
  }
404
435
  function optionRunnerImport(declaration, checker) {
405
436
  if (ts.isBindingElement(declaration) && ts.isVariableDeclaration(declaration.parent.parent)) {
406
- if (!declaration.initializer &&
407
- !declaration.dotDotDotToken &&
408
- requiresNodeTest(declaration.parent.parent, checker)) {
437
+ const moduleName = requiredRunnerModule(declaration.parent.parent, checker);
438
+ if (!declaration.initializer && !declaration.dotDotDotToken && moduleName) {
409
439
  const name = declaration.propertyName ?? declaration.name;
410
440
  if (ts.isIdentifier(name) || ts.isStringLiteral(name))
411
- return { moduleName: 'node:test', exportName: name.text };
441
+ return { moduleName, exportName: name.text };
412
442
  }
413
443
  }
414
444
  else if (ts.isImportSpecifier(declaration) || ts.isImportClause(declaration)) {
@@ -424,6 +454,37 @@ function optionRunnerImport(declaration, checker) {
424
454
  return { moduleName: module.text, exportName };
425
455
  }
426
456
  }
457
+ function nodeTestImportIdentity(binding, checker) {
458
+ const declaration = binding.declarations?.[0];
459
+ if (declaration && (ts.isVariableDeclaration(declaration) || ts.isNamespaceImport(declaration))) {
460
+ const name = ts.getNameOfDeclaration(declaration);
461
+ if (name && namespaceRunnerModule(name, checker) === 'node:test')
462
+ return 'node-test';
463
+ }
464
+ const imported = declaration && optionRunnerImport(declaration, checker);
465
+ if (imported?.moduleName !== 'node:test')
466
+ return;
467
+ const kind = optionRunnerExport(imported.moduleName, imported.exportName);
468
+ if (kind === 'node-test' || kind === 'node-suite')
469
+ return kind;
470
+ }
471
+ function vitestRegistrationIdentity(name) {
472
+ if (name === 'test' || name === 'it')
473
+ return 'vitest:test';
474
+ if (name === 'describe' || name === 'suite')
475
+ return 'vitest:suite';
476
+ }
477
+ function vitestRunnerImportIdentity(binding, member, checker) {
478
+ const declaration = binding.declarations?.[0];
479
+ if (!declaration)
480
+ return;
481
+ const imported = optionRunnerImport(declaration, checker);
482
+ if (imported?.moduleName === 'vitest')
483
+ return vitestRegistrationIdentity(imported.exportName);
484
+ const name = ts.getNameOfDeclaration(declaration);
485
+ if (name && namespaceRunnerModule(name, checker) === 'vitest')
486
+ return vitestRegistrationIdentity(member) ?? 'vitest-module';
487
+ }
427
488
  function hasFocusedTestOptions(node, sourceFile) {
428
489
  if (!ts.isCallExpression(node))
429
490
  return false;
@@ -435,18 +496,31 @@ function hasFocusedTestOptions(node, sourceFile) {
435
496
  const runnerKind = optionRunnerKind(node.expression, originalProgram(sourceFile).getTypeChecker());
436
497
  return runnerKind === 'vitest' ? options === second : runnerKind === 'node-test' || runnerKind === 'node-suite';
437
498
  }
499
+ function isDirectFocusedTestModifier(node) {
500
+ if (!ts.isPropertyAccessExpression(node) || node.questionDotToken || node.name.text !== 'only')
501
+ return false;
502
+ const call = node.parent;
503
+ if (!ts.isCallExpression(call) || call.expression !== node)
504
+ return false;
505
+ const sourceFile = node.getSourceFile();
506
+ return (isFocusedMember(node, runnerNamesOf(sourceFile)) &&
507
+ optionRunnerKind(node.expression, originalProgram(sourceFile).getTypeChecker()) !== undefined &&
508
+ !call.arguments.some(mayFocusAfterRemovingModifier));
509
+ }
510
+ function mayFocusAfterRemovingModifier(argument) {
511
+ const value = unwrapTestExpression(argument);
512
+ if (isPrimitiveLiteral(value) || ts.isArrowFunction(value) || ts.isFunctionExpression(value))
513
+ return false;
514
+ if (!ts.isObjectLiteralExpression(value))
515
+ return true;
516
+ if (value.properties.some(ts.isAccessor))
517
+ return true;
518
+ return !setsOnlyFalse(value) && value.properties.some((property) => mayDefineKey(property, 'only'));
519
+ }
438
520
  function findingAt(sourceFile, file, position, { ruleId, message }) {
439
521
  const { line, character } = sourceFile.getLineAndCharacterOfPosition(position);
440
522
  return { file, line: line + 1, column: character + 1, ruleId, message };
441
523
  }
442
- function isExcludedSource(file, sourceFile) {
443
- const normalized = file.replaceAll('\\', '/');
444
- return (isVendoredOrSamplePath(normalized) ||
445
- GENERATED_PATH.test(normalized) ||
446
- /\.d\.[cm]?ts$/i.test(normalized) ||
447
- isVendoredMinified(file) ||
448
- Boolean(generatedSource(sourceFile, file)));
449
- }
450
524
  function isTestFile(sourceFile, file) {
451
525
  return Boolean(testPathKindInProject(sourceFile.fileName, () => file));
452
526
  }
@@ -454,14 +528,14 @@ function checkFocusedTests(sourceFile, file) {
454
528
  if (!/\bonly\b|\bf(?:it|describe)\b/.test(sourceFile.text))
455
529
  return [];
456
530
  const kind = testPathKindInProject(sourceFile.fileName, () => file);
457
- if (kind !== 'test-file' && kind !== 'test-directory' && kind !== 'e2e' && !hasTestCaseFileName(file))
531
+ const isTest = kind === 'test-file' || kind === 'test-directory' || kind === 'e2e' || hasTestCaseFileName(file);
532
+ if (!isTest && (kind || !BENCHMARK_FILE.test(file)))
458
533
  return [];
459
534
  const findings = [];
460
- const runnerNames = runnerNamesOf(sourceFile);
535
+ const runnerNames = isTest ? runnerNamesOf(sourceFile) : new Set();
461
536
  walkNodes(sourceFile, (node) => {
462
537
  if (!isFocusedMember(node, runnerNames) &&
463
- !isJasmineFocusedCall(node) &&
464
- !hasFocusedTestOptions(node, sourceFile)) {
538
+ !(isTest && (isJasmineFocusedCall(node) || hasFocusedTestOptions(node, sourceFile)))) {
465
539
  return;
466
540
  }
467
541
  findings.push(findingAt(sourceFile, file, node.getStart(sourceFile), {
@@ -473,7 +547,8 @@ function checkFocusedTests(sourceFile, file) {
473
547
  }
474
548
  function suppressionReason(commentText) {
475
549
  const lastNewline = commentText.lastIndexOf('\n');
476
- const match = SUPPRESSION_DIRECTIVE.exec(commentText.slice(lastNewline + 1));
550
+ const directive = commentText.startsWith('//') ? LINE_SUPPRESSION_DIRECTIVE : BLOCK_SUPPRESSION_DIRECTIVE;
551
+ const match = directive.exec(commentText.slice(lastNewline + 1));
477
552
  if (!match)
478
553
  return;
479
554
  // Text after the directive counts as a reason only when it holds a word, so `-` or `*/` alone do not.
@@ -504,6 +579,18 @@ function commentRangesOf(sourceFile) {
504
579
  });
505
580
  return ranges;
506
581
  }
582
+ function hasInvalidTestCaseReason(sourceFile, file, position) {
583
+ const { line } = sourceFile.getLineAndCharacterOfPosition(position);
584
+ if (line === 0)
585
+ return false;
586
+ const starts = sourceFile.getLineStarts();
587
+ const lineStart = starts[line];
588
+ if (sourceFile.text.slice(lineStart, position).trim())
589
+ return false;
590
+ const previousLine = sourceFile.text.slice(starts[line - 1], lineStart).trimEnd();
591
+ const reason = INVALID_TEST_CASE_REASON.exec(previousLine)?.[1];
592
+ return Boolean(reason && WORD_CHARACTER.test(reason) && isTestFile(sourceFile, file));
593
+ }
507
594
  function checkSuppressionReasons(sourceFile, file) {
508
595
  if (!WATCHED_DIRECTIVE.test(sourceFile.text))
509
596
  return [];
@@ -512,6 +599,8 @@ function checkSuppressionReasons(sourceFile, file) {
512
599
  const result = suppressionReason(sourceFile.text.slice(range.pos, range.end));
513
600
  if (!result || result.hasReason)
514
601
  continue;
602
+ if (result.directive === 'expect-error' && hasInvalidTestCaseReason(sourceFile, file, range.pos))
603
+ continue;
515
604
  findings.push(findingAt(sourceFile, file, range.pos, {
516
605
  ruleId: 'ts-suppression-without-reason',
517
606
  message: `\`@ts-${result.directive}\` silences the compiler with no explanation, so a later reader cannot tell whether the error is still real. Add the reason after the directive, or fix the type error.`,
@@ -541,7 +630,7 @@ function checkDoubleTypeAssertions(sourceFile, file) {
541
630
  return [];
542
631
  const findings = [];
543
632
  walkNodes(sourceFile, (node) => {
544
- if (!isDoubleAssertion(node))
633
+ if (!isDoubleAssertion(node) || targetsEnclosingTypeParameter(node))
545
634
  return;
546
635
  findings.push(findingAt(sourceFile, file, node.getStart(sourceFile), {
547
636
  ruleId: 'double-type-assertion',
@@ -557,6 +646,7 @@ function checkTypeSafetyHygiene(sourceFile, file) {
557
646
  ...checkFocusedTests(sourceFile, file),
558
647
  ...checkSuppressionReasons(sourceFile, file),
559
648
  ...checkDoubleTypeAssertions(sourceFile, file),
649
+ ...checkTypeEscapeHatches(sourceFile, file),
560
650
  ];
561
651
  }
562
- export { checkTypeSafetyHygiene };
652
+ export { checkTypeSafetyHygiene, isDirectFocusedTestModifier, nodeTestImportIdentity, requiredRunnerModuleCall, vitestRunnerImportIdentity, };
@@ -0,0 +1,15 @@
1
+ import { generatedSource } from './duplicates.js';
2
+ import { isVendoredMinified } from '../../shared/analysis/execution-context.js';
3
+ import { isVendoredOrSamplePath } from '../analysis/source-exclusions.js';
4
+ // Code generators (GraphQL codegen, Prisma, OpenAPI clients) write casts and directives the team cannot edit.
5
+ const GENERATED_PATH = /(?:^|\/)(?:__generated__|generated[\w-]*|gen)\/|\.(?:generated|gen)\.[cm]?[jt]sx?$/i;
6
+ // Declaration files, generated, vendored and sample code that the type-safety rules leave to their owners.
7
+ function isExcludedSource(file, sourceFile) {
8
+ const normalized = file.replaceAll('\\', '/');
9
+ return (isVendoredOrSamplePath(normalized) ||
10
+ GENERATED_PATH.test(normalized) ||
11
+ /\.d\.[cm]?ts$/i.test(normalized) ||
12
+ isVendoredMinified(file) ||
13
+ Boolean(generatedSource(sourceFile, file)));
14
+ }
15
+ export { isExcludedSource };
@@ -6,6 +6,7 @@ const knownRules = new Set([
6
6
  'deprecated-node-api',
7
7
  'double-type-assertion',
8
8
  'duplicate-implementation',
9
+ 'explicit-any',
9
10
  'file-placement',
10
11
  'focused-test-committed',
11
12
  'folder-boundary',
@@ -13,11 +14,13 @@ const knownRules = new Set([
13
14
  'large-class',
14
15
  'large-module',
15
16
  'long-parameter-list',
17
+ 'python-interactive-debugger',
16
18
  'query-mutates-state',
17
19
  'stray-console',
18
20
  'ts-suppression-without-reason',
19
21
  'tsconfig-strict-disabled',
20
22
  'unreferenced-file',
23
+ 'unsafe-wide-type',
21
24
  'unused-export',
22
25
  'unused-import',
23
26
  'unused-local-function',
@@ -35,6 +38,7 @@ const impactByRule = {
35
38
  'deprecated-node-api': 'medium',
36
39
  'double-type-assertion': 'low',
37
40
  'duplicate-implementation': 'medium',
41
+ 'explicit-any': 'low',
38
42
  'file-placement': 'low',
39
43
  'focused-test-committed': 'medium',
40
44
  'folder-boundary': 'medium',
@@ -42,12 +46,14 @@ const impactByRule = {
42
46
  'large-class': 'low',
43
47
  'large-module': 'low',
44
48
  'long-parameter-list': 'low',
49
+ 'python-interactive-debugger': 'medium',
45
50
  'query-mutates-state': 'medium',
46
51
  'stray-console': 'low',
47
52
  'syntax-error': 'medium',
48
53
  'ts-suppression-without-reason': 'low',
49
54
  'tsconfig-strict-disabled': 'medium',
50
55
  'unreferenced-file': 'low',
56
+ 'unsafe-wide-type': 'low',
51
57
  'unused-export': 'low',
52
58
  'unused-import': 'low',
53
59
  'unused-local-function': 'low',
@@ -64,6 +70,7 @@ const descriptionByRule = {
64
70
  'deprecated-node-api': 'A deprecated Node.js API is used: new Buffer(), url.parse() or fs.exists().',
65
71
  'double-type-assertion': 'A value is cast through unknown or any to a second type, bypassing the type checker.',
66
72
  'duplicate-implementation': 'Substantial functions share the same implementation.',
73
+ 'explicit-any': 'An explicit any type turns off type checking for a value.',
67
74
  'file-placement': 'A file with a configured suffix sits outside its allowed folders.',
68
75
  'focused-test-committed': 'A committed .only, only: true, fit or fdescribe can make the test runner skip other tests.',
69
76
  'folder-boundary': 'An import crosses a folder boundary the team declared.',
@@ -71,12 +78,14 @@ const descriptionByRule = {
71
78
  'large-class': 'A class has more than 30 methods, accessors, constructors or function-valued fields.',
72
79
  'large-module': 'A file has more than 600 lines of code.',
73
80
  'long-parameter-list': 'A function takes more than 5 positional parameters.',
81
+ 'python-interactive-debugger': 'A Python call enters an interactive debugger in production source.',
74
82
  'query-mutates-state': 'A method marked @maintainabilityQuery writes through this.',
75
83
  'stray-console': 'A console call in production code bypasses the logger, so its output has no level or structure.',
76
84
  'syntax-error': 'A native parser could not read the file, so it is skipped and listed and the scan exits 2.',
77
85
  'ts-suppression-without-reason': 'A @ts-ignore, @ts-expect-error or @ts-nocheck directive has no explanation.',
78
86
  'tsconfig-strict-disabled': 'A tsconfig turns off strict type checking.',
79
87
  'unreferenced-file': 'A source file that nothing imports and that is not an entry point.',
88
+ 'unsafe-wide-type': 'A Function, Object or {} type accepts almost any value, so the compiler checks little.',
80
89
  'unused-export': 'An export that no scanned file imports.',
81
90
  'unused-import': 'An imported name is never used in the file.',
82
91
  'unused-local-function': 'A private function declaration has no references.',
@@ -43,7 +43,12 @@ async function scanChangedFiles(root, policy, changedFiles, { parallelFrom = PAR
43
43
  edges.push(edge);
44
44
  constEnums.set(file, analysis.constEnums);
45
45
  });
46
- const polyglot = await analyzePolyglot({ root, files: polyglotTargets, includeDuplicates: false });
46
+ const polyglot = await analyzePolyglot({
47
+ root,
48
+ files: polyglotTargets,
49
+ includeDuplicates: false,
50
+ parameterLimit: (file) => (policy.limitsFor?.(file) ?? policy.limits).longParameterCount,
51
+ });
47
52
  for (const finding of polyglot.findings)
48
53
  findings.push(finding);
49
54
  for (const finding of checkTsconfigStrictness(root, inventory.filter((file) => changed.has(file))))
@@ -1,6 +1,7 @@
1
1
  import { parentPort, workerData } from 'node:worker_threads';
2
2
  import { createResolver } from './cli/inputs.js';
3
3
  import { readSourceFiles, analyzeSource } from './analysis/analyze-source.js';
4
+ import { errorMessage } from '../shared/system/error-code.js';
4
5
  const { root, jsFiles, analysisOptions } = workerData;
5
6
  if (!parentPort)
6
7
  throw new Error('scan-worker must run as a worker thread.');
@@ -9,9 +10,6 @@ const resolve = createResolver(root, new Set(jsFiles));
9
10
  // Each request is a batch of project-relative files; the reply keeps their order. A failure is
10
11
  // reported per file so the caller can raise the first one in file order, as a single-threaded scan
11
12
  // would.
12
- function describeFailure(error) {
13
- return error instanceof Error ? error.message : String(error);
14
- }
15
13
  // A rejection in an async listener would crash the worker without a reply, so any failure outside
16
14
  // the per-file analysis is reported for every file of the batch instead.
17
15
  port.on('message', async ({ batch, files, limits }) => {
@@ -26,7 +24,7 @@ port.on('message', async ({ batch, files, limits }) => {
26
24
  });
27
25
  }
28
26
  catch (error) {
29
- return { failure: describeFailure(error) };
27
+ return { failure: errorMessage(error) };
30
28
  }
31
29
  });
32
30
  const reply = { batch, results };
@@ -35,7 +33,7 @@ port.on('message', async ({ batch, files, limits }) => {
35
33
  catch (error) {
36
34
  const reply = {
37
35
  batch,
38
- results: files.map(() => ({ failure: describeFailure(error) })),
36
+ results: files.map(() => ({ failure: errorMessage(error) })),
39
37
  };
40
38
  port.postMessage(reply);
41
39
  }
@@ -11,15 +11,18 @@ import { checkUnusedModules } from './unused/unused-modules.js';
11
11
  import { collectModuleUsage } from './unused/module-usage.js';
12
12
  import { checkPlacement } from './architecture/layout.js';
13
13
  import { nonJsLanguages, analyzePolyglot } from './polyglot.js';
14
+ import { defaultLimits } from './quality/limits.js';
14
15
  import { readSourceFiles, analyzeSource } from './analysis/analyze-source.js';
15
16
  import { checkTsconfigStrictness } from './quality/tsconfig-strict.js';
16
17
  import { identifierIndexOf, isPrivateManifest } from './analysis/source-facts.js';
17
18
  import { noteFlowSkips, recordUnparsedFile } from '../shared/reporting/flow-skips.js';
19
+ import { CliUsageError } from '../shared/system/sentry.js';
18
20
  // Starting a thread and loading TypeScript in it costs more than analysing a small project.
19
21
  const PARALLEL_FROM_FILES = 600;
20
22
  const MAXIMUM_WORKERS = 8;
23
+ const WORKER_LIMIT_VARIABLE = 'LOADWISE_MAINT_WORKERS';
21
24
  const BATCH_SIZE = 16;
22
- // Resolve per-file settings on the main thread; only numeric limits cross the worker boundary.
25
+ // Resolve per-file settings on the main thread; only data crosses the worker boundary.
23
26
  async function analyzeInParallel(root, jsFiles, workerCount, analysisOptions) {
24
27
  const { limitsFor, ...workerOptions } = analysisOptions;
25
28
  const results = Array.from({ length: jsFiles.length });
@@ -76,7 +79,12 @@ async function analyzeSequentially(root, jsFiles, analysisOptions) {
76
79
  }));
77
80
  }
78
81
  function analyzeFiles(root, jsFiles, parallelFrom, analysisOptions) {
79
- const workerCount = Math.min(MAXIMUM_WORKERS, os.availableParallelism() - 1);
82
+ const configuredLimit = process.env[WORKER_LIMIT_VARIABLE];
83
+ const workerLimit = configuredLimit ? Number(configuredLimit) : MAXIMUM_WORKERS;
84
+ if (!Number.isSafeInteger(workerLimit) || workerLimit < 1) {
85
+ throw new CliUsageError(`${WORKER_LIMIT_VARIABLE} must be a positive integer.`);
86
+ }
87
+ const workerCount = Math.min(workerLimit, MAXIMUM_WORKERS, os.availableParallelism() - 1);
80
88
  return jsFiles.length >= parallelFrom && workerCount > 1
81
89
  ? analyzeInParallel(root, jsFiles, workerCount, analysisOptions)
82
90
  : analyzeSequentially(root, jsFiles, analysisOptions);
@@ -152,7 +160,11 @@ function reportUnparsablePolyglot(root, skippedFiles, polyglot) {
152
160
  reportUnparsable(root, skippedFiles, file, [{ parseError }]);
153
161
  }
154
162
  async function analyzeWithPolyglot(root, jsFiles, otherSources, parallelFrom, options) {
155
- const polyglotPromise = analyzePolyglot({ root, files: otherSources });
163
+ const polyglotPromise = analyzePolyglot({
164
+ root,
165
+ files: otherSources,
166
+ parameterLimit: (file) => (options.limitsFor?.(file) ?? options.limits ?? defaultLimits).longParameterCount,
167
+ });
156
168
  try {
157
169
  const analyses = await analyzeFiles(root, jsFiles, parallelFrom, options);
158
170
  return { analyses, polyglot: await polyglotPromise };
@@ -187,6 +199,7 @@ async function scan(root, policy, { parallelFrom = PARALLEL_FROM_FILES, inScope,
187
199
  const fileFacts = new Map();
188
200
  const { analyses, polyglot } = await analyzeWithPolyglot(root, jsFiles, otherSources, parallelFrom, {
189
201
  dataAccess: policy.dataAccess,
202
+ declarativeRules: policy.declarativeRules,
190
203
  limits: policy.limits,
191
204
  limitsFor: policy.limitsFor,
192
205
  indexIdentifiers: identifierIndex !== undefined,
@@ -3,6 +3,7 @@ import path from 'node:path';
3
3
  import { innermostNodeAt } from '../../shared/fix/fix-hunks.js';
4
4
  import { ts, flaggedFunction, hasBlockBody, lineStart, lineEnd, nextLineStart, indentationAt, newlineOf, nameUsed, ownsLines, } from './helpers.js';
5
5
  import { stripExtension, moduleKey } from './duplicate-bindings.js';
6
+ import { normalizeSlashes } from '../../shared/system/posix-path.js';
6
7
  const forbiddenKinds = new Set([
7
8
  ts.SyntaxKind.ThisKeyword,
8
9
  ts.SyntaxKind.SuperKeyword,
@@ -20,7 +21,7 @@ export function siteAt(load, location) {
20
21
  if (fn && hasBlockBody(fn))
21
22
  return { file: location.file, entry, sourceFile: entry.sourceFile, fn };
22
23
  }
23
- export function isGenerator(fn) {
24
+ function isGenerator(fn) {
24
25
  return 'asteriskToken' in fn && fn.asteriskToken !== undefined;
25
26
  }
26
27
  export function isArrowSite(site) {
@@ -169,7 +170,7 @@ function inertModule(sourceFile, loadedModules = new Set()) {
169
170
  });
170
171
  }
171
172
  export function relativeSpecifier(fromFile, toFile, sourceFile) {
172
- let specifier = path.relative(path.dirname(fromFile), toFile).replaceAll('\\', '/');
173
+ let specifier = normalizeSlashes(path.relative(path.dirname(fromFile), toFile));
173
174
  const explicitExtensions = moduleImports(sourceFile).some((declaration) => /^\.{1,2}\/.*\.[cm]?js$/.test(declaration.moduleSpecifier.text));
174
175
  specifier = explicitExtensions ? specifier.replace(/\.([cm]?)tsx?$/, '.$1js') : stripExtension(specifier);
175
176
  return specifier.startsWith('.') ? specifier : './' + specifier;
@@ -20,6 +20,10 @@ function methodShape({ fn, sourceFile }) {
20
20
  const body = dedentLines(rest.join('\n'), indentationAt(sourceFile.text, fn.getStart(sourceFile)));
21
21
  return body === undefined ? undefined : head + '\n' + body;
22
22
  }
23
+ // The shared function keeps `async` because the copied body may await. Generators are not shared.
24
+ function isAsync(fn) {
25
+ return Boolean(fn.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword));
26
+ }
23
27
  function importDeclarationOf(declaration) {
24
28
  const owner = ts.isImportSpecifier(declaration)
25
29
  ? declaration.parent.parent.parent
@@ -141,7 +145,7 @@ function largestSharedMethodGroup(sites, helper, checker) {
141
145
  const candidate = sharedMethodCandidate(site, helper, checker);
142
146
  if (!candidate)
143
147
  continue;
144
- const key = candidate.shape + '\0' + candidate.referenceKeys;
148
+ const key = (isAsync(site.fn) ? 'async\0' : '') + candidate.shape + '\0' + candidate.referenceKeys;
145
149
  groups.set(key, [...(groups.get(key) ?? []), candidate]);
146
150
  }
147
151
  let largest = [];
@@ -358,7 +362,8 @@ function newHelperModule(group, helper, claimedModules) {
358
362
  stem = plainStem + numberedSeparator + number;
359
363
  }
360
364
  const imports = helperImports(first, references, folder);
361
- const moduleText = (imports.length ? imports.join('\n') + '\n\n' : '') + 'export function ' + helper + shape + '\n';
365
+ const keyword = (isAsync(first.fn) ? 'export async function ' : 'export function ') + helper;
366
+ const moduleText = (imports.length ? imports.join('\n') + '\n\n' : '') + keyword + shape + '\n';
362
367
  return {
363
368
  file: folder + '/' + stem + '.ts',
364
369
  text: header + moduleText.replaceAll('\n', newlineOf(first.sourceFile.text)),
@@ -9,6 +9,7 @@ import { claimedModuleNames, occupiedModuleName, moduleStem, sharedLicense } fro
9
9
  import { canonicalCandidate, exported, isArrowSite, isMethodSite, leadingDoc, moduleImports, quoteOf, relativeSpecifier, removal, rewriteCopy, siteAt, withInsertion, } from './duplicate-edits.js';
10
10
  import { shareConfigCallbacks, shareExportedArrows } from './duplicate-arrows.js';
11
11
  import { shareClassMethods } from './duplicate-methods.js';
12
+ import { normalizeSlashes } from '../../shared/system/posix-path.js';
12
13
  // Importing one decorated class module from the other can introduce a cycle or execute decorators
13
14
  // earlier. A new, independent module is an alternative for identical private helpers whose only
14
15
  // consumers call them.
@@ -28,10 +29,10 @@ function shareSiblingHelper(sites, checker, claimedModules) {
28
29
  const neighbors = fs.readdirSync(path.dirname(first.sourceFile.fileName));
29
30
  const stem = moduleStem(helper, neighbors);
30
31
  const header = sharedLicense(sites.map((site) => site.sourceFile));
31
- const occupiedNames = [...neighbors, ...claimedModuleNames(folder.replaceAll('\\', '/'), claimedModules)];
32
+ const occupiedNames = [...neighbors, ...claimedModuleNames(normalizeSlashes(folder), claimedModules)];
32
33
  if (header === undefined || occupiedModuleName(stem, occupiedNames))
33
34
  return;
34
- const file = path.posix.join(folder.replaceAll('\\', '/'), stem + '.ts');
35
+ const file = path.posix.join(normalizeSlashes(folder), stem + '.ts');
35
36
  const targets = [];
36
37
  for (const site of sites) {
37
38
  const { fn, sourceFile } = site;