@starci/eslint-canon-be 3.8.19 → 3.9.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 (164) hide show
  1. package/CHANGELOG.md +12 -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
@@ -10,7 +10,6 @@ import { isFeTestPath } from './rules/fe-no-tests.mjs';
10
10
  import { slotOwnsSecrets } from './rules/secrets.mjs';
11
11
  import { specPlacementFindings } from './rules/spec-placement.mjs';
12
12
  import { APP_SCOPE } from './slots.mjs';
13
-
14
13
  const KEBAB = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
15
14
  const SOURCE_ROOT = /^(?:src|apps)\//;
16
15
  const FREE_NAMES = new Set(['index.ts', 'main.ts']);
@@ -21,43 +20,49 @@ const PLAIN_ENTRY = /^<[a-z][a-z0-9-]*>.ts$/;
21
20
  */
22
21
  const DATA_ACCESS_HOME = 'SQL text is a constant in <name>.sql.ts of the capability persistence/ folder, and data access is the capability *.service.ts (or the application *.handler.ts) calling the shared EntityManager through its Inject<Conn>EntityManager()';
23
22
  const BANNED_SUFFIX_HOME = Object.freeze({ repository: DATA_ACCESS_HOME, store: DATA_ACCESS_HOME });
24
-
25
23
  function sourceFormContext(file, resolver, suffixes, bannedSuffixes) {
26
- if (!file.endsWith('.ts') || !SOURCE_ROOT.test(file)) return null;
27
- const c = resolver.classifyPath(file);
28
- if (c.status !== 'owned' || c.tracking === 'ignored') return null;
29
- const base = path.posix.basename(file);
30
- if (FREE_NAMES.has(base)) return null;
31
- const slot = resolver.slot(c.slot);
32
- // A file slot declares its one file by its path (be.platform.database.entities: src/modules/platform/database/entities.ts).
33
- if (slot?.path === c.path) return null;
34
- if ([...(slot?.requires ?? []), ...(slot?.allows ?? [])].includes(base)) return null;
35
- const admitted = allowsFile(resolver, file);
36
- // Environment parsing is an app slot role, not a source suffix admitted outside that matching app file.
37
- if (c.slot.startsWith('be.app.') && admitted?.allowed && admitted.entry === '<app>.env.ts') return null;
38
- if (admitted?.allowed && admitted.entry?.includes('/') && path.posix.basename(admitted.entry) === base) return null;
39
- // A plain entry names its file by a variable only (`<x>.ts`, or `compose/<area>.ts` of an app slot): a kebab name is its form.
40
- if (admitted?.allowed && PLAIN_ENTRY.test(path.posix.basename(admitted.entry ?? '')) && KEBAB.test(base.slice(0, -'.ts'.length))) return null;
41
- if (c.slot === 'be.persistence' && path.posix.basename(path.posix.dirname(file)) === 'migrations') return null;
42
- return { c, base, suffixes, bannedSuffixes };
24
+ if (!file.endsWith('.ts') || !SOURCE_ROOT.test(file))
25
+ return null;
26
+ const c = resolver.classifyPath(file);
27
+ if (c.status !== 'owned' || c.tracking === 'ignored')
28
+ return null;
29
+ const base = path.posix.basename(file);
30
+ if (FREE_NAMES.has(base))
31
+ return null;
32
+ const slot = resolver.slot(c.slot);
33
+ // A file slot declares its one file by its path (be.platform.database.entities: src/modules/platform/database/entities.ts).
34
+ if (slot?.path === c.path)
35
+ return null;
36
+ if ([...(slot?.requires ?? []), ...(slot?.allows ?? [])].includes(base))
37
+ return null;
38
+ const admitted = allowsFile(resolver, file);
39
+ // Environment parsing is an app slot role, not a source suffix admitted outside that matching app file.
40
+ if (c.slot.startsWith('be.app.') && admitted?.allowed && admitted.entry === '<app>.env.ts')
41
+ return null;
42
+ if (admitted?.allowed && admitted.entry?.includes('/') && path.posix.basename(admitted.entry) === base)
43
+ return null;
44
+ // A plain entry names its file by a variable only (`<x>.ts`, or `compose/<area>.ts` of an app slot): a kebab name is its form.
45
+ if (admitted?.allowed && PLAIN_ENTRY.test(path.posix.basename(admitted.entry ?? '')) && KEBAB.test(base.slice(0, -'.ts'.length)))
46
+ return null;
47
+ if (c.slot === 'be.persistence' && path.posix.basename(path.posix.dirname(file)) === 'migrations')
48
+ return null;
49
+ return { c, base, suffixes, bannedSuffixes };
43
50
  }
44
-
45
51
  function sourceFormFinding(file, { c, base, suffixes, bannedSuffixes }, boundSuffixes) {
46
- const parts = base.slice(0, -'.ts'.length).split('.');
47
- const banned = parts.slice(1).find((part) => bannedSuffixes.includes(part));
48
- if (banned) {
49
- const homeNote = BANNED_SUFFIX_HOME[banned] ? `. ${BANNED_SUFFIX_HOME[banned]}` : '';
50
- return { code: 'BE_SOURCE_FORM', level: 'error', path: file, suffix: banned, message: `${file}: the suffix .${banned} is banned; use a role from the closed suffix list (${suffixes.join(', ')})${homeNote}` };
51
- }
52
- if (boundSuffixes.has(parts.at(-1)) && parts.length >= 2 && boundSuffixes.get(parts.at(-1)).id !== c.slot) {
53
- return { code: 'BE_SOURCE_FORM', level: 'error', path: file, suffix: parts.at(-1), message: `${file}: the suffix .${parts.at(-1)}.ts belongs to ${boundSuffixes.get(parts.at(-1)).path} only; move the file there` };
54
- }
55
- if (parts.length < 2 || !parts.every((part) => KEBAB.test(part)) || !suffixes.includes(parts.at(-1))) {
56
- return { code: 'BE_SOURCE_FORM', level: 'error', path: file, message: `${file}: the name must be <kebab-name>.<suffix>.ts with a suffix from the closed list (${suffixes.join(', ')}), or index.ts, main.ts or a migration` };
57
- }
58
- return null;
52
+ const parts = base.slice(0, -'.ts'.length).split('.');
53
+ const banned = parts.slice(1).find((part) => bannedSuffixes.includes(part));
54
+ if (banned) {
55
+ const homeNote = BANNED_SUFFIX_HOME[banned] ? `. ${BANNED_SUFFIX_HOME[banned]}` : '';
56
+ return { code: 'BE_SOURCE_FORM', level: 'error', path: file, suffix: banned, message: `${file}: the suffix .${banned} is banned; use a role from the closed suffix list (${suffixes.join(', ')})${homeNote}` };
57
+ }
58
+ if (boundSuffixes.has(parts.at(-1)) && parts.length >= 2 && boundSuffixes.get(parts.at(-1)).id !== c.slot) {
59
+ return { code: 'BE_SOURCE_FORM', level: 'error', path: file, suffix: parts.at(-1), message: `${file}: the suffix .${parts.at(-1)}.ts belongs to ${boundSuffixes.get(parts.at(-1)).path} only; move the file there` };
60
+ }
61
+ if (parts.length < 2 || !parts.every((part) => KEBAB.test(part)) || !suffixes.includes(parts.at(-1))) {
62
+ return { code: 'BE_SOURCE_FORM', level: 'error', path: file, message: `${file}: the name must be <kebab-name>.<suffix>.ts with a suffix from the closed list (${suffixes.join(', ')}), or index.ts, main.ts or a migration` };
63
+ }
64
+ return null;
59
65
  }
60
-
61
66
  /**
62
67
  * BE_SOURCE_FORM (R89): every tracked src/ or apps/ TypeScript file of a back end is index.ts, main.ts, the one file a file
63
68
  * slot names by its path (the lite entity registry src/modules/platform/database/entities.ts), a migration of be.persistence, the matching <app>.env.ts explicitly admitted by its app slot, or <kebab-name>.<suffix>.ts with <suffix> in the closed vocabulary ruleParams.be.suffixes (a name such
@@ -65,83 +70,98 @@ function sourceFormFinding(file, { c, base, suffixes, bannedSuffixes }, boundSuf
65
70
  * name is refused by name. Paths no slot owns are HFS_SLOT_UNDECLARED's, not this code's.
66
71
  */
67
72
  function sourceFormFindings({ files, resolver }) {
68
- const { suffixes, bannedSuffixes } = resolver.ruleParams();
69
- // A suffix a slot names in its own file pattern (`*.builder.ts` of be.tests.fixtures.builders) is that slot's role: a file with it
70
- // anywhere else is refused, so a builder cannot live beside a service or in the fixtures root.
71
- const boundSuffixes = new Map();
72
- for (const slot of resolver.slots()) {
73
- const bound = /\*\.([a-z0-9-]+)\.ts$/.exec(slot.path ?? '')?.[1];
74
- if (bound && suffixes.includes(bound)) boundSuffixes.set(bound, slot);
75
- }
76
- const findings = [];
77
- for (const file of files) {
78
- const context = sourceFormContext(file, resolver, suffixes, bannedSuffixes);
79
- if (!context) continue;
80
- const finding = sourceFormFinding(file, context, boundSuffixes);
81
- if (finding) findings.push(finding);
82
- }
83
- return findings;
73
+ const { suffixes, bannedSuffixes } = resolver.ruleParams();
74
+ // A suffix a slot names in its own file pattern (`*.builder.ts` of be.tests.fixtures.builders) is that slot's role: a file with it
75
+ // anywhere else is refused, so a builder cannot live beside a service or in the fixtures root.
76
+ const boundSuffixes = new Map();
77
+ for (const slot of resolver.slots()) {
78
+ const bound = /\*\.([a-z0-9-]+)\.ts$/.exec(slot.path ?? '')?.[1];
79
+ if (bound && suffixes.includes(bound))
80
+ boundSuffixes.set(bound, slot);
81
+ }
82
+ const findings = [];
83
+ for (const file of files) {
84
+ const context = sourceFormContext(file, resolver, suffixes, bannedSuffixes);
85
+ if (!context)
86
+ continue;
87
+ const finding = sourceFormFinding(file, context, boundSuffixes);
88
+ if (finding)
89
+ findings.push(finding);
90
+ }
91
+ return findings;
84
92
  }
85
-
86
93
  function forbiddenPathFinding(file, c, resolver) {
87
- const slot = resolver.slot(c.slot);
88
- if (slotOwnsSecrets(slot)) return null;
89
- const own = slot.rules?.includes('HFS_TOOL_CONFIG_LOCAL') ? 'HFS_TOOL_CONFIG_LOCAL' : 'HFS_FORBIDDEN_PRESENT';
90
- const goesToNote = c.goesTo ? `; it belongs at ${c.goesTo}` : '';
91
- return { code: own, level: 'error', path: file, slot: c.slot, goesTo: c.goesTo, message: `${file} is tracked but ${c.slot} is forbidden in the tree${goesToNote}` };
94
+ const slot = resolver.slot(c.slot);
95
+ if (slotOwnsSecrets(slot))
96
+ return null;
97
+ const own = slot.rules?.includes('HFS_TOOL_CONFIG_LOCAL') ? 'HFS_TOOL_CONFIG_LOCAL' : 'HFS_FORBIDDEN_PRESENT';
98
+ const goesToNote = c.goesTo ? `; it belongs at ${c.goesTo}` : '';
99
+ return { code: own, level: 'error', path: file, slot: c.slot, goesTo: c.goesTo, message: `${file} is tracked but ${c.slot} is forbidden in the tree${goesToNote}` };
92
100
  }
93
-
94
101
  function pathStatusFinding(file, resolver) {
95
- const liteWork = liteStarciworkFinding(file, resolver);
96
- if (liteWork) return liteWork;
97
- const c = resolver.classifyPath(file);
98
- if (c.status === 'no-slot') {
99
- const nearestNote = c.nearest ? `; nearest slot ${c.nearest.slot} (${c.nearest.pattern}), matched ${c.nearest.matchedPrefix || '.'} then expected ${c.nearest.expectedNext ?? 'nothing'}` : '';
100
- return { code: 'HFS_SLOT_UNDECLARED', level: 'error', path: file, nearest: c.nearest, message: `${file} matches no slot${nearestNote}` };
101
- }
102
- if (c.status === 'ambiguous') return { code: 'HFS_SLOT_AMBIGUOUS', level: 'error', path: file, candidates: c.candidates, message: `${file} is owned equally by ${c.candidates.map((x) => x.slot ?? x).join(', ')}` };
103
- if (c.status === 'not-enabled') return { code: 'HFS_SLOT_NOT_ENABLED', level: 'error', path: file, slot: c.slot, message: `${file} belongs to ${c.slot}, an opt-in slot hfs.json neither lists in optionalSlots nor implies through an app kind` };
104
- if (c.status === 'forbidden') return forbiddenPathFinding(file, c, resolver);
105
- if (c.tracking === 'ignored') return { code: 'HFS_TRACKED_MUST_BE_IGNORED', level: 'error', path: file, slot: c.slot, message: `${file} is tracked but ${c.slot} must be gitignored` };
106
- return null;
102
+ const liteWork = liteStarciworkFinding(file, resolver);
103
+ if (liteWork)
104
+ return liteWork;
105
+ const c = resolver.classifyPath(file);
106
+ if (c.status === 'no-slot') {
107
+ const nearestNote = c.nearest ? `; nearest slot ${c.nearest.slot} (${c.nearest.pattern}), matched ${c.nearest.matchedPrefix || '.'} then expected ${c.nearest.expectedNext ?? 'nothing'}` : '';
108
+ return { code: 'HFS_SLOT_UNDECLARED', level: 'error', path: file, nearest: c.nearest, message: `${file} matches no slot${nearestNote}` };
109
+ }
110
+ if (c.status === 'ambiguous')
111
+ return { code: 'HFS_SLOT_AMBIGUOUS', level: 'error', path: file, candidates: c.candidates, message: `${file} is owned equally by ${c.candidates.map((x) => x.slot ?? x).join(', ')}` };
112
+ if (c.status === 'not-enabled')
113
+ return { code: 'HFS_SLOT_NOT_ENABLED', level: 'error', path: file, slot: c.slot, message: `${file} belongs to ${c.slot}, an opt-in slot hfs.json neither lists in optionalSlots nor implies through an app kind` };
114
+ if (c.status === 'forbidden')
115
+ return forbiddenPathFinding(file, c, resolver);
116
+ if (c.tracking === 'ignored')
117
+ return { code: 'HFS_TRACKED_MUST_BE_IGNORED', level: 'error', path: file, slot: c.slot, message: `${file} is tracked but ${c.slot} must be gitignored` };
118
+ return null;
107
119
  }
108
-
109
120
  /** The lite Work boundary, read from app.starciwork's edition-specific admission list, including paths a narrower slot owns. */
110
121
  export function liteStarciworkFinding(file, resolver, { dir = false } = {}) {
111
- if (resolver.repo?.edition !== 'lite' || !resolver.slot('app.starciwork')) return null;
112
- const p = resolver.classifyPath(file).path;
113
- if (!p.startsWith('.starciwork/')) return null;
114
- const admitted = allowsFile(resolver, dir ? `${p}/.probe` : p);
115
- if (admitted?.slot === 'app.starciwork' && admitted.allowed) return null;
116
- return { code: 'HFS_STARCIWORK_LITE_FORBIDDEN', level: 'error', path: p, slot: 'app.starciwork', message: `${p}: lite .starciwork holds only workspace.yaml and brand/ (plus .gitignore); remove this path or use the full edition` };
122
+ if (resolver.repo?.edition !== 'lite' || !resolver.slot('app.starciwork'))
123
+ return null;
124
+ const p = resolver.classifyPath(file).path;
125
+ if (!p.startsWith('.starciwork/'))
126
+ return null;
127
+ const admitted = allowsFile(resolver, dir ? `${p}/.probe` : p);
128
+ if (admitted?.slot === 'app.starciwork' && admitted.allowed)
129
+ return null;
130
+ return { code: 'HFS_STARCIWORK_LITE_FORBIDDEN', level: 'error', path: p, slot: 'app.starciwork', message: `${p}: lite .starciwork holds only workspace.yaml and brand/ (plus .gitignore); remove this path or use the full edition` };
117
131
  }
118
-
119
132
  /** Local lite Work leftovers, including metadata ignored by an old full-edition .gitignore. */
120
133
  export function liteStarciworkTreeFindings(repoRoot, resolver, tracked) {
121
- if (resolver.repo?.edition !== 'lite' || !resolver.slot('app.starciwork')) return [];
122
- let entries = [];
123
- try { entries = fs.readdirSync(path.join(repoRoot, '.starciwork'), { withFileTypes: true }); } catch { /* Work is optional. */ }
124
- const trackedSet = new Set(tracked);
125
- return entries.flatMap(entry => {
126
- const file = `.starciwork/${entry.name}`;
127
- if (trackedSet.has(file)) return [];
128
- const finding = liteStarciworkFinding(file, resolver, { dir: entry.isDirectory() });
129
- return finding ? [finding] : [];
130
- });
134
+ if (resolver.repo?.edition !== 'lite' || !resolver.slot('app.starciwork'))
135
+ return [];
136
+ let entries = [];
137
+ try {
138
+ entries = fs.readdirSync(path.join(repoRoot, '.starciwork'), { withFileTypes: true });
139
+ }
140
+ catch { /* Work is optional. */ }
141
+ const trackedSet = new Set(tracked);
142
+ return entries.flatMap(entry => {
143
+ const file = `.starciwork/${entry.name}`;
144
+ if (trackedSet.has(file))
145
+ return [];
146
+ const finding = liteStarciworkFinding(file, resolver, { dir: entry.isDirectory() });
147
+ return finding ? [finding] : [];
148
+ });
131
149
  }
132
-
133
150
  /** The findings of the slot manifest over `files` (repository-relative tracked paths) of a repository of `profile`. */
134
151
  export function pathFindings({ files, resolver, profile }) {
135
- const findings = [];
136
- for (const file of files) {
137
- if (profile === 'fe' && isFeTestPath(file)) continue; // a test path of a front end is FE_NO_TESTS's, the one finding of that file
138
- const finding = pathStatusFinding(file, resolver);
139
- if (finding) findings.push(finding);
140
- }
141
-
142
- if (profile === 'be') findings.push(...sourceFormFindings({ files, resolver }), ...specPlacementFindings({ files, resolver }));
143
- // The app root (scripts/, CI, hooks) holds no test layer: a spec there is the same finding as a spec of an operational script.
144
- else if (profile === APP_SCOPE) findings.push(...specPlacementFindings({ files, resolver }));
145
- // The lint canon's project graph serves these findings on a TypeScript file; the origin keeps them apart from the machine's.
146
- return findings.map((finding) => ({ ...finding, origin: 'repo' }));
152
+ const findings = [];
153
+ for (const file of files) {
154
+ if (profile === 'fe' && isFeTestPath(file))
155
+ continue; // a test path of a front end is FE_NO_TESTS's, the one finding of that file
156
+ const finding = pathStatusFinding(file, resolver);
157
+ if (finding)
158
+ findings.push(finding);
159
+ }
160
+ if (profile === 'be')
161
+ findings.push(...sourceFormFindings({ files, resolver }), ...specPlacementFindings({ files, resolver }));
162
+ // The app root (scripts/, CI, hooks) holds no test layer: a spec there is the same finding as a spec of an operational script.
163
+ else if (profile === APP_SCOPE)
164
+ findings.push(...specPlacementFindings({ files, resolver }));
165
+ // The lint canon's project graph serves these findings on a TypeScript file; the origin keeps them apart from the machine's.
166
+ return findings.map((finding) => ({ ...finding, origin: 'repo' }));
147
167
  }
@@ -7,40 +7,48 @@ import { revParseQuery } from '../api/git/rev-parse-query.mjs';
7
7
  import { remote as gitRemote } from '../api/git/remote.mjs';
8
8
  import { gitOutputOf } from '../lib/git.mjs';
9
9
  import { trimTrailingSlashes } from './trailing-slashes.mjs';
10
-
11
10
  /** One git call (a scripts/api/git call file) in `root`: its trimmed stdout; throws unless git exits 0. */
12
- const git = (call, root, args) => gitOutputOf(call(args, { cwd: root })).trim();
13
- const real = (p) => { try { return fs.realpathSync(p); } catch { return path.resolve(p); } };
14
- const GIT_SUFFIX_SOURCE = String.raw`\.git$`;
11
+ const git = (call, root, args) => gitOutputOf(call(args, { cwd: root })).trim(); // gitOutputOf threw unless git exited 0, whose stdout is text
12
+ const real = (p) => { try {
13
+ return fs.realpathSync(p);
14
+ }
15
+ catch {
16
+ return path.resolve(p);
17
+ } };
18
+ const GIT_SUFFIX_SOURCE = String.raw `\.git$`;
15
19
  const GIT_SUFFIX = new RegExp(GIT_SUFFIX_SOURCE, 'iu');
16
-
17
- // The identity of a folder that has its own .git entry holds while that entry is the same file system object (same inode, same modification time), so a
18
- // process asks Git once per such folder state instead of at every check. A folder with no .git entry of its own is asked every time.
19
20
  const known = new Map();
20
- const stateOf = (root) => { try { const stat = fs.statSync(path.join(root, '.git')); return `${real(root)}|${stat.ino}|${stat.mtimeMs}`; } catch { return null; } };
21
-
21
+ const stateOf = (root) => { try {
22
+ const stat = fs.statSync(path.join(root, '.git'));
23
+ return `${real(root)}|${stat.ino}|${stat.mtimeMs}`;
24
+ }
25
+ catch {
26
+ return null;
27
+ } };
22
28
  /** { repositoryRoot, inWorkTree, home } for `root`: home is the main checkout folder when root is a repository top level. */
23
29
  function identityOf(root) {
24
- const state = stateOf(root);
25
- if (state === null) return askGit(root);
26
- if (!known.has(state)) known.set(state, askGit(root));
27
- return known.get(state);
30
+ const state = stateOf(root);
31
+ if (state === null)
32
+ return askGit(root);
33
+ if (!known.has(state))
34
+ known.set(state, askGit(root));
35
+ return known.get(state);
28
36
  }
29
-
30
37
  function askGit(root) {
31
- let inWorkTree = false, repositoryRoot = false, home = null;
32
- try {
33
- // Identity comes from Git only when root IS a repository (or worktree) top level, never a folder inside one.
34
- // One git call answers both questions: the top level on the first line, the common git dir on the second.
35
- const [top, commonDir] = git(revParseQuery, root, ['--show-toplevel', '--git-common-dir']).split(String.fromCodePoint(10)).map((line) => line.trim());
36
- repositoryRoot = real(top) === real(root);
37
- inWorkTree = true;
38
- const common = path.resolve(root, commonDir);
39
- if (repositoryRoot && path.basename(common) === '.git') home = path.dirname(common);
40
- } catch { /* Not a Git work tree; the caller falls back to the folder and package name. */ }
41
- return { inWorkTree, repositoryRoot, home };
38
+ let inWorkTree = false, repositoryRoot = false, home = null;
39
+ try {
40
+ // Identity comes from Git only when root IS a repository (or worktree) top level, never a folder inside one.
41
+ // One git call answers both questions: the top level on the first line, the common git dir on the second.
42
+ const [top, commonDir] = git(revParseQuery, root, ['--show-toplevel', '--git-common-dir']).split(String.fromCodePoint(10)).map((line) => line.trim());
43
+ repositoryRoot = real(top) === real(root);
44
+ inWorkTree = true;
45
+ const common = path.resolve(root, commonDir);
46
+ if (repositoryRoot && path.basename(common) === '.git')
47
+ home = path.dirname(common);
48
+ }
49
+ catch { /* Not a Git work tree; the caller falls back to the folder and package name. */ }
50
+ return { inWorkTree, repositoryRoot, home };
42
51
  }
43
-
44
52
  /**
45
53
  * The product repository name: the origin remote's repository name (one name for every clone and worktree, whatever
46
54
  * folder holds it), else the main checkout's folder name (so a worktree and its main checkout agree), else package.json
@@ -48,24 +56,29 @@ function askGit(root) {
48
56
  * its own folder.
49
57
  */
50
58
  export function repositoryName(root) {
51
- const { inWorkTree, repositoryRoot, home } = identityOf(root);
52
- if (repositoryRoot) {
59
+ const { inWorkTree, repositoryRoot, home } = identityOf(root);
60
+ if (repositoryRoot) {
61
+ try {
62
+ const remote = trimTrailingSlashes(git(gitRemote, root, ['get-url', 'origin'])).replace(GIT_SUFFIX, '');
63
+ const name = remote.split(/[/:]/u).pop();
64
+ if (name)
65
+ return name;
66
+ }
67
+ catch { /* No origin remote. */ }
68
+ }
69
+ if (home)
70
+ return path.basename(home);
71
+ if (inWorkTree && !repositoryRoot)
72
+ return path.basename(root);
53
73
  try {
54
- const remote = trimTrailingSlashes(git(gitRemote, root, ['get-url', 'origin'])).replace(GIT_SUFFIX, '');
55
- const name = remote.split(/[/:]/u).pop();
56
- if (name) return name;
57
- } catch { /* No origin remote. */ }
58
- }
59
- if (home) return path.basename(home);
60
- if (inWorkTree && !repositoryRoot) return path.basename(root);
61
- try {
62
- const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
63
- if (typeof pkg.name === 'string' && pkg.name) return pkg.name.replace(/^@[^/]+\//u, '');
64
- } catch { /* No readable package.json. */ }
65
- return path.basename(root);
74
+ const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
75
+ if (typeof pkg.name === 'string' && pkg.name)
76
+ return pkg.name.replace(/^@[^/]+\//u, '');
77
+ }
78
+ catch { /* No readable package.json. */ }
79
+ return path.basename(root);
66
80
  }
67
-
68
81
  /** The folder whose siblings are this repository's sibling repositories: the main checkout for a worktree, else root. */
69
82
  export function repositoryHome(root) {
70
- return identityOf(root).home ?? path.resolve(root);
83
+ return identityOf(root).home ?? path.resolve(root);
71
84
  }