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
@@ -9,6 +9,7 @@ const bundleVersion = /^\/\*+!?\s*\*?\s*(?:@license\s+)?[\w@][\w@./-]*[ \t]+v?\d
9
9
  // The whole comment webpack's minifier writes when it extracts licenses; the same words in prose are authored.
10
10
  const bundleLicenseNotice = /^\/\*! For license information please see \S+\.LICENSE\.txt(?:\?\S*)? \*\/$/;
11
11
  const loggerNames = new Set(['console', 'logger', 'log']);
12
+ const loggingMethods = new Set(['log', 'info', 'warn', 'error', 'debug', 'trace', 'fatal', 'dir', 'table']);
12
13
  const cleanupMethods = new Set([
13
14
  'close',
14
15
  'destroy',
@@ -57,7 +58,11 @@ function isLoggingCall(statement) {
57
58
  const call = callOf(statement);
58
59
  if (!call)
59
60
  return false;
60
- const [base, owner] = calleeNames(call);
61
+ const names = calleeNames(call);
62
+ const [base, owner] = names;
63
+ const method = names.at(-1) ?? '';
64
+ if (!loggingMethods.has(method))
65
+ return false;
61
66
  return loggerNames.has(base) || (base === 'this' && /^_?(?:logger|log)$/i.test(owner ?? ''));
62
67
  }
63
68
  function isCleanupCall(statement) {
@@ -284,13 +289,18 @@ function onlySerializesTelemetry(tryBlock) {
284
289
  });
285
290
  return hasStringify && !hasOtherCall;
286
291
  }
292
+ const explanatoryComment = /\b(?:error|errors|exception|exceptions|fails?|failed|failing|failure|failures|throw|throws|thrown|reject|rejects|rejected|safe|ignore|ignored|ignoring|fall back|fallback|optional|best[- ]effort|non[- ]blocking|retry|retries|swallow|swallowed|expected|benign|harmless|no[- ]?op|will recover|defaults?|missing|continu\w*|skipp\w*|lint|eslint|loadwise)\b/i;
293
+ function hasExplanatoryLeadingComment(sourceFile, pos) {
294
+ const ranges = ts.getLeadingCommentRanges(sourceFile.text, pos);
295
+ return Boolean(ranges?.some((range) => explanatoryComment.test(sourceFile.text.slice(range.pos, range.end))));
296
+ }
287
297
  function swallowKind(sourceFile, clause) {
288
298
  const tryStatement = clause.parent;
289
299
  const statements = clause.block.statements;
290
300
  if (hasComment(sourceFile, clause.block))
291
301
  return;
292
- // A comment directly above the try, such as "non-blocking", explains the catch just as well.
293
- if (ts.getLeadingCommentRanges(sourceFile.text, tryStatement.pos)?.length)
302
+ // A comment directly above the try, such as "non-blocking", explains the catch only when it mentions error/fallback handling.
303
+ if (hasExplanatoryLeadingComment(sourceFile, tryStatement.pos))
294
304
  return;
295
305
  if (probesOptionalModule(tryStatement.tryBlock) || insideCleanupPath(tryStatement))
296
306
  return;
@@ -341,30 +351,106 @@ function swallowedErrorApplies(sourceFile, file, isGenerated) {
341
351
  !hasBundleBanner(sourceFile, file) &&
342
352
  !(isGenerated ?? generatedSource(sourceFile, file)));
343
353
  }
354
+ function isPromiseTypeNode(type) {
355
+ return (type !== undefined &&
356
+ ts.isTypeReferenceNode(type) &&
357
+ ts.isIdentifier(type.typeName) &&
358
+ (type.typeName.text === 'Promise' || type.typeName.text === 'PromiseLike'));
359
+ }
360
+ function declaresPromiseParameter(node, name) {
361
+ if (!ts.isFunctionLike(node))
362
+ return false;
363
+ return node.parameters.some((param) => ts.isIdentifier(param.name) && param.name.text === name && isPromiseTypeNode(param.type));
364
+ }
365
+ function declaresPromiseVariable(scope, name) {
366
+ if (!ts.isBlock(scope) && !ts.isSourceFile(scope))
367
+ return false;
368
+ return scope.statements.some((stmt) => ts.isVariableStatement(stmt) &&
369
+ stmt.declarationList.declarations.some((decl) => ts.isIdentifier(decl.name) &&
370
+ decl.name.text === name &&
371
+ (isPromiseTypeNode(decl.type) || (decl.initializer && isPromiseReceiver(decl.initializer, false)))));
372
+ }
373
+ function isPromiseTypedName(name, scopeNode) {
374
+ for (let current = scopeNode; current; current = current.parent) {
375
+ if (declaresPromiseParameter(current, name) || declaresPromiseVariable(current, name))
376
+ return true;
377
+ }
378
+ return false;
379
+ }
380
+ function isPromiseReceiver(expression, allowLookup = true) {
381
+ const receiver = withoutWrappers(expression);
382
+ if (ts.isNewExpression(receiver) && ts.isIdentifier(receiver.expression) && receiver.expression.text === 'Promise') {
383
+ return true;
384
+ }
385
+ if (ts.isCallExpression(receiver)) {
386
+ const callee = withoutWrappers(receiver.expression);
387
+ if (ts.isPropertyAccessExpression(callee)) {
388
+ const target = withoutWrappers(callee.expression);
389
+ if (ts.isIdentifier(target) && target.text === 'Promise')
390
+ return true;
391
+ if (['then', 'catch', 'finally'].includes(callee.name.text))
392
+ return true;
393
+ }
394
+ if (ts.isIdentifier(callee) && callee.text === 'fetch')
395
+ return true;
396
+ }
397
+ if (allowLookup && ts.isIdentifier(receiver)) {
398
+ return isPromiseTypedName(receiver.text, receiver);
399
+ }
400
+ return false;
401
+ }
344
402
  function checkSwallowedErrors(sourceFile, file, isGenerated) {
345
403
  if (!swallowedErrorApplies(sourceFile, file, isGenerated))
346
404
  return [];
347
405
  const findings = [];
348
406
  walkNodes(sourceFile, (node) => {
349
- if (!ts.isCatchClause(node))
350
- return;
351
- const kind = swallowKind(sourceFile, node);
352
- if (!kind)
407
+ if (ts.isCatchClause(node)) {
408
+ const kind = swallowKind(sourceFile, node);
409
+ if (!kind)
410
+ return;
411
+ const position = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
412
+ findings.push({
413
+ file,
414
+ line: position.line + 1,
415
+ column: position.character + 1,
416
+ ruleId: 'swallowed-error',
417
+ message: (kind === 'empty'
418
+ ? 'This catch block is empty.'
419
+ : 'This catch block only logs the error and the code after it continues.') + advice,
420
+ ...(kind === 'logs' &&
421
+ parsesInput(node.parent.tryBlock) && {
422
+ contextualReason: 'The try block parses input, so the logged failure may just mean no valid value was supplied.',
423
+ }),
424
+ });
353
425
  return;
354
- const position = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
355
- findings.push({
356
- file,
357
- line: position.line + 1,
358
- column: position.character + 1,
359
- ruleId: 'swallowed-error',
360
- message: (kind === 'empty'
361
- ? 'This catch block is empty.'
362
- : 'This catch block only logs the error and the code after it continues.') + advice,
363
- ...(kind === 'logs' &&
364
- parsesInput(node.parent.tryBlock) && {
365
- contextualReason: 'The try block parses input, so the logged failure may just mean no valid value was supplied.',
366
- }),
367
- });
426
+ }
427
+ if (ts.isCallExpression(node) &&
428
+ ts.isPropertyAccessExpression(node.expression) &&
429
+ node.expression.name.text === 'catch' &&
430
+ node.arguments.length >= 1 &&
431
+ isPromiseReceiver(node.expression.expression)) {
432
+ const callback = node.arguments[0];
433
+ if ((!ts.isArrowFunction(callback) && !ts.isFunctionExpression(callback)) || !ts.isBlock(callback.body))
434
+ return;
435
+ if (hasComment(sourceFile, callback.body))
436
+ return;
437
+ const statements = callback.body.statements;
438
+ const kind = !statements.length
439
+ ? 'empty'
440
+ : statements.every(isLoggingCall) && !logExplainsFallback(statements)
441
+ ? 'logs'
442
+ : undefined;
443
+ if (!kind)
444
+ return;
445
+ const position = sourceFile.getLineAndCharacterOfPosition(callback.getStart(sourceFile));
446
+ findings.push({
447
+ file,
448
+ line: position.line + 1,
449
+ column: position.character + 1,
450
+ ruleId: 'swallowed-error',
451
+ message: (kind === 'empty' ? 'This catch callback is empty.' : 'This catch callback only logs the error.') + advice,
452
+ });
453
+ }
368
454
  });
369
455
  return findings;
370
456
  }
@@ -43,9 +43,15 @@ function testCallback(call, checker, bindings) {
43
43
  const name = runnerName(runner, checker, bindings);
44
44
  if (!name || !testNames.has(name))
45
45
  return;
46
- const callback = unwrapExpression(call.arguments.at(-1));
47
- if (isTestCallback(callback))
48
- return callback;
46
+ const last = unwrapExpression(call.arguments.at(-1));
47
+ if (isTestCallback(last))
48
+ return last;
49
+ // Jest's timeout and Vitest's legacy timeout/options overloads follow the callback.
50
+ if (call.arguments.length !== 3)
51
+ return;
52
+ const middle = unwrapExpression(call.arguments[1]);
53
+ if (isTestCallback(middle))
54
+ return middle;
49
55
  }
50
56
  // A test double written as an object literal listens to nothing, whatever its name.
51
57
  function isObjectLiteralBinding(identifier, checker) {
@@ -163,10 +169,11 @@ function usesJest(sourceFile, checker) {
163
169
  found ||= node.moduleSpecifier.text === '@jest/globals';
164
170
  if (ts.isPropertyAccessExpression(node))
165
171
  found ||= isUnshadowedGlobal(node.expression, 'jest', checker);
172
+ return found;
166
173
  });
167
174
  return found;
168
175
  }
169
- function isIgnoredAfterEach(call, checker, bindings) {
176
+ function isIgnoredAfterEach(call, checker, bindings, hasJest) {
170
177
  const callee = unwrapExpression(call.expression);
171
178
  const name = isAccess(callee) ? staticMemberName(callee) : runnerName(callee, checker, bindings);
172
179
  if (name !== 'afterEach')
@@ -178,12 +185,12 @@ function isIgnoredAfterEach(call, checker, bindings) {
178
185
  // A member named `afterEach` on anything but a runner is a local registrar, which `jest` says nothing about.
179
186
  if (isAccess(callee) && !testNames.has(runnerName(owner, checker, bindings) ?? ''))
180
187
  return false;
181
- return usesJest(call.getSourceFile(), checker);
188
+ return hasJest();
182
189
  }
183
- function runsOutsideTeardown(registration, checker, bindings) {
190
+ function runsOutsideTeardown(registration, checker, bindings, hasJest) {
184
191
  if (!ts.isCallExpression(registration))
185
192
  return false;
186
- if (isIgnoredAfterEach(registration, checker, bindings))
193
+ if (isIgnoredAfterEach(registration, checker, bindings, hasJest))
187
194
  return true;
188
195
  const callee = unwrapExpression(registration.expression);
189
196
  if (ts.isIdentifier(callee))
@@ -193,7 +200,7 @@ function runsOutsideTeardown(registration, checker, bindings) {
193
200
  const member = staticMemberName(callee);
194
201
  return member !== undefined && (eventMethods.has(member) || nonTeardownNames.has(member));
195
202
  }
196
- function releaseExecution(call, callback, checker, bindings) {
203
+ function releaseExecution(call, callback, checker, bindings, hasJest) {
197
204
  const waitRegions = [];
198
205
  let catchOnly = false;
199
206
  const closures = [];
@@ -217,7 +224,8 @@ function releaseExecution(call, callback, checker, bindings) {
217
224
  if (!registration)
218
225
  return;
219
226
  const isHook = ts.isCallExpression(registration) && isCleanupHook(registration, callback, checker, bindings);
220
- if (!isHook && registrations.some((candidate) => candidate && runsOutsideTeardown(candidate, checker, bindings)))
227
+ if (!isHook &&
228
+ registrations.some((candidate) => candidate && runsOutsideTeardown(candidate, checker, bindings, hasJest)))
221
229
  return;
222
230
  return { action: registration, waitRegions: [], protectsOnly: !isHook };
223
231
  }
@@ -229,13 +237,77 @@ function containsOwnStatement(body, matches) {
229
237
  });
230
238
  return found;
231
239
  }
232
- // `await ready().catch(handler)` does not reject unless the handler throws.
233
- function catchesOwnRejection(awaited) {
240
+ function isSafeLiteralValue(expression) {
241
+ const inner = unwrapExpression(expression);
242
+ if (ts.isLiteralExpression(inner) ||
243
+ inner.kind === ts.SyntaxKind.TrueKeyword ||
244
+ inner.kind === ts.SyntaxKind.FalseKeyword ||
245
+ inner.kind === ts.SyntaxKind.NullKeyword ||
246
+ (ts.isIdentifier(inner) && inner.text === 'undefined'))
247
+ return true;
248
+ if (ts.isPrefixUnaryExpression(inner) &&
249
+ (inner.operator === ts.SyntaxKind.MinusToken || inner.operator === ts.SyntaxKind.PlusToken))
250
+ return ts.isNumericLiteral(inner.operand);
251
+ return false;
252
+ }
253
+ function isSafeLiteralHandler(argument) {
254
+ const fn = argument && unwrapExpression(argument);
255
+ if (!fn || (!ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn)))
256
+ return false;
257
+ // Plain identifier parameters bind without evaluating anything; initializers, destructuring and rest could throw.
258
+ if (fn.parameters.some((parameter) => !ts.isIdentifier(parameter.name) || parameter.initializer || parameter.dotDotDotToken))
259
+ return false;
260
+ if (fn.asteriskToken || fn.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword))
261
+ return false;
262
+ if (!ts.isBlock(fn.body))
263
+ return isSafeLiteralValue(fn.body);
264
+ return fn.body.statements.every((statement) => ts.isEmptyStatement(statement) ||
265
+ (ts.isReturnStatement(statement) && (!statement.expression || isSafeLiteralValue(statement.expression))));
266
+ }
267
+ function isNativePromiseType(type) {
268
+ if (type.isUnion())
269
+ return Boolean(type.types?.length && type.types.every(isNativePromiseType));
270
+ const symbol = type.getSymbol() ?? type.aliasSymbol;
271
+ return (symbol?.name === 'Promise' &&
272
+ Boolean(symbol.declarations?.some((decl) => decl.getSourceFile().isDeclarationFile)));
273
+ }
274
+ function isSafeSettledArgument(argument, checker) {
275
+ const unwrapped = unwrapExpression(argument);
276
+ if (ts.isArrayLiteralExpression(unwrapped)) {
277
+ return unwrapped.elements.every((element) => {
278
+ if (ts.isSpreadElement(element))
279
+ return false;
280
+ const item = unwrapExpression(element);
281
+ return ts.isIdentifier(item) || isSafeLiteralValue(item);
282
+ });
283
+ }
284
+ if (!ts.isIdentifier(unwrapped))
285
+ return false;
286
+ const symbolName = checker.getTypeAtLocation(unwrapped).getSymbol()?.name;
287
+ return symbolName === 'Array' || symbolName === 'ReadonlyArray';
288
+ }
289
+ // `await ready().catch(handler)`, `await Promise.allSettled([p1, p2])`, or a native `promise.then(ok, err)`
290
+ // with non-throwing literal-return handlers does not reject.
291
+ function catchesOwnRejection(awaited, checker) {
234
292
  const call = unwrapExpression(awaited.expression);
235
293
  if (!ts.isCallExpression(call))
236
294
  return false;
237
295
  const callee = unwrapExpression(call.expression);
238
- if (!isAccess(callee) || staticMemberName(callee) !== 'catch')
296
+ if (!isAccess(callee))
297
+ return false;
298
+ const method = staticMemberName(callee);
299
+ if (method === 'allSettled') {
300
+ return (call.arguments.length === 1 &&
301
+ isUnshadowedGlobal(callee.expression, 'Promise', checker) &&
302
+ isSafeSettledArgument(call.arguments[0], checker));
303
+ }
304
+ if (method === 'then') {
305
+ return (call.arguments.length >= 2 &&
306
+ isNativePromiseType(checker.getTypeAtLocation(callee.expression)) &&
307
+ isSafeLiteralHandler(call.arguments[0]) &&
308
+ isSafeLiteralHandler(call.arguments[1]));
309
+ }
310
+ if (method !== 'catch')
239
311
  return false;
240
312
  const handler = unwrapExpression(call.arguments[0]);
241
313
  if (!handler)
@@ -245,8 +317,8 @@ function catchesOwnRejection(awaited) {
245
317
  return !containsOwnStatement(handler.body, ts.isThrowStatement);
246
318
  }
247
319
  // True when a rejection is handled and execution still reaches the release.
248
- function rejectionReaches(awaited, release) {
249
- if (catchesOwnRejection(awaited))
320
+ function rejectionReaches(awaited, release, checker) {
321
+ if (catchesOwnRejection(awaited, checker))
250
322
  return true;
251
323
  for (let child = awaited, parent = child.parent; parent; child = parent, parent = parent.parent) {
252
324
  if (!ts.isTryStatement(parent) || parent.tryBlock !== child || !parent.catchClause)
@@ -257,7 +329,7 @@ function rejectionReaches(awaited, release) {
257
329
  }
258
330
  return false;
259
331
  }
260
- function cleanupAfterAwait(declaration, method, { callback, awaits }, checker, bindings) {
332
+ function cleanupAfterAwait(declaration, method, { callback, awaits }, { checker, bindings, hasJest }) {
261
333
  const waitsAfterCreation = awaits.filter((awaited) => awaited.pos >= declaration.end);
262
334
  if (waitsAfterCreation.length === 0)
263
335
  return;
@@ -270,7 +342,7 @@ function cleanupAfterAwait(declaration, method, { callback, awaits }, checker, b
270
342
  return;
271
343
  continue;
272
344
  }
273
- const release = releaseExecution(call, callback, checker, bindings);
345
+ const release = releaseExecution(call, callback, checker, bindings, hasJest);
274
346
  if (release)
275
347
  releases.push(release);
276
348
  }
@@ -278,7 +350,7 @@ function cleanupAfterAwait(declaration, method, { callback, awaits }, checker, b
278
350
  const hasProtectedCleanup = releases.some(({ action, waitRegions, catchOnly }) => (!catchOnly && action.end <= awaited.end) || waitRegions.some((region) => contains(region, awaited)));
279
351
  if (hasProtectedCleanup)
280
352
  continue;
281
- const late = releases.find(({ action, protectsOnly }) => !protectsOnly && action.getStart() >= awaited.end && !rejectionReaches(awaited, action));
353
+ const late = releases.find(({ action, protectsOnly }) => !protectsOnly && action.getStart() >= awaited.end && !rejectionReaches(awaited, action, checker));
282
354
  if (late)
283
355
  return late.action;
284
356
  }
@@ -292,6 +364,8 @@ function checkTestCleanupAfterAwait(sourceFile, file, checker) {
292
364
  const findings = [];
293
365
  const callbacks = new Set();
294
366
  const bindings = new Map();
367
+ let cachedUsesJest;
368
+ const hasJest = () => (cachedUsesJest ??= usesJest(sourceFile, checker));
295
369
  // A describe callback holds tests but does not execute their bodies.
296
370
  walkNodes(sourceFile, (container) => {
297
371
  if (!ts.isCallExpression(container))
@@ -315,7 +389,7 @@ function checkTestCleanupAfterAwait(sourceFile, file, checker) {
315
389
  const method = cleanupMethod(declaration, checker, bindings);
316
390
  if (!method)
317
391
  continue;
318
- const cleanup = cleanupAfterAwait(declaration, method, { callback, awaits }, checker, bindings);
392
+ const cleanup = cleanupAfterAwait(declaration, method, { callback, awaits }, { checker, bindings, hasJest });
319
393
  if (!cleanup)
320
394
  continue;
321
395
  findings.push(findingAt(sourceFile, file, cleanup, 'test-cleanup-after-await', `The test only cleans up \`${declaration.name.getText(sourceFile)}\` after an await. A rejection can leave it running. Register cleanup before awaiting or use a finally block.`));
@@ -1,9 +1,20 @@
1
1
  const reliabilityUsage = `Usage:
2
- loadwise rel [-p tsconfig.json | -p monorepo-root [--workspace name|path ...] | file.ts file.js ...] [--engine auto|native|js] [--policy policy.json] [--loadwise-config loadwise.config.json] [--schema snapshot.json] [--json | --format text|json|sarif|github] [--include-contextual] [--ignore rule-id] [--min-impact low|medium|high|critical] [--fail-on all|contract] [--baseline [file] | --write-baseline [file]] [--fix [--yes | --only id,...] [--no-comments] [--no-format]]
3
- loadwise rel [-p tsconfig.json] (--staged | --changed-since git-ref) [--json] [--include-contextual] [--ignore rule-id]
4
- loadwise rel contracts [--changed-since git-ref] [--json]
5
- loadwise rel migrations [paths...] [--changed-since git-ref] [--baseline file] [--write-baseline] [--dialect postgres|mysql] [--json] [--include-contextual] [--ignore rule-id]
6
- loadwise rel polyglot <file-or-directory> ... [--json]
2
+ loadwise rel [-p <project> | <files...>] [options]
3
+
4
+ Specialist commands
5
+ loadwise rel contracts [options] Compare API contracts against a Git ref
6
+ loadwise rel migrations [paths...] [options] Check database migrations
7
+ loadwise rel polyglot <paths...> Check non-JavaScript source files
8
+ Run loadwise rel <command> --help for specialist command options.
9
+
10
+ Source scan options
11
+ -p <project> --workspace <name|path> --engine <auto|native|js>
12
+ --loadwise-config <file> --policy <file> --schema <file>
13
+ --staged | --changed-since <git-ref> --ignore <rule-id>
14
+ --json | --format <text|json|sarif|github> --include-contextual
15
+ --min-impact <low|medium|high|critical> --fail-on <all|contract>
16
+ --baseline [file] | --write-baseline [file]
17
+ --fix [--yes | --only <ids>] [--no-comments] [--no-format]
7
18
 
8
19
  The reliability checker finds code that fails at runtime or under concurrency: unhandled rejections, swallowed errors, races, missing timeouts and idempotency, transactions that escape their client, and unsafe migrations and API changes.
9
20
  It shares the source check of loadwise perf: the same project discovery, policy, config, engines, baselines and fix flags apply, and \`loadwise check\` type-checks the project once for both.
@@ -1,10 +1,11 @@
1
1
  import { ts } from '../performance/engine/compiler.js';
2
2
  // Visits every node in source order with the selected compiler, so the native engine's trees walk the same way. An
3
- // explicit stack keeps operator chains thousands deep off the call stack.
3
+ // explicit stack keeps operator chains thousands deep off the call stack. A visitor that returns `true` stops the walk.
4
4
  function walkNodes(root, visit) {
5
5
  const pending = [root];
6
6
  for (let node = pending.pop(); node; node = pending.pop()) {
7
- visit(node);
7
+ if (visit(node) === true)
8
+ return;
8
9
  const children = [];
9
10
  ts.forEachChild(node, (child) => {
10
11
  children.push(child);
@@ -127,15 +127,31 @@ function isBreachRangePrefix(top, context) {
127
127
  if (!declaration || !ts.isVariableDeclaration(declaration) || !ts.isIdentifier(declaration.name))
128
128
  return false;
129
129
  const scope = enclosingFunction(declaration) ?? context.sourceFile;
130
- return referencesOf(declaration.name, scope, context.checker).some((reference) => {
130
+ if (ts.canHaveModifiers(declaration.parent.parent) &&
131
+ ts.getModifiers(declaration.parent.parent)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword))
132
+ return false;
133
+ const uses = referencesOf(declaration.name, scope, context.checker);
134
+ let hasPrefix = false;
135
+ for (const reference of uses) {
136
+ if (ts.findAncestor(reference, ts.isTypeQueryNode))
137
+ continue;
131
138
  const access = reference.parent;
132
- const call = access?.parent;
133
- return (ts.isPropertyAccessExpression(access) &&
134
- !!call &&
135
- ts.isCallExpression(call) &&
136
- call.expression === access &&
137
- isRangePrefixCall(call));
138
- });
139
+ if (!ts.isPropertyAccessExpression(access) || access.expression !== reference)
140
+ return false;
141
+ const call = access.parent;
142
+ if (!ts.isCallExpression(call) || call.expression !== access)
143
+ return false;
144
+ if (isRangePrefixCall(call)) {
145
+ hasPrefix = true;
146
+ continue;
147
+ }
148
+ // The range API returns suffixes for local comparison with the remainder of the digest.
149
+ if (!['slice', 'substring'].includes(access.name.text) ||
150
+ call.arguments.length !== 1 ||
151
+ call.arguments[0].getText() !== String(rangePrefixLength))
152
+ return false;
153
+ }
154
+ return hasPrefix;
139
155
  }
140
156
  function isKeyDerivationOrDigestAuth(top, context) {
141
157
  const fn = enclosingFunction(top);
@@ -3,6 +3,7 @@
3
3
  import { calleeName } from '../../performance/analysis/call-syntax.js';
4
4
  import { ts } from '../../performance/engine/compiler.js';
5
5
  import { isEffectivelySet, unwrapExpression } from '../../shared/analysis/ast-semantics.js';
6
+ import { signingAlgorithm, signingSourceHash } from './signing-algorithm.js';
6
7
  import { importedFrom } from '../bindings.js';
7
8
  import { fileMentions, libraryInfo, libraryFunction, resolveConstant, propertyKeyName, findProperty, hasSpread, enclosingFunction, functionName, isFunctionExpressionLike, referencesOf, } from './shared.js';
8
9
  const nestJwt = '@nestjs/jwt';
@@ -59,13 +60,25 @@ function isDecodeCall(call, context) {
59
60
  return false;
60
61
  return (info.method ?? info.exported) === 'decode';
61
62
  }
62
- function isVerifiedInside(scope, tokenText) {
63
+ function isVerifyCall(node, context) {
64
+ if (verifyNames.has(calleeName(node) ?? ''))
65
+ return true;
66
+ const info = libraryInfo(node, context);
67
+ if (!info?.module)
68
+ return false;
69
+ if (info.module !== 'jsonwebtoken' && info.module !== '@nestjs/jwt')
70
+ return false;
71
+ const name = info.method ?? info.exported;
72
+ return name === 'verify' || name === 'verifyAsync';
73
+ }
74
+ function isVerifiedInside(scope, tokenText, decodeCall, context) {
63
75
  let verified = false;
64
76
  (function visit(node) {
65
77
  if (verified)
66
78
  return;
67
79
  if (ts.isCallExpression(node) &&
68
- verifyNames.has(calleeName(node) ?? '') &&
80
+ node.end <= decodeCall.getStart() &&
81
+ isVerifyCall(node, context) &&
69
82
  node.arguments[0]?.getText() === tokenText)
70
83
  verified = true;
71
84
  ts.forEachChild(node, visit);
@@ -186,7 +199,7 @@ function checkJwtDecode(call, context) {
186
199
  if (!isDecodeCall(call, context))
187
200
  return;
188
201
  const scope = enclosingFunction(call) ?? context.sourceFile;
189
- if (isVerifiedInside(scope, call.arguments[0].getText()))
202
+ if (isVerifiedInside(scope, call.arguments[0].getText(), call, context))
190
203
  return;
191
204
  if (isTokenSignedHere(call.arguments[0], context))
192
205
  return;
@@ -308,9 +321,11 @@ function checkJwtVerify(call, context) {
308
321
  isEffectivelySet(options, 'algorithms', context.checker) !== false)
309
322
  return;
310
323
  }
311
- if (keyLooksAsymmetric(call.arguments[1], context))
312
- return context.report(call, 'jwt-verify-without-algorithms', messages.verify);
313
- context.report(call, 'jwt-verify-without-algorithms', messages.verify, 'The key is a shared secret, so an unpinned algorithm is less exploitable here.');
324
+ const reason = keyLooksAsymmetric(call.arguments[1], context)
325
+ ? undefined
326
+ : 'The key is a shared secret, so an unpinned algorithm is less exploitable here.';
327
+ const algorithm = signingAlgorithm(call, context);
328
+ context.report(call, 'jwt-verify-without-algorithms', messages.verify, reason, algorithm ? { signingAlgorithm: algorithm, signingSourceHash: signingSourceHash(context.sourceFile) } : undefined);
314
329
  }
315
330
  function isNoneLiteral(node) {
316
331
  return ts.isStringLiteralLike(node) && node.text.toLowerCase() === noneAlgorithm;
@@ -196,6 +196,46 @@ function targetNames(literal) {
196
196
  names.push(lastSegment(parent.left));
197
197
  return names.filter((name) => Boolean(name));
198
198
  }
199
+ const runtimeConfigFile = /(?:^|[\\/])config(?:[\\/]|$)/i;
200
+ function isProcessEnvAccess(node) {
201
+ return ((ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) &&
202
+ ts.isPropertyAccessExpression(node.expression) &&
203
+ ts.isIdentifier(node.expression.expression) &&
204
+ node.expression.expression.text === 'process' &&
205
+ node.expression.name.text === 'env');
206
+ }
207
+ // The left operand must itself yield the env value; `'Bearer ' + process.env.X` is always truthy.
208
+ function suppliesEnvValue(node) {
209
+ if (ts.isParenthesizedExpression(node) || ts.isNonNullExpression(node))
210
+ return suppliesEnvValue(node.expression);
211
+ // `x || 'configured'` is always truthy, so a fallback after it never runs.
212
+ if (ts.isBinaryExpression(node) &&
213
+ node.operatorToken.kind === ts.SyntaxKind.BarBarToken &&
214
+ ts.isStringLiteralLike(node.right) &&
215
+ node.right.text !== '')
216
+ return false;
217
+ if (ts.isBinaryExpression(node) &&
218
+ (node.operatorToken.kind === ts.SyntaxKind.BarBarToken ||
219
+ node.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken))
220
+ return suppliesEnvValue(node.left) || suppliesEnvValue(node.right);
221
+ if (ts.isCallExpression(node))
222
+ return suppliesEnvValue(node.expression);
223
+ if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node))
224
+ return isProcessEnvAccess(node) || suppliesEnvValue(node.expression);
225
+ return false;
226
+ }
227
+ function isEnvFallback(node) {
228
+ for (let current = node.parent; current; current = current.parent) {
229
+ if (ts.isBinaryExpression(current) &&
230
+ (current.operatorToken.kind === ts.SyntaxKind.BarBarToken ||
231
+ current.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken)) {
232
+ return node.pos >= current.right.pos && node.end <= current.right.end && suppliesEnvValue(current.left);
233
+ }
234
+ if (ts.isStatement(current) || ts.isFunctionLike(current))
235
+ break;
236
+ }
237
+ return false;
238
+ }
199
239
  function checkNamedSecret(literal, context) {
200
240
  const value = literal.text;
201
241
  if (value.length < shortestNamedSecret || /\s/.test(value))
@@ -207,7 +247,10 @@ function checkNamedSecret(literal, context) {
207
247
  return;
208
248
  if (publicKeyShape.test(value))
209
249
  return;
210
- if (isPlaceholder(value, name))
250
+ if (hasStrongPlaceholder(value))
251
+ return;
252
+ const deployableFallback = runtimeConfigFile.test(context.sourceFile.fileName) || isEnvFallback(literal);
253
+ if (!deployableFallback && isPlaceholder(value, name))
211
254
  return;
212
255
  if (characterClasses(value) < 2)
213
256
  return;
@@ -92,7 +92,9 @@ function referencesOf(identifier, scope, checker) {
92
92
  if (ts.isIdentifier(node) &&
93
93
  node !== identifier &&
94
94
  node.text === identifier.text &&
95
- checker.getSymbolAtLocation(node) === symbol)
95
+ (ts.isShorthandPropertyAssignment(node.parent)
96
+ ? checker.getShorthandAssignmentValueSymbol(node.parent)
97
+ : checker.getSymbolAtLocation(node)) === symbol)
96
98
  references.push(node);
97
99
  ts.forEachChild(node, visit);
98
100
  })(scope);