@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,124 +0,0 @@
1
- // path-key.mjs — spelling and comparing paths the way this host's filesystem does.
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- const WIN = process.platform === 'win32';
5
- /** `p` with every backslash turned into a forward slash; null and undefined read as ''. */
6
- export const slash = (p) => String(p ?? '').replaceAll('\\', '/');
7
- /** `text` without its trailing '/' run (a loop: a trailing-run pattern backtracks super-linearly). */
8
- export const trimTrailingSlashes = (text) => {
9
- for (let end = text.length;; end -= 1)
10
- if (end === 0 || text[end - 1] !== '/')
11
- return text.slice(0, end);
12
- };
13
- // A trailing '*' run with the one '/' before it (the glob suffix of 'dir/**'); text without a trailing '*' is unchanged.
14
- const stripTrailingStars = (text) => {
15
- let end = text.length;
16
- while (end > 0 && text[end - 1] === '*')
17
- end -= 1;
18
- if (end === text.length)
19
- return text;
20
- return text.slice(0, end > 0 && text[end - 1] === '/' ? end - 1 : end);
21
- };
22
- /** A relative path in git's spelling: forward slashes, no leading './'. */
23
- export const posixPath = (p) => slash(p).replace(/^\.\//, '');
24
- /** Whether posix `file` is `prefix` itself or under it (`file === prefix || file` starts with `prefix/`). */
25
- export const sameOrUnder = (file, prefix) => file === prefix || file.startsWith(`${prefix}/`);
26
- /** `p` case-folded where the filesystem ignores case (Windows). */
27
- export const foldCase = (p) => (WIN ? p.toLowerCase() : p);
28
- /** Whether two spellings name the same path on this host's filesystem. */
29
- export const samePath = (a, b) => foldCase(a) === foldCase(b);
30
- /**
31
- * A path's comparable identity: absolute, forward slashes, no trailing slash, case-folded on Windows.
32
- * `fold: true` folds case on every platform (a comparison against a lowercase-stored root needs it).
33
- */
34
- export const pathKey = (p, { fold = WIN } = {}) => {
35
- const key = trimTrailingSlashes(slash(path.resolve(p)));
36
- return fold ? key.toLowerCase() : key;
37
- };
38
- /** `a` is `b` or under it, or the reverse: two path spellings whose trees touch. */
39
- export const pathsOverlap = (a, b) => sameOrUnder(a, b) || sameOrUnder(b, a);
40
- /**
41
- * A path-ish string in compare form, options in spelling order:
42
- * `trim` blanks at the ends, `collapse` folds '//' runs to '/', `dot` drops a leading './',
43
- * `glob` strips a trailing glob ('star': '*'/'**' with their slash, 'double': a '/**' only),
44
- * `fold` lowercases. A trailing '/' always goes. Null reads as ''.
45
- * @param {string|number|null|undefined} p
46
- * @param {{trim?: boolean, collapse?: boolean, dot?: boolean, glob?: string|null, fold?: boolean}} [options]
47
- */
48
- export const normPath = (p, { trim = false, collapse = false, dot = false, glob = null, fold = false } = {}) => {
49
- let s = p == null ? '' : String(p);
50
- if (trim)
51
- s = s.trim();
52
- s = slash(s);
53
- if (collapse)
54
- s = s.replace(/\/{2,}/g, '/');
55
- if (dot)
56
- s = s.replace(/^\.\//, '');
57
- if (glob === 'star')
58
- s = stripTrailingStars(s);
59
- else if (glob === 'double')
60
- s = s.replace(/\/\*\*$/, '');
61
- s = trimTrailingSlashes(s);
62
- return fold ? s.toLowerCase() : s;
63
- };
64
- /** A work-relative path in one spelling: forward slashes, no leading ./, no trailing slash. */
65
- export const normWork = (p) => trimTrailingSlashes(String(p ?? '').trim().replaceAll('\\', '/').replace(/^\.\/+/, ''));
66
- /** `p` resolved and dereferenced (realpath where the path exists) — the canonical spelling of a checkout dir. */
67
- export const realPath = (p) => {
68
- const resolved = path.resolve(p);
69
- try {
70
- return fs.realpathSync.native(resolved);
71
- }
72
- catch {
73
- return resolved;
74
- }
75
- };
76
- /** `p` with its nearest existing ancestor dereferenced and the not-yet-created rest appended: a root's canonical spelling before it exists. */
77
- export const canonicalPath = (p) => {
78
- const rest = [];
79
- for (let at = path.resolve(p);; at = path.dirname(at)) {
80
- try {
81
- return path.join(fs.realpathSync.native(at), ...rest);
82
- }
83
- catch { /* not created yet */ }
84
- if (path.dirname(at) === at)
85
- return path.resolve(p);
86
- rest.unshift(path.basename(at));
87
- }
88
- };
89
- /** `p` resolved and case-folded where the filesystem ignores case — the Map key of an absolute path. */
90
- export const resolvedKey = (p) => foldCase(path.resolve(p));
91
- /** Whether `a` and `b` resolve to the same path (always case-folded, so differently-cased spellings count). */
92
- export const sameResolvedPath = (a, b) => pathKey(a, { fold: true }) === pathKey(b, { fold: true });
93
- /**
94
- * Whether `file` sits under `root`; `includeSelf` also admits the root itself. `key` normalizes
95
- * both sides first (e.g. the registry's realpath-folded treeKey) when their spellings need it.
96
- */
97
- export const insidePath = (root, file, { key = (p) => p, includeSelf = false } = {}) => {
98
- const rel = path.relative(key(root), key(file));
99
- return (includeSelf || Boolean(rel)) && !rel.startsWith('..') && !path.isAbsolute(rel);
100
- };
101
- /**
102
- * `candidate` (absolute, or relative to `base`) resolved and dereferenced, required to sit under `base` (or be it):
103
- * the boundary check for a path an operator, an agent or another process hands in. `base` is canonicalised once and the
104
- * candidate is judged below it, so `..` segments and links leading out are refused; returns the canonical path, or throws
105
- * a PATH_OUTSIDE_BASE refusal (`label` names the argument in the message).
106
- */
107
- export const containedPath = (base, candidate, { label = 'path' } = {}) => {
108
- const root = canonicalPath(base);
109
- const resolved = canonicalPath(path.resolve(root, String(candidate ?? '')));
110
- const prefix = root.endsWith(path.sep) ? root : root + path.sep;
111
- if (!insidePath(root, resolved, { includeSelf: true }) || (resolved !== root && !resolved.startsWith(prefix)))
112
- throw Object.assign(new Error(`${label} ${String(candidate)} is outside ${root} [PATH_OUTSIDE_BASE]`), { code: 'PATH_OUTSIDE_BASE' });
113
- return resolved;
114
- };
115
- /**
116
- * A path-ish value (a string or a {path} entry) in relative compare form: trimmed, forward slashes,
117
- * no trailing '/**' glob or slashes, no leading './'; `fold` lowercases for a case-insensitive key.
118
- */
119
- export const normRel = (p, { fold = false } = {}) => {
120
- const s = trimTrailingSlashes(String(typeof p === 'string' ? p : p?.path ?? '').trim().replaceAll('\\', '/').replace(/\/\*\*$/, '')).replace(/^\.\//, '');
121
- return fold ? s.toLowerCase() : s;
122
- };
123
- /** Whether `file` equals or sits under one of `prefixes` (posix spellings; `dot` counts a '.' prefix as covering all). */
124
- export const underAny = (file, prefixes, { dot = false } = {}) => (prefixes ?? []).some((p) => (dot && p === '.') || sameOrUnder(file, p));
@@ -1,47 +0,0 @@
1
- // read-text.mjs — the forgiving text read: a missing or unreadable file is the caller's fallback,
2
- // never a throw (the JSON twin is ./json.mjs readJsonFile, the YAML twin ./read-yaml.mjs).
3
- import fs from 'node:fs';
4
- import path from 'node:path';
5
- /** The text of `rel` under `root` ('/'-separated rel), or null when it is missing or unreadable. */
6
- export const readTextFile = (root, rel) => {
7
- try {
8
- return fs.readFileSync(path.join(root, ...String(rel).split('/')), 'utf8');
9
- }
10
- catch {
11
- return null;
12
- }
13
- };
14
- /** `file` read and parsed by `parse`, or `fallback` when it is missing, unreadable or malformed. */
15
- export const readParsedFile = (file, parse, fallback = null) => {
16
- try {
17
- return parse(fs.readFileSync(file, 'utf8'));
18
- }
19
- catch {
20
- return fallback;
21
- }
22
- };
23
- /**
24
- * Feed `file`'s lines to `onLine` reading in bounded chunks — a diff or a patch can exceed any single
25
- * string. `eol` is the line-ending pattern or literal (default CRLF-aware); a last unterminated line is fed too.
26
- */
27
- export function forEachFileLine(file, onLine, { chunkBytes = 8 * 1024 * 1024, eol = /\r?\n/ } = {}) {
28
- const fd = fs.openSync(file, 'r');
29
- try {
30
- const buf = Buffer.alloc(chunkBytes);
31
- let carry = '';
32
- for (;;) {
33
- const n = fs.readSync(fd, buf, 0, chunkBytes, null);
34
- if (n <= 0)
35
- break;
36
- const lines = (carry + buf.toString('utf8', 0, n)).split(eol);
37
- carry = lines.pop();
38
- for (const l of lines)
39
- onLine(l);
40
- }
41
- if (carry)
42
- onLine(carry);
43
- }
44
- finally {
45
- fs.closeSync(fd);
46
- }
47
- }
@@ -1,3 +0,0 @@
1
- // regex.mjs - building a RegExp from text.
2
- /** `text` with every regular-expression metacharacter escaped, so it matches itself literally. */
3
- export const escapeRegExp = (text) => String(text).replace(/[.*+?^${}()|[\]\\]/g, String.raw `\$&`);
@@ -1,243 +0,0 @@
1
- // rule-packs.mjs - an app's rule packs (PROJECT-LINT-3): the packages hfs.json `rulePacks` names, each adding the app's own laws to the harness's
2
- // gates without a local rule in a tool config. A pack is an installed package that exports `./rule-pack`, an ES module whose default export is
3
- // { schema: 'starci/rule-pack@1', name: '<the package name>', rules: [<rule>, ...] }
4
- // and every rule carries an id (`NIVO-BLOCK-1`), a finding code (`NIVO_BLOCK_INCOMPLETE`), a severity (error or warning), the spec that proves it
5
- // (a file of the package) and its doc (a file of the package or an https link), plus exactly one engine:
6
- // check a machine rule `(context) => findings` of the hfs family: `starci app check` runs it over the tracked files (context.files, context.read)
7
- // eslint { name, rule, sides } an ESLint rule the canon factories (eslint-canon-be, eslint-canon-fe, the packages config) load for the sides it names
8
- // A pack only adds: a rule with any other key (an `off`, `overrides` or `disable`), a code the harness already reports, or an id or code another
9
- // pack uses is refused (HFS_RULE_PACK_INVALID, R381) and the pack lends nothing. Pack findings go through the same policy as the harness's own:
10
- // a check rule is an hfs finding (blocking on every branch), an eslint rule a lint finding (report under a branch profile, held by the ratchet).
11
- import fs from 'node:fs';
12
- import { createRequire } from 'node:module';
13
- import path from 'node:path';
14
- export const RULE_PACK_SCHEMA = 'starci/rule-pack@1';
15
- /** The subpath a pack exports its manifest at. */
16
- export const RULE_PACK_ENTRY = 'rule-pack';
17
- /** The sides an eslint pack rule may name: the two side folders and the root packages. */
18
- export const PACK_SIDES = Object.freeze(['be', 'fe', 'packages']);
19
- const RULE_KEYS = new Set(['id', 'code', 'severity', 'spec', 'doc', 'check', 'eslint']);
20
- const ID = /^[A-Z][A-Z0-9]*(?:-[A-Z0-9]+)+$/u;
21
- const CODE = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/u;
22
- const ESLINT_NAME = /^[a-z][a-z0-9-]*$/u;
23
- const PACKAGE_NAME = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/u;
24
- const plain = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
25
- const text = (value) => (typeof value === 'string' && value.trim() !== '' ? value.trim() : null);
26
- const FAILURE_CODES = new URL('../../modules/kernel/failure-codes.yaml', import.meta.url);
27
- let harnessCodes = null;
28
- /**
29
- * Every code the harness reports (the top-level keys of its failure-code catalog), the codes a pack may not take; empty where the catalog is not
30
- * shipped (a canon package's runtime copy), where the app check refuses such a pack instead.
31
- */
32
- export function reservedCodes() {
33
- if (harnessCodes === null) {
34
- let catalog = '';
35
- try {
36
- catalog = fs.readFileSync(FAILURE_CODES, 'utf8');
37
- }
38
- catch { /* not shipped beside this copy */ }
39
- harnessCodes = new Set([...catalog.matchAll(/^([A-Z][A-Z0-9_]+):\s*$/gmu)].map((match) => match[1]));
40
- }
41
- return harnessCodes;
42
- }
43
- /** The app root above `start` (a side folder or the root itself): the nearest folder whose hfs.json declares kind app; null when there is none. */
44
- export function appRootOf(start) {
45
- for (let dir = path.resolve(start);; dir = path.dirname(dir)) {
46
- try {
47
- const declared = JSON.parse(fs.readFileSync(path.join(dir, 'hfs.json'), 'utf8'));
48
- if (declared.kind === 'app')
49
- return dir;
50
- }
51
- catch { /* no declaration here: one folder up */ }
52
- if (path.dirname(dir) === dir)
53
- return null;
54
- }
55
- }
56
- /** The pack names hfs.json `rulePacks` declares (its shape is judged by the declaration check). */
57
- export function declaredRulePacks(appRoot) {
58
- try {
59
- const declared = JSON.parse(fs.readFileSync(path.join(appRoot, 'hfs.json'), 'utf8'));
60
- return Array.isArray(declared.rulePacks) ? declared.rulePacks.filter((name) => typeof name === 'string') : [];
61
- }
62
- catch {
63
- return [];
64
- }
65
- }
66
- /** The problems of one rule entry of pack `pack` (whose folder is `root`), or the rule when it is sound. */
67
- function judgeRule(pack, root, entry, at) {
68
- const where = `rule ${String(at)}`;
69
- if (!plain(entry))
70
- return { problems: [`${where} is not an object`] };
71
- const problems = [];
72
- const extra = Object.keys(entry).filter((key) => !RULE_KEYS.has(key));
73
- if (extra.length > 0)
74
- problems.push(`${where} has ${extra.join(', ')}: a pack only adds rules, it never turns one off, overrides or lowers it (keys ${[...RULE_KEYS].join(', ')})`);
75
- const id = text(entry['id']), code = text(entry['code']), spec = text(entry['spec']), doc = text(entry['doc']);
76
- const label = id ?? where;
77
- if (id === null || !ID.test(id))
78
- problems.push(`${where}: id must be an upper-case law id such as NIVO-BLOCK-1`);
79
- if (code === null || !CODE.test(code))
80
- problems.push(`${label}: code must be an upper-case finding code such as NIVO_BLOCK_INCOMPLETE`);
81
- const severity = entry['severity'];
82
- if (severity !== 'error' && severity !== 'warning')
83
- problems.push(`${label}: severity must be error or warning`);
84
- const inPack = (file) => { const resolved = path.resolve(root, file); return resolved.startsWith(`${path.resolve(root)}${path.sep}`) && fs.existsSync(resolved); };
85
- if (spec === null || !inPack(spec))
86
- problems.push(`${label}: spec must name the file of the package that proves the rule (${spec ?? 'none'} is not there)`);
87
- if (doc === null || !(/^https:\/\/\S+$/u.test(doc) || inPack(doc)))
88
- problems.push(`${label}: doc must be a file of the package or an https link (${doc ?? 'none'})`);
89
- const check = entry['check'];
90
- const eslint = entry['eslint'];
91
- if ((check === undefined) === (eslint === undefined))
92
- problems.push(`${label}: a rule has exactly one engine, check (a machine rule of the app check) or eslint (a rule the canon factories load)`);
93
- if (check !== undefined && typeof check !== 'function')
94
- problems.push(`${label}: check must be a function (context) => findings`);
95
- let lint;
96
- if (eslint !== undefined) {
97
- const name = plain(eslint) ? text(eslint['name']) : null;
98
- const rule = plain(eslint) ? eslint['rule'] : undefined;
99
- const sides = plain(eslint) && Array.isArray(eslint['sides']) ? eslint['sides'] : [];
100
- if (name === null || !ESLINT_NAME.test(name))
101
- problems.push(`${label}: eslint.name must be a kebab-case rule name`);
102
- if (!plain(rule) || typeof rule['create'] !== 'function')
103
- problems.push(`${label}: eslint.rule must be an ESLint rule module with create()`);
104
- if (sides.length === 0 || sides.some((side) => !PACK_SIDES.includes(side)))
105
- problems.push(`${label}: eslint.sides must name some of ${PACK_SIDES.join(', ')}`);
106
- if (name !== null && plain(rule))
107
- lint = { name, rule: rule, sides: sides };
108
- }
109
- if (problems.length > 0)
110
- return { problems };
111
- return { rule: { pack, id: id, code: code, severity: severity, spec: spec, doc: doc, ...(typeof check === 'function' ? { check: check } : {}), ...(lint === undefined ? {} : { eslint: lint }) }, problems: [] };
112
- }
113
- /**
114
- * The rule packs of the app at `appRoot`, loaded through the app's own install (a pack is an ES module required synchronously, so a pack has no
115
- * top-level await) and judged. `reserved` holds the codes the harness reports: a pack never reuses one.
116
- */
117
- export function loadRulePacks(appRoot, reserved = reservedCodes()) {
118
- const result = { rules: [], problems: [] };
119
- const names = declaredRulePacks(appRoot);
120
- const ids = new Map(), codes = new Map();
121
- const requireHere = createRequire(path.join(appRoot, 'package.json'));
122
- for (const name of names) {
123
- const fail = (message) => { result.problems.push({ pack: name, message }); };
124
- if (!PACKAGE_NAME.test(name)) {
125
- fail('is not a package name');
126
- continue;
127
- }
128
- let manifest, root;
129
- try {
130
- root = path.dirname(requireHere.resolve(`${name}/package.json`));
131
- const loaded = requireHere(`${name}/${RULE_PACK_ENTRY}`);
132
- manifest = loaded.default ?? loaded;
133
- }
134
- catch (error) {
135
- fail(`cannot be loaded from the app's install (${name}/${RULE_PACK_ENTRY}): ${String(error?.message ?? error).split('\n')[0]}`);
136
- continue;
137
- }
138
- if (!plain(manifest) || manifest['schema'] !== RULE_PACK_SCHEMA) {
139
- fail(`its ${RULE_PACK_ENTRY} export is not a ${RULE_PACK_SCHEMA} manifest`);
140
- continue;
141
- }
142
- if (manifest['name'] !== name) {
143
- fail(`its manifest names ${String(manifest['name'])}, not the package`);
144
- continue;
145
- }
146
- const extra = Object.keys(manifest).filter((key) => !['schema', 'name', 'rules'].includes(key));
147
- if (extra.length > 0) {
148
- fail(`its manifest has ${extra.join(', ')}: a pack holds only schema, name and the rules it adds`);
149
- continue;
150
- }
151
- const entries = Array.isArray(manifest['rules']) ? manifest['rules'] : [];
152
- if (entries.length === 0) {
153
- fail('adds no rule');
154
- continue;
155
- }
156
- const judged = entries.map((entry, at) => judgeRule(name, root, entry, at));
157
- const problems = judged.flatMap((one) => one.problems);
158
- const sound = judged.flatMap((one) => (one.rule === undefined ? [] : [one.rule]));
159
- for (const [at, rule] of sound.entries()) {
160
- if (sound.findIndex((other) => other.id === rule.id) < at)
161
- problems.push(`${rule.id}: the id is also a rule of ${name}`);
162
- if (sound.findIndex((other) => other.code === rule.code) < at)
163
- problems.push(`${rule.id}: ${rule.code} is also a code of ${name}`);
164
- if (reserved.has(rule.code))
165
- problems.push(`${rule.id}: ${rule.code} is a code the harness reports; a pack adds its own codes and never stands in for a harness rule`);
166
- const otherId = ids.get(rule.id), otherCode = codes.get(rule.code);
167
- if (otherId !== undefined)
168
- problems.push(`${rule.id}: the id is also a rule of ${otherId}`);
169
- if (otherCode !== undefined)
170
- problems.push(`${rule.id}: ${rule.code} is also a code of ${otherCode}`);
171
- }
172
- if (problems.length > 0) {
173
- for (const message of problems)
174
- fail(message);
175
- continue;
176
- }
177
- for (const rule of sound) {
178
- ids.set(rule.id, name);
179
- codes.set(rule.code, name);
180
- result.rules.push(rule);
181
- }
182
- }
183
- return result;
184
- }
185
- /** One plugin object per pack and rule set, so two blocks of one config that name a pack hand ESLint the same plugin. */
186
- const plugins = new Map();
187
- const pluginOf = (pack, rules) => {
188
- const key = `${pack}|${rules.map((rule) => rule.id).join(',')}`;
189
- let made = plugins.get(key);
190
- if (made === undefined) {
191
- made = { rules: Object.fromEntries(rules.map((rule) => [rule.eslint?.name, rule.eslint?.rule])) };
192
- plugins.set(key, made);
193
- }
194
- return made;
195
- };
196
- /**
197
- * The flat-config blocks that load the eslint rules of the app's packs for `side`, for a canon factory: one plugin per pack (named by the package)
198
- * and each rule at its severity. Throws when a pack is refused: a lint run never guesses which of an app's laws hold.
199
- */
200
- export function packEslintConfigs(start, side, files = ['**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}']) {
201
- const appRoot = appRootOf(start);
202
- if (appRoot === null || declaredRulePacks(appRoot).length === 0)
203
- return [];
204
- const packs = loadRulePacks(appRoot);
205
- if (packs.problems.length > 0)
206
- throw new Error(`HFS_RULE_PACK_INVALID: ${packs.problems.map((problem) => `${problem.pack} ${problem.message}`).join('; ')} (hfs.json rulePacks, PROJECT-LINT-3)`);
207
- const byPack = new Map();
208
- for (const rule of packs.rules)
209
- if (rule.eslint?.sides.includes(side))
210
- byPack.set(rule.pack, [...(byPack.get(rule.pack) ?? []), rule]);
211
- return [...byPack].map(([pack, rules]) => ({
212
- files: [...files],
213
- plugins: { [pack]: pluginOf(pack, rules) },
214
- rules: Object.fromEntries(rules.map((rule) => [`${pack}/${rule.eslint?.name}`, rule.severity === 'error' ? 'error' : 'warn'])),
215
- }));
216
- }
217
- /** The findings of the check rules of the app's packs over `files`, and one HFS_RULE_PACK_INVALID per refused pack or per rule that threw. */
218
- export function rulePackFindings({ repoRoot, files, reserved, read }) {
219
- const packs = loadRulePacks(repoRoot, reserved);
220
- const out = packs.problems.map((problem) => ({ code: RULE_PACK_INVALID, level: 'error', path: 'hfs.json', message: `hfs.json rulePacks: ${problem.pack} ${problem.message} (R381, PROJECT-LINT-3)` }));
221
- const context = Object.freeze({ repoRoot, files: Object.freeze([...files]), read });
222
- for (const rule of packs.rules) {
223
- if (rule.check === undefined)
224
- continue;
225
- let found;
226
- try {
227
- found = rule.check(context);
228
- }
229
- catch (error) {
230
- out.push({ code: RULE_PACK_INVALID, level: 'error', path: 'hfs.json', message: `hfs.json rulePacks: ${rule.pack} ${rule.id} threw (${String(error?.message ?? error).split('\n')[0]}); a rule that cannot judge is no rule (R381)` });
231
- continue;
232
- }
233
- for (const finding of Array.isArray(found) ? found : []) {
234
- if (!plain(finding) || text(finding.path) === null || text(finding.message) === null) {
235
- out.push({ code: RULE_PACK_INVALID, level: 'error', path: 'hfs.json', message: `hfs.json rulePacks: ${rule.pack} ${rule.id} returned a finding without a path and a message (R381)` });
236
- continue;
237
- }
238
- out.push({ code: rule.code, level: rule.severity, path: String(finding.path), message: `${String(finding.message)} (${rule.id}, ${rule.doc})`, ...(typeof finding.line === 'number' ? { line: finding.line } : {}), ...(typeof finding.column === 'number' ? { column: finding.column } : {}) });
239
- }
240
- }
241
- return out;
242
- }
243
- export const RULE_PACK_INVALID = 'HFS_RULE_PACK_INVALID';
@@ -1,4 +0,0 @@
1
- // same-text.mjs - text equality that ignores the line-ending form and a trailing blank tail (a git runner may trim stdout, a work tree may
2
- // carry CRLF): the one comparison the database rules use for a committed file against its base or against a regenerated one.
3
- /** True when both texts exist and are equal once CRLF is folded to LF and trailing whitespace at the end is dropped. */
4
- export const sameText = (a, b) => a !== null && b !== null && a.replaceAll('\r\n', '\n').trimEnd() === b.replaceAll('\r\n', '\n').trimEnd();