@starci/eslint-canon-be 3.4.57 → 3.6.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 (197) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +11 -2
  3. package/dist/ambient-id.d.ts +9 -0
  4. package/{ambient-id.mjs → dist/ambient-id.js} +43 -39
  5. package/dist/app-composition.d.ts +21 -0
  6. package/{app-composition.mjs → dist/app-composition.js} +396 -300
  7. package/dist/async-discipline.d.ts +9 -0
  8. package/dist/async-discipline.js +77 -0
  9. package/dist/authorization.d.ts +12 -0
  10. package/{authorization.mjs → dist/authorization.js} +53 -59
  11. package/dist/boundary-schema.d.ts +15 -0
  12. package/{boundary-schema.mjs → dist/boundary-schema.js} +120 -105
  13. package/dist/builders.d.ts +21 -0
  14. package/{builders.mjs → dist/builders.js} +162 -146
  15. package/dist/cli.d.ts +15 -0
  16. package/{cli.mjs → dist/cli.js} +97 -82
  17. package/dist/comments.d.ts +52 -0
  18. package/dist/comments.js +412 -0
  19. package/dist/config-owner.d.ts +24 -0
  20. package/{config-owner.mjs → dist/config-owner.js} +256 -219
  21. package/dist/connections.d.ts +12 -0
  22. package/{connections.mjs → dist/connections.js} +138 -140
  23. package/dist/cookies.d.ts +9 -0
  24. package/{cookies.mjs → dist/cookies.js} +58 -58
  25. package/dist/cqrs.d.ts +27 -0
  26. package/{cqrs.mjs → dist/cqrs.js} +341 -282
  27. package/dist/data-access.d.ts +50 -0
  28. package/{data-access.mjs → dist/data-access.js} +238 -243
  29. package/dist/default-deny.d.ts +15 -0
  30. package/{default-deny.mjs → dist/default-deny.js} +103 -88
  31. package/dist/e2e-flow.d.ts +25 -0
  32. package/{e2e-flow.mjs → dist/e2e-flow.js} +113 -112
  33. package/dist/edge-hardening.d.ts +10 -0
  34. package/dist/edge-hardening.js +173 -0
  35. package/dist/error-handling.d.ts +21 -0
  36. package/{error-handling.mjs → dist/error-handling.js} +289 -239
  37. package/dist/event-bus.d.ts +14 -0
  38. package/{event-bus.mjs → dist/event-bus.js} +146 -129
  39. package/dist/feature-thin.d.ts +12 -0
  40. package/{feature-thin.mjs → dist/feature-thin.js} +208 -191
  41. package/dist/function-budget.d.ts +7 -0
  42. package/{function-budget.mjs → dist/function-budget.js} +24 -27
  43. package/dist/health-ready.d.ts +10 -0
  44. package/dist/health-ready.js +703 -0
  45. package/dist/idempotency.d.ts +10 -0
  46. package/{idempotency.mjs → dist/idempotency.js} +296 -226
  47. package/dist/index.d.ts +54 -0
  48. package/{index.mjs → dist/index.js} +91 -109
  49. package/dist/infra-owner.d.ts +18 -0
  50. package/{infra-owner.mjs → dist/infra-owner.js} +58 -51
  51. package/dist/injection.d.ts +30 -0
  52. package/{injection.mjs → dist/injection.js} +397 -344
  53. package/dist/input-bounds.d.ts +15 -0
  54. package/{input-bounds.mjs → dist/input-bounds.js} +143 -132
  55. package/dist/jobs.d.ts +17 -0
  56. package/{jobs.mjs → dist/jobs.js} +116 -99
  57. package/dist/jwt-alg.d.ts +6 -0
  58. package/dist/jwt-alg.js +49 -0
  59. package/dist/lib/app-roles.d.ts +25 -0
  60. package/{lib/app-roles.mjs → dist/lib/app-roles.js} +15 -17
  61. package/dist/lib/ast.d.ts +40 -0
  62. package/dist/lib/ast.js +100 -0
  63. package/dist/lib/client-idempotency.d.ts +3 -0
  64. package/{lib/client-idempotency.mjs → dist/lib/client-idempotency.js} +316 -268
  65. package/dist/lib/config.d.ts +36 -0
  66. package/{lib/config.mjs → dist/lib/config.js} +24 -27
  67. package/dist/lib/db-writes.d.ts +29 -0
  68. package/{lib/db-writes.mjs → dist/lib/db-writes.js} +27 -27
  69. package/dist/lib/declared.d.ts +77 -0
  70. package/{lib/declared.mjs → dist/lib/declared.js} +83 -78
  71. package/dist/lib/doors.d.ts +50 -0
  72. package/{lib/doors.mjs → dist/lib/doors.js} +45 -50
  73. package/dist/lib/edition.d.ts +25 -0
  74. package/{lib/edition.mjs → dist/lib/edition.js} +15 -20
  75. package/dist/lib/entity-writes.d.ts +7 -0
  76. package/{lib/entity-writes.mjs → dist/lib/entity-writes.js} +31 -22
  77. package/dist/lib/hfs.d.ts +34 -0
  78. package/{lib/hfs.mjs → dist/lib/hfs.js} +31 -29
  79. package/dist/lib/import-source.d.ts +63 -0
  80. package/dist/lib/import-source.js +134 -0
  81. package/dist/lib/path.d.ts +8 -0
  82. package/{lib/path.mjs → dist/lib/path.js} +4 -7
  83. package/dist/lib/persistence.d.ts +115 -0
  84. package/{lib/persistence.mjs → dist/lib/persistence.js} +55 -66
  85. package/dist/lib/ports.d.ts +70 -0
  86. package/{lib/ports.mjs → dist/lib/ports.js} +62 -66
  87. package/dist/lib/rule.d.ts +31 -0
  88. package/dist/lib/rule.js +2 -0
  89. package/dist/lib/runtime-root.d.ts +4 -0
  90. package/dist/lib/runtime-root.js +10 -0
  91. package/dist/lib/schema-values.d.ts +13 -0
  92. package/{lib/schema-values.mjs → dist/lib/schema-values.js} +67 -59
  93. package/dist/lib/specifier.d.ts +12 -0
  94. package/dist/lib/specifier.js +29 -0
  95. package/dist/lib/subject-values.d.ts +4 -0
  96. package/dist/lib/subject-values.js +61 -0
  97. package/dist/lib/transactions.d.ts +18 -0
  98. package/{lib/transactions.mjs → dist/lib/transactions.js} +17 -15
  99. package/dist/lib/transport-slots.d.ts +17 -0
  100. package/{lib/transport-slots.mjs → dist/lib/transport-slots.js} +2 -4
  101. package/dist/lib/types.d.ts +96 -0
  102. package/dist/lib/types.js +150 -0
  103. package/dist/lib/unit-spec.d.ts +48 -0
  104. package/{lib/unit-spec.mjs → dist/lib/unit-spec.js} +35 -44
  105. package/dist/lib/webhook-ack.d.ts +4 -0
  106. package/{lib/webhook-ack.mjs → dist/lib/webhook-ack.js} +78 -62
  107. package/dist/lib/webhook-handoff-inbox.d.ts +3 -0
  108. package/{lib/webhook-handoff-inbox.mjs → dist/lib/webhook-handoff-inbox.js} +195 -167
  109. package/dist/lib/webhook-handoff-intake.d.ts +4 -0
  110. package/{lib/webhook-handoff-intake.mjs → dist/lib/webhook-handoff-intake.js} +125 -102
  111. package/dist/lib/webhook-handoff.d.ts +15 -0
  112. package/{lib/webhook-handoff.mjs → dist/lib/webhook-handoff.js} +107 -100
  113. package/dist/lib/webhook-verifiers.d.ts +20 -0
  114. package/{lib/webhook-verifiers.mjs → dist/lib/webhook-verifiers.js} +108 -104
  115. package/dist/lib/why.d.ts +9 -0
  116. package/{lib/why.mjs → dist/lib/why.js} +6 -6
  117. package/dist/log-safety.d.ts +20 -0
  118. package/dist/log-safety.js +308 -0
  119. package/dist/module-layering.d.ts +42 -0
  120. package/dist/module-layering.js +257 -0
  121. package/dist/module-shape.d.ts +47 -0
  122. package/{module-shape.mjs → dist/module-shape.js} +278 -236
  123. package/dist/naming.d.ts +49 -0
  124. package/dist/naming.js +246 -0
  125. package/dist/observability.d.ts +25 -0
  126. package/dist/observability.js +245 -0
  127. package/dist/operations.d.ts +23 -0
  128. package/{operations.mjs → dist/operations.js} +410 -332
  129. package/dist/project-graph.d.ts +9 -0
  130. package/{project-graph.mjs → dist/project-graph.js} +8 -13
  131. package/dist/projections.d.ts +11 -0
  132. package/{projections.mjs → dist/projections.js} +60 -57
  133. package/dist/query-safety.d.ts +21 -0
  134. package/{query-safety.mjs → dist/query-safety.js} +92 -108
  135. package/dist/realtime.d.ts +15 -0
  136. package/{realtime.mjs → dist/realtime.js} +108 -106
  137. package/dist/resilience.d.ts +15 -0
  138. package/dist/resilience.js +319 -0
  139. package/dist/schema-authority.d.ts +15 -0
  140. package/{schema-authority.mjs → dist/schema-authority.js} +256 -220
  141. package/dist/service-deps.d.ts +17 -0
  142. package/{service-deps.mjs → dist/service-deps.js} +133 -130
  143. package/dist/service-isolation.d.ts +8 -0
  144. package/dist/service-isolation.js +76 -0
  145. package/dist/size-budget.d.ts +9 -0
  146. package/{size-budget.mjs → dist/size-budget.js} +27 -27
  147. package/dist/sonar-parity.d.ts +5 -0
  148. package/{sonar-parity.mjs → dist/sonar-parity.js} +7 -7
  149. package/dist/spec-no-skip.d.ts +9 -0
  150. package/dist/spec-no-skip.js +81 -0
  151. package/dist/spec-quality.d.ts +10 -0
  152. package/{spec-quality.mjs → dist/spec-quality.js} +103 -87
  153. package/dist/suppression.d.ts +26 -0
  154. package/{suppression.mjs → dist/suppression.js} +30 -45
  155. package/dist/temporal.d.ts +9 -0
  156. package/{temporal.mjs → dist/temporal.js} +75 -65
  157. package/dist/test-world.d.ts +28 -0
  158. package/{test-world.mjs → dist/test-world.js} +102 -83
  159. package/dist/testing.d.ts +51 -0
  160. package/dist/testing.js +368 -0
  161. package/dist/third-party-owner.d.ts +8 -0
  162. package/{third-party-owner.mjs → dist/third-party-owner.js} +105 -91
  163. package/dist/transport.d.ts +24 -0
  164. package/{transport.mjs → dist/transport.js} +279 -240
  165. package/dist/type-safety.d.ts +25 -0
  166. package/dist/type-safety.js +297 -0
  167. package/dist/unit-spec.d.ts +30 -0
  168. package/{unit-spec.mjs → dist/unit-spec.js} +473 -399
  169. package/dist/uploads.d.ts +9 -0
  170. package/{uploads.mjs → dist/uploads.js} +62 -54
  171. package/dist/user-copy.d.ts +9 -0
  172. package/{user-copy.mjs → dist/user-copy.js} +76 -67
  173. package/dist/webhooks.d.ts +16 -0
  174. package/{webhooks.mjs → dist/webhooks.js} +243 -231
  175. package/package.json +17 -8
  176. package/runtime/knowledge/hfs/canon-pins.yaml +22 -14
  177. package/runtime/knowledge/hfs/rules.yaml +23 -0
  178. package/runtime/scripts/lib/package-at.mjs +5 -5
  179. package/async-discipline.mjs +0 -83
  180. package/comments.mjs +0 -416
  181. package/edge-hardening.mjs +0 -139
  182. package/health-ready.mjs +0 -539
  183. package/jwt-alg.mjs +0 -45
  184. package/lib/ast.mjs +0 -88
  185. package/lib/import-source.mjs +0 -104
  186. package/lib/specifier.mjs +0 -27
  187. package/lib/subject-values.mjs +0 -55
  188. package/lib/types.mjs +0 -133
  189. package/log-safety.mjs +0 -303
  190. package/module-layering.mjs +0 -270
  191. package/naming.mjs +0 -251
  192. package/observability.mjs +0 -241
  193. package/resilience.mjs +0 -304
  194. package/service-isolation.mjs +0 -75
  195. package/spec-no-skip.mjs +0 -85
  196. package/testing.mjs +0 -384
  197. package/type-safety.mjs +0 -323
@@ -24,25 +24,20 @@
24
24
  *
25
25
  * No test lane is exempt: a spec builds its `EnvSource` from a literal record and never touches the process environment.
26
26
  */
27
- import ts from "typescript"
28
- import { APP_ENV_ROLE, appRoleOf } from "./lib/app-roles.mjs"
29
- import { keyName, staticText, walk, wordsOf } from "./lib/ast.mjs"
30
- import { isOwnedBy, isOwnedType, originsOf } from "./lib/declared.mjs"
31
- import { hfsOf, inTestWorld } from "./lib/hfs.mjs"
32
- import { isDeclarationFile, normalizePath } from "./lib/path.mjs"
33
- import { moduleOf, originsOfType, typed } from "./lib/types.mjs"
34
-
27
+ import ts from "typescript";
28
+ import { APP_ENV_ROLE, appRoleOf } from "./lib/app-roles.js";
29
+ import { keyName, staticText, walk, wordsOf } from "./lib/ast.js";
30
+ import { isOwnedBy, isOwnedType, originsOf } from "./lib/declared.js";
31
+ import { hfsOf, inTestWorld } from "./lib/hfs.js";
32
+ import { isDeclarationFile, normalizePath } from "./lib/path.js";
33
+ import { moduleOf, originsOfType, typed } from "./lib/types.js";
35
34
  /** The test composition root (slot `be.tests.world`): it composes app options like `main.ts` and hands run state to jest workers through the environment. */
36
- const isTestWorld = inTestWorld
37
-
38
- const PROCESS_MODULES = new Set(["process", "node:process"])
39
-
35
+ const isTestWorld = inTestWorld;
36
+ const PROCESS_MODULES = new Set(["process", "node:process"]);
40
37
  /** `@nestjs/config`, `dotenv` and their subpaths. */
41
- const isConfigPackage = (source) => /^(?:@nestjs\/config|dotenv)(?:\/|$)/.test(source)
42
-
38
+ const isConfigPackage = (source) => /^(?:@nestjs\/config|dotenv)(?:\/|$)/.test(source);
43
39
  /** True when the property of a member expression spells `env`. */
44
- const spellsEnv = (node) => (node.computed ? staticText(node.property) === "env" : keyName(node.property) === "env")
45
-
40
+ const spellsEnv = (node) => (node.computed ? staticText(node.property) === "env" : keyName(node.property) === "env");
46
41
  /** Only EnvSource, the app bootstrap roles and the test world read the process environment. */
47
42
  export const noDirectEnvRead = {
48
43
  meta: {
@@ -56,149 +51,174 @@ export const noDirectEnvRead = {
56
51
  },
57
52
  },
58
53
  create(context) {
59
- const filename = normalizePath(context.filename || context.getFilename())
60
- if (isDeclarationFile(filename)) return {}
61
- const hfs = hfsOf(context)
62
- const inConfigOwner = isOwnedBy(hfs, filename, "platform", "config")
63
- let declaresEnvSource = false
54
+ const filename = normalizePath(context.filename || context.getFilename());
55
+ if (isDeclarationFile(filename))
56
+ return {};
57
+ const hfs = hfsOf(context);
58
+ const inConfigOwner = isOwnedBy(hfs, filename, "platform", "config");
59
+ let declaresEnvSource = false;
64
60
  const variableOf = (identifier) => {
65
61
  for (let scope = context.sourceCode.getScope(identifier); scope; scope = scope.upper) {
66
- const variable = scope.set.get(identifier.name)
67
- if (variable) return variable
62
+ const variable = scope.set.get(identifier.name);
63
+ if (variable)
64
+ return variable;
68
65
  }
69
- return null
70
- }
71
- const isGlobal = (node) => node?.type === "Identifier" && ["globalThis", "global"].includes(node.name) && !variableOf(node)?.defs.length
66
+ return null;
67
+ };
68
+ const isGlobal = (node) => node?.type === "Identifier" && ["globalThis", "global"].includes(node.name) && !variableOf(node)?.defs.length;
72
69
  // Resolve aliases by their lexical binding: an identically named local or parameter is not Node's process.
73
70
  const isProcess = (node, seen = new Set()) => {
74
- if (!node) return false
75
- if (["TSAsExpression", "TSTypeAssertion", "TSNonNullExpression", "TSSatisfiesExpression", "ChainExpression"].includes(node.type)) return isProcess(node.expression, seen)
71
+ if (!node)
72
+ return false;
73
+ if (node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "TSSatisfiesExpression" || node.type === "ChainExpression")
74
+ return isProcess(node.expression, seen);
76
75
  if (node.type === "MemberExpression") {
77
- return isGlobal(node.object) && (node.computed ? staticText(node.property) : keyName(node.property)) === "process"
76
+ return isGlobal(node.object) && (node.computed ? staticText(node.property) : keyName(node.property)) === "process";
78
77
  }
79
- if (node.type !== "Identifier") return false
80
- const variable = variableOf(node)
81
- if (!variable?.defs.length) return node.name === "process"
82
- if (seen.has(node)) return false
83
- seen.add(node)
78
+ if (node.type !== "Identifier")
79
+ return false;
80
+ const variable = variableOf(node);
81
+ if (!variable?.defs.length)
82
+ return node.name === "process";
83
+ if (seen.has(node))
84
+ return false;
85
+ seen.add(node);
84
86
  return variable.defs.some((definition) => {
85
87
  if (definition.type === "ImportBinding") {
86
- const specifier = definition.node
87
- return PROCESS_MODULES.has(definition.parent.source.value)
88
- && (specifier.type !== "ImportSpecifier" || keyName(specifier.imported) === "default")
88
+ const specifier = definition.node;
89
+ return definition.parent.type === "ImportDeclaration" && PROCESS_MODULES.has(definition.parent.source.value)
90
+ && (specifier.type !== "ImportSpecifier" || keyName(specifier.imported) === "default");
89
91
  }
90
- if (definition.type !== "Variable") return false
91
- const readScope = context.sourceCode.getScope(node).variableScope
92
- const write = variable.references.filter((reference) => reference.isWrite()
93
- && [readScope, variable.scope.variableScope].includes(reference.from.variableScope)
94
- && reference.writeExpr?.range[1] <= node.range[0])
95
- .sort((left, right) => right.identifier.range[0] - left.identifier.range[0])[0]
92
+ if (definition.type !== "Variable")
93
+ return false;
94
+ const readScope = context.sourceCode.getScope(node).variableScope;
95
+ const write = variable.references.filter((reference) => {
96
+ if (!reference.isWrite() || ![readScope, variable.scope.variableScope].includes(reference.from.variableScope))
97
+ return false;
98
+ const writeEnd = reference.writeExpr?.range[1];
99
+ return writeEnd !== undefined && writeEnd <= node.range[0];
100
+ })
101
+ .sort((left, right) => right.identifier.range[0] - left.identifier.range[0])[0];
96
102
  // A const captured by a function keeps its initializer even when the function is declared first.
97
- const source = write?.writeExpr ?? (definition.parent.kind === "const" ? definition.node.init : null)
98
- if (!source) return false
99
- const identifier = write?.identifier ?? definition.name
100
- const parent = identifier.parent
103
+ const source = write?.writeExpr ?? (definition.parent.kind === "const" ? definition.node.init : null);
104
+ if (!source)
105
+ return false;
106
+ const identifier = write?.identifier ?? definition.name;
107
+ const parent = identifier.parent;
101
108
  if (parent.type === "Property" && parent.value === identifier && parent.parent.type === "ObjectPattern") {
102
- return isGlobal(source) && (parent.computed ? staticText(parent.key) : keyName(parent.key)) === "process"
109
+ return isGlobal(source) && (parent.computed ? staticText(parent.key) : keyName(parent.key)) === "process";
103
110
  }
104
- return isProcess(source, seen)
105
- })
106
- }
107
- const isEnvSourceFile = () => inConfigOwner && declaresEnvSource
108
- const inWorld = isTestWorld(hfs, filename)
109
- const appRole = appRoleOf(hfs, filename)?.entry
110
- const inAppEntry = appRole === "main.ts" || appRole === APP_ENV_ROLE
111
+ return isProcess(source, seen);
112
+ });
113
+ };
114
+ const isEnvSourceFile = () => inConfigOwner && declaresEnvSource;
115
+ const inWorld = isTestWorld(hfs, filename);
116
+ const appRole = appRoleOf(hfs, filename)?.entry;
117
+ const inAppEntry = appRole === "main.ts" || appRole === APP_ENV_ROLE;
111
118
  const reportEnv = (node) => {
112
- if (!isEnvSourceFile() && !inWorld && !inAppEntry) context.report({ node, messageId: "env" })
113
- }
119
+ if (!isEnvSourceFile() && !inWorld && !inAppEntry)
120
+ context.report({ node, messageId: "env" });
121
+ };
114
122
  const reportSource = (node, source) => {
115
- if (isConfigPackage(source)) context.report({ node, messageId: "package", data: { source } })
116
- }
123
+ if (isConfigPackage(source))
124
+ context.report({ node, messageId: "package", data: { source } });
125
+ };
117
126
  return {
118
127
  Program(program) {
119
128
  declaresEnvSource = program.body.some((statement) => {
120
- const declaration = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" ? statement.declaration : statement
121
- return declaration?.type === "ClassDeclaration" && declaration.id?.name === "EnvSource"
122
- })
129
+ const declaration = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" ? statement.declaration : statement;
130
+ return declaration?.type === "ClassDeclaration" && declaration.id?.name === "EnvSource";
131
+ });
123
132
  },
124
133
  ImportDeclaration(node) {
125
- const source = String(node.source.value)
126
- reportSource(node, source)
127
- if (!PROCESS_MODULES.has(source)) return
134
+ const source = String(node.source.value);
135
+ reportSource(node, source);
136
+ if (!PROCESS_MODULES.has(source))
137
+ return;
128
138
  for (const specifier of node.specifiers) {
129
- if (specifier.type === "ImportSpecifier" && (specifier.imported.name ?? specifier.imported.value) === "env") reportEnv(specifier)
139
+ if (specifier.type === "ImportSpecifier" && (specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value) === "env")
140
+ reportEnv(specifier);
130
141
  }
131
142
  },
132
143
  ImportExpression(node) {
133
- const source = staticText(node.source)
134
- if (source !== null) reportSource(node, source)
144
+ const source = staticText(node.source);
145
+ if (source !== null)
146
+ reportSource(node, source);
135
147
  },
136
148
  MemberExpression(node) {
137
- if (isProcess(node.object) && spellsEnv(node)) reportEnv(node)
149
+ if (isProcess(node.object) && spellsEnv(node))
150
+ reportEnv(node);
138
151
  },
139
152
  VariableDeclarator(node) {
140
- if (!node.init || !isProcess(node.init) || node.id.type !== "ObjectPattern") return
141
- if (node.id.properties.some((property) => property.type === "Property" && (property.computed ? staticText(property.key) : keyName(property.key)) === "env")) reportEnv(node)
153
+ if (!node.init || !isProcess(node.init) || node.id.type !== "ObjectPattern")
154
+ return;
155
+ if (node.id.properties.some((property) => property.type === "Property" && (property.computed ? staticText(property.key) : keyName(property.key)) === "env"))
156
+ reportEnv(node);
142
157
  },
143
158
  AssignmentExpression(node) {
144
- if (node.operator !== "=" || node.left.type !== "ObjectPattern" || !isProcess(node.right)) return
145
- if (node.left.properties.some((property) => property.type === "Property" && (property.computed ? staticText(property.key) : keyName(property.key)) === "env")) reportEnv(node)
159
+ if (node.operator !== "=" || node.left.type !== "ObjectPattern" || !isProcess(node.right))
160
+ return;
161
+ if (node.left.properties.some((property) => property.type === "Property" && (property.computed ? staticText(property.key) : keyName(property.key)) === "env"))
162
+ reportEnv(node);
146
163
  },
147
164
  CallExpression(node) {
148
- const callee = node.callee
165
+ const callee = node.callee;
149
166
  if (callee.type === "Identifier" && callee.name === "require") {
150
- const source = staticText(node.arguments[0])
151
- if (source !== null) reportSource(node, source)
167
+ const source = staticText(node.arguments[0]);
168
+ if (source !== null)
169
+ reportSource(node, source);
152
170
  }
153
- if (callee.type !== "MemberExpression") return
171
+ if (callee.type !== "MemberExpression")
172
+ return;
154
173
  if (callee.object.type === "Identifier" && callee.object.name === "Reflect" && keyName(callee.property) === "get") {
155
- if (node.arguments[0] && isProcess(node.arguments[0]) && staticText(node.arguments[1]) === "env") reportEnv(node)
174
+ if (node.arguments[0] && isProcess(node.arguments[0]) && staticText(node.arguments[1]) === "env")
175
+ reportEnv(node);
156
176
  }
157
177
  if (["join", "resolve"].includes(keyName(callee.property) ?? "") && !isEnvSourceFile()) {
158
- let cwd = false
178
+ let cwd = false;
159
179
  walk(node, (child) => {
160
- if (child.type === "CallExpression" && child.callee.type === "MemberExpression" && isProcess(child.callee.object) && keyName(child.callee.property) === "cwd") cwd = true
161
- })
162
- if (!cwd) return
180
+ if (child.type === "CallExpression" && child.callee.type === "MemberExpression" && isProcess(child.callee.object) && keyName(child.callee.property) === "cwd")
181
+ cwd = true;
182
+ });
183
+ if (!cwd)
184
+ return;
163
185
  for (const argument of node.arguments) {
164
- const text = staticText(argument)
165
- const segment = text === null ? null : text.split(/[\\/]/).find((part) => part === "src" || part === ".starcistacks")
166
- if (segment) context.report({ node, messageId: "cwdPath", data: { segment } })
186
+ const text = staticText(argument);
187
+ const segment = text === null ? null : text.split(/[\\/]/).find((part) => part === "src" || part === ".starcistacks");
188
+ if (segment)
189
+ context.report({ node, messageId: "cwdPath", data: { segment } });
167
190
  }
168
191
  }
169
192
  },
170
- }
193
+ };
171
194
  },
172
- }
173
-
174
- const CONFIG_SUFFIX = ".config.ts"
175
- const OPTIONS_SUFFIX = ".options.ts"
176
- const CONFIG_SPEC_SUFFIX = ".config.spec.ts"
177
-
178
- const baseOf = (file) => normalizePath(file).split("/").at(-1) ?? ""
179
-
195
+ };
196
+ const CONFIG_SUFFIX = ".config.ts";
197
+ const OPTIONS_SUFFIX = ".options.ts";
198
+ const CONFIG_SPEC_SUFFIX = ".config.spec.ts";
199
+ const baseOf = (file) => normalizePath(file).split("/").at(-1) ?? "";
180
200
  /** A file in a slot of the repository whose role is `<c>.config.ts` (a file with the suffix that no slot claims is not one). */
181
- const isConfigFile = (hfs, file) => baseOf(file).endsWith(CONFIG_SUFFIX) && hfs.slotOf(file) !== null
182
-
201
+ const isConfigFile = (hfs, file) => baseOf(file).endsWith(CONFIG_SUFFIX) && hfs.slotOf(file) !== null;
183
202
  /** A file in a slot of the repository whose role is `<c>.options.ts`. */
184
- const isOptionsFile = (hfs, file) => baseOf(file).endsWith(OPTIONS_SUFFIX) && hfs.slotOf(file) !== null
185
-
203
+ const isOptionsFile = (hfs, file) => baseOf(file).endsWith(OPTIONS_SUFFIX) && hfs.slotOf(file) !== null;
186
204
  /** The declaration of a plain function (declaration, or arrow/function expression bound to a variable), else null: a method is not a getter. */
187
205
  const functionDeclarationOf = (declaration) => {
188
- if (!declaration) return null
189
- if (ts.isFunctionDeclaration(declaration)) return declaration
190
- if ((ts.isArrowFunction(declaration) || ts.isFunctionExpression(declaration)) && ts.isVariableDeclaration(declaration.parent)) return declaration
191
- return null
192
- }
193
-
206
+ if (!declaration)
207
+ return null;
208
+ if (ts.isFunctionDeclaration(declaration))
209
+ return declaration;
210
+ if ((ts.isArrowFunction(declaration) || ts.isFunctionExpression(declaration)) && ts.isVariableDeclaration(declaration.parent))
211
+ return declaration;
212
+ return null;
213
+ };
194
214
  /** True when the node is evaluated when the module loads: no function, method or class member body encloses it. */
195
215
  const isModuleScope = (node) => {
196
216
  for (let parent = node.parent; parent; parent = parent.parent) {
197
- if (/Function|MethodDefinition|PropertyDefinition|StaticBlock/.test(parent.type)) return false
217
+ if (/Function|MethodDefinition|PropertyDefinition|StaticBlock/.test(parent.type))
218
+ return false;
198
219
  }
199
- return true
200
- }
201
-
220
+ return true;
221
+ };
202
222
  /** Config is parsed once, in `main.ts` or its app's env file; other app roles do not read the environment. */
203
223
  export const configParsedInMain = {
204
224
  meta: {
@@ -211,54 +231,60 @@ export const configParsedInMain = {
211
231
  },
212
232
  },
213
233
  create(context) {
214
- const filename = normalizePath(context.filename || context.getFilename())
215
- if (isDeclarationFile(filename)) return {}
216
- const hfs = hfsOf(context)
217
- const slot = hfs.slotOf(filename) ?? ""
234
+ const filename = normalizePath(context.filename || context.getFilename());
235
+ if (isDeclarationFile(filename))
236
+ return {};
237
+ const hfs = hfsOf(context);
238
+ const slot = hfs.slotOf(filename) ?? "";
218
239
  // The app entry and its matching env file parse options; options files and composition groups only consume them.
219
240
  // The test world and provider contract specs parse the declared sandbox keys to register their modules.
220
- const inApp = slot.startsWith("be.app.")
221
- const role = appRoleOf(hfs, filename)?.entry
222
- const isEntry = role === "main.ts" || role === APP_ENV_ROLE
223
- const isComposingTest = isTestWorld(hfs, filename) || slot === "be.tests.contract"
224
- const isOwnSpec = !inApp && baseOf(filename).endsWith(CONFIG_SPEC_SUFFIX)
225
- if (isEntry || isComposingTest || isOwnSpec) return {}
226
- const { checker, toTs } = typed(context)
241
+ const inApp = slot.startsWith("be.app.");
242
+ const role = appRoleOf(hfs, filename)?.entry;
243
+ const isEntry = role === "main.ts" || role === APP_ENV_ROLE;
244
+ const isComposingTest = isTestWorld(hfs, filename) || slot === "be.tests.contract";
245
+ const isOwnSpec = !inApp && baseOf(filename).endsWith(CONFIG_SPEC_SUFFIX);
246
+ if (isEntry || isComposingTest || isOwnSpec)
247
+ return {};
248
+ const { checker, toTs } = typed(context);
227
249
  return {
228
250
  CallExpression(node) {
229
- const tsCall = toTs(node)
230
- if (!tsCall) return
231
- const signature = checker.getResolvedSignature(tsCall)
232
- const resolvedDeclaration = signature?.declaration
251
+ const tsCall = toTs(node);
252
+ if (!tsCall)
253
+ return;
254
+ const signature = checker.getResolvedSignature(tsCall);
255
+ const resolvedDeclaration = signature?.declaration;
233
256
  if (inApp && resolvedDeclaration && ts.isMethodDeclaration(resolvedDeclaration)
234
257
  && ts.isClassDeclaration(resolvedDeclaration.parent) && resolvedDeclaration.parent.name?.text === "EnvSource") {
235
- const declaredIn = normalizePath(resolvedDeclaration.getSourceFile().fileName)
258
+ const declaredIn = normalizePath(resolvedDeclaration.getSourceFile().fileName);
236
259
  if (isOwnedBy(hfs, declaredIn, "platform", "config")) {
237
- context.report({ node, messageId: "parsed", data: { name: context.sourceCode.getText(node.callee), file: baseOf(declaredIn) } })
238
- return
260
+ context.report({ node, messageId: "parsed", data: { name: context.sourceCode.getText(node.callee), file: baseOf(declaredIn) } });
261
+ return;
239
262
  }
240
263
  }
241
- const declaration = functionDeclarationOf(resolvedDeclaration)
242
- if (!declaration) return
243
- const declaredIn = normalizePath(declaration.getSourceFile().fileName)
244
- const name = context.sourceCode.getText(node.callee)
264
+ const declaration = functionDeclarationOf(resolvedDeclaration);
265
+ // a declaration comes from a signature, so `!signature` adds no case
266
+ if (!declaration || !signature)
267
+ return;
268
+ const declaredIn = normalizePath(declaration.getSourceFile().fileName);
269
+ const name = context.sourceCode.getText(node.callee);
245
270
  if (isConfigFile(hfs, declaredIn) || appRoleOf(hfs, declaredIn)?.entry === APP_ENV_ROLE) {
246
- if (declaredIn !== filename) context.report({ node, messageId: "parsed", data: { name, file: baseOf(declaredIn) } })
247
- return
271
+ if (declaredIn !== filename)
272
+ context.report({ node, messageId: "parsed", data: { name, file: baseOf(declaredIn) } });
273
+ return;
248
274
  }
249
- if (!isModuleScope(node)) return
250
- const returned = originsOfType(checker, checker.getReturnTypeOfSignature(signature))
251
- if (returned.some((origin) => isOptionsFile(hfs, origin.file))) context.report({ node, messageId: "moduleScope", data: { name } })
275
+ if (!isModuleScope(node))
276
+ return;
277
+ const returned = originsOfType(checker, checker.getReturnTypeOfSignature(signature));
278
+ if (returned.some((origin) => isOptionsFile(hfs, origin.file)))
279
+ context.report({ node, messageId: "moduleScope", data: { name } });
252
280
  },
253
- }
281
+ };
254
282
  },
255
- }
256
-
283
+ };
257
284
  /** The brand classes of `platform/config` a default must never be given to. */
258
- const BRANDS = new Set(["Secret", "Url"])
259
- const SECRET_READERS = new Set(["secret", "url", "host"])
260
- const DEFAULT_LITERAL = /^(?:localhost|127\.0\.0\.1|0\.0\.0\.0|https?:\/\/.*)?$/i
261
-
285
+ const BRANDS = new Set(["Secret", "Url"]);
286
+ const SECRET_READERS = new Set(["secret", "url", "host"]);
287
+ const DEFAULT_LITERAL = /^(?:localhost|127\.0\.0\.1|0\.0\.0\.0|https?:\/\/.*)?$/i;
262
288
  /** No secret or URL value has a default of any kind: a missing value stops the boot. */
263
289
  export const noSecretDefault = {
264
290
  meta: {
@@ -272,56 +298,65 @@ export const noSecretDefault = {
272
298
  },
273
299
  },
274
300
  create(context) {
275
- const filename = normalizePath(context.filename || context.getFilename())
276
- if (isDeclarationFile(filename)) return {}
277
- const hfs = hfsOf(context)
301
+ const filename = normalizePath(context.filename || context.getFilename());
302
+ if (isDeclarationFile(filename))
303
+ return {};
304
+ const hfs = hfsOf(context);
278
305
  /** True when the node's type is (or contains) `Secret` or `Url` as `platform/config` declares them. */
279
- const isBrand = (node) => originsOf(context, node).some((origin) => BRANDS.has(origin.name) && isOwnedBy(hfs, origin.file, "platform", "config"))
280
- const isEnvSource = (node) => originsOf(context, node).some((origin) => origin.name === "EnvSource" && isOwnedBy(hfs, origin.file, "platform", "config"))
306
+ const isBrand = (node) => originsOf(context, node).some((origin) => BRANDS.has(origin.name) && isOwnedBy(hfs, origin.file, "platform", "config"));
307
+ const isEnvSource = (node) => originsOf(context, node).some((origin) => origin.name === "EnvSource" && isOwnedBy(hfs, origin.file, "platform", "config"));
281
308
  const checkFallback = (node, operator, left) => {
282
- if (isBrand(left)) context.report({ node, messageId: "fallback", data: { operator } })
283
- }
309
+ if (isBrand(left))
310
+ context.report({ node, messageId: "fallback", data: { operator } });
311
+ };
284
312
  return {
285
313
  LogicalExpression(node) {
286
- if (node.operator === "??" || node.operator === "||") checkFallback(node, node.operator, node.left)
314
+ if (node.operator === "??" || node.operator === "||")
315
+ checkFallback(node, node.operator, node.left);
287
316
  },
288
317
  AssignmentExpression(node) {
289
- if (node.operator === "??=" || node.operator === "||=") checkFallback(node, node.operator, node.left)
318
+ if (node.operator === "??=" || node.operator === "||=")
319
+ checkFallback(node, node.operator, node.left);
290
320
  },
291
321
  CallExpression(node) {
292
- if (node.arguments.length < 2) return
293
- const callee = node.callee
294
- const method = callee.type === "MemberExpression" && !callee.computed ? keyName(callee.property) : null
295
- const onEnvSource = method !== null && isEnvSource(callee.object)
322
+ if (node.arguments.length < 2)
323
+ return;
324
+ const defaultArgument = node.arguments[1];
325
+ if (defaultArgument === undefined)
326
+ return;
327
+ const callee = node.callee;
328
+ const method = callee.type === "MemberExpression" && !callee.computed ? keyName(callee.property) : null;
329
+ // a method name comes only from a member expression, so the type test adds no case
330
+ const onEnvSource = method !== null && callee.type === "MemberExpression" && isEnvSource(callee.object);
296
331
  if (onEnvSource && (SECRET_READERS.has(method) || isBrand(node))) {
297
- context.report({ node: node.arguments[1], messageId: "argument", data: { method } })
298
- return
332
+ context.report({ node: defaultArgument, messageId: "argument", data: { method } });
333
+ return;
299
334
  }
300
- if (!isBrand(node)) return
335
+ if (!isBrand(node))
336
+ return;
301
337
  const literal = node.arguments.slice(1).find((argument) => {
302
- const text = staticText(argument)
303
- return text !== null && DEFAULT_LITERAL.test(text)
304
- })
305
- if (literal) context.report({ node: literal, messageId: "literal" })
338
+ const text = staticText(argument);
339
+ return text !== null && DEFAULT_LITERAL.test(text);
340
+ });
341
+ if (literal)
342
+ context.report({ node: literal, messageId: "literal" });
306
343
  },
307
- }
344
+ };
308
345
  },
309
- }
310
-
311
- const SECRET_COMPARE_WORDS = new Set(["secret", "password", "passwd", "passphrase", "token", "signature", "hmac", "credential", "credentials", "apikey", "authorization"])
312
- const KEY_PREFIXES = new Set(["api", "secret", "private", "access", "signing", "encryption", "master", "auth", "jwt", "session"])
313
- const NOT_A_VALUE_WORDS = new Set(["type", "kind", "length", "count", "ttl", "name", "prefix", "header", "scheme", "field", "path", "regex", "pattern"])
314
-
346
+ };
347
+ const SECRET_COMPARE_WORDS = new Set(["secret", "password", "passwd", "passphrase", "token", "signature", "hmac", "credential", "credentials", "apikey", "authorization"]);
348
+ const KEY_PREFIXES = new Set(["api", "secret", "private", "access", "signing", "encryption", "master", "auth", "jwt", "session"]);
349
+ const NOT_A_VALUE_WORDS = new Set(["type", "kind", "length", "count", "ttl", "name", "prefix", "header", "scheme", "field", "path", "regex", "pattern"]);
315
350
  /** The identifier or property a comparison operand ends in, else null. */
316
351
  const operandName = (node) => {
317
- if (node.type === "Identifier") return node.name
318
- if (node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier") return node.property.name
319
- return null
320
- }
321
-
352
+ if (node.type === "Identifier")
353
+ return node.name;
354
+ if (node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier")
355
+ return node.property.name;
356
+ return null;
357
+ };
322
358
  /** Words before the last one that make a token a counter or a cursor, not a credential. */
323
- const NOT_A_CREDENTIAL_QUALIFIERS = new Set(["fencing", "idempotency", "cursor", "page", "next", "continuation", "pagination", "sync", "csrf"])
324
-
359
+ const NOT_A_CREDENTIAL_QUALIFIERS = new Set(["fencing", "idempotency", "cursor", "page", "next", "continuation", "pagination", "sync", "csrf"]);
325
360
  /**
326
361
  * Whether a value's own name says it IS a credential: its last word is one (`password`, `accessToken`, `clientSecret`,
327
362
  * `signingKey`), unless the name is an UPPER_SNAKE constant naming a key or a counter or cursor qualifies it. Shared by the
@@ -329,41 +364,42 @@ const NOT_A_CREDENTIAL_QUALIFIERS = new Set(["fencing", "idempotency", "cursor",
329
364
  */
330
365
  export const isCredentialName = (name) => {
331
366
  // an UPPER_SNAKE name is a constant naming a key, not the value it names
332
- if (/^[A-Z][A-Z0-9_]*$/.test(name)) return false
333
- const words = wordsOf(name)
334
- const last = words.at(-1)
335
- if (!last || NOT_A_VALUE_WORDS.has(last) || words.some((word) => NOT_A_CREDENTIAL_QUALIFIERS.has(word))) return false
336
- return SECRET_COMPARE_WORDS.has(last) || (last === "key" && words.length > 1 && KEY_PREFIXES.has(words.at(-2)))
337
- }
338
-
367
+ if (/^[A-Z][A-Z0-9_]*$/.test(name))
368
+ return false;
369
+ const words = wordsOf(name);
370
+ const last = words.at(-1);
371
+ if (!last || NOT_A_VALUE_WORDS.has(last) || words.some((word) => NOT_A_CREDENTIAL_QUALIFIERS.has(word)))
372
+ return false;
373
+ const prefix = words.at(-2);
374
+ return SECRET_COMPARE_WORDS.has(last) || (last === "key" && words.length > 1 && prefix !== undefined && KEY_PREFIXES.has(prefix));
375
+ };
339
376
  /** An emptiness or presence check reveals nothing a timing attack could use. */
340
- const isPresenceOperand = (node) =>
341
- (node.type === "Literal" && (node.value === null || node.value === "" || typeof node.value === "boolean")) ||
377
+ const isPresenceOperand = (node) => (node.type === "Literal" && (node.value === null || node.value === "" || typeof node.value === "boolean")) ||
342
378
  (node.type === "Identifier" && node.name === "undefined") ||
343
- (node.type === "UnaryExpression" && node.operator === "typeof")
344
-
379
+ (node.type === "UnaryExpression" && node.operator === "typeof");
345
380
  /** A value typed by the `Secret` brand of `platform/config`, or read out of one (`secret.reveal()`, `secret.value`): the TYPE says it is a secret. */
346
381
  const isSecretValue = (context, node) => {
347
- const holder = node.type === "CallExpression" && node.callee.type === "MemberExpression" ? node.callee.object : node.type === "MemberExpression" ? node.object : null
348
- return isOwnedType(context, node, "Secret", "platform", "config") || (holder !== null && isOwnedType(context, holder, "Secret", "platform", "config"))
349
- }
350
-
382
+ const holder = node.type === "CallExpression" && node.callee.type === "MemberExpression" ? node.callee.object : node.type === "MemberExpression" ? node.object : null;
383
+ return isOwnedType(context, node, "Secret", "platform", "config") || (holder !== null && isOwnedType(context, holder, "Secret", "platform", "config"));
384
+ };
351
385
  /** The packages that declare the Node crypto types: a digest read out of a `Hash` or `Hmac` is secret-derived material. */
352
- const CRYPTO_PACKAGES = new Set(["crypto", "node:crypto"])
353
-
386
+ const CRYPTO_PACKAGES = new Set(["crypto", "node:crypto"]);
354
387
  /** A `.digest(...)` of a `Hash` or `Hmac` of Node's crypto, found by where the called signature is declared, never by the receiver's name. */
355
388
  const isCryptoDigest = (context, node) => {
356
- if (node.type !== "CallExpression" || node.callee.type !== "MemberExpression") return false
357
- const { checker, toTs } = typed(context)
358
- const tsCall = toTs(node)
359
- const declaration = tsCall ? checker.getResolvedSignature(tsCall)?.declaration : undefined
360
- if (!declaration || !declaration.name || declaration.name.getText() !== "digest") return false
361
- const owner = declaration.parent
362
- const ownerName = (ts.isInterfaceDeclaration(owner) || ts.isClassDeclaration(owner)) && owner.name ? owner.name.text : ""
363
- if (ownerName !== "Hash" && ownerName !== "Hmac") return false
364
- return CRYPTO_PACKAGES.has(moduleOf(declaration, String(declaration.getSourceFile().fileName).split("\\").join("/")))
365
- }
366
-
389
+ if (node.type !== "CallExpression" || node.callee.type !== "MemberExpression")
390
+ return false;
391
+ const { checker, toTs } = typed(context);
392
+ const tsCall = toTs(node);
393
+ const declaration = tsCall ? checker.getResolvedSignature(tsCall)?.declaration : undefined;
394
+ const declaredName = declaration && "name" in declaration ? declaration.name : undefined;
395
+ if (!declaration || !declaredName || declaredName.getText() !== "digest")
396
+ return false;
397
+ const owner = declaration.parent;
398
+ const ownerName = (ts.isInterfaceDeclaration(owner) || ts.isClassDeclaration(owner)) && owner.name ? owner.name.text : "";
399
+ if (ownerName !== "Hash" && ownerName !== "Hmac")
400
+ return false;
401
+ return CRYPTO_PACKAGES.has(moduleOf(declaration, String(declaration.getSourceFile().fileName).split("\\").join("/")));
402
+ };
367
403
  /** A secret is compared with `timingSafeEqual`, never with an equality operator. */
368
404
  export const secretCompareTimingSafe = {
369
405
  meta: {
@@ -375,40 +411,41 @@ export const secretCompareTimingSafe = {
375
411
  },
376
412
  },
377
413
  create(context) {
378
- const filename = normalizePath(context.filename || context.getFilename())
379
- if (isDeclarationFile(filename)) return {}
414
+ const filename = normalizePath(context.filename || context.getFilename());
415
+ if (isDeclarationFile(filename))
416
+ return {};
380
417
  return {
381
418
  BinaryExpression(node) {
382
- if (!["===", "!==", "==", "!="].includes(node.operator)) return
383
- if (isPresenceOperand(node.left) || isPresenceOperand(node.right)) return
419
+ if (!["===", "!==", "==", "!="].includes(node.operator))
420
+ return;
421
+ if (isPresenceOperand(node.left) || isPresenceOperand(node.right))
422
+ return;
384
423
  for (const side of [node.left, node.right]) {
385
424
  if (isSecretValue(context, side) || isCryptoDigest(context, side)) {
386
- context.report({ node, messageId: "compare", data: { name: context.sourceCode.getText(side), operator: node.operator } })
387
- return
425
+ context.report({ node, messageId: "compare", data: { name: context.sourceCode.getText(side), operator: node.operator } });
426
+ return;
388
427
  }
389
- const name = operandName(side)
428
+ const name = operandName(side);
390
429
  if (name && isCredentialName(name)) {
391
- context.report({ node, messageId: "compare", data: { name, operator: node.operator } })
392
- return
430
+ context.report({ node, messageId: "compare", data: { name, operator: node.operator } });
431
+ return;
393
432
  }
394
433
  }
395
434
  },
396
- }
435
+ };
397
436
  },
398
- }
399
-
437
+ };
400
438
  /** The rules this law contributes to the plugin. */
401
439
  export const rules = {
402
440
  "no-direct-env-read": noDirectEnvRead,
403
441
  "config-parsed-in-main": configParsedInMain,
404
442
  "no-secret-default": noSecretDefault,
405
443
  "secret-compare-timing-safe": secretCompareTimingSafe,
406
- }
407
-
444
+ };
408
445
  /** All four start at error: a secret in source or a timing leak is never a warning. */
409
446
  export const recommended = {
410
447
  "starci-be/no-direct-env-read": "error",
411
448
  "starci-be/config-parsed-in-main": "error",
412
449
  "starci-be/no-secret-default": "error",
413
450
  "starci-be/secret-compare-timing-safe": "error",
414
- }
451
+ };