@starci/eslint-canon-be 3.5.0 → 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 (195) hide show
  1. package/CHANGELOG.md +15 -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 +17 -10
  177. package/async-discipline.mjs +0 -83
  178. package/comments.mjs +0 -416
  179. package/edge-hardening.mjs +0 -139
  180. package/health-ready.mjs +0 -539
  181. package/jwt-alg.mjs +0 -45
  182. package/lib/ast.mjs +0 -88
  183. package/lib/import-source.mjs +0 -104
  184. package/lib/specifier.mjs +0 -27
  185. package/lib/subject-values.mjs +0 -55
  186. package/lib/types.mjs +0 -133
  187. package/log-safety.mjs +0 -303
  188. package/module-layering.mjs +0 -270
  189. package/naming.mjs +0 -251
  190. package/observability.mjs +0 -241
  191. package/resilience.mjs +0 -304
  192. package/service-isolation.mjs +0 -75
  193. package/spec-no-skip.mjs +0 -85
  194. package/testing.mjs +0 -384
  195. package/type-safety.mjs +0 -323
@@ -15,22 +15,17 @@
15
15
  * A receiver is recognised by its TYPE, an entity by its declaration (a class decorated with typeorm's `@Entity`), a builder file by
16
16
  * its slot; nothing is matched by a name.
17
17
  */
18
- import { basename } from "node:path"
19
- import ts from "typescript"
20
- import { INSERTING_SQL, isDatabaseReceiver, methodOf, queryText, WRITING_SQL } from "./lib/db-writes.mjs"
21
- import { hfsOf } from "./lib/hfs.mjs"
22
- import { moduleOf, typed } from "./lib/types.mjs"
23
-
18
+ import { basename } from "node:path";
19
+ import ts from "typescript";
20
+ import { INSERTING_SQL, isDatabaseReceiver, methodOf, queryText, WRITING_SQL } from "./lib/db-writes.js";
21
+ import { hfsOf } from "./lib/hfs.js";
22
+ import { moduleOf, resolvedSymbol, typed } from "./lib/types.js";
24
23
  /** The file name of a linted path, in forward-slash form. */
25
- const baseOf = (filename) => basename(String(filename || "").replace(/\\/g, "/"))
26
-
24
+ const baseOf = (filename) => basename(String(filename || "").replace(/\\/g, "/"));
27
25
  // -- spec-no-raw-insert ----------------------------------------------------------------------------
28
-
29
- const WRITE_METHODS = new Set(["save", "insert", "upsert", "update", "delete", "remove", "softDelete", "softRemove", "recover", "restore"])
30
-
26
+ const WRITE_METHODS = new Set(["save", "insert", "upsert", "update", "delete", "remove", "softDelete", "softRemove", "recover", "restore"]);
31
27
  /** A unit service spec, an integration spec or an e2e spec. */
32
- const isSpecName = (name) => /\.(?:spec|integration-spec|e2e-spec)\.[cm]?ts$/.test(name)
33
-
28
+ const isSpecName = (name) => /\.(?:spec|integration-spec|e2e-spec)\.[cm]?ts$/.test(name);
34
29
  /** A spec arranges rows through a builder, never by writing them itself. */
35
30
  export const specNoRawInsert = {
36
31
  meta: {
@@ -43,48 +38,52 @@ export const specNoRawInsert = {
43
38
  },
44
39
  },
45
40
  create(context) {
46
- if (!isSpecName(baseOf(context.filename || context.getFilename()))) return {}
47
- const sourceCode = context.sourceCode || context.getSourceCode()
41
+ if (!isSpecName(baseOf(context.filename || context.getFilename())))
42
+ return {};
43
+ const sourceCode = context.sourceCode || context.getSourceCode();
48
44
  return {
49
45
  CallExpression(node) {
50
- const callee = node.callee
51
- if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier") return
52
- const method = callee.property.name
53
- if (!WRITE_METHODS.has(method) && method !== "query") return
54
- if (!isDatabaseReceiver(context, callee.object)) return
46
+ const callee = node.callee;
47
+ if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
48
+ return;
49
+ const method = callee.property.name;
50
+ if (!WRITE_METHODS.has(method) && method !== "query")
51
+ return;
52
+ if (!isDatabaseReceiver(context, callee.object))
53
+ return;
55
54
  if (method === "query") {
56
- const text = queryText(node.arguments[0], sourceCode.getScope(node))
57
- if (text !== null && WRITING_SQL.test(text)) context.report({ node, messageId: "sql" })
58
- return
55
+ const text = queryText(node.arguments[0], sourceCode.getScope(node));
56
+ if (text !== null && WRITING_SQL.test(text))
57
+ context.report({ node, messageId: "sql" });
58
+ return;
59
59
  }
60
- context.report({ node, messageId: "write", data: { method } })
60
+ context.report({ node, messageId: "write", data: { method } });
61
61
  },
62
- }
62
+ };
63
63
  },
64
- }
65
-
64
+ };
66
65
  // -- spec-no-repeated-row-literal ------------------------------------------------------------------
67
-
68
66
  /** True when a class declaration carries typeorm's `@Entity(...)`, resolved by where the decorator is declared. */
69
67
  const isEntityClass = (checker, declaration) => {
70
- if (!ts.isClassDeclaration(declaration)) return false
68
+ if (!ts.isClassDeclaration(declaration))
69
+ return false;
71
70
  return (ts.getDecorators(declaration) ?? []).some((decorator) => {
72
- const callee = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression
73
- const symbol = checker.getSymbolAtLocation(callee)
74
- if (!symbol) return false
75
- const target = ts.skipAlias(symbol, checker)
76
- return (target.getDeclarations?.() ?? []).some((found) => moduleOf(found, String(found.getSourceFile().fileName).replace(/\\/g, "/")) === "typeorm")
77
- })
78
- }
79
-
71
+ const callee = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
72
+ const symbol = checker.getSymbolAtLocation(callee);
73
+ if (!symbol)
74
+ return false;
75
+ const target = resolvedSymbol(checker, symbol);
76
+ return (target?.getDeclarations?.() ?? []).some((found) => moduleOf(found, String(found.getSourceFile().fileName).replace(/\\/g, "/")) === "typeorm");
77
+ });
78
+ };
80
79
  /** The entity class declarations a type stands for: itself, a union member, or the argument of a `Partial<Entity>` style alias. */
81
80
  const entityClassesOf = (checker, type) => {
82
- if (!type) return []
83
- const parts = type.isUnion?.() ? type.types : [type]
84
- const candidates = parts.flatMap((part) => [part, ...(part.aliasTypeArguments ?? [])])
85
- return candidates.flatMap((candidate) => (candidate.getSymbol?.()?.getDeclarations?.() ?? []).filter((declaration) => isEntityClass(checker, declaration)))
86
- }
87
-
81
+ if (!type)
82
+ return [];
83
+ const parts = type.isUnion?.() ? type.types : [type];
84
+ const candidates = parts.flatMap((part) => [part, ...(part.aliasTypeArguments ?? [])]);
85
+ return candidates.flatMap((candidate) => (candidate.getSymbol?.()?.getDeclarations?.() ?? []).filter((declaration) => isEntityClass(checker, declaration)));
86
+ };
88
87
  /** A spec builds each persistence entity as an object literal at most once; further rows come from a builder. */
89
88
  export const specNoRepeatedRowLiteral = {
90
89
  meta: {
@@ -96,48 +95,50 @@ export const specNoRepeatedRowLiteral = {
96
95
  },
97
96
  },
98
97
  create(context) {
99
- if (!isSpecName(baseOf(context.filename || context.getFilename()))) return {}
100
- const { checker, toTs } = typed(context)
101
- const firstLine = new Map()
98
+ if (!isSpecName(baseOf(context.filename || context.getFilename())))
99
+ return {};
100
+ const { checker, toTs } = typed(context);
101
+ const firstLine = new Map();
102
102
  return {
103
103
  ObjectExpression(node) {
104
- if (node.properties.length === 0 || node.properties.some((property) => property.type === "SpreadElement")) return
105
- const tsNode = toTs(node)
106
- const [entity] = entityClassesOf(checker, tsNode && checker.getContextualType(tsNode))
107
- if (!entity) return
108
- const seen = firstLine.get(entity)
109
- if (seen === undefined) firstLine.set(entity, node.loc.start.line)
110
- else context.report({ node, messageId: "repeated", data: { entity: entity.name?.text ?? "entity", line: String(seen) } })
104
+ if (node.properties.length === 0 || node.properties.some((property) => property.type === "SpreadElement"))
105
+ return;
106
+ const tsNode = toTs(node);
107
+ const [entity] = entityClassesOf(checker, tsNode && checker.getContextualType(tsNode));
108
+ if (!entity)
109
+ return;
110
+ const seen = firstLine.get(entity);
111
+ if (seen === undefined)
112
+ firstLine.set(entity, node.loc.start.line);
113
+ else
114
+ context.report({ node, messageId: "repeated", data: { entity: entity.name?.text ?? "entity", line: String(seen) } });
111
115
  },
112
- }
116
+ };
113
117
  },
114
- }
115
-
118
+ };
116
119
  // -- persisting-builder-in-builders-slot -----------------------------------------------------------
117
-
118
- const BUILDERS = "be.tests.fixtures.builders"
120
+ const BUILDERS = "be.tests.fixtures.builders";
119
121
  /** The spec slots of the test tree; a spec is judged by the spec rules, not as a builder. */
120
- const SPEC_SLOTS = new Set(["be.tests.integration", "be.tests.e2e", "be.tests.contract"])
121
- const CREATING_METHODS = new Set(["save", "insert", "upsert"])
122
-
122
+ const SPEC_SLOTS = new Set(["be.tests.integration", "be.tests.e2e", "be.tests.contract"]);
123
+ const CREATING_METHODS = new Set(["save", "insert", "upsert"]);
123
124
  /** A file of the test tree that is not a spec and is not the builders slot. */
124
- const isTestSupport = (slot) => typeof slot === "string" && slot.startsWith("be.tests.") && slot !== BUILDERS && !SPEC_SLOTS.has(slot)
125
-
125
+ const isTestSupport = (slot) => typeof slot === "string" && slot.startsWith("be.tests.") && slot !== BUILDERS && !SPEC_SLOTS.has(slot);
126
126
  /** The top-level statement that holds a node. */
127
127
  const topStatementOf = (node) => {
128
- let current = node
129
- while (current.parent && current.parent.type !== "Program") current = current.parent
130
- return current
131
- }
132
-
128
+ let current = node;
129
+ while (current.parent && current.parent.type !== "Program")
130
+ current = current.parent;
131
+ return current;
132
+ };
133
133
  /** The names a top-level statement declares. */
134
134
  const declaredNames = (statement) => {
135
- const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement
136
- if (!declaration) return []
137
- if (declaration.type === "VariableDeclaration") return declaration.declarations.flatMap((entry) => (entry.id.type === "Identifier" ? [entry.id.name] : []))
138
- return declaration.id ? [declaration.id.name] : []
139
- }
140
-
135
+ const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
136
+ if (!declaration)
137
+ return [];
138
+ if (declaration.type === "VariableDeclaration")
139
+ return declaration.declarations.flatMap((entry) => (entry.id.type === "Identifier" ? [entry.id.name] : []));
140
+ return "id" in declaration && declaration.id && declaration.id.type === "Identifier" ? [declaration.id.name] : [];
141
+ };
141
142
  /** A module of the test tree that exports something creating persisted rows is a builder and lives in the builders slot. */
142
143
  export const persistingBuilderInBuildersSlot = {
143
144
  meta: {
@@ -149,45 +150,52 @@ export const persistingBuilderInBuildersSlot = {
149
150
  },
150
151
  },
151
152
  create(context) {
152
- if (!isTestSupport(hfsOf(context).slotOf(context.filename || context.getFilename()))) return {}
153
- const sourceCode = context.sourceCode || context.getSourceCode()
154
- const writes = new Set()
155
- const references = new Map()
153
+ if (!isTestSupport(hfsOf(context).slotOf(context.filename || context.getFilename())))
154
+ return {};
155
+ const sourceCode = context.sourceCode || context.getSourceCode();
156
+ const writes = new Set();
157
+ const references = new Map();
156
158
  const isCreation = (node) => {
157
- const method = methodOf(node)
158
- if (!method || !isDatabaseReceiver(context, node.callee.object)) return false
159
- if (CREATING_METHODS.has(method)) return true
160
- return method === "query" && INSERTING_SQL.test(queryText(node.arguments[0], sourceCode.getScope(node)) ?? "")
161
- }
159
+ const method = methodOf(node);
160
+ if (!method || node.callee.type !== "MemberExpression" || !isDatabaseReceiver(context, node.callee.object))
161
+ return false;
162
+ if (CREATING_METHODS.has(method))
163
+ return true;
164
+ return method === "query" && INSERTING_SQL.test(queryText(node.arguments[0], sourceCode.getScope(node)) ?? "");
165
+ };
162
166
  return {
163
167
  CallExpression(node) {
164
- if (isCreation(node)) writes.add(topStatementOf(node))
168
+ if (isCreation(node))
169
+ writes.add(topStatementOf(node));
165
170
  },
166
171
  Identifier(node) {
167
- const statement = topStatementOf(node)
168
- if (!references.has(statement)) references.set(statement, new Set())
169
- references.get(statement).add(node.name)
172
+ const statement = topStatementOf(node);
173
+ let names = references.get(statement);
174
+ if (!names) {
175
+ names = new Set();
176
+ references.set(statement, names);
177
+ }
178
+ names.add(node.name);
170
179
  },
171
180
  "Program:exit"(program) {
172
- const exported = new Set(program.body.flatMap((statement) => (statement.type === "ExportNamedDeclaration" && !statement.declaration && !statement.source ? statement.specifiers.map((specifier) => specifier.local.name) : [])))
173
- const writerNames = new Set(program.body.filter((statement) => writes.has(statement)).flatMap(declaredNames))
181
+ const exported = new Set(program.body.flatMap((statement) => (statement.type === "ExportNamedDeclaration" && !statement.declaration && !statement.source ? statement.specifiers.map((specifier) => specifier.local.name) : [])));
182
+ const writerNames = new Set(program.body.filter((statement) => writes.has(statement)).flatMap(declaredNames));
174
183
  for (const statement of program.body) {
175
- const isExported = statement.type === "ExportNamedDeclaration" ? Boolean(statement.declaration) : declaredNames(statement).some((name) => exported.has(name))
176
- if (!isExported) continue
177
- const uses = references.get(statement) ?? new Set()
178
- if (!writes.has(statement) && ![...uses].some((name) => writerNames.has(name))) continue
179
- context.report({ node: statement, messageId: "misplaced", data: { name: declaredNames(statement)[0] ?? "This export" } })
184
+ const isExported = statement.type === "ExportNamedDeclaration" ? Boolean(statement.declaration) : declaredNames(statement).some((name) => exported.has(name));
185
+ if (!isExported)
186
+ continue;
187
+ const uses = references.get(statement) ?? new Set();
188
+ if (!writes.has(statement) && ![...uses].some((name) => writerNames.has(name)))
189
+ continue;
190
+ context.report({ node: statement, messageId: "misplaced", data: { name: declaredNames(statement)[0] ?? "This export" } });
180
191
  }
181
192
  },
182
- }
193
+ };
183
194
  },
184
- }
185
-
195
+ };
186
196
  // -- builder-arranges-only -------------------------------------------------------------------------
187
-
188
- const JEST_GLOBALS = new Set(["expect", "jest", "describe", "it", "test", "beforeAll", "beforeEach", "afterAll", "afterEach", "fail"])
189
- const RANDOM_FUNCTIONS = new Set(["randomUUID", "randomBytes", "randomInt", "randomFillSync", "randomFill", "getRandomValues"])
190
-
197
+ const JEST_GLOBALS = new Set(["expect", "jest", "describe", "it", "test", "beforeAll", "beforeEach", "afterAll", "afterEach", "fail"]);
198
+ const RANDOM_FUNCTIONS = new Set(["randomUUID", "randomBytes", "randomInt", "randomFillSync", "randomFill", "getRandomValues"]);
191
199
  /** A builder arranges data only: no assertion, deterministic defaults. */
192
200
  export const builderArrangesOnly = {
193
201
  meta: {
@@ -200,48 +208,53 @@ export const builderArrangesOnly = {
200
208
  },
201
209
  },
202
210
  create(context) {
203
- if (hfsOf(context).slotOf(context.filename || context.getFilename()) !== BUILDERS) return {}
204
- const sourceCode = context.sourceCode || context.getSourceCode()
211
+ if (hfsOf(context).slotOf(context.filename || context.getFilename()) !== BUILDERS)
212
+ return {};
213
+ const sourceCode = context.sourceCode || context.getSourceCode();
205
214
  /** True when the identifier is not declared in the file (a framework global, not a local named `test`). */
206
215
  const isGlobal = (node) => {
207
216
  for (let scope = sourceCode.getScope(node); scope; scope = scope.upper) {
208
- const variable = scope.set.get(node.name)
209
- if (variable) return variable.defs.length === 0
217
+ const variable = scope.set.get(node.name);
218
+ if (variable)
219
+ return variable.defs.length === 0;
210
220
  }
211
- return true
212
- }
221
+ return true;
222
+ };
213
223
  return {
214
224
  ImportDeclaration(node) {
215
- if (["expect", "@jest/globals"].includes(node.source.value)) context.report({ node, messageId: "assertion", data: { name: node.source.value } })
225
+ if (["expect", "@jest/globals"].includes(node.source.value))
226
+ context.report({ node, messageId: "assertion", data: { name: node.source.value } });
216
227
  },
217
228
  Identifier(node) {
218
- const parent = node.parent
219
- const used = (parent.type === "CallExpression" && parent.callee === node) || (parent.type === "MemberExpression" && parent.object === node)
220
- if (used && JEST_GLOBALS.has(node.name) && isGlobal(node)) context.report({ node, messageId: "assertion", data: { name: node.name } })
229
+ const parent = node.parent;
230
+ const used = (parent.type === "CallExpression" && parent.callee === node) || (parent.type === "MemberExpression" && parent.object === node);
231
+ if (used && JEST_GLOBALS.has(node.name) && isGlobal(node))
232
+ context.report({ node, messageId: "assertion", data: { name: node.name } });
221
233
  },
222
234
  CallExpression(node) {
223
- const callee = node.callee
235
+ const callee = node.callee;
224
236
  if (callee.type === "Identifier" && RANDOM_FUNCTIONS.has(callee.name)) {
225
- context.report({ node, messageId: "random", data: { name: `${callee.name}()` } })
226
- return
237
+ context.report({ node, messageId: "random", data: { name: `${callee.name}()` } });
238
+ return;
227
239
  }
228
- if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier" || callee.object.type !== "Identifier") return
229
- const owner = callee.object.name
230
- const method = callee.property.name
231
- const clock = owner === "Date" && method === "now"
232
- const dice = owner === "Math" && method === "random"
233
- const crypto = RANDOM_FUNCTIONS.has(method) || (/^(?:crypto|webcrypto)$/.test(owner) && method.startsWith("random"))
234
- if (clock || dice || crypto) context.report({ node, messageId: "random", data: { name: `${owner}.${method}()` } })
240
+ if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier" || callee.object.type !== "Identifier")
241
+ return;
242
+ const owner = callee.object.name;
243
+ const method = callee.property.name;
244
+ const clock = owner === "Date" && method === "now";
245
+ const dice = owner === "Math" && method === "random";
246
+ const crypto = RANDOM_FUNCTIONS.has(method) || (/^(?:crypto|webcrypto)$/.test(owner) && method.startsWith("random"));
247
+ if (clock || dice || crypto)
248
+ context.report({ node, messageId: "random", data: { name: `${owner}.${method}()` } });
235
249
  },
236
250
  NewExpression(node) {
237
- if (node.callee.type === "Identifier" && node.callee.name === "Date" && node.arguments.length === 0) context.report({ node, messageId: "random", data: { name: "new Date()" } })
251
+ if (node.callee.type === "Identifier" && node.callee.name === "Date" && node.arguments.length === 0)
252
+ context.report({ node, messageId: "random", data: { name: "new Date()" } });
238
253
  },
239
- }
254
+ };
240
255
  },
241
- }
242
-
256
+ };
243
257
  // -- tests-keep-constraints ------------------------------------------------------------------------
244
-
245
258
  const CONSTRAINT_SQL = [
246
259
  /session_replication_role/i,
247
260
  /\bDISABLE\s+TRIGGER\b/i,
@@ -250,9 +263,8 @@ const CONSTRAINT_SQL = [
250
263
  /\bSET\s+CONSTRAINTS\b[\s\S]*\bDEFERRED\b/i,
251
264
  /\bALTER\s+TABLE\b[\s\S]*\bDISABLE\b/i,
252
265
  /\bDROP\s+CONSTRAINT\b/i,
253
- ]
254
- const CONSTRAINT_METHODS = new Set(["dropForeignKey", "dropForeignKeys", "dropCheckConstraint", "dropCheckConstraints", "dropUniqueConstraint", "dropUniqueConstraints"])
255
-
266
+ ];
267
+ const CONSTRAINT_METHODS = new Set(["dropForeignKey", "dropForeignKeys", "dropCheckConstraint", "dropCheckConstraints", "dropUniqueConstraint", "dropUniqueConstraints"]);
256
268
  /** The test tree keeps every database constraint on. */
257
269
  export const testsKeepConstraints = {
258
270
  meta: {
@@ -265,27 +277,32 @@ export const testsKeepConstraints = {
265
277
  },
266
278
  },
267
279
  create(context) {
268
- const slot = hfsOf(context).slotOf(context.filename || context.getFilename())
269
- if (typeof slot !== "string" || !slot.startsWith("be.tests.")) return {}
270
- const sourceCode = context.sourceCode || context.getSourceCode()
280
+ const slot = hfsOf(context).slotOf(context.filename || context.getFilename());
281
+ if (typeof slot !== "string" || !slot.startsWith("be.tests."))
282
+ return {};
283
+ const sourceCode = context.sourceCode || context.getSourceCode();
271
284
  const check = (node, text) => {
272
- const found = CONSTRAINT_SQL.find((pattern) => pattern.test(text ?? ""))
273
- if (found) context.report({ node, messageId: "sql", data: { what: text.match(found)[0] } })
274
- }
285
+ const found = CONSTRAINT_SQL.find((pattern) => pattern.test(text ?? ""));
286
+ const what = found ? text?.match(found) : null;
287
+ if (found && what)
288
+ context.report({ node, messageId: "sql", data: { what: what[0] } });
289
+ };
275
290
  return {
276
291
  CallExpression(node) {
277
- const method = methodOf(node)
278
- if (!method || !isDatabaseReceiver(context, node.callee.object)) return
279
- if (method === "query") check(node, queryText(node.arguments[0], sourceCode.getScope(node)))
280
- else if (CONSTRAINT_METHODS.has(method)) context.report({ node, messageId: "method", data: { method } })
292
+ const method = methodOf(node);
293
+ if (!method || node.callee.type !== "MemberExpression" || !isDatabaseReceiver(context, node.callee.object))
294
+ return;
295
+ if (method === "query")
296
+ check(node, queryText(node.arguments[0], sourceCode.getScope(node)));
297
+ else if (CONSTRAINT_METHODS.has(method))
298
+ context.report({ node, messageId: "method", data: { method } });
281
299
  },
282
300
  TaggedTemplateExpression(node) {
283
- check(node, queryText(node, null))
301
+ check(node, queryText(node, null));
284
302
  },
285
- }
303
+ };
286
304
  },
287
- }
288
-
305
+ };
289
306
  /** The rules this law contributes to the plugin. */
290
307
  export const rules = {
291
308
  "persisting-builder-in-builders-slot": persistingBuilderInBuildersSlot,
@@ -293,8 +310,7 @@ export const rules = {
293
310
  "spec-no-repeated-row-literal": specNoRepeatedRowLiteral,
294
311
  "builder-arranges-only": builderArrangesOnly,
295
312
  "tests-keep-constraints": testsKeepConstraints,
296
- }
297
-
313
+ };
298
314
  /** Every rule of this law ships at `error`. */
299
315
  export const recommended = {
300
316
  "starci-be/persisting-builder-in-builders-slot": "error",
@@ -302,4 +318,4 @@ export const recommended = {
302
318
  "starci-be/spec-no-repeated-row-literal": "error",
303
319
  "starci-be/builder-arranges-only": "error",
304
320
  "starci-be/tests-keep-constraints": "error",
305
- }
321
+ };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type { Recommended, RuleModule } from "./lib/rule.js";
2
+ /** The cli app boots with CommandFactory.run and never serves HTTP or a microservice. */
3
+ export declare const cliBootstrap: RuleModule;
4
+ /** A nest-commander command is declared only where the cli feature root keeps it, one per file, a sub-command a CommandRunner. */
5
+ export declare const cliCommandShape: RuleModule;
6
+ /** nest-commander belongs to the cli app and the cli feature root; nothing else parses arguments or opens an action door. */
7
+ export declare const cliOwner: RuleModule;
8
+ /** The rules this law contributes to the plugin. */
9
+ export declare const rules: {
10
+ "cli-bootstrap": RuleModule;
11
+ "cli-command-shape": RuleModule;
12
+ "cli-owner": RuleModule;
13
+ };
14
+ /** Every rule is an error from the start: HFS keeps no baseline. */
15
+ export declare const recommended: Recommended;