@starci/eslint-canon-be 3.18.4 → 3.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/dist/comments.js +1 -1
  4. package/dist/explicit-surface.js +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/jwt-alg.js +1 -1
  7. package/dist/lib/edition.d.ts +1 -1
  8. package/dist/lib/edition.js +1 -1
  9. package/dist/lib/hfs-view.d.ts +5 -0
  10. package/dist/lib/hfs.d.ts +0 -6
  11. package/dist/lib/hfs.js +7 -5
  12. package/dist/lib/runtime-root.d.ts +6 -1
  13. package/dist/lib/runtime-root.js +8 -2
  14. package/dist/lib/subject-values.js +1 -1
  15. package/dist/module-layering.js +2 -2
  16. package/dist/project-graph.js +1 -1
  17. package/dist/schema-authority.js +66 -2
  18. package/dist/third-party-owner.js +1 -1
  19. package/package.json +3 -1
  20. package/runtime/bundle.json +1 -190
  21. package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
  22. package/runtime/scripts/hfs/project-graph.mjs +6 -6
  23. package/runtime/scripts/hfs/project-rule.mjs +3 -3
  24. package/runtime/config.example.yaml +0 -194
  25. package/runtime/engine/by-code-unit.mjs +0 -12
  26. package/runtime/engine/config.mjs +0 -461
  27. package/runtime/engine/invalid-config.mjs +0 -15
  28. package/runtime/engine/model-config.mjs +0 -112
  29. package/runtime/engine/orca-config.mjs +0 -34
  30. package/runtime/engine/plain-object.mjs +0 -5
  31. package/runtime/engine/release-config.mjs +0 -32
  32. package/runtime/engine/removed-vocabulary.mjs +0 -27
  33. package/runtime/engine/resources-config.mjs +0 -59
  34. package/runtime/engine/runtime-root.mjs +0 -138
  35. package/runtime/engine/secrets.mjs +0 -202
  36. package/runtime/engine/sonar-config.mjs +0 -24
  37. package/runtime/engine/temp-root.mjs +0 -26
  38. package/runtime/engine/yaml.mjs +0 -161
  39. package/runtime/knowledge/grammars/index.yaml +0 -114
  40. package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
  41. package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
  42. package/runtime/knowledge/hfs/rules.yaml +0 -6760
  43. package/runtime/knowledge/hfs/slots.yaml +0 -2783
  44. package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
  45. package/runtime/knowledge/sonar-gate.yaml +0 -151
  46. package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
  47. package/runtime/modules/models/registry.yaml +0 -221
  48. package/runtime/modules/models/runtimes.yaml +0 -556
  49. package/runtime/modules/models/tiers.yaml +0 -66
  50. package/runtime/scripts/api/git/cat-file.mjs +0 -4
  51. package/runtime/scripts/api/git/config-get.mjs +0 -9
  52. package/runtime/scripts/api/git/diff.mjs +0 -4
  53. package/runtime/scripts/api/git/lib.mjs +0 -80
  54. package/runtime/scripts/api/git/ls-files.mjs +0 -5
  55. package/runtime/scripts/api/git/ls-tree.mjs +0 -4
  56. package/runtime/scripts/api/git/merge-base.mjs +0 -8
  57. package/runtime/scripts/api/git/remote.mjs +0 -4
  58. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
  59. package/runtime/scripts/api/git/show.mjs +0 -5
  60. package/runtime/scripts/api/git/tag.mjs +0 -4
  61. package/runtime/scripts/hfs/allows.mjs +0 -77
  62. package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
  63. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
  64. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
  65. package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
  66. package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
  67. package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
  68. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
  69. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
  70. package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
  71. package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
  72. package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
  73. package/runtime/scripts/hfs/architecture/config.mjs +0 -407
  74. package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
  75. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
  76. package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
  77. package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
  78. package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
  79. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
  80. package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
  81. package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
  82. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
  83. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
  84. package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
  85. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
  86. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
  87. package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
  88. package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
  89. package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
  90. package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
  91. package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
  92. package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
  93. package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
  94. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
  95. package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
  96. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
  97. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
  98. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
  99. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
  100. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
  101. package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
  102. package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
  103. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
  104. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
  105. package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
  106. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
  107. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
  108. package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
  109. package/runtime/scripts/hfs/architecture/index.mjs +0 -402
  110. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
  111. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
  112. package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
  113. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
  114. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
  115. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
  116. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
  117. package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
  118. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
  119. package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
  120. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
  121. package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
  122. package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
  123. package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
  124. package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
  125. package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
  126. package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
  127. package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
  128. package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
  129. package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
  130. package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
  131. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
  132. package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
  133. package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
  134. package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
  135. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
  136. package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
  137. package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
  138. package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
  139. package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
  140. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
  141. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
  142. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
  143. package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
  144. package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
  145. package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
  146. package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
  147. package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
  148. package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
  149. package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
  150. package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
  151. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
  152. package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
  153. package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
  154. package/runtime/scripts/hfs/edition-slots.mjs +0 -80
  155. package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
  156. package/runtime/scripts/hfs/linear-text.mjs +0 -30
  157. package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
  158. package/runtime/scripts/hfs/param-names.mjs +0 -13
  159. package/runtime/scripts/hfs/path-findings.mjs +0 -167
  160. package/runtime/scripts/hfs/repo-identity.mjs +0 -89
  161. package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
  162. package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
  163. package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
  164. package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
  165. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
  166. package/runtime/scripts/hfs/rules/read.mjs +0 -45
  167. package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
  168. package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
  169. package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
  170. package/runtime/scripts/hfs/slot-classify.mjs +0 -69
  171. package/runtime/scripts/hfs/slot-errors.mjs +0 -12
  172. package/runtime/scripts/hfs/slot-imports.mjs +0 -98
  173. package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
  174. package/runtime/scripts/hfs/slot-match.mjs +0 -164
  175. package/runtime/scripts/hfs/slot-path.mjs +0 -6
  176. package/runtime/scripts/hfs/slot-required.mjs +0 -95
  177. package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
  178. package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
  179. package/runtime/scripts/hfs/slots.mjs +0 -306
  180. package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
  181. package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
  182. package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
  183. package/runtime/scripts/hfs/view.mjs +0 -180
  184. package/runtime/scripts/lib/declaration-surface.mjs +0 -166
  185. package/runtime/scripts/lib/dockerfile.mjs +0 -164
  186. package/runtime/scripts/lib/env.mjs +0 -18
  187. package/runtime/scripts/lib/event-contract.mjs +0 -102
  188. package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
  189. package/runtime/scripts/lib/git.mjs +0 -35
  190. package/runtime/scripts/lib/glob.mjs +0 -32
  191. package/runtime/scripts/lib/grammar-lint.mjs +0 -57
  192. package/runtime/scripts/lib/i18n.mjs +0 -82
  193. package/runtime/scripts/lib/in-order.mjs +0 -90
  194. package/runtime/scripts/lib/json-clone.mjs +0 -70
  195. package/runtime/scripts/lib/json.mjs +0 -44
  196. package/runtime/scripts/lib/language.mjs +0 -233
  197. package/runtime/scripts/lib/list.mjs +0 -26
  198. package/runtime/scripts/lib/mutation-fence.mjs +0 -20
  199. package/runtime/scripts/lib/package-at.mjs +0 -62
  200. package/runtime/scripts/lib/path-key.mjs +0 -124
  201. package/runtime/scripts/lib/read-text.mjs +0 -47
  202. package/runtime/scripts/lib/regex.mjs +0 -3
  203. package/runtime/scripts/lib/rule-packs.mjs +0 -243
  204. package/runtime/scripts/lib/same-text.mjs +0 -4
  205. package/runtime/scripts/lib/secret-patterns.mjs +0 -230
  206. package/runtime/scripts/lib/sops-envelope.mjs +0 -212
  207. package/runtime/scripts/lib/stack-services.mjs +0 -191
  208. package/runtime/scripts/lib/ts-analysis.mjs +0 -39
  209. package/runtime/scripts/lib/ts-ast.mjs +0 -63
  210. package/runtime/scripts/lib/walk.mjs +0 -45
  211. package/runtime/scripts/lib/yaml-cached.mjs +0 -14
@@ -1,92 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { treeOf } from './required-files.mjs';
4
- import { byCodeUnit } from '../../lib/list.mjs';
5
- /**
6
- * R63 `package-shape` (FE_PACKAGE_SHAPE, knowledge/hfs/README.md 6.2). A shared package is built to `dist` and says what it
7
- * exports. The package manifest of every package owner (slots repo.packages and fe.package.ui, packages/<pkg>/package.json)
8
- * must have:
9
- *
10
- * - a `scripts.build`;
11
- * - an explicit `exports` map: present, no `*` pattern in a subpath, no folder mapping;
12
- * - every export target, and `main`, `module`, `types` and `typings` when present, inside `./dist/`: a target into `src/`
13
- * ships source that was never built.
14
- *
15
- * `export *` in the package entry is ARCH_OWNER_EXPORT_STAR, a dead unit is HFS_UNUSED_EXPORT and the package tiers are the
16
- * eslint rule `monorepo-tier-belongs-to-its-side`; none is judged a second time here.
17
- */
18
- export const PACKAGE_SHAPE_RULE_IDS = ['FE_PACKAGE_SHAPE'];
19
- const RULE = 'FE_PACKAGE_SHAPE';
20
- const UNREADABLE = Symbol('unreadable');
21
- /** Every string target of an exports value (a string, a condition map, an array of either), with the condition path. */
22
- function targetsOf(value, trail = []) {
23
- if (typeof value === 'string')
24
- return [{ target: value, trail }];
25
- if (Array.isArray(value))
26
- return value.flatMap((item, index) => targetsOf(item, [...trail, String(index)]));
27
- if (value && typeof value === 'object')
28
- return Object.entries(value).flatMap(([key, item]) => targetsOf(item, [...trail, key]));
29
- return [];
30
- }
31
- const insideDist = (target) => path.posix.normalize(target).replace(/^\.\//u, '').startsWith('dist/');
32
- function packageRoots(config, resolver) {
33
- const roots = new Set();
34
- for (const rel of treeOf(config.root).files) {
35
- const owner = resolver.ownerOf(rel);
36
- if (owner && resolver.slot(owner.slot)?.tier === 'package')
37
- roots.add(owner.root);
38
- }
39
- return [...roots].sort(byCodeUnit);
40
- }
41
- function readManifest(config, manifestRel) {
42
- try {
43
- return JSON.parse(fs.readFileSync(path.join(config.root, ...manifestRel.split('/')), 'utf8')); // reason: parsed from disk; the fields read are checked at use
44
- }
45
- catch {
46
- return UNREADABLE;
47
- }
48
- }
49
- function reportExportIssues(manifest, manifestRel, report) {
50
- if (manifest.exports === undefined) {
51
- report(`${manifestRel} declares no exports map; a package lists what it exports, subpath by subpath, each pointing into ./dist/.`);
52
- return;
53
- }
54
- if (typeof manifest.exports === 'object' && !Array.isArray(manifest.exports)) {
55
- for (const key of Object.keys(manifest.exports)) { // reason: typeof narrows to object | null; a null exports map throws here exactly as before
56
- if (key.includes('*') || key.endsWith('/'))
57
- report(`exports key "${key}" of ${manifestRel} is a pattern or folder mapping; list each exported subpath explicitly.`, { export: key });
58
- }
59
- }
60
- for (const { target, trail } of targetsOf(manifest.exports)) {
61
- if (!insideDist(target))
62
- report(`exports target "${target}" (${trail.join(' > ') || '.'}) of ${manifestRel} is not inside ./dist/; a package exports what it built, never its source.`, { export: target });
63
- }
64
- }
65
- function reportManifestIssues(manifest, manifestRel, report) {
66
- if (typeof manifest.scripts?.build !== 'string' || !manifest.scripts.build.trim())
67
- report(`${manifestRel} has no scripts.build; a shared package is built to dist before an app consumes it.`);
68
- reportExportIssues(manifest, manifestRel, report);
69
- for (const field of ['main', 'module', 'types', 'typings']) {
70
- if (typeof manifest[field] === 'string' && !insideDist(manifest[field]))
71
- report(`${field} "${manifest[field]}" of ${manifestRel} is not inside ./dist/; a package points at what it built.`, { field });
72
- }
73
- }
74
- function inspectPackage(config, root, violations) {
75
- const manifestRel = `${root}/package.json`;
76
- const report = (message, extra = {}) => violations.push({ ruleId: RULE, path: manifestRel, line: 1, column: 1, package: root, message, ...extra });
77
- const manifest = readManifest(config, manifestRel);
78
- if (manifest === UNREADABLE)
79
- return false;
80
- reportManifestIssues(manifest, manifestRel, report);
81
- return true;
82
- }
83
- export function checkPackageShape({ config, graph }) {
84
- const roots = packageRoots(config, graph.resolver);
85
- const violations = [];
86
- let packages = 0;
87
- for (const root of roots) {
88
- if (inspectPackage(config, root, violations))
89
- packages += 1;
90
- }
91
- return { violations, coverage: { status: 'checked', packages } };
92
- }
@@ -1,173 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { repositoryName } from '../repo-identity.mjs';
4
- import { managedScriptNames } from './managed-scripts.mjs';
5
- import { trimTrailingChars } from '../linear-text.mjs';
6
- const RUNTIME_ROOT_MARKDOWN = new Set(['README.md', 'CONTEXT.md', 'CONTRIBUTING.md', 'CHANGELOG.md', 'THIRD_PARTY_NOTICES.md']);
7
- const PRODUCT_ROOT_MARKDOWN = new Set(['README.md']);
8
- const README_SECTIONS = ['Overview', 'Stack', 'Repository layout', 'Development'];
9
- const DEVELOPMENT_SCRIPTS = ['typecheck', 'lint', 'build', 'test'];
10
- const README_HEADING = new RegExp(['^## ', '(.+?)', String.raw `\s*$`].join(''), 'u');
11
- const README_URL = new RegExp(['https?:', String.raw `\/\/`, String.raw `[^\s<>)"']+`].join(''), 'giu');
12
- function privateHost(hostname) {
13
- const host = hostname.toLowerCase().replace(/^\[|\]$/g, '').replace(/\.$/, '');
14
- if (host === 'localhost' || host === '::1' || host === '0.0.0.0' ||
15
- /(?:\.localhost|\.local|\.internal|\.lan)$/u.test(host))
16
- return true;
17
- if (host.includes(':'))
18
- return /^(?:::|f[cd][0-9a-f]*:|fe[89ab][0-9a-f]*:)/iu.test(host);
19
- if (!host.includes('.'))
20
- return true;
21
- const octets = host.split('.');
22
- if (octets.length !== 4 || !octets.every(part => /^\d{1,3}$/u.test(part) && Number(part) <= 255))
23
- return false;
24
- const [a = Number.NaN, b = Number.NaN] = octets.map(Number);
25
- return a === 0 || a === 10 || a === 127 || a === 169 && b === 254 ||
26
- a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168 || a === 100 && b >= 64 && b <= 127;
27
- }
28
- function scriptCommand(name) {
29
- const escaped = name.replace(/[.*+?^${}()|[\]\\]/gu, String.raw `\$&`);
30
- return new RegExp(name === 'test' ? String.raw `npm (?:run test|test)(?![\w:-])` : String.raw `npm run ${escaped}(?![\w:-])`, 'u');
31
- }
32
- function addFinding(state, ruleId, entry, message, line = 1) {
33
- state.violations.push({ ruleId, path: entry, line, column: 1, message });
34
- }
35
- function checkRootPackageManager(state) {
36
- try {
37
- const pkg = JSON.parse(fs.readFileSync(path.join(state.root, 'package.json'), 'utf8'));
38
- if (pkg.packageManager && !/^npm@\d/u.test(pkg.packageManager))
39
- addFinding(state, 'HFS_PACKAGE_MANAGER_MIXED', 'package.json', `packageManager ${pkg.packageManager} contradicts the npm package-lock.json contract.`);
40
- }
41
- catch { /* The repository's package/config checks own unreadable or invalid JSON. */ }
42
- }
43
- function checkRootPresentation(state) {
44
- const { runtime, tree } = state;
45
- for (const entry of tree.top) {
46
- if (/\.md$/iu.test(entry) && !(runtime ? RUNTIME_ROOT_MARKDOWN : PRODUCT_ROOT_MARKDOWN).has(entry))
47
- addFinding(state, 'HFS_ROOT_MARKDOWN_FORBIDDEN', entry, `Root Markdown ${entry} belongs under docs/ or the owning Work record.`);
48
- if (state.nonNpmEntries.has(entry))
49
- addFinding(state, 'HFS_PACKAGE_MANAGER_MIXED', entry, `${entry} contradicts the npm package manager contract.`);
50
- }
51
- for (const entry of ['.gitattributes', 'README.md']) {
52
- if (!tree.hasFile(entry))
53
- addFinding(state, 'HFS_ROOT_ENTRY_MISSING', entry, `Repository presentation requires root ${entry}.`);
54
- }
55
- if (tree.hasFile('package.json'))
56
- checkRootPackageManager(state);
57
- }
58
- function readmeSectionBody(lines, headings, section) {
59
- const start = headings.find(item => item.name === section)?.index;
60
- if (start === undefined)
61
- return '';
62
- const end = headings.find(item => item.index > start)?.index ?? lines.length;
63
- return lines.slice(start + 1, end).join('\n');
64
- }
65
- function checkReadmeHeadings(state, lines) {
66
- const { root, runtime, tree } = state;
67
- const name = runtime ? 'StarCi' : repositoryName(root);
68
- if ((lines[0] ?? '').trim().toLowerCase() !== `# ${name}`.toLowerCase())
69
- addFinding(state, 'HFS_README_TITLE_INVALID', 'README.md', `README.md must start with # ${name}.`);
70
- const description = lines.slice(1).find(line => line.trim());
71
- if (!description || /^\s*(?:#|!\[|\[!\[)/u.test(description) || description.trim().length > 240)
72
- addFinding(state, 'HFS_README_DESCRIPTION_INVALID', 'README.md', 'Place one concise description line directly below the repository name.');
73
- const headings = lines.map((line, index) => ({ name: README_HEADING.exec(line)?.[1], index })).filter((item) => Boolean(item.name));
74
- const required = [...README_SECTIONS, ...(tree.hasDir('.starciwork') ? ['Work'] : [])];
75
- let previous = -1;
76
- for (const section of required) {
77
- const found = headings.find(item => item.name === section);
78
- if (!found)
79
- addFinding(state, 'HFS_README_SECTION_MISSING', 'README.md', `README.md requires a ## ${section} section.`);
80
- else if (found.index <= previous)
81
- addFinding(state, 'HFS_README_SECTION_ORDER', 'README.md', `## ${section} must follow the preceding standard section.`, found.index + 1);
82
- else
83
- previous = found.index;
84
- }
85
- return headings;
86
- }
87
- function checkReadmeDevelopment(state, lines, headings) {
88
- if (state.runtime || !headings.some(item => item.name === 'Development'))
89
- return;
90
- const development = readmeSectionBody(lines, headings, 'Development');
91
- const scripts = DEVELOPMENT_SCRIPTS.filter(name => managedScriptNames(state.profile, state.edition).has(name));
92
- const commands = [/npm (?:ci|install)/u, ...scripts.map(scriptCommand)];
93
- if (commands.some(command => !command.test(development))) {
94
- addFinding(state, 'HFS_README_DEVELOPMENT_INCOMPLETE', 'README.md', 'Development must show npm install and the managed script commands: '
95
- + scripts.map(name => (name === 'test' ? 'npm test' : `npm run ${name}`)).join(', ') + '.');
96
- }
97
- }
98
- function checkReadmeWorkPointer(state, lines, headings) {
99
- if (state.tree.hasDir('.starciwork') && headings.some(item => item.name === 'Work') &&
100
- !/\.starciwork\b/u.test(readmeSectionBody(lines, headings, 'Work')))
101
- addFinding(state, 'HFS_README_WORK_POINTER_MISSING', 'README.md', 'Work must point at the backend .starciwork tree.');
102
- }
103
- function inspectReadmeUrl(state, value, line) {
104
- try {
105
- if (privateHost(new URL(value).hostname))
106
- addFinding(state, 'HFS_README_PRIVATE_URL', 'README.md', `README URL ${value} points at a local or private host.`, line);
107
- }
108
- catch { /* Malformed URLs are outside this presentation rule. */ }
109
- }
110
- function badgeTargets(prose) {
111
- return [
112
- ...[...prose.matchAll(/!\[([^\]]*)\]\(([^)]+)\)/gu)].map(match => ({ alt: match[1] ?? '', target: match[2] ?? '' })),
113
- ...[...prose.matchAll(/<img\b[^>]*>/giu)].map(match => ({
114
- alt: /\balt=["']([^"']*)["']/iu.exec(match[0])?.[1] ?? '',
115
- target: /\bsrc=["']([^"']*)["']/iu.exec(match[0])?.[1] ?? '',
116
- })),
117
- ];
118
- }
119
- function inspectBadgeTarget(state, alt, rawTarget, line) {
120
- const target = rawTarget.trim().replace(/^<|>$/gu, '');
121
- if (!/badge/iu.test(alt) && !/badge|shields\.io|badgen\.net/iu.test(target))
122
- return;
123
- try {
124
- const url = new URL(target);
125
- if (url.protocol !== 'https:' || privateHost(url.hostname) ||
126
- /^(?:img\.shields\.io|badgen\.net)$/iu.test(url.hostname) && url.pathname.startsWith('/badge/'))
127
- addFinding(state, 'HFS_README_BADGE_NOT_LIVE', 'README.md', `Badge ${target} must represent a live external HTTPS service.`, line);
128
- }
129
- catch {
130
- addFinding(state, 'HFS_README_BADGE_NOT_LIVE', 'README.md', `Badge ${target} must use a live external HTTPS service.`, line);
131
- }
132
- }
133
- function inspectReadmeLine(state, line, index, scan) {
134
- if (/^\s*```/u.test(line)) {
135
- scan.fenced = !scan.fenced;
136
- return;
137
- }
138
- if (scan.fenced)
139
- return;
140
- const prose = line.replace(/`[^`]*`/gu, '');
141
- for (const match of prose.matchAll(README_URL))
142
- inspectReadmeUrl(state, trimTrailingChars(match[0], '.,;!?'), index + 1);
143
- for (const badge of badgeTargets(prose))
144
- inspectBadgeTarget(state, badge.alt, badge.target, index + 1);
145
- }
146
- function checkReadmeLines(state, lines) {
147
- const scan = { fenced: false };
148
- for (let index = 0; index < lines.length; index += 1)
149
- inspectReadmeLine(state, lines[index] ?? '', index, scan);
150
- }
151
- function presentationResult(state) {
152
- return { violations: state.violations, coverage: { status: 'checked', source: state.tree.source } };
153
- }
154
- export function checkRepoPresentationImpl({ root, runtime, tree, profile, edition, nonNpmEntries }) {
155
- const state = { root, runtime, tree, profile, edition, nonNpmEntries, violations: [] };
156
- checkRootPresentation(state);
157
- if (!tree.hasFile('README.md'))
158
- return presentationResult(state);
159
- let readme;
160
- try {
161
- readme = fs.readFileSync(path.join(root, 'README.md'), 'utf8');
162
- }
163
- catch {
164
- addFinding(state, 'HFS_ROOT_ENTRY_MISSING', 'README.md', 'Tracked README.md is not readable.');
165
- return presentationResult(state);
166
- }
167
- const lines = readme.split(/\r?\n/u);
168
- const headings = checkReadmeHeadings(state, lines);
169
- checkReadmeDevelopment(state, lines, headings);
170
- checkReadmeWorkPointer(state, lines, headings);
171
- checkReadmeLines(state, lines);
172
- return presentationResult(state);
173
- }
@@ -1,330 +0,0 @@
1
- import { byCodeUnit } from '../../lib/list.mjs';
2
- export const REACHABILITY_RULE_IDS = ['BE_FEATURE_NOT_COMPOSED', 'FE_OWNER_REACHABLE', 'FE_HREF_RESOLVES'];
3
- const BE_CAPABILITY_SLOTS = new Set(['be.domain', 'be.integrations', 'be.platform', 'be.platform.logging']);
4
- const TEST_FILE = /(?:\.(?:spec|test|stories|e2e-spec)\.[cm]?[jt]sx?$)|(?:(?:^|\/)__tests__\/)/;
5
- const ROUTE_FILE = /^(?:page|route)\.(?:tsx|ts|jsx|js)$/;
6
- const PLACEHOLDER = '\u0000';
7
- const REGEX_SPECIALS = /[.*+?^${}()|[\]\\]/g;
8
- const ESCAPE_MATCH = String.raw `\$&`;
9
- /** Breadth-first reach over runtime, non-type-only edges (re-exports included) from `roots`. */
10
- function reachFrom(graph, roots) {
11
- const forward = new Map();
12
- for (const edge of graph.edges) {
13
- if (!edge.runtime)
14
- continue;
15
- if (!forward.has(edge.from))
16
- forward.set(edge.from, []);
17
- forward.get(edge.from)?.push(edge.to);
18
- }
19
- const reached = new Set(roots);
20
- const queue = [...roots];
21
- while (queue.length) {
22
- for (const next of forward.get(queue.shift()) ?? []) {
23
- if (reached.has(next))
24
- continue;
25
- reached.add(next);
26
- queue.push(next);
27
- }
28
- }
29
- return reached;
30
- }
31
- function ownerFiles(graph) {
32
- const byUnit = new Map();
33
- for (const [rel, node] of graph.files) {
34
- if (!node.owner)
35
- continue;
36
- const key = `${node.owner.slot}:${node.owner.root}`;
37
- if (!byUnit.has(key))
38
- byUnit.set(key, []);
39
- byUnit.get(key)?.push(rel);
40
- }
41
- return byUnit;
42
- }
43
- /** The file that stands for an owner in a finding: its public entry when the graph holds one, else its first file. */
44
- function entryOf(root, files) {
45
- const base = root.replace(/\/$/, '');
46
- const entry = new RegExp(String.raw `^${base.replace(REGEX_SPECIALS, ESCAPE_MATCH)}/index\.[tj]sx?$`);
47
- return files.find(rel => entry.test(rel)) ?? [...files].sort(byCodeUnit)[0];
48
- }
49
- function backendAppRoots(byUnit) {
50
- const rootFiles = [];
51
- const appRoots = new Set();
52
- for (const [key, files] of byUnit) {
53
- const slot = key.slice(0, key.indexOf(':'));
54
- if (!slot.startsWith('be.app.'))
55
- continue;
56
- appRoots.add(key.slice(key.indexOf(':') + 1));
57
- for (const rel of files)
58
- if (!TEST_FILE.test(rel))
59
- rootFiles.push(rel);
60
- }
61
- return { rootFiles, roots: [...appRoots].sort(byCodeUnit) };
62
- }
63
- function reportUncomposedBackendOwners(byUnit, reached, roots, counts, violations) {
64
- for (const [key, files] of [...byUnit].sort(([a], [b]) => a.localeCompare(b))) {
65
- const slot = key.slice(0, key.indexOf(':'));
66
- const root = key.slice(key.indexOf(':') + 1);
67
- const feature = slot === 'be.feature';
68
- if (!feature && !BE_CAPABILITY_SLOTS.has(slot))
69
- continue;
70
- counts[feature ? 'features' : 'modules'] += 1;
71
- if (files.some(rel => reached.has(rel)))
72
- continue;
73
- counts.notComposed += 1;
74
- const label = root.replace(/\/$/, '');
75
- violations.push({
76
- ruleId: 'BE_FEATURE_NOT_COMPOSED',
77
- path: entryOf(root, files), owner: label, slot, appRoots: roots,
78
- message: `${feature ? 'Feature' : 'Module'} ${label} is not composed into any app: no runtime import path leads from ${roots.join(', ')} to it (a type-only import composes nothing), so it is dead code that no process serves.`,
79
- });
80
- }
81
- }
82
- function checkBackend(graph) {
83
- const byUnit = ownerFiles(graph);
84
- const { rootFiles, roots } = backendAppRoots(byUnit);
85
- const counts = { features: 0, modules: 0, appRoots: roots.length, notComposed: 0 };
86
- if (!roots.length)
87
- return { violations: [], coverage: { status: 'unavailable', reason: 'no be.app.* owner instance holds a source file, so there is no app root to compose into', ...counts } };
88
- const reached = reachFrom(graph, rootFiles);
89
- const violations = [];
90
- reportUncomposedBackendOwners(byUnit, reached, roots, counts, violations);
91
- reportUncomposedTransports(graph, reached, roots, counts, violations);
92
- return { violations, coverage: { status: 'checked', ...counts } };
93
- }
94
- /** A reached feature does not compose its other transport modules. Judge each module's runtime path. */
95
- function reportUncomposedTransports(graph, reached, roots, counts, violations) {
96
- for (const [rel, node] of graph.files) {
97
- if (!node.owner || !rel.startsWith('src/features/') || TEST_FILE.test(rel))
98
- continue;
99
- if (!/\/transport\/[^/]+\/[^/]+\.module\.[cm]?[jt]sx?$/.test(rel) || reached.has(rel))
100
- continue;
101
- counts.notComposed += 1;
102
- violations.push({
103
- ruleId: 'BE_FEATURE_NOT_COMPOSED', path: rel, owner: node.owner.root, slot: node.slot, appRoots: roots,
104
- message: `Transport module ${rel} is not composed into any app: no runtime import path leads from ${roots.join(', ')} to it (a type-only import composes nothing).`,
105
- });
106
- }
107
- }
108
- /** Route table of one app: arrays of segments, each {kind:'static'|'dyn'|'catch'|'optcatch', text}. */
109
- function routeSegmentsOf(parts) {
110
- const segments = [];
111
- let usable = true;
112
- for (const part of parts) {
113
- if (/^\([^.)][^)]*\)$/.test(part))
114
- continue; // route group
115
- if (part.startsWith('@'))
116
- continue; // parallel slot: no URL segment
117
- if (part.startsWith('_') || /^\(\.+\)/.test(part)) {
118
- usable = false;
119
- break;
120
- } // private folder, intercepting route
121
- segments.push(part);
122
- }
123
- if (!usable)
124
- return null;
125
- if (segments[0] === '[locale]')
126
- segments.shift();
127
- return segments;
128
- }
129
- function routeSegmentOf(part) {
130
- if (/^\[\[\.\.\..+\]\]$/.test(part))
131
- return { kind: 'optcatch', text: part };
132
- if (/^\[\.\.\..+\]$/.test(part))
133
- return { kind: 'catch', text: part };
134
- if (/^\[.+\]$/.test(part))
135
- return { kind: 'dyn', text: part };
136
- return { kind: 'static', text: part };
137
- }
138
- function routeTable(graph, app) {
139
- const prefix = `apps/${app}/src/app/`;
140
- const routes = [];
141
- for (const rel of graph.files.keys()) {
142
- if (!rel.startsWith(prefix))
143
- continue;
144
- const parts = rel.slice(prefix.length).split('/');
145
- if (!ROUTE_FILE.test(parts.at(-1)))
146
- continue;
147
- const segments = routeSegmentsOf(parts.slice(0, -1));
148
- if (segments === null)
149
- continue;
150
- routes.push(segments.map(routeSegmentOf));
151
- }
152
- return routes;
153
- }
154
- /** One href segment (may contain PLACEHOLDER for a template expression) against one route segment. */
155
- function segmentMatches(hrefSegment, routeSegment) {
156
- if (!hrefSegment.includes(PLACEHOLDER))
157
- return routeSegment.kind === 'dyn' || routeSegment.text === hrefSegment;
158
- if (routeSegment.kind === 'dyn' || routeSegment.kind === 'catch' || routeSegment.kind === 'optcatch')
159
- return true;
160
- const parts = hrefSegment.split(PLACEHOLDER).map(part => part.replace(/[.*+?^${}()|[\]\\]/g, String.raw `\$&`));
161
- return new RegExp(`^${parts.join('.*')}$`).test(routeSegment.text);
162
- }
163
- function matchRoute(hrefSegments, route, at = 0, from = 0) {
164
- if (from === route.length)
165
- return at === hrefSegments.length;
166
- const routeSegment = route[from];
167
- if (routeSegment.kind === 'optcatch' && matchRoute(hrefSegments, route, at, from + 1))
168
- return true;
169
- if (routeSegment.kind === 'catch' || routeSegment.kind === 'optcatch') {
170
- for (let take = 1; at + take <= hrefSegments.length; take += 1)
171
- if (matchRoute(hrefSegments, route, at + take, from + 1))
172
- return true;
173
- return false;
174
- }
175
- if (at >= hrefSegments.length || !segmentMatches(hrefSegments[at], routeSegment))
176
- return false;
177
- return matchRoute(hrefSegments, route, at + 1, from + 1);
178
- }
179
- function hrefResolves(href, routes) {
180
- const cut = href.search(/[?#]/);
181
- const pathOnly = cut === -1 ? href : href.slice(0, cut);
182
- const segments = pathOnly.split('/').slice(1).filter(segment => segment !== '');
183
- const candidates = [segments];
184
- // A leading locale (a literal `en`/`vi-VN` or a bare template expression) is what [locale] carries: try without it too.
185
- if (segments.length && (/^[a-z]{2}(?:-[a-zA-Z]{2})?$/.test(segments[0]) || segments[0] === PLACEHOLDER))
186
- candidates.push(segments.slice(1));
187
- return candidates.some(candidate => routes.some(route => matchRoute(candidate, route)));
188
- }
189
- /** The text of a string-ish expression with PLACEHOLDER for each ${...}; null when it is not a literal we can read. */
190
- function literalText(ts, node) {
191
- if (!node)
192
- return null;
193
- while (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isNonNullExpression?.(node))
194
- node = node.expression;
195
- if (ts.isStringLiteralLike(node))
196
- return node.text; // includes NoSubstitutionTemplateLiteral
197
- if (ts.isTemplateExpression(node))
198
- return node.head.text + node.templateSpans.map(span => PLACEHOLDER + span.literal.text).join('');
199
- return null;
200
- }
201
- const NAVIGATION_CALLS = new Set(['redirect', 'permanentRedirect']);
202
- const ROUTER_METHODS = new Set(['push', 'replace', 'prefetch']);
203
- /** Every href-like target in a source file: {node, text|null (null = computed)}. */
204
- function jsxHrefTarget(ts, node) {
205
- if (!ts.isJsxAttribute(node) || !ts.isIdentifier(node.name) || node.name.text !== 'href' || !node.initializer)
206
- return null;
207
- const value = ts.isJsxExpression(node.initializer) ? node.initializer.expression : node.initializer;
208
- return { node: value ?? node, text: value ? literalText(ts, value) : null };
209
- }
210
- function routerNameOf(ts, callee) {
211
- if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression))
212
- return callee.expression.text;
213
- if (ts.isPropertyAccessExpression(callee) && ts.isPropertyAccessExpression(callee.expression))
214
- return callee.expression.name.text;
215
- return '';
216
- }
217
- function isNavigationTarget(ts, callee) {
218
- const routerName = routerNameOf(ts, callee);
219
- return (ts.isIdentifier(callee) && NAVIGATION_CALLS.has(callee.text))
220
- || (ts.isPropertyAccessExpression(callee) && ROUTER_METHODS.has(callee.name.text) && /router$/i.test(routerName));
221
- }
222
- function callHrefTarget(ts, node) {
223
- if (!ts.isCallExpression(node) || !node.arguments.length)
224
- return null;
225
- const callee = node.expression;
226
- if (!isNavigationTarget(ts, callee))
227
- return null;
228
- return { node: node.arguments[0], text: literalText(ts, node.arguments[0]) };
229
- }
230
- function hrefTargetOf(ts, node) {
231
- return jsxHrefTarget(ts, node) ?? callHrefTarget(ts, node);
232
- }
233
- function hrefTargets(ts, sourceFile) {
234
- const found = [];
235
- const visit = (node) => {
236
- const target = hrefTargetOf(ts, node);
237
- if (target)
238
- found.push(target);
239
- ts.forEachChild(node, visit);
240
- };
241
- visit(sourceFile);
242
- return found;
243
- }
244
- function appRouteRoots(graph) {
245
- const apps = new Map();
246
- for (const [rel, node] of graph.files) {
247
- if (node.slot !== 'fe.route')
248
- continue;
249
- const app = /^apps\/([^/]+)\/src\/app\//.exec(rel)?.[1];
250
- if (!app)
251
- continue;
252
- if (!apps.has(app))
253
- apps.set(app, []);
254
- apps.get(app)?.push(rel);
255
- }
256
- return apps;
257
- }
258
- function reportUnreachableFrontendFeatures(byUnit, reachedByApp, counts, violations) {
259
- for (const [key, files] of [...byUnit].sort(([a], [b]) => a.localeCompare(b))) {
260
- if (!key.startsWith('fe.feature:'))
261
- continue;
262
- const root = key.slice('fe.feature:'.length);
263
- const app = /^apps\/([^/]+)\//.exec(root)?.[1];
264
- counts.pages += 1;
265
- const reached = reachedByApp.get(app);
266
- if (reached && files.some(rel => reached.has(rel))) {
267
- counts.mounted += 1;
268
- continue;
269
- }
270
- const label = root.replace(/\/$/, '');
271
- violations.push({
272
- ruleId: 'FE_OWNER_REACHABLE', path: entryOf(root, files), owner: label, app,
273
- message: `${label} is not mounted: no runtime import path leads from a route file under apps/${app}/src/app to it (a type-only import mounts nothing), so the page is never shown.`,
274
- });
275
- }
276
- }
277
- function routeApps(graph, apps) {
278
- return [...new Set([...apps.keys(), ...[...graph.files.keys()].map(rel => /^apps\/([^/]+)\/src\//.exec(rel)?.[1]).filter((app) => Boolean(app))])].sort(byCodeUnit);
279
- }
280
- function hrefNeedsSkipping(text, routes) {
281
- if (text === null || !text.startsWith('/') || text.startsWith('//') || !routes.length)
282
- return true;
283
- const hrefPath = text.split(/[?#]/)[0];
284
- return /\.[A-Za-z0-9]{1,6}$/.test(hrefPath.split('/').at(-1)); // static asset
285
- }
286
- function reportUnresolvedHref(app, rel, node, target, prefix, violations) {
287
- const point = node.sourceFile.getLineAndCharacterOfPosition(target.node.getStart(node.sourceFile));
288
- const shown = target.text.split(PLACEHOLDER).join('${…}');
289
- violations.push({
290
- ruleId: 'FE_HREF_RESOLVES', path: rel, line: point.line + 1, column: point.character + 1, app, href: shown,
291
- message: `href "${shown}" matches no route of app ${app}: no page.tsx or route.ts under ${prefix}app serves that path.`,
292
- });
293
- }
294
- function inspectAppHrefTargets(app, graph, ts, routes, counts, violations) {
295
- const prefix = `apps/${app}/src/`;
296
- for (const [rel, node] of graph.files) {
297
- if (!rel.startsWith(prefix) || TEST_FILE.test(rel))
298
- continue;
299
- for (const target of hrefTargets(ts, node.sourceFile)) {
300
- counts.hrefs += 1;
301
- if (hrefNeedsSkipping(target.text, routes)) {
302
- counts.hrefsSkipped += 1;
303
- continue;
304
- }
305
- if (hrefResolves(target.text, routes)) {
306
- counts.hrefsResolved += 1;
307
- continue;
308
- }
309
- reportUnresolvedHref(app, rel, node, target, prefix, violations);
310
- }
311
- }
312
- }
313
- function checkFrontend(_config, context, graph) {
314
- const ts = context.ts ?? context.loaded.ts;
315
- const byUnit = ownerFiles(graph);
316
- const apps = appRouteRoots(graph);
317
- const counts = { pages: 0, mounted: 0, hrefs: 0, hrefsResolved: 0, hrefsSkipped: 0, routes: 0 };
318
- const violations = [];
319
- const reachedByApp = new Map([...apps].map(([app, roots]) => [app, reachFrom(graph, roots)]));
320
- reportUnreachableFrontendFeatures(byUnit, reachedByApp, counts, violations);
321
- for (const app of routeApps(graph, apps)) {
322
- const routes = routeTable(graph, app);
323
- counts.routes += routes.length;
324
- inspectAppHrefTargets(app, graph, ts, routes, counts, violations);
325
- }
326
- return { violations, coverage: { status: 'checked', ...counts } };
327
- }
328
- export function checkReachability({ config, context, graph }) {
329
- return graph.profile === 'be' ? checkBackend(graph) : checkFrontend(config, context, graph);
330
- }