@starci/eslint-canon-be 3.8.20 → 3.9.2

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 (164) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/runtime/bundle.json +192 -0
  4. package/runtime/engine/by-code-unit.mjs +6 -6
  5. package/runtime/engine/model-config.mjs +98 -76
  6. package/runtime/engine/orca-config.mjs +22 -17
  7. package/runtime/engine/release-config.mjs +22 -18
  8. package/runtime/engine/removed-vocabulary.mjs +21 -20
  9. package/runtime/engine/resources-config.mjs +42 -35
  10. package/runtime/engine/runtime-root.mjs +11 -13
  11. package/runtime/engine/secrets.mjs +170 -102
  12. package/runtime/engine/sonar-config.mjs +16 -13
  13. package/runtime/engine/temp-root.mjs +3 -9
  14. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  15. package/runtime/knowledge/hfs/rules.yaml +6 -6
  16. package/runtime/knowledge/hfs/slots.yaml +2 -2
  17. package/runtime/knowledge/sonar-gate.yaml +1 -1
  18. package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
  19. package/runtime/scripts/api/git/cat-file.mjs +0 -1
  20. package/runtime/scripts/api/git/config-get.mjs +1 -2
  21. package/runtime/scripts/api/git/diff.mjs +0 -1
  22. package/runtime/scripts/api/git/lib.mjs +32 -32
  23. package/runtime/scripts/api/git/ls-files.mjs +0 -1
  24. package/runtime/scripts/api/git/ls-tree.mjs +0 -1
  25. package/runtime/scripts/api/git/merge-base.mjs +2 -3
  26. package/runtime/scripts/api/git/remote.mjs +0 -1
  27. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
  28. package/runtime/scripts/api/git/show.mjs +0 -1
  29. package/runtime/scripts/hfs/allows.mjs +37 -38
  30. package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
  31. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
  32. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
  33. package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
  34. package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
  35. package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
  36. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
  37. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
  38. package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
  39. package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
  40. package/runtime/scripts/hfs/architecture/config.mjs +302 -268
  41. package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
  42. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
  43. package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
  44. package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
  45. package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
  46. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
  47. package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
  48. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
  49. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
  50. package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
  51. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
  52. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
  53. package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
  54. package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
  55. package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
  56. package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
  57. package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
  58. package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
  59. package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
  60. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
  61. package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
  62. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
  63. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
  64. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
  65. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
  66. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
  67. package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
  68. package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
  69. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
  70. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
  71. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
  72. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
  73. package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
  74. package/runtime/scripts/hfs/architecture/index.mjs +272 -272
  75. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
  76. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
  77. package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
  78. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
  79. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
  80. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
  81. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
  82. package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
  83. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
  84. package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
  85. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
  86. package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
  87. package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
  88. package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
  89. package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
  90. package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
  91. package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
  92. package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
  93. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
  94. package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
  95. package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
  96. package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
  97. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
  98. package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
  99. package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
  100. package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
  101. package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
  102. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
  103. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
  104. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
  105. package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
  106. package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
  107. package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
  108. package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
  109. package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
  110. package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
  111. package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
  112. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
  113. package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
  114. package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
  115. package/runtime/scripts/hfs/edition-slots.mjs +43 -40
  116. package/runtime/scripts/hfs/linear-text.mjs +20 -20
  117. package/runtime/scripts/hfs/param-names.mjs +6 -11
  118. package/runtime/scripts/hfs/path-findings.mjs +120 -100
  119. package/runtime/scripts/hfs/repo-identity.mjs +55 -42
  120. package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
  121. package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
  122. package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
  123. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
  124. package/runtime/scripts/hfs/rules/read.mjs +19 -15
  125. package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
  126. package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
  127. package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
  128. package/runtime/scripts/hfs/slot-classify.mjs +42 -38
  129. package/runtime/scripts/hfs/slot-errors.mjs +8 -7
  130. package/runtime/scripts/hfs/slot-imports.mjs +70 -63
  131. package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
  132. package/runtime/scripts/hfs/slot-match.mjs +122 -111
  133. package/runtime/scripts/hfs/slot-path.mjs +0 -2
  134. package/runtime/scripts/hfs/slot-required.mjs +65 -59
  135. package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
  136. package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
  137. package/runtime/scripts/hfs/slots.mjs +175 -152
  138. package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
  139. package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
  140. package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
  141. package/runtime/scripts/hfs/view.mjs +38 -40
  142. package/runtime/scripts/lib/dockerfile.mjs +131 -114
  143. package/runtime/scripts/lib/env.mjs +3 -6
  144. package/runtime/scripts/lib/event-contract.mjs +73 -78
  145. package/runtime/scripts/lib/git.mjs +15 -16
  146. package/runtime/scripts/lib/glob.mjs +23 -14
  147. package/runtime/scripts/lib/grammar-lint.mjs +33 -37
  148. package/runtime/scripts/lib/i18n.mjs +32 -35
  149. package/runtime/scripts/lib/in-order.mjs +57 -38
  150. package/runtime/scripts/lib/json-clone.mjs +45 -36
  151. package/runtime/scripts/lib/json.mjs +26 -14
  152. package/runtime/scripts/lib/language.mjs +133 -129
  153. package/runtime/scripts/lib/list.mjs +9 -14
  154. package/runtime/scripts/lib/mutation-fence.mjs +10 -5
  155. package/runtime/scripts/lib/path-key.mjs +53 -38
  156. package/runtime/scripts/lib/read-text.mjs +30 -17
  157. package/runtime/scripts/lib/regex.mjs +1 -2
  158. package/runtime/scripts/lib/same-text.mjs +0 -1
  159. package/runtime/scripts/lib/sops-envelope.mjs +148 -120
  160. package/runtime/scripts/lib/stack-services.mjs +128 -129
  161. package/runtime/scripts/lib/ts-analysis.mjs +28 -26
  162. package/runtime/scripts/lib/ts-ast.mjs +36 -42
  163. package/runtime/scripts/lib/walk.mjs +33 -27
  164. package/runtime/scripts/lib/yaml-cached.mjs +4 -4
@@ -1,5 +1,4 @@
1
1
  import { machineKit } from './machine-ast.mjs';
2
-
3
2
  /**
4
3
  * R41 `default-deny-app-guard` (BE_DEFAULT_DENY). Every api app root provides its `APP_GUARD` entries in the order
5
4
  * throttler -> CSRF origin guard -> CredentialGuard -> AuthGuard, each exactly once, so no request reaches a handler before it was
@@ -13,144 +12,164 @@ import { machineKit } from './machine-ast.mjs';
13
12
  * Other guards are permitted between them; a missing, repeated or reordered one of the three is a finding.
14
13
  */
15
14
  export const DEFAULT_DENY_RULE_IDS = ['BE_DEFAULT_DENY'];
16
-
17
15
  const RULE = 'BE_DEFAULT_DENY';
18
16
  const ORDER = ['throttler', 'csrf', 'credential', 'auth'];
19
17
  const ORIGIN_HEADERS = new Set(['origin', 'referer', 'referrer']);
20
18
  const METADATA_READERS = new Set(['get', 'getAll', 'getAllAndMerge', 'getAllAndOverride']);
21
19
  const LABEL = { throttler: 'the throttler guard', csrf: 'the CSRF origin guard of platform/http-security', credential: 'CredentialGuard of domain/identity', auth: 'AuthGuard of domain/identity' };
22
-
23
20
  const keySymbol = (kit, checker, node) => (node ? kit.aliased(checker, kit.symbolAt(checker, node)) ?? null : null);
24
-
25
21
  const extendsThrottlerType = (kit, checker, declaration, type, depth) => {
26
- if (kit.isImportOf(checker, type.expression, 'ThrottlerGuard', '@nestjs/throttler')) return true;
27
- return kit.declarationsOf(checker, type.expression).some(parent => parent !== declaration && extendsThrottler(kit, parent, depth + 1));
22
+ if (kit.isImportOf(checker, type.expression, 'ThrottlerGuard', '@nestjs/throttler'))
23
+ return true;
24
+ return kit.declarationsOf(checker, type.expression).some(parent => parent !== declaration && extendsThrottler(kit, parent, depth + 1));
28
25
  };
29
-
30
26
  function extendsThrottler(kit, declaration, depth = 0) {
31
- if (!kit.ts.isClassDeclaration(declaration) || depth > 8) return false;
32
- const checker = kit.checkerOf(declaration.getSourceFile());
33
- if (!checker) return false;
34
- const types = (declaration.heritageClauses ?? []).flatMap(clause => [...clause.types]);
35
- return types.some(type => extendsThrottlerType(kit, checker, declaration, type, depth));
27
+ const ts = kit.ts;
28
+ if (!ts.isClassDeclaration(declaration) || depth > 8)
29
+ return false;
30
+ const checker = kit.checkerOf(declaration.getSourceFile());
31
+ if (!checker)
32
+ return false;
33
+ const types = (declaration.heritageClauses ?? []).flatMap(clause => [...clause.types]);
34
+ return types.some(type => extendsThrottlerType(kit, checker, declaration, type, depth));
36
35
  }
37
-
38
36
  const collectSetMetadataKeys = (kit, file, keys) => {
39
- const { ts } = kit;
40
- const checker = kit.checkerOf(file.sourceFile);
41
- if (!checker) return;
42
- kit.walk(file.sourceFile, node => {
43
- if (ts.isCallExpression(node) && kit.isImportOf(checker, node.expression, 'SetMetadata', '@nestjs/common')) {
44
- const key = keySymbol(kit, checker, node.arguments[0]);
45
- if (key) keys.add(key);
46
- }
47
- return true;
48
- });
37
+ const { ts } = kit;
38
+ const checker = kit.checkerOf(file.sourceFile);
39
+ if (!checker)
40
+ return;
41
+ kit.walk(file.sourceFile, (node) => {
42
+ if (ts.isCallExpression(node) && kit.isImportOf(checker, node.expression, 'SetMetadata', '@nestjs/common')) {
43
+ const key = keySymbol(kit, checker, node.arguments[0]);
44
+ if (key)
45
+ keys.add(key);
46
+ }
47
+ return true;
48
+ });
49
49
  };
50
-
51
50
  /** The symbols a SetMetadata call of the owner writes as metadata keys: what its door decorators (`@RateLimit(tier)`) attach. */
52
51
  const writtenKeys = (kit, graph, owner, cache) => {
53
- if (cache.has(owner.root)) return cache.get(owner.root);
54
- const keys = new Set();
55
- for (const file of graph.files.values()) {
56
- if (file.owner?.root === owner.root) collectSetMetadataKeys(kit, file, keys);
57
- }
58
- cache.set(owner.root, keys);
59
- return keys;
52
+ const cached = cache.get(owner.root);
53
+ if (cached)
54
+ return cached;
55
+ const keys = new Set();
56
+ for (const file of graph.files.values()) {
57
+ if (file.owner?.root === owner.root)
58
+ collectSetMetadataKeys(kit, file, keys);
59
+ }
60
+ cache.set(owner.root, keys);
61
+ return keys;
60
62
  };
61
-
62
63
  /** True when the class reads a request origin or referer header (the origin/referer allowlist of the CSRF guard). */
63
64
  const readsOrigin = (kit, declaration) => {
64
- const { ts } = kit;
65
- let found = false;
66
- kit.walk(declaration, node => {
67
- let name = null;
68
- if (ts.isPropertyAccessExpression(node)) name = node.name.text;
69
- else if (ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression)) name = node.argumentExpression.text;
70
- if (name && ORIGIN_HEADERS.has(name.toLowerCase())) found = true;
71
- return !found;
72
- });
73
- return found;
65
+ const { ts } = kit;
66
+ let found = false;
67
+ kit.walk(declaration, (node) => {
68
+ let name = null;
69
+ if (ts.isPropertyAccessExpression(node))
70
+ name = node.name.text;
71
+ else if (ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression))
72
+ name = node.argumentExpression.text;
73
+ if (name && ORIGIN_HEADERS.has(name.toLowerCase()))
74
+ found = true;
75
+ return !found;
76
+ });
77
+ return found;
74
78
  };
75
-
76
79
  const isMetadataRead = (ts, node) => ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && METADATA_READERS.has(node.expression.name.text);
77
-
78
80
  /** True when the class reads, through a metadata getter, a key its own capability's SetMetadata decorators write. */
79
81
  const readsDoorMetadata = (kit, graph, keyCache, declaration, owner) => {
80
- const checker = kit.checkerOf(declaration.getSourceFile());
81
- if (!checker) return false;
82
- const keys = writtenKeys(kit, graph, owner, keyCache);
83
- let found = false;
84
- kit.walk(declaration, node => {
85
- if (isMetadataRead(kit.ts, node)) {
86
- const key = keySymbol(kit, checker, node.arguments[0]);
87
- if (key && keys.has(key)) found = true;
88
- }
89
- return !found;
90
- });
91
- return found;
82
+ const checker = kit.checkerOf(declaration.getSourceFile());
83
+ if (!checker)
84
+ return false;
85
+ const keys = writtenKeys(kit, graph, owner, keyCache);
86
+ let found = false;
87
+ kit.walk(declaration, (node) => {
88
+ if (isMetadataRead(kit.ts, node)) {
89
+ const key = keySymbol(kit, checker, node.arguments[0]);
90
+ if (key && keys.has(key))
91
+ found = true;
92
+ }
93
+ return !found;
94
+ });
95
+ return found;
92
96
  };
93
-
94
97
  const classifyDeclaration = (kit, graph, keyCache, declaration) => {
95
- const { ts } = kit;
96
- const owner = kit.ownerOfDeclaration(declaration);
97
- if (owner?.tier === 'platform' && owner.name === 'http-security' && ts.isClassDeclaration(declaration)) {
98
- if (readsOrigin(kit, declaration)) return 'csrf';
99
- if (readsDoorMetadata(kit, graph, keyCache, declaration, owner)) return 'throttler';
100
- }
101
- if (owner?.tier === 'domain' && owner.name === 'identity' && ts.isClassDeclaration(declaration) && declaration.name?.text === 'AuthGuard') return 'auth';
102
- if (owner?.tier === 'domain' && owner.name === 'identity' && ts.isClassDeclaration(declaration) && declaration.name?.text === 'CredentialGuard') return 'credential';
103
- return null;
98
+ const ts = kit.ts;
99
+ const owner = kit.ownerOfDeclaration(declaration);
100
+ if (owner?.tier === 'platform' && owner.name === 'http-security' && ts.isClassDeclaration(declaration)) {
101
+ if (readsOrigin(kit, declaration))
102
+ return 'csrf';
103
+ if (readsDoorMetadata(kit, graph, keyCache, declaration, owner))
104
+ return 'throttler';
105
+ }
106
+ if (owner?.tier === 'domain' && owner.name === 'identity' && ts.isClassDeclaration(declaration) && declaration.name?.text === 'AuthGuard')
107
+ return 'auth';
108
+ if (owner?.tier === 'domain' && owner.name === 'identity' && ts.isClassDeclaration(declaration) && declaration.name?.text === 'CredentialGuard')
109
+ return 'credential';
110
+ return null;
104
111
  };
105
-
106
112
  const classify = (kit, graph, keyCache, checker, node) => {
107
- if (!node) return null;
108
- if (kit.importBinding(checker, node)?.module === '@nestjs/throttler') return 'throttler';
109
- const declarations = kit.declarationsOf(checker, node);
110
- if (declarations.some(declaration => extendsThrottler(kit, declaration))) return 'throttler';
111
- for (const declaration of declarations) {
112
- const role = classifyDeclaration(kit, graph, keyCache, declaration);
113
- if (role) return role;
114
- }
115
- return null;
113
+ if (!node)
114
+ return null;
115
+ if (kit.importBinding(checker, node)?.module === '@nestjs/throttler')
116
+ return 'throttler';
117
+ const declarations = kit.declarationsOf(checker, node);
118
+ if (declarations.some(declaration => extendsThrottler(kit, declaration)))
119
+ return 'throttler';
120
+ for (const declaration of declarations) {
121
+ const role = classifyDeclaration(kit, graph, keyCache, declaration);
122
+ if (role)
123
+ return role;
124
+ }
125
+ return null;
116
126
  };
117
-
118
127
  const roleMessages = (app, roles, anchor) => {
119
- const out = [];
120
- for (const role of ORDER) {
121
- const entries = roles.filter(item => item.role === role);
122
- if (entries.length === 0) out.push({ node: anchor, message: `App ${app.name} does not provide ${LABEL[role]} as an APP_GUARD; an api app is denied by default: throttler, then CSRF origin guard, then CredentialGuard, then AuthGuard.` });
123
- else if (entries.length > 1) out.push({ node: entries[1].guard.node, message: `App ${app.name} provides ${LABEL[role]} more than once as an APP_GUARD.` });
124
- }
125
- return out;
128
+ const out = [];
129
+ for (const role of ORDER) {
130
+ const entries = roles.filter(item => item.role === role);
131
+ if (entries.length === 0)
132
+ out.push({ node: anchor, message: `App ${app.name} does not provide ${LABEL[role]} as an APP_GUARD; an api app is denied by default: throttler, then CSRF origin guard, then CredentialGuard, then AuthGuard.` });
133
+ else if (entries.length > 1 && entries[1])
134
+ out.push({ node: entries[1].guard.node, message: `App ${app.name} provides ${LABEL[role]} more than once as an APP_GUARD.` });
135
+ }
136
+ return out;
126
137
  };
127
-
128
138
  const orderMessages = (app, roles) => {
129
- const indexes = ORDER.map(role => roles.findIndex(item => item.role === role));
130
- if (!indexes.every(index => index >= 0)) return [];
131
- const out = [];
132
- for (let i = 1; i < indexes.length; i += 1) {
133
- if (indexes[i] < indexes[i - 1]) out.push({ node: roles[indexes[i]].guard.node, message: `App ${app.name} provides ${LABEL[ORDER[i]]} before ${LABEL[ORDER[i - 1]]}; the APP_GUARD order is throttler, CSRF origin guard, CredentialGuard, AuthGuard.` });
134
- }
135
- return out;
139
+ const indexes = ORDER.map(role => roles.findIndex(item => item.role === role));
140
+ if (!indexes.every(index => index >= 0))
141
+ return [];
142
+ const out = [];
143
+ for (let i = 1; i < indexes.length; i += 1) {
144
+ const index = indexes[i];
145
+ const previous = indexes[i - 1];
146
+ const role = ORDER[i];
147
+ const before = ORDER[i - 1];
148
+ const entry = index === undefined ? undefined : roles[index];
149
+ if (index === undefined || previous === undefined || role === undefined || before === undefined || entry === undefined)
150
+ continue;
151
+ if (index < previous)
152
+ out.push({ node: entry.guard.node, message: `App ${app.name} provides ${LABEL[role]} before ${LABEL[before]}; the APP_GUARD order is throttler, CSRF origin guard, CredentialGuard, AuthGuard.` });
153
+ }
154
+ return out;
136
155
  };
137
-
138
156
  export function checkDefaultDeny(input) {
139
- const { config } = input;
140
- const kit = machineKit(input);
141
- const violations = [];
142
- const keyCache = new Map();
143
- let apps = 0;
144
-
145
- for (const app of config.apps.filter(item => item.kind === 'api')) {
146
- const root = kit.appRoot(app.name);
147
- if (!root) continue;
148
- apps += 1;
149
- const guards = kit.providersOf(root, 'APP_GUARD', '@nestjs/core');
150
- const roles = guards.map(guard => ({ guard, role: classify(kit, input.graph, keyCache, guard.checker, guard.useClass) }));
151
- const anchor = guards[0]?.node ?? root.sourceFile.statements[0] ?? root.sourceFile;
152
- const messages = [...roleMessages(app, roles, anchor), ...orderMessages(app, roles)];
153
- for (const { node, message } of messages) violations.push({ ruleId: RULE, path: root.rel, ...kit.at(root.rel, root.sourceFile, node), app: app.name, message });
154
- }
155
- return { violations, coverage: { status: 'checked', apps } };
157
+ const { config } = input;
158
+ const kit = machineKit(input);
159
+ const violations = [];
160
+ const keyCache = new Map();
161
+ let apps = 0;
162
+ for (const app of config.apps.filter(item => item.kind === 'api')) {
163
+ const root = kit.appRoot(app.name);
164
+ if (!root)
165
+ continue;
166
+ apps += 1;
167
+ const guards = kit.providersOf(root, 'APP_GUARD', '@nestjs/core');
168
+ const roles = guards.map(guard => ({ guard, role: classify(kit, input.graph, keyCache, guard.checker, guard.useClass) }));
169
+ const anchor = guards[0]?.node ?? root.sourceFile.statements[0] ?? root.sourceFile;
170
+ const messages = [...roleMessages(app, roles, anchor), ...orderMessages(app, roles)];
171
+ for (const { node, message } of messages)
172
+ violations.push({ ruleId: RULE, path: root.rel, ...kit.at(root.rel, root.sourceFile, node), app: app.name, message });
173
+ }
174
+ return { violations, coverage: { status: 'checked', apps } };
156
175
  }
@@ -3,7 +3,6 @@ import path from 'node:path';
3
3
  import { treeOf } from './required-files.mjs';
4
4
  import { documentLanguageHits, isDocument, isLocalizedDataFile } from '../../lib/language.mjs';
5
5
  import { byCodeUnit } from '../../lib/list.mjs';
6
-
7
6
  /**
8
7
  * R96 `doc-language` (HFS_DOC_NOT_ENGLISH). Every Markdown and YAML document under knowledge/, docs/, src/ and apps/ is English:
9
8
  * prose, patterns and examples alike, and a code fence inside Markdown counts because an example is read exactly like the
@@ -14,27 +13,33 @@ import { byCodeUnit } from '../../lib/list.mjs';
14
13
  * inside a catalog slot is judged like any other document. No comment pragma, no path pattern.
15
14
  */
16
15
  export const DOC_LANGUAGE_RULE_IDS = ['HFS_DOC_NOT_ENGLISH'];
17
-
18
16
  const RULE = 'HFS_DOC_NOT_ENGLISH';
19
17
  /** The top-level folders whose documents this check reads. */
20
18
  const DOCUMENT_ROOTS = Object.freeze(['knowledge', 'docs', 'src', 'apps']);
21
-
22
19
  export function checkDocLanguage({ config, graph }) {
23
- const resolver = graph.resolver;
24
- const tree = treeOf(config.root);
25
- const violations = [];
26
- let files = 0;
27
- for (const file of [...tree.files].sort(byCodeUnit)) {
28
- if (!DOCUMENT_ROOTS.includes(file.split('/')[0]) || !isDocument(file) || file.split('/').includes('node_modules')) continue;
29
- const classified = resolver.classifyPath(file);
30
- if (isLocalizedDataFile(file, classified.status === 'owned' ? classified.slot : null)) continue;
31
- let text;
32
- try { text = fs.readFileSync(path.join(config.root, ...file.split('/')), 'utf8'); } catch { continue; }
33
- files += 1;
34
- for (const hit of documentLanguageHits(file, text)) {
35
- violations.push({ ruleId: RULE, path: file, line: hit.line, column: hit.column,
36
- message: `${file}:${hit.line} carries a Vietnamese letter. Documents are English (prose, patterns, examples and code fences); only YAML data in a message-catalog or i18n-fixtures slot may hold another language. Write the line in English.` });
20
+ const resolver = graph.resolver;
21
+ const tree = treeOf(config.root);
22
+ const violations = [];
23
+ let files = 0;
24
+ for (const file of [...tree.files].sort(byCodeUnit)) {
25
+ if (!DOCUMENT_ROOTS.includes(file.split('/')[0] ?? '') || !isDocument(file) || file.split('/').includes('node_modules'))
26
+ continue;
27
+ const classified = resolver.classifyPath(file);
28
+ const dataSlot = classified.status === 'owned' ? classified.slot : null;
29
+ if (dataSlot !== null && isLocalizedDataFile(file, dataSlot))
30
+ continue;
31
+ let text;
32
+ try {
33
+ text = fs.readFileSync(path.join(config.root, ...file.split('/')), 'utf8');
34
+ }
35
+ catch {
36
+ continue;
37
+ }
38
+ files += 1;
39
+ for (const hit of documentLanguageHits(file, text)) {
40
+ violations.push({ ruleId: RULE, path: file, line: hit.line, column: hit.column,
41
+ message: `${file}:${hit.line} carries a Vietnamese letter. Documents are English (prose, patterns, examples and code fences); only YAML data in a message-catalog or i18n-fixtures slot may hold another language. Write the line in English.` });
42
+ }
37
43
  }
38
- }
39
- return { violations, coverage: { status: 'checked', files } };
44
+ return { violations, coverage: { status: 'checked', files } };
40
45
  }
@@ -1,5 +1,4 @@
1
1
  import { braceVariants, globExpression } from '../../lib/glob.mjs';
2
-
3
2
  /**
4
3
  * The entity registry (persistence.md BE-PERSISTENCE-3): the one file whose slot plays `role: entity-registry`
5
4
  * (`be.platform.database.entities`, lite's `src/modules/platform/database/entities.ts`). It lists every capability's `<c>Entities`
@@ -8,46 +7,45 @@ import { braceVariants, globExpression } from '../../lib/glob.mjs';
8
7
  * The tier matrix (tiers.mjs), the public-entry check (owners.mjs) and the lint rule `import-owner-entry` read it here.
9
8
  */
10
9
  export const ENTITY_REGISTRY_ROLE = 'entity-registry';
11
-
12
10
  /** The tiers whose capabilities contribute an entity list to the registry. */
13
11
  const CONTRIBUTING_TIERS = new Set(['domain', 'platform']);
14
-
15
12
  /** The entity list a capability exports: `<c>Entities`, `<c>` its folder name in camelCase. */
16
- export const entityListName = capability => `${capability.replace(/-([a-z0-9])/g, (_, next) => next.toUpperCase())}Entities`;
17
-
13
+ export const entityListName = (capability) => `${capability.replace(/-([a-z0-9])/g, (_, next) => next.toUpperCase())}Entities`;
18
14
  /** The slot of `file` (side-relative or absolute) when it plays the entity-registry role, else null. */
19
15
  export function registrySlot(resolver, file) {
20
- const slot = resolver?.slotOf?.(file);
21
- return slot?.role === ENTITY_REGISTRY_ROLE ? slot : null;
16
+ const slot = resolver?.slotOf?.(file);
17
+ return slot?.role === ENTITY_REGISTRY_ROLE ? slot : null;
22
18
  }
23
-
24
19
  /**
25
20
  * Whether `file` is one of the importers the registry slot admits by deep path (`importedBy`, side-relative patterns); an app-wide
26
21
  * resolver answers for a side-prefixed path (`be/apps/...`), which is read without its side folder.
27
22
  */
28
23
  export function registryImporter(resolver, slot, file) {
29
- const side = resolver?.sideOf?.(file);
30
- const rel = side ? file.slice(side.length + 1) : file;
31
- return (slot.importedBy ?? []).some(pattern => braceVariants(pattern).some(variant => globExpression(variant).test(rel)));
24
+ const side = resolver?.sideOf?.(file);
25
+ const rel = side ? file.slice(side.length + 1) : file;
26
+ return (slot.importedBy ?? []).some(pattern => braceVariants(pattern).some((variant) => globExpression(variant).test(rel)));
32
27
  }
33
-
34
28
  /** The names an import declaration binds by name; null for a default, namespace or side-effect import and for any re-export. */
35
29
  function namedImports(declaration) {
36
- const clause = declaration?.importClause;
37
- if (!clause || clause.name || !Array.isArray(clause.namedBindings?.elements) || !clause.namedBindings.elements.length) return null;
38
- return clause.namedBindings.elements.map(element => (element.propertyName ?? element.name).text);
30
+ const clause = declaration?.importClause;
31
+ const bindings = clause?.namedBindings;
32
+ if (!clause || clause.name || !Array.isArray(bindings?.elements) || !bindings.elements.length)
33
+ return null;
34
+ return bindings.elements.map(element => (element.propertyName ?? element.name).text);
39
35
  }
40
-
41
36
  /**
42
37
  * Whether an owner-graph edge (side-relative `from` and `to`, `edge.declaration` the TypeScript statement) is the registry naming a
43
38
  * capability's entity list: it leaves the registry, imports the public entry (`index.ts`) of a domain or platform capability, and
44
39
  * binds that capability's `<c>Entities` and nothing else.
45
40
  */
46
41
  export function registryListImport(resolver, edge) {
47
- if (!registrySlot(resolver, edge.from)) return false;
48
- const owner = resolver.ownerOf(edge.to);
49
- if (!owner || !CONTRIBUTING_TIERS.has(resolver.slot(owner.slot)?.tier) || edge.to !== `${owner.root}/index.ts`) return false;
50
- const names = namedImports(edge.edge?.declaration ?? edge.declaration);
51
- const listName = entityListName(owner.root.split('/').at(-1));
52
- return names !== null && names.every(name => name === listName);
42
+ if (!registrySlot(resolver, edge.from))
43
+ return false;
44
+ const owner = resolver.ownerOf(edge.to);
45
+ const tier = owner ? resolver.slot(owner.slot)?.tier : undefined;
46
+ if (!owner || !CONTRIBUTING_TIERS.has(tier ?? '') || edge.to !== `${owner.root}/index.ts`)
47
+ return false;
48
+ const names = namedImports(edge.edge?.declaration ?? edge.declaration);
49
+ const listName = entityListName(owner.root.split('/').at(-1) ?? '');
50
+ return names !== null && names.every(name => name === listName);
53
51
  }
@@ -1,7 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import { machineKit } from './machine-ast.mjs';
3
3
  import { isTestWorldSlot } from '../test-world-slot.mjs';
4
-
5
4
  /**
6
5
  * R33 `entrypoint-only-in-apps` (BE_ENTRYPOINT_ONLY_IN_APPS). A process starts in `apps/<app>/src/main.ts` only:
7
6
  * `NestFactory.create*` (from @nestjs/core) and a top-level `bootstrap()` call anywhere else are entrypoints hiding in a
@@ -13,61 +12,64 @@ import { isTestWorldSlot } from '../test-world-slot.mjs';
13
12
  * other test slots stay refused.
14
13
  */
15
14
  export const ENTRYPOINT_RULE_IDS = ['BE_ENTRYPOINT_ONLY_IN_APPS'];
16
-
17
15
  const RULE = 'BE_ENTRYPOINT_ONLY_IN_APPS';
18
-
19
16
  const TRANSPARENT = ['isVoidExpression', 'isAwaitExpression', 'isParenthesizedExpression', 'isNonNullExpression'];
20
-
17
+ const isTransparent = (ts, node) => TRANSPARENT.some(test => ts[test](node));
21
18
  /** The identifier a top-level statement calls: `bootstrap()`, `void bootstrap()`, `bootstrap().catch(...)`. */
22
19
  function calledIdentifier(ts, expression) {
23
- let current = expression;
24
- for (;;) {
25
- if (TRANSPARENT.some(test => ts[test](current))) current = current.expression;
26
- else if (ts.isCallExpression(current)) {
27
- if (ts.isIdentifier(current.expression)) return current.expression;
28
- current = current.expression;
29
- } else if (ts.isPropertyAccessExpression(current)) current = current.expression;
30
- else return null;
31
- }
20
+ let current = expression;
21
+ for (;;) {
22
+ if (isTransparent(ts, current))
23
+ current = current.expression;
24
+ else if (ts.isCallExpression(current)) {
25
+ if (ts.isIdentifier(current.expression))
26
+ return current.expression;
27
+ current = current.expression;
28
+ }
29
+ else if (ts.isPropertyAccessExpression(current))
30
+ current = current.expression;
31
+ else
32
+ return null;
33
+ }
32
34
  }
33
-
34
35
  const isNestFactoryCreate = (kit, ts, checker, node) => ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text.startsWith('create')
35
- && kit.isImportOf(checker, node.expression.expression, 'NestFactory', '@nestjs/core');
36
-
37
- const isMainFile = file => (Boolean(file.slot?.startsWith('be.app.')) && path.posix.basename(file.rel) === 'main.ts') || isTestWorldSlot(file.slot);
38
-
36
+ && kit.isImportOf(checker, node.expression.expression, 'NestFactory', '@nestjs/core');
37
+ const isMainFile = (file) => (Boolean(file.slot?.startsWith('be.app.')) && path.posix.basename(file.rel) === 'main.ts') || isTestWorldSlot(file.slot);
39
38
  /** Counts the NestFactory.create* calls of an entrypoint owner and reports them in any other file. */
40
39
  function inspectFactoryCalls(kit, file, isMain, report) {
41
- const { ts } = kit;
42
- const checker = kit.checkerOf(file.sourceFile);
43
- let entrypoints = 0;
44
- kit.walk(file.sourceFile, node => {
45
- if (!isNestFactoryCreate(kit, ts, checker, node)) return;
46
- if (isMain) entrypoints += 1;
47
- else report(node, `NestFactory.${node.expression.name.text}() starts a process outside apps/<app>/src/main.ts; entrypoints live in an app's main.ts only.`);
48
- });
49
- return entrypoints;
40
+ const { ts } = kit;
41
+ const checker = kit.checkerOf(file.sourceFile);
42
+ let entrypoints = 0;
43
+ kit.walk(file.sourceFile, (node) => {
44
+ if (!isNestFactoryCreate(kit, ts, checker, node))
45
+ return;
46
+ if (isMain)
47
+ entrypoints += 1;
48
+ else
49
+ report(node, `NestFactory.${node.expression.name.text}() starts a process outside apps/<app>/src/main.ts; entrypoints live in an app's main.ts only.`);
50
+ });
51
+ return entrypoints;
50
52
  }
51
-
52
53
  function inspectBootstrapCalls(ts, file, report) {
53
- for (const statement of file.sourceFile.statements) {
54
- if (!ts.isExpressionStatement(statement)) continue;
55
- if (calledIdentifier(ts, statement.expression)?.text === 'bootstrap') {
56
- report(statement, "A top-level bootstrap() call starts a process outside apps/<app>/src/main.ts; entrypoints live in an app's main.ts only.");
54
+ for (const statement of file.sourceFile.statements) {
55
+ if (!ts.isExpressionStatement(statement))
56
+ continue;
57
+ if (calledIdentifier(ts, statement.expression)?.text === 'bootstrap') {
58
+ report(statement, "A top-level bootstrap() call starts a process outside apps/<app>/src/main.ts; entrypoints live in an app's main.ts only.");
59
+ }
57
60
  }
58
- }
59
61
  }
60
-
61
62
  export function checkEntrypoints(input) {
62
- const { graph } = input;
63
- const kit = machineKit(input);
64
- const violations = [];
65
- let entrypoints = 0;
66
- for (const file of graph.files.values()) {
67
- const isMain = isMainFile(file);
68
- const report = (node, message) => violations.push({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, node), message });
69
- entrypoints += inspectFactoryCalls(kit, file, isMain, report);
70
- if (!isMain) inspectBootstrapCalls(kit.ts, file, report);
71
- }
72
- return { violations, coverage: { status: 'checked', entrypoints } };
63
+ const { graph } = input;
64
+ const kit = machineKit(input);
65
+ const violations = [];
66
+ let entrypoints = 0;
67
+ for (const file of graph.files.values()) {
68
+ const isMain = isMainFile(file);
69
+ const report = (node, message) => violations.push({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, node), message });
70
+ entrypoints += inspectFactoryCalls(kit, file, isMain, report);
71
+ if (!isMain)
72
+ inspectBootstrapCalls(kit.ts, file, report);
73
+ }
74
+ return { violations, coverage: { status: 'checked', entrypoints } };
73
75
  }
@@ -1,6 +1,5 @@
1
1
  import path from 'node:path';
2
2
  import { machineKit, upperSnake } from './machine-ast.mjs';
3
-
4
3
  /**
5
4
  * R38 error codes (BE_ERROR_HOME, machine half; the eslint half judges the error classes). The string value of every
6
5
  * member of a `<C>ErrorCode` enum in a capability's `errors/<c>.error.ts` is a string literal shaped
@@ -8,45 +7,48 @@ import { machineKit, upperSnake } from './machine-ast.mjs';
8
7
  * whole repository, so a code names one refusal and one capability for the client and the log.
9
8
  */
10
9
  export const ERROR_CODE_RULE_IDS = ['BE_ERROR_HOME'];
11
-
12
10
  const RULE = 'BE_ERROR_HOME';
13
-
14
11
  // Judge each member of one <C>ErrorCode enum; returns how many string-literal codes it held.
15
12
  const checkEnumCodes = (statement, { file, capability, shape, kit, ts, seen, violations }) => {
16
- let checked = 0;
17
- for (const member of statement.members) {
18
- const report = message => violations.push({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, member), message });
19
- const name = kit.propertyNameText(member.name) ?? '?';
20
- const value = member.initializer && ts.isStringLiteralLike(member.initializer) ? member.initializer.text : null;
21
- if (value === null) { report(`${statement.name.text}.${name} must be a string literal code (\`${capability}_<WHAT>\`); a computed or numeric code cannot be checked or told apart in a log.`); continue; }
22
- checked += 1;
23
- if (!shape.test(value) || /_(?:ERROR|EXCEPTION)$/u.test(value)) {
24
- report(`${statement.name.text}.${name} = "${value}" must match ${capability}_<WHAT> in UPPER_SNAKE with the capability prefix and no _ERROR or _EXCEPTION suffix.`);
13
+ let checked = 0;
14
+ for (const member of statement.members) {
15
+ const report = (message) => { violations.push({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, member), message }); };
16
+ const name = kit.propertyNameText(member.name) ?? '?';
17
+ const value = member.initializer && ts.isStringLiteralLike(member.initializer) ? member.initializer.text : null;
18
+ if (value === null) {
19
+ report(`${statement.name.text}.${name} must be a string literal code (\`${capability}_<WHAT>\`); a computed or numeric code cannot be checked or told apart in a log.`);
20
+ continue;
21
+ }
22
+ checked += 1;
23
+ if (!shape.test(value) || /_(?:ERROR|EXCEPTION)$/u.test(value)) {
24
+ report(`${statement.name.text}.${name} = "${value}" must match ${capability}_<WHAT> in UPPER_SNAKE with the capability prefix and no _ERROR or _EXCEPTION suffix.`);
25
+ }
26
+ if (seen.has(value))
27
+ report(`Error code "${value}" is already declared in ${seen.get(value)}; a code is unique across the repository.`);
28
+ else
29
+ seen.set(value, file.rel);
25
30
  }
26
- if (seen.has(value)) report(`Error code "${value}" is already declared in ${seen.get(value)}; a code is unique across the repository.`);
27
- else seen.set(value, file.rel);
28
- }
29
- return checked;
31
+ return checked;
30
32
  };
31
-
32
33
  export function checkErrorCodes(input) {
33
- const { graph } = input;
34
- const kit = machineKit(input);
35
- const { ts } = kit;
36
- const violations = [];
37
- const seen = new Map();
38
- let enums = 0;
39
- let codes = 0;
40
- const files = [...graph.files.values()].filter(file => file.slot === 'be.errors' && file.owner && path.posix.basename(file.rel).endsWith('.error.ts'))
41
- .sort((a, b) => a.rel.localeCompare(b.rel));
42
- for (const file of files) {
43
- const capability = upperSnake(path.posix.basename(file.owner.root));
44
- const shape = new RegExp(`^${capability}_[A-Z0-9]+(?:_[A-Z0-9]+)*$`, 'u');
45
- for (const statement of file.sourceFile.statements) {
46
- if (!ts.isEnumDeclaration(statement) || !statement.name.text.endsWith('ErrorCode')) continue;
47
- enums += 1;
48
- codes += checkEnumCodes(statement, { file, capability, shape, kit, ts, seen, violations });
34
+ const { graph } = input;
35
+ const kit = machineKit(input);
36
+ const { ts } = kit;
37
+ const violations = [];
38
+ const seen = new Map();
39
+ let enums = 0;
40
+ let codes = 0;
41
+ const files = [...graph.files.values()].filter((file) => file.slot === 'be.errors' && file.owner !== null && path.posix.basename(file.rel).endsWith('.error.ts'))
42
+ .sort((a, b) => a.rel.localeCompare(b.rel));
43
+ for (const file of files) {
44
+ const capability = upperSnake(path.posix.basename(file.owner.root));
45
+ const shape = new RegExp(`^${capability}_[A-Z0-9]+(?:_[A-Z0-9]+)*$`, 'u');
46
+ for (const statement of file.sourceFile.statements) {
47
+ if (!ts.isEnumDeclaration(statement) || !statement.name.text.endsWith('ErrorCode'))
48
+ continue;
49
+ enums += 1;
50
+ codes += checkEnumCodes(statement, { file, capability, shape, kit, ts, seen, violations });
51
+ }
49
52
  }
50
- }
51
- return { violations, coverage: { status: 'checked', enums, codes } };
53
+ return { violations, coverage: { status: 'checked', enums, codes } };
52
54
  }