@starci/eslint-canon-be 3.5.0 → 3.6.1

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 (198) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +13 -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-view.d.ts +127 -0
  78. package/dist/lib/hfs-view.js +1 -0
  79. package/dist/lib/hfs.d.ts +34 -0
  80. package/{lib/hfs.mjs → dist/lib/hfs.js} +31 -29
  81. package/dist/lib/import-source.d.ts +63 -0
  82. package/dist/lib/import-source.js +134 -0
  83. package/dist/lib/path.d.ts +8 -0
  84. package/{lib/path.mjs → dist/lib/path.js} +4 -7
  85. package/dist/lib/persistence.d.ts +115 -0
  86. package/{lib/persistence.mjs → dist/lib/persistence.js} +55 -66
  87. package/dist/lib/ports.d.ts +70 -0
  88. package/{lib/ports.mjs → dist/lib/ports.js} +62 -66
  89. package/dist/lib/rule.d.ts +31 -0
  90. package/dist/lib/rule.js +2 -0
  91. package/dist/lib/runtime-root.d.ts +4 -0
  92. package/dist/lib/runtime-root.js +10 -0
  93. package/dist/lib/schema-values.d.ts +13 -0
  94. package/{lib/schema-values.mjs → dist/lib/schema-values.js} +67 -59
  95. package/dist/lib/specifier.d.ts +12 -0
  96. package/dist/lib/specifier.js +29 -0
  97. package/dist/lib/subject-values.d.ts +4 -0
  98. package/dist/lib/subject-values.js +61 -0
  99. package/dist/lib/transactions.d.ts +18 -0
  100. package/{lib/transactions.mjs → dist/lib/transactions.js} +17 -15
  101. package/dist/lib/transport-slots.d.ts +17 -0
  102. package/{lib/transport-slots.mjs → dist/lib/transport-slots.js} +2 -4
  103. package/dist/lib/types.d.ts +96 -0
  104. package/dist/lib/types.js +150 -0
  105. package/dist/lib/unit-spec.d.ts +48 -0
  106. package/{lib/unit-spec.mjs → dist/lib/unit-spec.js} +35 -44
  107. package/dist/lib/webhook-ack.d.ts +4 -0
  108. package/{lib/webhook-ack.mjs → dist/lib/webhook-ack.js} +78 -62
  109. package/dist/lib/webhook-handoff-inbox.d.ts +3 -0
  110. package/{lib/webhook-handoff-inbox.mjs → dist/lib/webhook-handoff-inbox.js} +195 -167
  111. package/dist/lib/webhook-handoff-intake.d.ts +4 -0
  112. package/{lib/webhook-handoff-intake.mjs → dist/lib/webhook-handoff-intake.js} +125 -102
  113. package/dist/lib/webhook-handoff.d.ts +15 -0
  114. package/{lib/webhook-handoff.mjs → dist/lib/webhook-handoff.js} +107 -100
  115. package/dist/lib/webhook-verifiers.d.ts +20 -0
  116. package/{lib/webhook-verifiers.mjs → dist/lib/webhook-verifiers.js} +108 -104
  117. package/dist/lib/why.d.ts +9 -0
  118. package/{lib/why.mjs → dist/lib/why.js} +6 -6
  119. package/dist/log-safety.d.ts +20 -0
  120. package/dist/log-safety.js +308 -0
  121. package/dist/module-layering.d.ts +42 -0
  122. package/dist/module-layering.js +257 -0
  123. package/dist/module-shape.d.ts +47 -0
  124. package/{module-shape.mjs → dist/module-shape.js} +278 -236
  125. package/dist/naming.d.ts +49 -0
  126. package/dist/naming.js +246 -0
  127. package/dist/observability.d.ts +25 -0
  128. package/dist/observability.js +245 -0
  129. package/dist/operations.d.ts +23 -0
  130. package/{operations.mjs → dist/operations.js} +410 -332
  131. package/dist/project-graph.d.ts +9 -0
  132. package/{project-graph.mjs → dist/project-graph.js} +8 -13
  133. package/dist/projections.d.ts +11 -0
  134. package/{projections.mjs → dist/projections.js} +60 -57
  135. package/dist/query-safety.d.ts +21 -0
  136. package/{query-safety.mjs → dist/query-safety.js} +92 -108
  137. package/dist/realtime.d.ts +15 -0
  138. package/{realtime.mjs → dist/realtime.js} +108 -106
  139. package/dist/resilience.d.ts +15 -0
  140. package/dist/resilience.js +319 -0
  141. package/dist/schema-authority.d.ts +15 -0
  142. package/{schema-authority.mjs → dist/schema-authority.js} +256 -220
  143. package/dist/service-deps.d.ts +17 -0
  144. package/{service-deps.mjs → dist/service-deps.js} +133 -130
  145. package/dist/service-isolation.d.ts +8 -0
  146. package/dist/service-isolation.js +76 -0
  147. package/dist/size-budget.d.ts +9 -0
  148. package/{size-budget.mjs → dist/size-budget.js} +27 -27
  149. package/dist/sonar-parity.d.ts +5 -0
  150. package/{sonar-parity.mjs → dist/sonar-parity.js} +7 -7
  151. package/dist/spec-no-skip.d.ts +9 -0
  152. package/dist/spec-no-skip.js +81 -0
  153. package/dist/spec-quality.d.ts +10 -0
  154. package/{spec-quality.mjs → dist/spec-quality.js} +103 -87
  155. package/dist/suppression.d.ts +26 -0
  156. package/{suppression.mjs → dist/suppression.js} +30 -45
  157. package/dist/temporal.d.ts +9 -0
  158. package/{temporal.mjs → dist/temporal.js} +75 -65
  159. package/dist/test-world.d.ts +28 -0
  160. package/{test-world.mjs → dist/test-world.js} +102 -83
  161. package/dist/testing.d.ts +51 -0
  162. package/dist/testing.js +368 -0
  163. package/dist/third-party-owner.d.ts +8 -0
  164. package/{third-party-owner.mjs → dist/third-party-owner.js} +105 -91
  165. package/dist/transport.d.ts +24 -0
  166. package/{transport.mjs → dist/transport.js} +279 -240
  167. package/dist/type-safety.d.ts +25 -0
  168. package/dist/type-safety.js +297 -0
  169. package/dist/unit-spec.d.ts +30 -0
  170. package/{unit-spec.mjs → dist/unit-spec.js} +473 -399
  171. package/dist/uploads.d.ts +9 -0
  172. package/{uploads.mjs → dist/uploads.js} +62 -54
  173. package/dist/user-copy.d.ts +9 -0
  174. package/{user-copy.mjs → dist/user-copy.js} +76 -67
  175. package/dist/webhooks.d.ts +16 -0
  176. package/{webhooks.mjs → dist/webhooks.js} +243 -231
  177. package/package.json +23 -8
  178. package/runtime/knowledge/hfs/canon-pins.yaml +18 -11
  179. package/runtime/scripts/hfs/repo-identity.mjs +5 -4
  180. package/async-discipline.mjs +0 -83
  181. package/comments.mjs +0 -416
  182. package/edge-hardening.mjs +0 -139
  183. package/health-ready.mjs +0 -539
  184. package/jwt-alg.mjs +0 -45
  185. package/lib/ast.mjs +0 -88
  186. package/lib/import-source.mjs +0 -104
  187. package/lib/specifier.mjs +0 -27
  188. package/lib/subject-values.mjs +0 -55
  189. package/lib/types.mjs +0 -133
  190. package/log-safety.mjs +0 -303
  191. package/module-layering.mjs +0 -270
  192. package/naming.mjs +0 -251
  193. package/observability.mjs +0 -241
  194. package/resilience.mjs +0 -304
  195. package/service-isolation.mjs +0 -75
  196. package/spec-no-skip.mjs +0 -85
  197. package/testing.mjs +0 -384
  198. package/type-safety.mjs +0 -323
@@ -27,49 +27,47 @@
27
27
  *
28
28
  * Paths are asked of the slot manifest (`lib/unit-spec.mjs`), a name is judged by the import that binds it, never by its spelling.
29
29
  */
30
- import { hfsOf } from "./lib/hfs.mjs"
31
- import { keyName, walk } from "./lib/ast.mjs"
32
- import { importOf, isImportedFrom } from "./lib/import-source.mjs"
33
- import ts from "typescript"
34
- import { normalizePath } from "./lib/path.mjs"
35
- import { isPackageType, typeOrigins, typed } from "./lib/types.mjs"
36
- import { baseOf, isServiceSpecFile, isUnitSpecFile, isValueRoleSpec, unitRoleOfSpec } from "./lib/unit-spec.mjs"
37
- import { isRealSubjectValue, valueObjectsOfSibling } from "./lib/subject-values.mjs"
38
- import { ownerNameOf } from "./lib/ports.mjs"
39
- import { siblingIsValueSchema } from "./lib/schema-values.mjs"
40
-
41
- const TESTING_PACKAGE = "@nestjs/testing"
42
-
30
+ import { hfsOf } from "./lib/hfs.js";
31
+ import { keyName, memberKeyValue, nameOrValue, walk } from "./lib/ast.js";
32
+ import { importOf, isImportedFrom } from "./lib/import-source.js";
33
+ import { normalizePath } from "./lib/path.js";
34
+ import { isPackageType, resolvedSymbol, typeOrigins, typed } from "./lib/types.js";
35
+ import { baseOf, isServiceSpecFile, isUnitSpecFile, isValueRoleSpec, unitRoleOfSpec } from "./lib/unit-spec.js";
36
+ import { isRealSubjectValue, valueObjectsOfSibling } from "./lib/subject-values.js";
37
+ import { ownerNameOf } from "./lib/ports.js";
38
+ import { siblingIsValueSchema } from "./lib/schema-values.js";
39
+ const TESTING_PACKAGE = "@nestjs/testing";
43
40
  /** Existing service specs and every other unit-tested logic role declared by the manifest. */
44
- const isFormSpecFile = (hfs, filename) => isServiceSpecFile(hfs, filename) || unitRoleOfSpec(hfs, filename) !== null
45
-
41
+ const isFormSpecFile = (hfs, filename) => isServiceSpecFile(hfs, filename) || unitRoleOfSpec(hfs, filename) !== null;
46
42
  /** Whether this callee creates a Nest testing module through its actual import. */
47
43
  const isTestingFactory = (context, callee) => {
48
- if (callee.type !== "MemberExpression" || callee.computed || keyName(callee.property) !== "createTestingModule") return false
49
- const found = importOf(context, callee.object)
50
- return found?.source === TESTING_PACKAGE && found.imported === "Test"
51
- }
52
-
44
+ if (callee.type !== "MemberExpression" || callee.computed || keyName(callee.property) !== "createTestingModule")
45
+ return false;
46
+ const found = importOf(context, callee.object);
47
+ return found?.source === TESTING_PACKAGE && found.imported === "Test";
48
+ };
53
49
  /** The last call in a chain `Test.createTestingModule(...).<a>().<b>()`: the `createTestingModule` call at its root, or null. */
54
50
  const testingModuleRoot = (context, node) => {
55
- let cursor = node
51
+ let cursor = node;
56
52
  while (cursor) {
57
53
  if (cursor.type === "CallExpression") {
58
- const callee = cursor.callee
59
- if (isTestingFactory(context, callee)) return cursor
60
- cursor = callee.type === "MemberExpression" ? callee.object : null
61
- } else if (cursor.type === "MemberExpression") cursor = cursor.object
62
- else if (cursor.type === "AwaitExpression") cursor = cursor.argument
63
- else return null
54
+ const callee = cursor.callee;
55
+ if (isTestingFactory(context, callee))
56
+ return cursor;
57
+ cursor = callee.type === "MemberExpression" ? callee.object : null;
58
+ }
59
+ else if (cursor.type === "MemberExpression")
60
+ cursor = cursor.object;
61
+ else if (cursor.type === "AwaitExpression")
62
+ cursor = cursor.argument;
63
+ else
64
+ return null;
64
65
  }
65
- return null
66
- }
67
-
66
+ return null;
67
+ };
68
68
  /** True for `Test.createTestingModule(...)` where `Test` is the import of `@nestjs/testing`. */
69
- const isCreateTestingModule = (context, node) => node.type === "CallExpression" && testingModuleRoot(context, node) === node
70
-
69
+ const isCreateTestingModule = (context, node) => node.type === "CallExpression" && testingModuleRoot(context, node) === node;
71
70
  // -- spec-builds-with-testing-module ---------------------------------------------------------------------------
72
-
73
71
  /** A logic-role spec builds its subject through the Nest testing module. */
74
72
  export const specBuildsWithTestingModule = {
75
73
  meta: {
@@ -83,40 +81,47 @@ export const specBuildsWithTestingModule = {
83
81
  },
84
82
  },
85
83
  create(context) {
86
- const filename = context.filename || context.getFilename()
84
+ const filename = context.filename || context.getFilename();
87
85
  // a value role (a zod schema) declares a value Nest never constructs: its spec parses it and builds no module, but only when the
88
86
  // sibling really is one (a boundary schema of an owner tier holding zod values and types, nothing else); any other file keeps the rule
89
- const hfs = hfsOf(context)
90
- if (!isFormSpecFile(hfs, filename)) return {}
91
- if (isValueRoleSpec(hfs, filename) && siblingIsValueSchema(hfs, filename)) return {}
87
+ const hfs = hfsOf(context);
88
+ if (!isFormSpecFile(hfs, filename))
89
+ return {};
90
+ if (isValueRoleSpec(hfs, filename) && siblingIsValueSchema(hfs, filename))
91
+ return {};
92
92
  // a value-object subject (undecorated, no constructor injection token) is built with `new`: Nest never constructs it
93
- const valueObjectSpec = valueObjectsOfSibling(context).length > 0
94
- let created = null
95
- let compiled = false
96
- let read = false
93
+ const valueObjectSpec = valueObjectsOfSibling(context).length > 0;
94
+ let created = null;
95
+ let compiled = false;
96
+ let read = false;
97
97
  return {
98
98
  CallExpression(node) {
99
- if (isCreateTestingModule(context, node)) created ??= node
100
- const callee = node.callee
101
- if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier") return
102
- if (callee.property.name === "compile" && (testingModuleRoot(context, callee.object) !== null || isPackageType(context, callee.object, "TestingModuleBuilder", TESTING_PACKAGE))) compiled = true
103
- if (callee.property.name === "get" && isPackageType(context, callee.object, "TestingModule", TESTING_PACKAGE)) read = true
99
+ if (isCreateTestingModule(context, node))
100
+ created ??= node;
101
+ const callee = node.callee;
102
+ if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
103
+ return;
104
+ if (callee.property.name === "compile" && (testingModuleRoot(context, callee.object) !== null || isPackageType(context, callee.object, "TestingModuleBuilder", TESTING_PACKAGE)))
105
+ compiled = true;
106
+ if (callee.property.name === "get" && isPackageType(context, callee.object, "TestingModule", TESTING_PACKAGE))
107
+ read = true;
104
108
  },
105
109
  "Program:exit"(node) {
106
- if (created === null && valueObjectSpec) return
107
- if (created === null) context.report({ node, messageId: "noModule" })
108
- else if (!compiled) context.report({ node: created, messageId: "noCompile" })
109
- else if (!read) context.report({ node: created, messageId: "noGet" })
110
+ if (created === null && valueObjectSpec)
111
+ return;
112
+ if (created === null)
113
+ context.report({ node, messageId: "noModule" });
114
+ else if (!compiled)
115
+ context.report({ node: created, messageId: "noCompile" });
116
+ else if (!read)
117
+ context.report({ node: created, messageId: "noGet" });
110
118
  },
111
- }
119
+ };
112
120
  },
113
- }
114
-
121
+ };
115
122
  // -- spec-no-new-subject ---------------------------------------------------------------------------------------
116
-
117
123
  /** The last path segment of a module specifier, without an extension. */
118
- const moduleStem = (specifier) => String(specifier).replace(/\\/g, "/").split("/").pop().replace(/\.[cm]?[jt]s$/, "")
119
-
124
+ const moduleStem = (specifier) => (String(specifier).replace(/\\/g, "/").split("/").pop() ?? "").replace(/\.[cm]?[jt]s$/, "");
120
125
  /** The logic-role subject is never constructed by hand. */
121
126
  export const specNoNewSubject = {
122
127
  meta: {
@@ -128,35 +133,36 @@ export const specNoNewSubject = {
128
133
  },
129
134
  },
130
135
  create(context) {
131
- const filename = context.filename || context.getFilename()
132
- if (!isFormSpecFile(hfsOf(context), filename)) return {}
133
- const stem = baseOf(filename).replace(/\.spec\.ts$/, "")
134
- const locals = new Set()
135
- const namespaces = new Set()
136
- const valueObjects = new Set(valueObjectsOfSibling(context))
136
+ const filename = context.filename || context.getFilename();
137
+ if (!isFormSpecFile(hfsOf(context), filename))
138
+ return {};
139
+ const stem = baseOf(filename).replace(/\.spec\.ts$/, "");
140
+ const locals = new Set();
141
+ const namespaces = new Set();
142
+ const valueObjects = new Set(valueObjectsOfSibling(context));
137
143
  return {
138
144
  ImportDeclaration(node) {
139
- if (moduleStem(node.source.value) !== stem) return
145
+ if (moduleStem(node.source.value) !== stem)
146
+ return;
140
147
  for (const specifier of node.specifiers) {
141
- if (specifier.type === "ImportSpecifier" && valueObjects.has(specifier.imported.name ?? specifier.imported.value)) continue
142
- (specifier.type === "ImportNamespaceSpecifier" ? namespaces : locals).add(specifier.local.name)
148
+ if (specifier.type === "ImportSpecifier" && valueObjects.has(specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value))
149
+ continue;
150
+ (specifier.type === "ImportNamespaceSpecifier" ? namespaces : locals).add(specifier.local.name);
143
151
  }
144
152
  },
145
153
  NewExpression(node) {
146
- const callee = node.callee
154
+ const callee = node.callee;
147
155
  const subject = callee.type === "Identifier" && locals.has(callee.name)
148
- || callee.type === "MemberExpression" && !callee.computed && callee.object.type === "Identifier" && namespaces.has(callee.object.name)
149
- if (subject) context.report({ node, messageId: "construct", data: { name: context.sourceCode.getText(callee) } })
156
+ || callee.type === "MemberExpression" && !callee.computed && callee.object.type === "Identifier" && namespaces.has(callee.object.name);
157
+ if (subject)
158
+ context.report({ node, messageId: "construct", data: { name: context.sourceCode.getText(callee) } });
150
159
  },
151
- }
160
+ };
152
161
  },
153
- }
154
-
162
+ };
155
163
  // -- spec-module-definition-only-providers -----------------------------------------------------------------------
156
-
157
164
  /** The `override*` members of `TestingModuleBuilder`. */
158
- const OVERRIDES = new Set(["overrideProvider", "overrideGuard", "overrideModule", "overrideFilter", "overridePipe", "overrideInterceptor"])
159
-
165
+ const OVERRIDES = new Set(["overrideProvider", "overrideGuard", "overrideModule", "overrideFilter", "overridePipe", "overrideInterceptor"]);
160
166
  /** The testing module lists providers and nothing else. */
161
167
  export const specModuleDefinitionOnlyProviders = {
162
168
  meta: {
@@ -169,44 +175,48 @@ export const specModuleDefinitionOnlyProviders = {
169
175
  },
170
176
  },
171
177
  create(context) {
172
- if (!isFormSpecFile(hfsOf(context), context.filename || context.getFilename())) return {}
178
+ if (!isFormSpecFile(hfsOf(context), context.filename || context.getFilename()))
179
+ return {};
173
180
  return {
174
181
  CallExpression(node) {
175
182
  if (isCreateTestingModule(context, node)) {
176
- const definition = node.arguments[0]
177
- if (definition?.type !== "ObjectExpression") return
183
+ const definition = node.arguments[0];
184
+ if (definition?.type !== "ObjectExpression")
185
+ return;
178
186
  for (const property of definition.properties) {
179
- const key = property.type === "Property" ? (property.key.name ?? property.key.value) : null
180
- if (key === "imports") context.report({ node: property, messageId: "imports" })
187
+ const key = property.type === "Property" ? nameOrValue(property.key) : null;
188
+ if (key === "imports")
189
+ context.report({ node: property, messageId: "imports" });
181
190
  }
182
- return
191
+ return;
183
192
  }
184
- const callee = node.callee
193
+ const callee = node.callee;
185
194
  if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && OVERRIDES.has(callee.property.name)) {
186
- context.report({ node: callee.property, messageId: "override", data: { method: callee.property.name } })
195
+ context.report({ node: callee.property, messageId: "override", data: { method: callee.property.name } });
187
196
  }
188
197
  },
189
- }
198
+ };
190
199
  },
191
- }
192
-
200
+ };
193
201
  // -- spec-no-module-mock ---------------------------------------------------------------------------------------
194
-
195
202
  /** The `jest` members that replace or fetch a module for the whole file. */
196
- const MODULE_MOCKS = new Set(["mock", "doMock", "unstable_mockModule", "requireMock", "setMock"])
197
-
203
+ const MODULE_MOCKS = new Set(["mock", "doMock", "unstable_mockModule", "requireMock", "setMock"]);
198
204
  /** Whether the identifier `name` is the ambient global (or, when `source` is given, that import), not a local binding: `jest` and `expect` are the jest globals or `@jest/globals` imports. */
199
205
  const isAmbientOrImported = (context, node, name, source) => {
200
- if (node.type !== "Identifier" || node.name !== name) return false
201
- const imported = importOf(context, node)
202
- if (imported) return source !== null && imported.source === source && imported.imported === name
206
+ if (node.type !== "Identifier" || node.name !== name)
207
+ return false;
208
+ const imported = importOf(context, node);
209
+ if (imported)
210
+ return source !== null && imported.source === source && imported.imported === name;
203
211
  for (let scope = context.sourceCode.getScope(node); scope; scope = scope.upper) {
204
- const variable = scope.set.get(name)
205
- if (variable) return variable.defs.length === 0 || scope.type === "global" || variable.defs.every((definition) => definition.node?.parent?.declare === true)
212
+ const variable = scope.set.get(name);
213
+ if (variable)
214
+ return variable.defs.length === 0 || scope.type === "global" || variable.defs.every((definition) => isDeclared(definition.node?.parent));
206
215
  }
207
- return true
208
- }
209
-
216
+ return true;
217
+ };
218
+ /** `node?.declare === true` of any node: an ambient (`declare`) declaration. */
219
+ const isDeclared = (node) => node !== null && node !== undefined && "declare" in node && node.declare === true;
210
220
  /** A unit spec replaces no module, its own or a library's. */
211
221
  export const specNoModuleMock = {
212
222
  meta: {
@@ -218,120 +228,131 @@ export const specNoModuleMock = {
218
228
  },
219
229
  },
220
230
  create(context) {
221
- if (!isUnitSpecFile(hfsOf(context), context.filename || context.getFilename())) return {}
231
+ if (!isUnitSpecFile(hfsOf(context), context.filename || context.getFilename()))
232
+ return {};
222
233
  return {
223
234
  CallExpression(node) {
224
- const callee = node.callee
225
- if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier" || !MODULE_MOCKS.has(callee.property.name)) return
226
- if (isAmbientOrImported(context, callee.object, "jest", "@jest/globals")) context.report({ node, messageId: "moduleMock", data: { method: callee.property.name } })
235
+ const callee = node.callee;
236
+ if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier" || !MODULE_MOCKS.has(callee.property.name))
237
+ return;
238
+ if (isAmbientOrImported(context, callee.object, "jest", "@jest/globals"))
239
+ context.report({ node, messageId: "moduleMock", data: { method: callee.property.name } });
227
240
  },
228
- }
241
+ };
229
242
  },
230
- }
231
-
243
+ };
232
244
  // -- no-return-only-generic --------------------------------------------------------------------------------------
233
-
234
245
  /** Names a type reference or type query spells, anywhere below a type node. */
235
246
  const typeNamesIn = (node) => {
236
- const names = new Set()
247
+ const names = new Set();
237
248
  walk(node, (child) => {
238
- if (child.type === "TSTypeReference" && child.typeName.type === "Identifier") names.add(child.typeName.name)
239
- })
240
- return names
241
- }
242
-
249
+ if (child.type === "TSTypeReference" && child.typeName.type === "Identifier")
250
+ names.add(child.typeName.name);
251
+ });
252
+ return names;
253
+ };
243
254
  /** The expressions a function returns (its expression body, or each `return` of its own body). */
244
255
  const returnedExpressions = (fn) => {
245
- if (!fn.body) return []
246
- if (fn.body.type !== "BlockStatement") return [fn.body]
247
- const found = []
256
+ if (!fn.body)
257
+ return [];
258
+ if (fn.body.type !== "BlockStatement")
259
+ return [fn.body];
260
+ const found = [];
248
261
  walk(fn.body, (node) => {
249
- if (node.type === "ReturnStatement" && node.argument) found.push(node.argument)
250
- }, { intoFunctions: false })
251
- return found
252
- }
253
-
254
- /** The expression under any chain of assertions, parentheses and awaits. */
255
- const peel = (expression) => {
256
- let node = expression
257
- while (node && (node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "TSSatisfiesExpression" || node.type === "AwaitExpression")) node = node.expression ?? node.argument
258
- return node
262
+ if (node.type === "ReturnStatement" && node.argument)
263
+ found.push(node.argument);
264
+ }, { intoFunctions: false });
265
+ return found;
266
+ };
267
+ function peel(expression) {
268
+ let node = expression;
269
+ // the assertions hold `expression`, an await holds `argument` (`node.expression ?? node.argument`)
270
+ while (node && (node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "TSSatisfiesExpression" || node.type === "AwaitExpression"))
271
+ node = node.type === "AwaitExpression" ? node.argument : node.expression;
272
+ return node;
259
273
  }
260
-
261
274
  /** Whether a call is `Object.assign(new X(), ...)`; gives X's name. */
262
275
  const assignedClassOf = (node) => {
263
- if (node?.type !== "CallExpression") return null
264
- const callee = node.callee
265
- if (callee.type !== "MemberExpression" || callee.computed || callee.object.type !== "Identifier" || callee.object.name !== "Object" || callee.property.name !== "assign") return null
266
- const target = node.arguments[0]
267
- return target?.type === "NewExpression" && target.callee.type === "Identifier" ? target.callee.name : null
268
- }
269
-
276
+ if (node?.type !== "CallExpression")
277
+ return null;
278
+ const callee = node.callee;
279
+ if (callee.type !== "MemberExpression" || callee.computed || callee.object.type !== "Identifier" || callee.object.name !== "Object" || callee.property.name !== "assign")
280
+ return null;
281
+ const target = node.arguments[0];
282
+ return target?.type === "NewExpression" && target.callee.type === "Identifier" ? target.callee.name : null;
283
+ };
270
284
  /** The declared name of a function or the property that holds it. */
271
285
  const functionNameOf = (fn) => {
272
- if (fn.id?.name) return fn.id.name
273
- const parent = fn.parent
274
- if (parent?.type === "VariableDeclarator" && parent.id.type === "Identifier") return parent.id.name
275
- if (parent?.type === "Property" || parent?.type === "MethodDefinition") return parent.key.name ?? parent.key.value
276
- return "this function"
277
- }
278
-
286
+ if (fn.id?.name)
287
+ return fn.id.name;
288
+ const parent = fn.parent;
289
+ if (parent?.type === "VariableDeclarator" && parent.id.type === "Identifier")
290
+ return parent.id.name;
291
+ if (parent?.type === "Property" || parent?.type === "MethodDefinition")
292
+ return nameOrValue(parent.key);
293
+ return "this function";
294
+ };
295
+ /** `param.typeAnnotation ?? param.left?.typeAnnotation` of a parameter of any kind. */
296
+ const parameterAnnotationOf = (param) => {
297
+ const own = "typeAnnotation" in param ? param.typeAnnotation : undefined;
298
+ return own ?? ("left" in param ? param.left?.typeAnnotation : undefined);
299
+ };
279
300
  /** Names that the parameter types mention. */
280
301
  const parameterTypeNames = (fn) => {
281
- const names = new Set()
302
+ const names = new Set();
282
303
  for (const param of fn.params) {
283
- for (const spelled of typeNamesIn(param.typeAnnotation ?? param.left?.typeAnnotation)) names.add(spelled)
304
+ for (const spelled of typeNamesIn(parameterAnnotationOf(param)))
305
+ names.add(spelled);
284
306
  }
285
- return names
286
- }
287
-
307
+ return names;
308
+ };
288
309
  /** Report type parameters chosen only by the caller's expected return type. */
289
310
  const reportReturnOnlyParameters = (context, fn, name) => {
290
- const declared = fn.typeParameters?.params ?? []
291
- const returned = fn.returnType?.typeAnnotation
292
- if (declared.length === 0 || !returned) return false
293
- const inReturn = typeNamesIn(returned)
294
- const inParams = parameterTypeNames(fn)
295
- let generic = false
311
+ const declared = fn.typeParameters?.params ?? [];
312
+ const returned = fn.returnType?.typeAnnotation;
313
+ if (declared.length === 0 || !returned)
314
+ return false;
315
+ const inReturn = typeNamesIn(returned);
316
+ const inParams = parameterTypeNames(fn);
317
+ let generic = false;
296
318
  for (const param of declared) {
297
- const spelled = param.name.name
319
+ const spelled = param.name.name;
298
320
  // A parameter mentioned by another parameter's bound is driven by the caller's arguments.
299
- const inBounds = declared.some((other) => other !== param && (typeNamesIn(other.constraint).has(spelled) || typeNamesIn(other.default).has(spelled)))
321
+ const inBounds = declared.some((other) => other !== param && (typeNamesIn(other.constraint).has(spelled) || typeNamesIn(other.default).has(spelled)));
300
322
  if (inReturn.has(spelled) && !inParams.has(spelled) && !inBounds) {
301
- generic = true
302
- context.report({ node: param, messageId: "returnOnly", data: { name, param: spelled } })
323
+ generic = true;
324
+ context.report({ node: param, messageId: "returnOnly", data: { name, param: spelled } });
303
325
  }
304
326
  }
305
- return generic
306
- }
307
-
327
+ return generic;
328
+ };
308
329
  /** Untyped parameters handed back by a spec helper. */
309
330
  const looseParameters = (fn) => {
310
- const loose = new Map()
331
+ const loose = new Map();
311
332
  for (const param of fn.params) {
312
- const target = param.type === "AssignmentPattern" ? param.left : param
313
- const kind = target.type === "Identifier" ? target.typeAnnotation?.typeAnnotation?.type : undefined
314
- if (kind === "TSUnknownKeyword" || kind === "TSAnyKeyword") loose.set(target.name, kind === "TSAnyKeyword" ? "any" : "unknown")
333
+ const target = param.type === "AssignmentPattern" ? param.left : param;
334
+ const kind = target.type === "Identifier" ? target.typeAnnotation?.typeAnnotation?.type : undefined;
335
+ // `kind` is set only for an identifier, so the type test adds no case
336
+ if (target.type === "Identifier" && (kind === "TSUnknownKeyword" || kind === "TSAnyKeyword"))
337
+ loose.set(target.name, kind === "TSAnyKeyword" ? "any" : "unknown");
315
338
  }
316
- return loose
317
- }
318
-
339
+ return loose;
340
+ };
319
341
  /** Report a helper return that launders an untyped value or a different class. */
320
342
  const reportHelperReturn = (context, expression, { name, generic, loose, returned }) => {
321
- const value = peel(expression)
322
- const returnedType = returned?.type
323
- const concrete = returnedType !== undefined && returnedType !== "TSUnknownKeyword" && returnedType !== "TSAnyKeyword"
343
+ const value = peel(expression);
344
+ const returnedType = returned?.type;
345
+ const concrete = returnedType !== undefined && returnedType !== "TSUnknownKeyword" && returnedType !== "TSAnyKeyword";
324
346
  if (!generic && value.type === "Identifier" && loose.has(value.name) && (concrete || value !== expression)) {
325
- context.report({ node: expression, messageId: "launder", data: { name, kind: loose.get(value.name) } })
326
- return true
347
+ context.report({ node: expression, messageId: "launder", data: { name, kind: loose.get(value.name) } });
348
+ return true;
327
349
  }
328
- const klass = assignedClassOf(value)
350
+ const klass = assignedClassOf(value);
329
351
  if (klass !== null && returned?.type === "TSTypeReference" && returned.typeName.type === "Identifier" && returned.typeName.name !== klass) {
330
- context.report({ node: expression, messageId: "assign", data: { klass, returned: returned.typeName.name } })
352
+ context.report({ node: expression, messageId: "assign", data: { klass, returned: returned.typeName.name } });
331
353
  }
332
- return false
333
- }
334
-
354
+ return false;
355
+ };
335
356
  /** A helper of a spec or of the fixtures is not a cast with a name. */
336
357
  export const noReturnOnlyGeneric = {
337
358
  meta: {
@@ -346,71 +367,88 @@ export const noReturnOnlyGeneric = {
346
367
  },
347
368
  },
348
369
  create(context) {
349
- const hfs = hfsOf(context)
350
- const filename = context.filename || context.getFilename()
351
- if (!/\.(?:e2e-|integration-|contract-)?spec\.[cm]?ts$/.test(baseOf(filename)) && hfs.slotOf(filename) !== "be.tests.fixtures") return {}
370
+ const hfs = hfsOf(context);
371
+ const filename = context.filename || context.getFilename();
372
+ if (!/\.(?:e2e-|integration-|contract-)?spec\.[cm]?ts$/.test(baseOf(filename)) && hfs.slotOf(filename) !== "be.tests.fixtures")
373
+ return {};
352
374
  const check = (fn) => {
353
- const name = functionNameOf(fn)
354
- const generic = reportReturnOnlyParameters(context, fn, name)
355
- const returned = fn.returnType?.typeAnnotation
356
- if (fn.body === null || fn.body === undefined) return
357
- const loose = looseParameters(fn)
375
+ const name = functionNameOf(fn);
376
+ const generic = reportReturnOnlyParameters(context, fn, name);
377
+ const returned = fn.returnType?.typeAnnotation;
378
+ if (fn.body === null || fn.body === undefined)
379
+ return;
380
+ const loose = looseParameters(fn);
358
381
  for (const expression of returnedExpressions(fn)) {
359
- if (reportHelperReturn(context, expression, { name, generic, loose, returned })) return
382
+ if (reportHelperReturn(context, expression, { name, generic, loose, returned }))
383
+ return;
360
384
  }
361
- }
385
+ };
362
386
  return {
363
387
  FunctionDeclaration: check,
364
388
  FunctionExpression: check,
365
389
  ArrowFunctionExpression: check,
366
390
  TSDeclareFunction: check,
367
391
  CallExpression(node) {
368
- const callee = node.callee
369
- if (callee.type !== "MemberExpression" || callee.computed || callee.object.type !== "Identifier" || callee.object.name !== "JSON" || callee.property.name !== "parse") return
370
- const argument = node.arguments[0]
371
- if (argument?.type === "CallExpression" && argument.callee.type === "MemberExpression" && argument.callee.object.type === "Identifier" && argument.callee.object.name === "JSON" && argument.callee.property.name === "stringify") {
372
- context.report({ node, messageId: "json" })
392
+ const callee = node.callee;
393
+ if (callee.type !== "MemberExpression" || callee.computed || callee.object.type !== "Identifier" || callee.object.name !== "JSON" || callee.property.name !== "parse")
394
+ return;
395
+ const argument = node.arguments[0];
396
+ if (argument?.type === "CallExpression" && argument.callee.type === "MemberExpression" && argument.callee.object.type === "Identifier" && argument.callee.object.name === "JSON" && "name" in argument.callee.property && argument.callee.property.name === "stringify") {
397
+ context.report({ node, messageId: "json" });
373
398
  }
374
399
  },
375
- }
400
+ };
376
401
  },
377
- }
378
-
402
+ };
379
403
  // -- spec-infra-double-from-kit --------------------------------------------------------------------------------
380
-
381
404
  /** `EntityManager` -> `ENTITY_MANAGER`, `redis-cache` -> `REDIS_CACHE`. */
382
- const screamingSnake = (name) => String(name).replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").toUpperCase().replace(/[^A-Z0-9]+/g, "_")
383
-
405
+ const screamingSnake = (name) => String(name).replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").toUpperCase().replace(/[^A-Z0-9]+/g, "_");
384
406
  /** The name a provider token spells: an identifier, the last member of `Tokens.CLOCK`, a string, a called token factory's name. */
385
407
  const tokenName = (node) => {
386
- if (!node) return null
387
- if (node.type === "Identifier") return node.name
388
- if (node.type === "Literal" && typeof node.value === "string") return node.value
389
- if (node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier") return node.property.name
390
- if (node.type === "CallExpression") return tokenName(node.callee)
391
- return null
392
- }
393
-
408
+ if (!node)
409
+ return null;
410
+ if (node.type === "Identifier")
411
+ return node.name;
412
+ if (node.type === "Literal" && typeof node.value === "string")
413
+ return node.value;
414
+ if (node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier")
415
+ return node.property.name;
416
+ if (node.type === "CallExpression")
417
+ return tokenName(node.callee);
418
+ return null;
419
+ };
420
+ /** Whether a manifest value is a double entry (`{ double, forms }`). */
421
+ const isKitDouble = (value) => typeof value === "object" && value !== null && "double" in value && typeof value.double === "string"
422
+ && "forms" in value && Array.isArray(value.forms) && value.forms.every((form) => typeof form === "string");
423
+ /** A manifest key the shared `specDoubles` type does not name (`fallback`, an entry's `from`), read as data. */
424
+ const keyOf = (value, key) => (key in value ? Reflect.get(value, key) : undefined);
394
425
  /** The compiled table of a manifest's `specDoubles`, cached per manifest object. */
395
- const COMPILED = new WeakMap()
426
+ const COMPILED = new WeakMap();
396
427
  const tableOf = (specDoubles) => {
397
- let compiled = COMPILED.get(specDoubles)
428
+ let compiled = COMPILED.get(specDoubles);
398
429
  if (!compiled) {
399
- compiled = { kit: specDoubles.kit, entries: specDoubles.doubles.map((entry) => ({ ...entry, pattern: new RegExp(entry.token), from: entry.from === undefined ? undefined : new RegExp(entry.from) })), fallback: specDoubles.fallback }
400
- COMPILED.set(specDoubles, compiled)
430
+ const fallback = keyOf(specDoubles, "fallback");
431
+ compiled = {
432
+ kit: specDoubles.kit,
433
+ entries: specDoubles.doubles.map((entry) => {
434
+ const from = keyOf(entry, "from");
435
+ return { ...entry, pattern: new RegExp(entry.token), from: from === undefined ? undefined : new RegExp(String(from)) };
436
+ }),
437
+ fallback: isKitDouble(fallback) ? fallback : undefined,
438
+ };
439
+ COMPILED.set(specDoubles, compiled);
401
440
  }
402
- return compiled
403
- }
404
-
441
+ return compiled;
442
+ };
405
443
  /** The file and exported name a token identifier is declared in, after following every import and re-export, or null when it cannot be resolved. */
406
444
  const declarationOf = (context, token) => {
407
- const { checker, toTs } = typed(context)
408
- const symbol = checker.getSymbolAtLocation(toTs(token))
409
- const target = symbol?.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol
410
- const declaration = target?.getDeclarations?.()?.[0]
411
- return declaration === undefined ? null : { file: normalizePath(declaration.getSourceFile().fileName), name: target.getName() }
412
- }
413
-
445
+ const { checker, toTs } = typed(context);
446
+ const symbol = checker.getSymbolAtLocation(toTs(token));
447
+ const target = resolvedSymbol(checker, symbol);
448
+ const declaration = target?.getDeclarations?.()?.[0];
449
+ // a declaration comes from a resolved symbol, so `target === undefined` adds no case
450
+ return declaration === undefined || target === undefined ? null : { file: normalizePath(declaration.getSourceFile().fileName), name: target.getName() };
451
+ };
414
452
  /**
415
453
  * Whether a table entry applies to a provider token. The spelling picks the entry; when the entry names where its port is declared
416
454
  * (`from`, a pattern over the declaring file), the declaration decides, never the import written in the spec: a token declared in
@@ -419,108 +457,114 @@ const declarationOf = (context, token) => {
419
457
  * that cannot be resolved, or is declared in the spec itself, is judged by its spelling alone.
420
458
  */
421
459
  const entryApplies = (context, entry, spelled, token) => {
422
- if (entry.from === undefined || token?.type !== "Identifier") return entry.pattern.test(spelled)
423
- const declared = declarationOf(context, token)
424
- if (declared === null || declared.file === normalizePath(context.filename || context.getFilename())) return entry.pattern.test(spelled)
425
- if (!entry.from.test(declared.file)) return !declared.file.includes("/src/modules/") && entry.pattern.test(spelled)
426
- return entry.pattern.test(spelled) || entry.pattern.test(screamingSnake(declared.name))
427
- }
428
-
460
+ if (entry.from === undefined || token?.type !== "Identifier")
461
+ return entry.pattern.test(spelled);
462
+ const declared = declarationOf(context, token);
463
+ if (declared === null || declared.file === normalizePath(context.filename || context.getFilename()))
464
+ return entry.pattern.test(spelled);
465
+ if (!entry.from.test(declared.file))
466
+ return !declared.file.includes("/src/modules/") && entry.pattern.test(spelled);
467
+ return entry.pattern.test(spelled) || entry.pattern.test(screamingSnake(declared.name));
468
+ };
429
469
  /** A const identifier's initializer, or null when its value cannot be followed. */
430
470
  const constantInitializer = (context, value) => {
431
471
  for (let scope = context.sourceCode.getScope(value); scope; scope = scope.upper) {
432
- const variable = scope.set.get(value.name)
433
- if (!variable) continue
434
- const definition = variable.defs[0]
435
- if (definition?.type === "Variable" && definition.node.id.type === "Identifier" && definition.node.init && definition.parent.kind === "const") return definition.node.init
436
- return null
472
+ const variable = scope.set.get(value.name);
473
+ if (!variable)
474
+ continue;
475
+ const definition = variable.defs[0];
476
+ if (definition?.type === "Variable" && definition.node.id.type === "Identifier" && definition.node.init && definition.parent.kind === "const")
477
+ return definition.node.init;
478
+ return null;
437
479
  }
438
- return null
439
- }
440
-
480
+ return null;
481
+ };
441
482
  /** An imported token retains its declared identity through const aliases and assertion wrappers. */
442
483
  const originsOfToken = (context, token) => {
443
- let value = peel(token)
444
- const seen = new Set()
484
+ let value = peel(token);
485
+ const seen = new Set();
445
486
  while (value?.type === "Identifier" && !seen.has(value)) {
446
- seen.add(value)
447
- const initial = peel(constantInitializer(context, value))
448
- if (!initial || !["Identifier", "MemberExpression"].includes(initial.type)) break
449
- value = initial
487
+ seen.add(value);
488
+ const initial = peel(constantInitializer(context, value));
489
+ if (!initial || !["Identifier", "MemberExpression"].includes(initial.type))
490
+ break;
491
+ value = initial;
450
492
  }
451
- return typeOrigins(context, value)
452
- }
453
-
493
+ return typeOrigins(context, value);
494
+ };
454
495
  /** Inbox is the platform port; a service or producer whose name contains Inbox remains an ordinary collaborator. */
455
496
  const providerDoubleEntry = (context, hfs, table, token, normalised) => {
456
- const named = (name, from) => table.entries.find((entry) => entryApplies(context, entry, screamingSnake(name), from)) ?? table.fallback
457
- const lexical = named(normalised, token)
458
- const inbox = named("INBOX")
459
- const origins = originsOfToken(context, token)
460
- const platform = origins.filter((origin) => origin.module === null && hfs.tierOf(origin.file) === "platform")
461
- if (platform.some((origin) => origin.name === "INBOX" && ownerNameOf(hfs, origin.file) === "inbox")) return inbox
462
- if (lexical !== inbox || origins.length === 0) return lexical
463
- return platform.map((origin) => named(origin.name)).find((entry) => entry !== inbox) ?? table.fallback
464
- }
465
-
497
+ const named = (name, from) => table.entries.find((entry) => entryApplies(context, entry, screamingSnake(name), from)) ?? table.fallback;
498
+ const lexical = named(normalised, token);
499
+ const inbox = named("INBOX");
500
+ const origins = originsOfToken(context, token);
501
+ const platform = origins.filter((origin) => origin.module === null && hfs.tierOf(origin.file) === "platform");
502
+ if (platform.some((origin) => origin.name === "INBOX" && ownerNameOf(hfs, origin.file) === "inbox"))
503
+ return inbox;
504
+ if (lexical !== inbox || origins.length === 0)
505
+ return lexical;
506
+ return platform.map((origin) => named(origin.name)).find((entry) => entry !== inbox) ?? table.fallback;
507
+ };
466
508
  /** A value's form and the double it names: `{ form, name }`, or null when it is not a form the table knows. */
467
509
  const formOf = (context, node, depth = 0) => {
468
- const value = peel(node)
510
+ const value = peel(node);
469
511
  switch (value.type) {
470
512
  case "CallExpression":
471
- if (value.callee.type === "Identifier") return { form: "call", name: value.callee.name, node: value.callee }
472
- if (value.callee.type === "CallExpression" && value.callee.callee.type === "Identifier") return { form: "curried", name: value.callee.callee.name, node: value.callee.callee }
473
- return null
513
+ if (value.callee.type === "Identifier")
514
+ return { form: "call", name: value.callee.name, node: value.callee };
515
+ if (value.callee.type === "CallExpression" && value.callee.callee.type === "Identifier")
516
+ return { form: "curried", name: value.callee.callee.name, node: value.callee.callee };
517
+ return null;
474
518
  case "NewExpression":
475
- return value.callee.type === "Identifier" ? { form: "new", name: value.callee.name, node: value.callee } : null
519
+ return value.callee.type === "Identifier" ? { form: "new", name: value.callee.name, node: value.callee } : null;
476
520
  case "MemberExpression": {
477
521
  // a member of a kit `mock<T>()` object is that mock's double (`mock<{ open: F }>().open`)
478
- if (value.computed || depth >= 3) return null
479
- const owner = formOf(context, value.object, depth + 1)
480
- return owner?.form === "call" && owner.name === "mock" ? owner : null
522
+ if (value.computed || depth >= 3)
523
+ return null;
524
+ const owner = formOf(context, value.object, depth + 1);
525
+ return owner?.form === "call" && owner.name === "mock" ? owner : null;
481
526
  }
482
527
  case "ObjectExpression":
483
- return { form: "object" }
528
+ return { form: "object" };
484
529
  case "ArrayExpression":
485
- return { form: "array" }
530
+ return { form: "array" };
486
531
  case "Literal":
487
- return { form: "primitive" }
532
+ return { form: "primitive" };
488
533
  case "TemplateLiteral":
489
- return value.expressions.length === 0 ? { form: "primitive" } : null
534
+ return value.expressions.length === 0 ? { form: "primitive" } : null;
490
535
  case "Identifier": {
491
- if (depth >= 3) return null
492
- const initializer = constantInitializer(context, value)
493
- return initializer === null ? null : formOf(context, initializer, depth + 1)
536
+ if (depth >= 3)
537
+ return null;
538
+ const initializer = constantInitializer(context, value);
539
+ return initializer === null ? null : formOf(context, initializer, depth + 1);
494
540
  }
495
541
  default:
496
- return null
542
+ return null;
497
543
  }
498
- }
499
-
544
+ };
500
545
  /** The kit type each double produces, by declared name: what a parameter or a property typed so is a double of. */
501
- const KIT_TYPES = Object.freeze({ MockEntityManager: "mockEntityManager", FakeCache: "fakeCache", FakeLock: "fakeLock", RecordingEventBus: "recordingEventBus", RecordingQueueOutbox: "recordingQueueOutbox", FakeClock: "FakeClock", FakeIds: "fakeIds", FakeTransaction: "fakeTransaction" })
502
-
546
+ const KIT_TYPES = Object.freeze({ MockEntityManager: "mockEntityManager", FakeCache: "fakeCache", FakeLock: "fakeLock", RecordingEventBus: "recordingEventBus", RecordingQueueOutbox: "recordingQueueOutbox", FakeClock: "FakeClock", FakeIds: "fakeIds", FakeTransaction: "fakeTransaction" });
503
547
  /** The kit double a value's TYPE says it is (a helper parameter typed `MockEntityManager`, `tx.em` of a `fakeTransaction`), or null. */
504
548
  const kitDoubleOfType = (context, node, kit) => {
505
- const found = typeOrigins(context, node).find((origin) => Object.hasOwn(KIT_TYPES, origin.name) && origin.module === kit)
506
- return found ? KIT_TYPES[found.name] : null
507
- }
508
-
549
+ const found = typeOrigins(context, node).find((origin) => Object.hasOwn(KIT_TYPES, origin.name) && origin.module === kit);
550
+ return found ? KIT_TYPES[found.name] : null;
551
+ };
509
552
  /** How an actual double value is written in a diagnostic. */
510
553
  const describeDoubleValue = (found) => {
511
- if (found.name === undefined) return `a ${found.form} value`
512
- const prefix = found.form === "new" ? "new " : ""
513
- return `\`${prefix}${found.name}(...)\``
514
- }
515
-
554
+ if (found.name === undefined)
555
+ return `a ${found.form} value`;
556
+ const prefix = found.form === "new" ? "new " : "";
557
+ return `\`${prefix}${found.name}(...)\``;
558
+ };
516
559
  /** Judge a provider that is traced by its declared type instead of its initializer. */
517
560
  const checkTypedDouble = (context, node, table, entry, data) => {
518
- const typedAs = kitDoubleOfType(context, node.value, table.kit)
519
- if (typedAs === null) return context.report({ node: node.value, messageId: "unknown", data })
520
- if (typedAs !== entry.double) return context.report({ node: node.value, messageId: "wrong", data: { ...data, got: `a \`${typedAs}\` double` } })
521
- return undefined
522
- }
523
-
561
+ const typedAs = kitDoubleOfType(context, node.value, table.kit);
562
+ if (typedAs === null)
563
+ return context.report({ node: node.value, messageId: "unknown", data });
564
+ if (typedAs !== entry.double)
565
+ return context.report({ node: node.value, messageId: "wrong", data: { ...data, got: `a \`${typedAs}\` double` } });
566
+ return undefined;
567
+ };
524
568
  /** The double a token's provider value must come from. */
525
569
  export const specInfraDoubleFromKit = {
526
570
  meta: {
@@ -534,48 +578,59 @@ export const specInfraDoubleFromKit = {
534
578
  },
535
579
  },
536
580
  create(context) {
537
- const hfs = hfsOf(context)
538
- if (!isFormSpecFile(hfs, context.filename || context.getFilename())) return {}
539
- const table = tableOf(hfs.ruleParams.specDoubles)
581
+ const hfs = hfsOf(context);
582
+ if (!isFormSpecFile(hfs, context.filename || context.getFilename()))
583
+ return {};
584
+ const table = tableOf(hfs.ruleParams.specDoubles);
540
585
  const describe = (entry) => {
541
- const forms = entry.forms.map((form) => ({ call: `\`${entry.double}(...)\``, new: `\`new ${entry.double}(...)\``, curried: `\`${entry.double}(...)(...)\``, object: "a plain object literal of real values", primitive: "a real value", array: "an array" })[form])
542
- return forms.join(" or ")
543
- }
586
+ const forms = entry.forms.map((form) => {
587
+ const phrases = { call: `\`${entry.double}(...)\``, new: `\`new ${entry.double}(...)\``, curried: `\`${entry.double}(...)(...)\``, object: "a plain object literal of real values", primitive: "a real value", array: "an array" };
588
+ return phrases[form];
589
+ });
590
+ return forms.join(" or ");
591
+ };
544
592
  return {
545
593
  Property(node) {
546
- if (node.parent.type !== "ObjectExpression" || (node.key.name ?? node.key.value) !== "useValue") return
547
- if (isRealSubjectValue(context, node.value)) return
548
- const provide = node.parent.properties.find((property) => property.type === "Property" && (property.key.name ?? property.key.value) === "provide")
549
- const spelled = tokenName(provide?.value)
550
- if (spelled === null) return
551
- const normalised = screamingSnake(spelled)
552
- const entry = providerDoubleEntry(context, hfs, table, provide.value, normalised)
553
- const found = formOf(context, node.value)
554
- const want = describe(entry)
555
- const data = { token: spelled, want, kit: table.kit }
594
+ if (node.parent.type !== "ObjectExpression" || nameOrValue(node.key) !== "useValue")
595
+ return;
596
+ if (isRealSubjectValue(context, node.value))
597
+ return;
598
+ const provide = node.parent.properties.find((property) => property.type === "Property" && nameOrValue(property.key) === "provide");
599
+ const spelled = tokenName(provide?.value);
600
+ // a spelled token comes from a found `provide`, so `provide === undefined` adds no case
601
+ if (spelled === null || provide === undefined)
602
+ return;
603
+ const normalised = screamingSnake(spelled);
604
+ const entry = providerDoubleEntry(context, hfs, table, provide.value, normalised);
605
+ // a manifest without a `fallback` double has no entry for this token: reading its forms failed here before
606
+ if (entry === undefined)
607
+ throw new TypeError(`ruleParams.be.specDoubles has no double for ${spelled} and no fallback`);
608
+ const found = formOf(context, node.value);
609
+ const want = describe(entry);
610
+ const data = { token: spelled, want, kit: table.kit };
556
611
  if (found === null) {
557
612
  // not a call, a literal or a traceable const: the declared type of the value decides (a helper parameter, `tx.em`)
558
- return checkTypedDouble(context, node, table, entry, data)
613
+ return checkTypedDouble(context, node, table, entry, data);
559
614
  }
560
615
  if (!entry.forms.includes(found.form)) {
561
- const got = describeDoubleValue(found)
562
- return context.report({ node: node.value, messageId: "wrong", data: { ...data, got } })
616
+ const got = describeDoubleValue(found);
617
+ return context.report({ node: node.value, messageId: "wrong", data: { ...data, got } });
563
618
  }
564
- if (found.name === undefined) return undefined
565
- const imported = importOf(context, found.node)
566
- if (found.name !== entry.double) return context.report({ node: node.value, messageId: "wrong", data: { ...data, got: describeDoubleValue(found) } })
567
- if (!imported || !(imported.source === table.kit || imported.source.startsWith(`${table.kit}/`)) || imported.imported !== entry.double) return context.report({ node: node.value, messageId: "notKit", data: { ...data, name: found.name } })
568
- return undefined
619
+ if (found.name === undefined)
620
+ return undefined;
621
+ const imported = importOf(context, found.node);
622
+ if (found.name !== entry.double)
623
+ return context.report({ node: node.value, messageId: "wrong", data: { ...data, got: describeDoubleValue(found) } });
624
+ if (!imported || !(imported.source === table.kit || imported.source.startsWith(`${table.kit}/`)) || imported.imported !== entry.double)
625
+ return context.report({ node: node.value, messageId: "notKit", data: { ...data, name: found.name } });
626
+ return undefined;
569
627
  },
570
- }
628
+ };
571
629
  },
572
- }
573
-
630
+ };
574
631
  // -- spec-exact-values -----------------------------------------------------------------------------------------
575
-
576
632
  /** The global constructors whose `expect.any(...)` accepts every value of a kind, so asserts nothing exact. */
577
- const LOOSE_KINDS = new Set(["String", "Number", "Date"])
578
-
633
+ const LOOSE_KINDS = new Set(["String", "Number", "Date"]);
579
634
  /** A unit spec asserts the exact id and the exact date, never "some string" or "some date". */
580
635
  export const specExactValues = {
581
636
  meta: {
@@ -587,96 +642,111 @@ export const specExactValues = {
587
642
  },
588
643
  },
589
644
  create(context) {
590
- if (!isFormSpecFile(hfsOf(context), context.filename || context.getFilename())) return {}
645
+ if (!isFormSpecFile(hfsOf(context), context.filename || context.getFilename()))
646
+ return {};
591
647
  return {
592
648
  CallExpression(node) {
593
- const callee = node.callee
594
- if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier" || callee.property.name !== "any") return
595
- if (!isAmbientOrImported(context, callee.object, "expect", "@jest/globals")) return
596
- const kind = node.arguments[0]
597
- if (kind?.type !== "Identifier" || !LOOSE_KINDS.has(kind.name) || !isAmbientOrImported(context, kind, kind.name, null)) return
598
- const what = { String: "string", Number: "number", Date: "date" }[kind.name]
599
- const exact = kind.name === "Date" ? "the clock's date, for example `clock.now()` of the `FakeClock` the spec provides" : "the id the `fakeIds()` double hands out"
600
- context.report({ node, messageId: "loose", data: { kind: kind.name, what, exact } })
649
+ const callee = node.callee;
650
+ if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier" || callee.property.name !== "any")
651
+ return;
652
+ if (!isAmbientOrImported(context, callee.object, "expect", "@jest/globals"))
653
+ return;
654
+ const kind = node.arguments[0];
655
+ if (kind?.type !== "Identifier" || !LOOSE_KINDS.has(kind.name) || !isAmbientOrImported(context, kind, kind.name, null))
656
+ return;
657
+ const whatOf = { String: "string", Number: "number", Date: "date" };
658
+ const what = whatOf[kind.name];
659
+ const exact = kind.name === "Date" ? "the clock's date, for example `clock.now()` of the `FakeClock` the spec provides" : "the id the `fakeIds()` double hands out";
660
+ context.report({ node, messageId: "loose", data: { kind: kind.name, what, exact } });
601
661
  },
602
- }
662
+ };
603
663
  },
604
- }
605
-
664
+ };
606
665
  // -- spec-behavior-assertion -----------------------------------------------------------------------------------
607
-
608
- const PRESENCE_MATCHERS = new Set(["toBeDefined", "toBeTruthy"])
609
-
666
+ const PRESENCE_MATCHERS = new Set(["toBeDefined", "toBeTruthy"]);
610
667
  /** The matcher in `expect(value).not.resolves.toEqual(...)`, or null for another receiver. */
611
668
  const matcherOf = (context, node) => {
612
- const callee = node.callee
613
- if (callee.type !== "MemberExpression") return null
614
- const matcher = callee.computed ? callee.property.value : callee.property.name
615
- if (typeof matcher !== "string" || !matcher.startsWith("to")) return null
616
- let receiver = callee.object
617
- while (receiver.type === "MemberExpression") receiver = receiver.object
618
- if (receiver.type !== "CallExpression") return null
619
- if (!isImportedFrom(context, receiver.callee, "@jest/globals", "expect") && !isAmbientOrImported(context, receiver.callee, "expect", "@jest/globals")) return null
620
- return matcher
621
- }
622
-
623
- const TEST_MODIFIERS = new Set(["only", "skip", "concurrent", "failing", "each"])
624
-
669
+ const callee = node.callee;
670
+ if (callee.type !== "MemberExpression")
671
+ return null;
672
+ const matcher = memberKeyValue(callee);
673
+ if (typeof matcher !== "string" || !matcher.startsWith("to"))
674
+ return null;
675
+ let receiver = callee.object;
676
+ while (receiver.type === "MemberExpression")
677
+ receiver = receiver.object;
678
+ if (receiver.type !== "CallExpression")
679
+ return null;
680
+ if (!isImportedFrom(context, receiver.callee, "@jest/globals", "expect") && !isAmbientOrImported(context, receiver.callee, "expect", "@jest/globals"))
681
+ return null;
682
+ return matcher;
683
+ };
684
+ const TEST_MODIFIERS = new Set(["only", "skip", "concurrent", "failing", "each"]);
625
685
  /** A Jest test registration, including modifiers and both forms of `each`. */
626
686
  const isTestFunction = (context, node) => {
627
- if (!node) return false
628
- if (isImportedFrom(context, node, "@jest/globals", ["it", "test"])) return true
629
- if (isAmbientOrImported(context, node, "it", "@jest/globals") || isAmbientOrImported(context, node, "test", "@jest/globals")) return true
630
- if (node.type === "MemberExpression" && TEST_MODIFIERS.has(keyName(node.property))) return isTestFunction(context, node.object)
631
- if (node.type === "CallExpression" && node.callee.type === "MemberExpression" && keyName(node.callee.property) === "each") return isTestFunction(context, node.callee.object)
632
- if (node.type === "TaggedTemplateExpression" && node.tag.type === "MemberExpression" && keyName(node.tag.property) === "each") return isTestFunction(context, node.tag.object)
633
- return false
634
- }
635
-
687
+ if (!node)
688
+ return false;
689
+ if (isImportedFrom(context, node, "@jest/globals", ["it", "test"]))
690
+ return true;
691
+ if (isAmbientOrImported(context, node, "it", "@jest/globals") || isAmbientOrImported(context, node, "test", "@jest/globals"))
692
+ return true;
693
+ if (node.type === "MemberExpression" && TEST_MODIFIERS.has(keyName(node.property)))
694
+ return isTestFunction(context, node.object);
695
+ if (node.type === "CallExpression" && node.callee.type === "MemberExpression" && keyName(node.callee.property) === "each")
696
+ return isTestFunction(context, node.callee.object);
697
+ if (node.type === "TaggedTemplateExpression" && node.tag.type === "MemberExpression" && keyName(node.tag.property) === "each")
698
+ return isTestFunction(context, node.tag.object);
699
+ return false;
700
+ };
636
701
  /** The local value an identifier binds, when it can name a callback or assertion helper. */
637
702
  const functionBinding = (context, node) => {
638
703
  for (let scope = context.sourceCode.getScope(node); scope; scope = scope.upper) {
639
- const variable = scope.set.get(node.name)
640
- if (!variable) continue
641
- const definition = variable.defs[0]
642
- if (definition?.type === "FunctionName") return definition.node
643
- if (definition?.type === "Variable") return definition.node.init
644
- return null
704
+ const variable = scope.set.get(node.name);
705
+ if (!variable)
706
+ continue;
707
+ const definition = variable.defs[0];
708
+ if (definition?.type === "FunctionName")
709
+ return definition.node;
710
+ if (definition?.type === "Variable")
711
+ return definition.node.init;
712
+ return null;
645
713
  }
646
- return null
647
- }
648
-
714
+ return null;
715
+ };
649
716
  /** An inline function or a locally bound function, following aliases without cycles. */
650
717
  const functionOf = (context, expression) => {
651
- let node = peel(expression)
652
- const seen = new Set()
718
+ let node = peel(expression);
719
+ const seen = new Set();
653
720
  while (node?.type === "Identifier") {
654
- if (seen.has(node)) return null
655
- seen.add(node)
656
- node = peel(functionBinding(context, node))
721
+ if (seen.has(node))
722
+ return null;
723
+ seen.add(node);
724
+ node = peel(functionBinding(context, node));
657
725
  }
658
- if (!node) return null
659
- return ["ArrowFunctionExpression", "FunctionExpression", "FunctionDeclaration"].includes(node.type) ? node : null
660
- }
661
-
726
+ if (!node)
727
+ return null;
728
+ return node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration" ? node : null;
729
+ };
662
730
  /** Assertions in the callback's executed syntax, including local helpers and passed callbacks. */
663
731
  const hasAssertion = (context, fn, seen = new Set()) => {
664
- if (seen.has(fn)) return false
665
- seen.add(fn)
666
- let found = false
732
+ if (seen.has(fn))
733
+ return false;
734
+ seen.add(fn);
735
+ let found = false;
667
736
  walk(fn.body, (node) => {
668
- if (found || node.type !== "CallExpression") return
737
+ if (found || node.type !== "CallExpression")
738
+ return;
669
739
  if (matcherOf(context, node) !== null) {
670
- found = true
671
- return
740
+ found = true;
741
+ return;
672
742
  }
673
- if (isTestFunction(context, node.callee)) return
674
- const functions = [node.callee, ...node.arguments].map((expression) => functionOf(context, expression)).filter(Boolean)
675
- found = functions.some((helper) => hasAssertion(context, helper, seen))
676
- }, { intoFunctions: false })
677
- return found
678
- }
679
-
743
+ if (isTestFunction(context, node.callee))
744
+ return;
745
+ const functions = [node.callee, ...node.arguments].map((expression) => functionOf(context, expression)).filter((helper) => Boolean(helper));
746
+ found = functions.some((helper) => hasAssertion(context, helper, seen));
747
+ }, { intoFunctions: false });
748
+ return found;
749
+ };
680
750
  /** Presence alone does not prove the behavior of a logic-role subject. */
681
751
  export const specBehaviorAssertion = {
682
752
  meta: {
@@ -689,27 +759,32 @@ export const specBehaviorAssertion = {
689
759
  },
690
760
  },
691
761
  create(context) {
692
- if (!isFormSpecFile(hfsOf(context), context.filename || context.getFilename())) return {}
693
- let firstPresence = null
694
- let behavior = false
762
+ if (!isFormSpecFile(hfsOf(context), context.filename || context.getFilename()))
763
+ return {};
764
+ let firstPresence = null;
765
+ let behavior = false;
695
766
  return {
696
767
  CallExpression(node) {
697
768
  if (isTestFunction(context, node.callee)) {
698
- const callback = functionOf(context, node.arguments[1])
699
- if (callback !== null && !hasAssertion(context, callback)) context.report({ node, messageId: "zeroAssertions" })
769
+ const callback = functionOf(context, node.arguments[1]);
770
+ if (callback !== null && !hasAssertion(context, callback))
771
+ context.report({ node, messageId: "zeroAssertions" });
700
772
  }
701
- const matcher = matcherOf(context, node)
702
- if (matcher === null) return
703
- if (PRESENCE_MATCHERS.has(matcher)) firstPresence ??= node
704
- else behavior = true
773
+ const matcher = matcherOf(context, node);
774
+ if (matcher === null)
775
+ return;
776
+ if (PRESENCE_MATCHERS.has(matcher))
777
+ firstPresence ??= node;
778
+ else
779
+ behavior = true;
705
780
  },
706
781
  "Program:exit"() {
707
- if (firstPresence !== null && !behavior) context.report({ node: firstPresence, messageId: "presenceOnly" })
782
+ if (firstPresence !== null && !behavior)
783
+ context.report({ node: firstPresence, messageId: "presenceOnly" });
708
784
  },
709
- }
785
+ };
710
786
  },
711
- }
712
-
787
+ };
713
788
  /** The rules this law contributes to the plugin. */
714
789
  export const rules = {
715
790
  "spec-builds-with-testing-module": specBuildsWithTestingModule,
@@ -720,8 +795,7 @@ export const rules = {
720
795
  "spec-infra-double-from-kit": specInfraDoubleFromKit,
721
796
  "spec-exact-values": specExactValues,
722
797
  "spec-behavior-assertion": specBehaviorAssertion,
723
- }
724
-
798
+ };
725
799
  /** Every rule of this law ships at `error`. */
726
800
  export const recommended = {
727
801
  "starci-be/spec-builds-with-testing-module": "error",
@@ -732,4 +806,4 @@ export const recommended = {
732
806
  "starci-be/spec-infra-double-from-kit": "error",
733
807
  "starci-be/spec-exact-values": "error",
734
808
  "starci-be/spec-behavior-assertion": "error",
735
- }
809
+ };