@starci/eslint-canon-be 3.8.20 → 3.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/runtime/bundle.json +192 -0
- package/runtime/engine/by-code-unit.mjs +6 -6
- package/runtime/engine/model-config.mjs +98 -76
- package/runtime/engine/orca-config.mjs +22 -17
- package/runtime/engine/release-config.mjs +22 -18
- package/runtime/engine/removed-vocabulary.mjs +21 -20
- package/runtime/engine/resources-config.mjs +42 -35
- package/runtime/engine/runtime-root.mjs +11 -13
- package/runtime/engine/secrets.mjs +170 -102
- package/runtime/engine/sonar-config.mjs +16 -13
- package/runtime/engine/temp-root.mjs +3 -9
- package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
- package/runtime/knowledge/hfs/rules.yaml +6 -6
- package/runtime/knowledge/hfs/slots.yaml +2 -2
- package/runtime/knowledge/sonar-gate.yaml +1 -1
- package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
- package/runtime/scripts/api/git/cat-file.mjs +0 -1
- package/runtime/scripts/api/git/config-get.mjs +1 -2
- package/runtime/scripts/api/git/diff.mjs +0 -1
- package/runtime/scripts/api/git/lib.mjs +32 -32
- package/runtime/scripts/api/git/ls-files.mjs +0 -1
- package/runtime/scripts/api/git/ls-tree.mjs +0 -1
- package/runtime/scripts/api/git/merge-base.mjs +2 -3
- package/runtime/scripts/api/git/remote.mjs +0 -1
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
- package/runtime/scripts/api/git/show.mjs +0 -1
- package/runtime/scripts/hfs/allows.mjs +37 -38
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
- package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
- package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
- package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
- package/runtime/scripts/hfs/architecture/config.mjs +302 -268
- package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
- package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
- package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
- package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
- package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
- package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
- package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
- package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
- package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
- package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
- package/runtime/scripts/hfs/architecture/index.mjs +272 -272
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
- package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
- package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
- package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
- package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
- package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
- package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
- package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
- package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
- package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
- package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
- package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
- package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
- package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
- package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
- package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
- package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
- package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
- package/runtime/scripts/hfs/edition-slots.mjs +43 -40
- package/runtime/scripts/hfs/linear-text.mjs +20 -20
- package/runtime/scripts/hfs/param-names.mjs +6 -11
- package/runtime/scripts/hfs/path-findings.mjs +120 -100
- package/runtime/scripts/hfs/repo-identity.mjs +55 -42
- package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
- package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
- package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
- package/runtime/scripts/hfs/rules/read.mjs +19 -15
- package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
- package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
- package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
- package/runtime/scripts/hfs/slot-classify.mjs +42 -38
- package/runtime/scripts/hfs/slot-errors.mjs +8 -7
- package/runtime/scripts/hfs/slot-imports.mjs +70 -63
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
- package/runtime/scripts/hfs/slot-match.mjs +122 -111
- package/runtime/scripts/hfs/slot-path.mjs +0 -2
- package/runtime/scripts/hfs/slot-required.mjs +65 -59
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
- package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
- package/runtime/scripts/hfs/slots.mjs +175 -152
- package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
- package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
- package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
- package/runtime/scripts/hfs/view.mjs +38 -40
- package/runtime/scripts/lib/dockerfile.mjs +131 -114
- package/runtime/scripts/lib/env.mjs +3 -6
- package/runtime/scripts/lib/event-contract.mjs +73 -78
- package/runtime/scripts/lib/git.mjs +15 -16
- package/runtime/scripts/lib/glob.mjs +23 -14
- package/runtime/scripts/lib/grammar-lint.mjs +33 -37
- package/runtime/scripts/lib/i18n.mjs +32 -35
- package/runtime/scripts/lib/in-order.mjs +57 -38
- package/runtime/scripts/lib/json-clone.mjs +45 -36
- package/runtime/scripts/lib/json.mjs +26 -14
- package/runtime/scripts/lib/language.mjs +133 -129
- package/runtime/scripts/lib/list.mjs +9 -14
- package/runtime/scripts/lib/mutation-fence.mjs +10 -5
- package/runtime/scripts/lib/path-key.mjs +53 -38
- package/runtime/scripts/lib/read-text.mjs +30 -17
- package/runtime/scripts/lib/regex.mjs +1 -2
- package/runtime/scripts/lib/same-text.mjs +0 -1
- package/runtime/scripts/lib/sops-envelope.mjs +148 -120
- package/runtime/scripts/lib/stack-services.mjs +128 -129
- package/runtime/scripts/lib/ts-analysis.mjs +28 -26
- package/runtime/scripts/lib/ts-ast.mjs +36 -42
- package/runtime/scripts/lib/walk.mjs +33 -27
- package/runtime/scripts/lib/yaml-cached.mjs +4 -4
|
@@ -5,7 +5,6 @@ import { revParseQuery } from '../../api/git/rev-parse-query.mjs';
|
|
|
5
5
|
import { gitOutputOf } from '../../lib/git.mjs';
|
|
6
6
|
import { trimTrailingSlashes } from '../trailing-slashes.mjs';
|
|
7
7
|
import { requiredFileApplies } from '../slot-required.mjs';
|
|
8
|
-
|
|
9
8
|
/**
|
|
10
9
|
* HFS check 5: the files and directories the slot manifest requires (knowledge/hfs/slots.yaml `requires`,
|
|
11
10
|
* `requiredInstances`, `minInstances`, required app kinds) must exist in the repository tree. Everything is read through the
|
|
@@ -21,212 +20,218 @@ import { requiredFileApplies } from '../slot-required.mjs';
|
|
|
21
20
|
* on disk), else the filesystem without node_modules, .git, dist and .next.
|
|
22
21
|
*/
|
|
23
22
|
export const REQUIRED_FILE_RULE_IDS = ['FE_ERROR_BOUNDARY_MISSING', 'HFS_REQUIRED_FILE_MISSING'];
|
|
24
|
-
|
|
25
23
|
const SKIPPED_DIRECTORIES = new Set(['node_modules', '.git', 'dist', '.next']);
|
|
26
24
|
const ERROR_BOUNDARY_FILE = /^(?:global-error|error|not-found|loading)\.tsx$/u;
|
|
27
25
|
const ALSO_JUDGED_TIER_NONE = new Set(['fe.app.next']);
|
|
28
|
-
|
|
29
26
|
function gitFiles(root) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
try {
|
|
28
|
+
// gitOutputOf threw unless git exited 0, whose stdout is text
|
|
29
|
+
const run = (call, args) => gitOutputOf(call(args, { cwd: root, maxBuffer: 256 * 1024 * 1024 }));
|
|
30
|
+
run(revParseQuery, ['--is-inside-work-tree']);
|
|
31
|
+
const deleted = new Set(run(lsFiles, ['--deleted', '-z', '--', '.']).split('\0').filter(Boolean));
|
|
32
|
+
return run(lsFiles, ['--cached', '-z', '--', '.']).split('\0').filter(file => file && !deleted.has(file));
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
40
38
|
function diskFiles(root, relative = '') {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
const out = [];
|
|
40
|
+
let entries;
|
|
41
|
+
try {
|
|
42
|
+
entries = fs.readdirSync(path.join(root, ...relative.split('/').filter(Boolean)), { withFileTypes: true });
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
for (const entry of entries) {
|
|
48
|
+
if (SKIPPED_DIRECTORIES.has(entry.name))
|
|
49
|
+
continue;
|
|
50
|
+
const child = relative ? `${relative}/${entry.name}` : entry.name;
|
|
51
|
+
if (entry.isDirectory())
|
|
52
|
+
out.push(...diskFiles(root, child));
|
|
53
|
+
else
|
|
54
|
+
out.push(child);
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
53
58
|
let runTrees = null;
|
|
54
|
-
|
|
55
59
|
/** Runs `run` with one tree read per root: every checker of one machine run shares the repository listing instead of spawning git again. */
|
|
56
60
|
export function withTreeCache(run) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
61
|
+
const outer = runTrees;
|
|
62
|
+
runTrees = outer ?? new Map();
|
|
63
|
+
try {
|
|
64
|
+
return run();
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
runTrees = outer;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
66
70
|
function readTree(root) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
71
|
+
const list = gitFiles(root) ?? diskFiles(root);
|
|
72
|
+
const files = new Set(list);
|
|
73
|
+
const directories = new Set();
|
|
74
|
+
for (const file of list) {
|
|
75
|
+
const parts = file.split('/');
|
|
76
|
+
for (let i = 1; i < parts.length; i += 1)
|
|
77
|
+
directories.add(parts.slice(0, i).join('/'));
|
|
78
|
+
}
|
|
79
|
+
return { files, directories };
|
|
80
|
+
}
|
|
77
81
|
/** The repository tree as file and directory sets over posix relatives. */
|
|
78
82
|
export function treeOf(root) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
if (!runTrees)
|
|
84
|
+
return readTree(root);
|
|
85
|
+
let tree = runTrees.get(root);
|
|
86
|
+
if (!tree) {
|
|
87
|
+
tree = readTree(root);
|
|
88
|
+
runTrees.set(root, tree);
|
|
89
|
+
}
|
|
90
|
+
return tree;
|
|
82
91
|
}
|
|
83
|
-
|
|
84
92
|
/**
|
|
85
93
|
* The prelude every tree-walking architecture checker shares: the input's config/graph/context, the compiler,
|
|
86
94
|
* the slot resolver and the tracked repository tree.
|
|
87
95
|
*/
|
|
88
96
|
export function checkerScope({ config, graph, context }) {
|
|
89
|
-
|
|
97
|
+
return { config, graph, context, ts: context.ts, resolver: graph.resolver, tree: treeOf(config.root) };
|
|
90
98
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
99
|
+
const rootOfTarget = (target) => {
|
|
100
|
+
if (target.endsWith('/'))
|
|
101
|
+
return trimTrailingSlashes(target);
|
|
102
|
+
const parent = path.posix.dirname(target);
|
|
103
|
+
return parent === '.' ? '' : parent;
|
|
96
104
|
};
|
|
97
|
-
|
|
98
105
|
function ruleFor(slotId, target, rootExists) {
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
if (slotId === 'fe.app.next' && rootExists && ERROR_BOUNDARY_FILE.test(path.posix.basename(trimTrailingSlashes(target))))
|
|
107
|
+
return 'FE_ERROR_BOUNDARY_MISSING';
|
|
108
|
+
return 'HFS_REQUIRED_FILE_MISSING';
|
|
101
109
|
}
|
|
102
|
-
|
|
103
110
|
function slotIsJudged(resolver, slotId) {
|
|
104
|
-
|
|
105
|
-
|
|
111
|
+
const slot = resolver.slot(slotId);
|
|
112
|
+
return slot != null && (slot.tier !== 'none' || ALSO_JUDGED_TIER_NONE.has(slotId));
|
|
106
113
|
}
|
|
107
|
-
|
|
108
114
|
function addRequirement(requirements, slot, target, root) {
|
|
109
|
-
|
|
115
|
+
if (!requirements.has(target))
|
|
116
|
+
requirements.set(target, { slot, target, root });
|
|
110
117
|
}
|
|
111
|
-
|
|
112
118
|
function collectDeclaredRequirements(declared, requirements, instances, judged) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
const currentRoot = new Map();
|
|
120
|
+
for (const item of declared.paths) {
|
|
121
|
+
if (!judged(item.slot))
|
|
122
|
+
continue;
|
|
123
|
+
if (item.via !== 'requires') {
|
|
124
|
+
const root = rootOfTarget(item.path);
|
|
125
|
+
currentRoot.set(item.slot, root);
|
|
126
|
+
instances.add(`${item.slot}|${root}`);
|
|
127
|
+
addRequirement(requirements, item.slot, item.path, root);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
addRequirement(requirements, item.slot, item.path, currentRoot.get(item.slot) ?? '');
|
|
131
|
+
}
|
|
123
132
|
}
|
|
124
|
-
}
|
|
125
133
|
}
|
|
126
|
-
|
|
127
134
|
function addInstanceRequirements(resolver, classified, representative, requirements, instances, seenInstances, judged) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
135
|
+
const { slot: slotId, root } = classified;
|
|
136
|
+
const key = `${slotId}|${root}`;
|
|
137
|
+
if (seenInstances.has(key) || !judged(slotId))
|
|
138
|
+
return;
|
|
139
|
+
seenInstances.add(key);
|
|
140
|
+
instances.add(key);
|
|
141
|
+
for (const target of resolver.requiredFiles(representative))
|
|
142
|
+
addRequirement(requirements, slotId, target, root);
|
|
143
|
+
}
|
|
136
144
|
function addOwnerRequirements(resolver, owner, requirements, instances, seenInstances, judged) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
const key = `${owner.slot}|${owner.root}`;
|
|
146
|
+
const ownerSlot = resolver.slot(owner.slot);
|
|
147
|
+
// judged() already answered false for a slot the resolver does not know
|
|
148
|
+
if (seenInstances.has(key) || !judged(owner.slot) || !ownerSlot || !resolver.slotEnabled(ownerSlot))
|
|
149
|
+
return;
|
|
150
|
+
seenInstances.add(key);
|
|
151
|
+
instances.add(key);
|
|
152
|
+
for (const entry of ownerSlot.requires ?? []) {
|
|
153
|
+
const rooted = entry.startsWith('/');
|
|
154
|
+
const filled = (rooted ? entry.slice(1) : entry).replace(/<([A-Za-z][A-Za-z0-9-]*)>/g, (whole, name) => owner.bindings[name] ?? whole);
|
|
155
|
+
addRequirement(requirements, owner.slot, rooted || !owner.root ? filled : `${owner.root}/${filled}`, owner.root);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
148
158
|
function noteInstance(found, slotId, root) {
|
|
149
|
-
|
|
150
|
-
|
|
159
|
+
let roots = found.get(slotId);
|
|
160
|
+
if (!roots) {
|
|
161
|
+
roots = new Set();
|
|
162
|
+
found.set(slotId, roots);
|
|
163
|
+
}
|
|
164
|
+
roots.add(root);
|
|
151
165
|
}
|
|
152
|
-
|
|
153
166
|
function collectTreeRequirements(tree, resolver, requirements, instances, judged) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
167
|
+
const seenInstances = new Set();
|
|
168
|
+
const found = new Map(); // slot -> Set(root) of instances seen while walking
|
|
169
|
+
for (const file of tree.files) {
|
|
170
|
+
const classified = resolver.classifyPath(file);
|
|
171
|
+
if (classified.status === 'owned' && classified.slot) {
|
|
172
|
+
noteInstance(found, classified.slot, classified.root);
|
|
173
|
+
addInstanceRequirements(resolver, { slot: classified.slot, root: classified.root }, file, requirements, instances, seenInstances, judged);
|
|
174
|
+
}
|
|
175
|
+
const owner = resolver.ownerOf(file);
|
|
176
|
+
if (owner) {
|
|
177
|
+
noteInstance(found, owner.slot, owner.root);
|
|
178
|
+
// an owner root may classify to a more specific slot (modules/i18n) or a nested one, so expand the owner slot's own requires
|
|
179
|
+
addOwnerRequirements(resolver, owner, requirements, instances, seenInstances, judged);
|
|
180
|
+
}
|
|
161
181
|
}
|
|
162
|
-
|
|
163
|
-
if (owner) {
|
|
164
|
-
noteInstance(found, owner.slot, owner.root);
|
|
165
|
-
// an owner root may classify to a more specific slot (modules/i18n) or a nested one, so expand the owner slot's own requires
|
|
166
|
-
addOwnerRequirements(resolver, owner, requirements, instances, seenInstances, judged);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return found;
|
|
182
|
+
return found;
|
|
170
183
|
}
|
|
171
|
-
|
|
172
184
|
function requirementExists(tree, target) {
|
|
173
|
-
|
|
185
|
+
return target.endsWith('/') ? tree.directories.has(trimTrailingSlashes(target)) : tree.files.has(target);
|
|
174
186
|
}
|
|
175
|
-
|
|
176
187
|
function reportMissingRequirement(requirement, tree, report) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
|
|
188
|
+
if (requirementExists(tree, requirement.target) || !requiredFileApplies(requirement.slot, requirement.target, tree.files))
|
|
189
|
+
return;
|
|
190
|
+
const rootExists = !requirement.root || tree.directories.has(requirement.root);
|
|
191
|
+
if (!rootExists) {
|
|
192
|
+
report(ruleFor(requirement.slot, requirement.target, false), requirement.root, requirement.slot, requirement.root, { kind: 'directory' }, `Required directory ${requirement.root} (slot ${requirement.slot}) does not exist; the slot manifest requires it, along with what it holds.`);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const kind = requirement.target.endsWith('/') ? 'directory' : 'file';
|
|
196
|
+
const rootNote = requirement.root ? ` (${requirement.root})` : '';
|
|
197
|
+
report(ruleFor(requirement.slot, requirement.target, true), trimTrailingSlashes(requirement.target), requirement.slot, requirement.root, { kind }, `Required ${kind} ${trimTrailingSlashes(requirement.target)} is missing; slot ${requirement.slot} requires it in every instance${rootNote}.`);
|
|
198
|
+
}
|
|
190
199
|
function reportMissingRequirements(requirements, tree, report) {
|
|
191
|
-
|
|
200
|
+
for (const requirement of requirements.values())
|
|
201
|
+
reportMissingRequirement(requirement, tree, report);
|
|
192
202
|
}
|
|
193
|
-
|
|
194
203
|
function reportMinimumRequirements(minimums, resolver, judged, found, report) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
204
|
+
for (const minimum of minimums) {
|
|
205
|
+
if (!judged(minimum.slot))
|
|
206
|
+
continue;
|
|
207
|
+
const count = minimum.appKind !== undefined
|
|
208
|
+
? resolver.repo.apps.filter(app => app.kind === minimum.appKind).length
|
|
209
|
+
: (found.get(minimum.slot)?.size ?? 0);
|
|
210
|
+
if (count >= minimum.min)
|
|
211
|
+
continue;
|
|
212
|
+
const appKindNote = minimum.appKind ? ' (an app of kind ' + minimum.appKind + ' declared in hfs.json)' : '';
|
|
213
|
+
report('HFS_REQUIRED_FILE_MISSING', 'hfs.json', minimum.slot, '', { minimum: minimum.min, found: count }, `Slot ${minimum.slot} needs at least ${minimum.min} instance${minimum.min === 1 ? '' : 's'}${appKindNote}; the repository has ${count}.`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
207
216
|
export function checkRequiredFiles({ config, graph }) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
reportMinimumRequirements(declared.minimums, resolver, judged, found, report);
|
|
230
|
-
|
|
231
|
-
return { violations, coverage: { status: 'checked', instances: instances.size, requirements: requirements.size, missing: violations.length } };
|
|
217
|
+
const resolver = graph?.resolver ?? config.hfs;
|
|
218
|
+
const tree = treeOf(config.root);
|
|
219
|
+
const judged = slotId => slotIsJudged(resolver, slotId);
|
|
220
|
+
const requirements = new Map(); // repository-relative target (as written, dirs end with /) -> {slot, target, root}
|
|
221
|
+
const instances = new Set();
|
|
222
|
+
const declared = resolver.requiredPaths();
|
|
223
|
+
collectDeclaredRequirements(declared, requirements, instances, judged);
|
|
224
|
+
const found = collectTreeRequirements(tree, resolver, requirements, instances, judged);
|
|
225
|
+
const violations = [];
|
|
226
|
+
const reported = new Set();
|
|
227
|
+
const report = (ruleId, target, slotId, root, extra, message) => {
|
|
228
|
+
const key = `${ruleId}|${target}`;
|
|
229
|
+
if (reported.has(key))
|
|
230
|
+
return;
|
|
231
|
+
reported.add(key);
|
|
232
|
+
violations.push({ ruleId, path: target, slot: slotId, ...(root ? { root } : {}), ...extra, message });
|
|
233
|
+
};
|
|
234
|
+
reportMissingRequirements(requirements, tree, report);
|
|
235
|
+
reportMinimumRequirements(declared.minimums, resolver, judged, found, report);
|
|
236
|
+
return { violations, coverage: { status: 'checked', instances: instances.size, requirements: requirements.size, missing: violations.length } };
|
|
232
237
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { machineKit } from './machine-ast.mjs';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* R54 `route-files-thin` (FE_ROUTE_FILES_THIN, knowledge/hfs/README.md 6.2). A route file only mounts an owner: it holds no
|
|
6
5
|
* inline component, no drawing and no hook. For every file of the route slot (fe.route, apps/<app>/src/app) named
|
|
@@ -16,110 +15,119 @@ import { machineKit } from './machine-ast.mjs';
|
|
|
16
15
|
* FE_ROUTE_CLIENT_BOUNDARY and FE_ROUTE_CLIENT_HOOK checks of frontend.mjs and are not judged a second time here.
|
|
17
16
|
*/
|
|
18
17
|
export const ROUTE_FILES_THIN_RULE_IDS = ['FE_ROUTE_FILES_THIN'];
|
|
19
|
-
|
|
20
18
|
const RULE = 'FE_ROUTE_FILES_THIN';
|
|
21
19
|
const ROUTE_SLOT = 'fe.route';
|
|
22
20
|
const MOUNTING_ROUTES = new Set(['layout', 'template', 'loading', 'not-found']);
|
|
23
21
|
const HOOK_ROUTES = new Set([...MOUNTING_ROUTES, 'page']);
|
|
24
22
|
const HOOK_NAME = /^use[A-Z0-9]/u;
|
|
25
23
|
const HOOKS_SLOT = 'fe.hooks';
|
|
26
|
-
|
|
27
24
|
/** The client providers (fe.components.providers) wrap the mounted owner like a package shell; they are not a second owner. */
|
|
28
25
|
const PROVIDERS_SLOT = 'fe.components.providers';
|
|
29
|
-
const isFeatureOwner = target => target?.tier === 'feature' && target.slot !== PROVIDERS_SLOT;
|
|
26
|
+
const isFeatureOwner = (target) => target?.tier === 'feature' && target.slot !== PROVIDERS_SLOT;
|
|
30
27
|
const isFunction = (ts, node) => ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node);
|
|
31
28
|
const jsxOf = (ts, node) => ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node);
|
|
32
|
-
|
|
33
29
|
function tagOf(ts, node) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
if (ts.isJsxElement(node))
|
|
31
|
+
return node.openingElement.tagName;
|
|
32
|
+
if (ts.isJsxSelfClosingElement(node))
|
|
33
|
+
return node.tagName;
|
|
34
|
+
return null;
|
|
37
35
|
}
|
|
38
|
-
|
|
39
36
|
function addExportAssignmentDefaults(ts, statement, kit, checker, defaults) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
const target = statement.expression;
|
|
38
|
+
if (!ts.isIdentifier(target)) {
|
|
39
|
+
defaults.add(target);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
for (const declaration of kit.declarationsOf(checker, target))
|
|
43
|
+
defaults.add(ts.isVariableDeclaration(declaration) ? declaration.initializer ?? declaration : declaration);
|
|
43
44
|
}
|
|
44
|
-
|
|
45
45
|
function routeDefaults(ts, file, kit, checker) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
const defaults = new Set();
|
|
47
|
+
for (const statement of file.sourceFile.statements) {
|
|
48
|
+
if (ts.isFunctionDeclaration(statement) && statement.modifiers?.some((item) => item.kind === ts.SyntaxKind.DefaultKeyword))
|
|
49
|
+
defaults.add(statement);
|
|
50
|
+
if (ts.isExportAssignment(statement) && !statement.isExportEquals)
|
|
51
|
+
addExportAssignmentDefaults(ts, statement, kit, checker, defaults);
|
|
52
|
+
}
|
|
53
|
+
return defaults;
|
|
52
54
|
}
|
|
53
|
-
|
|
54
55
|
/** True when the function contains JSX that is not inside a nested function. */
|
|
55
56
|
function drawsDirectly(ts, fn) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
let found = false;
|
|
58
|
+
const visit = (node) => {
|
|
59
|
+
if (found)
|
|
60
|
+
return;
|
|
61
|
+
if (node !== fn && isFunction(ts, node))
|
|
62
|
+
return;
|
|
63
|
+
if (jsxOf(ts, node)) {
|
|
64
|
+
found = true;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
ts.forEachChild(node, visit);
|
|
68
|
+
};
|
|
69
|
+
visit(fn);
|
|
70
|
+
return found;
|
|
65
71
|
}
|
|
66
|
-
|
|
67
72
|
function reportRoute(violations, kit, file, stem, node, message, extra = {}) {
|
|
68
|
-
|
|
73
|
+
violations.push({ ruleId: RULE, ...kit.at(file.rel, file.sourceFile, node), message, route: stem, ...extra });
|
|
69
74
|
}
|
|
70
|
-
|
|
71
75
|
function inspectMountingTag(tag, { graph, kit, ts, file, stem, checker, violations, state }) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
if (ts.isIdentifier(tag) && /^[a-z]/u.test(tag.text)) {
|
|
77
|
+
reportRoute(violations, kit, file, stem, tag, `<${tag.text}> is drawing in a ${stem} route file; a route file mounts one feature and draws nothing. Move the markup into the feature.`);
|
|
78
|
+
}
|
|
79
|
+
else if (kit.declarationsOf(checker, ts.isPropertyAccessExpression(tag) ? tag.name : tag).some(declaration => isFeatureOwner(graph.files.get(kit.graphPath(declaration) ?? '')))) {
|
|
80
|
+
state.owners += 1;
|
|
81
|
+
}
|
|
77
82
|
}
|
|
78
|
-
|
|
79
83
|
function inspectHookCall(node, { graph, kit, ts, file, stem, checker, violations }) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
const callee = ts.isIdentifier(node.expression) ? node.expression : null;
|
|
85
|
+
if (!callee || !HOOK_NAME.test(callee.text))
|
|
86
|
+
return;
|
|
87
|
+
const binding = kit.importBinding(checker, callee);
|
|
88
|
+
const inHooks = kit.declarationsOf(checker, callee).some(declaration => graph.files.get(kit.graphPath(declaration) ?? '')?.slot === HOOKS_SLOT);
|
|
89
|
+
if (binding || inHooks)
|
|
90
|
+
reportRoute(violations, kit, file, stem, callee, `${callee.text} is a hook called in a ${stem} route file; a route file is a server adapter and holds no hook. Read the data in the feature it mounts.`);
|
|
85
91
|
}
|
|
86
|
-
|
|
87
92
|
function inspectRouteNode(node, context) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
const { kit, ts, file, stem, mounting, defaults, violations, state } = context;
|
|
94
|
+
if (jsxOf(ts, node))
|
|
95
|
+
state.hasJsx = true;
|
|
96
|
+
const tag = tagOf(ts, node);
|
|
97
|
+
if (mounting && tag)
|
|
98
|
+
inspectMountingTag(tag, context);
|
|
99
|
+
if (mounting && isFunction(ts, node) && !defaults.has(node) && drawsDirectly(ts, node)) {
|
|
100
|
+
reportRoute(violations, kit, file, stem, node, `A function other than the default export draws JSX in a ${stem} route file; that is an inline component. Move it into the feature the route mounts.`);
|
|
101
|
+
}
|
|
102
|
+
if (ts.isCallExpression(node))
|
|
103
|
+
inspectHookCall(node, context);
|
|
104
|
+
return true;
|
|
97
105
|
}
|
|
98
|
-
|
|
99
106
|
function inspectRouteFile(graph, kit, file, stem, violations) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
const { ts } = kit;
|
|
108
|
+
const mounting = MOUNTING_ROUTES.has(stem);
|
|
109
|
+
const checker = kit.checkerOf(file.sourceFile);
|
|
110
|
+
const defaults = routeDefaults(ts, file, kit, checker);
|
|
111
|
+
const state = { hasJsx: false, owners: 0 };
|
|
112
|
+
kit.walk(file.sourceFile, (node) => inspectRouteNode(node, { graph, kit, ts, file, stem, mounting, checker, defaults, violations, state }));
|
|
113
|
+
if (mounting && state.hasJsx && state.owners !== 1) {
|
|
114
|
+
violations.push({ ruleId: RULE, path: file.rel, line: 1, column: 1, route: stem, owners: state.owners,
|
|
115
|
+
message: `${file.rel} mounts ${state.owners} feature owners; a ${stem} route file mounts exactly one feature (a layouts- or pages-tier component of the app), optionally inside a package shell.` });
|
|
116
|
+
}
|
|
110
117
|
}
|
|
111
|
-
|
|
112
118
|
export function checkRouteFilesThin(input) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
119
|
+
const { graph } = input;
|
|
120
|
+
const kit = machineKit(input);
|
|
121
|
+
const violations = [];
|
|
122
|
+
let routes = 0;
|
|
123
|
+
for (const file of graph.files.values()) {
|
|
124
|
+
if (file.slot !== ROUTE_SLOT)
|
|
125
|
+
continue;
|
|
126
|
+
const stem = path.posix.basename(file.rel).replace(/\.[cm]?[jt]sx?$/u, '');
|
|
127
|
+
if (!HOOK_ROUTES.has(stem))
|
|
128
|
+
continue;
|
|
129
|
+
routes += 1;
|
|
130
|
+
inspectRouteFile(graph, kit, file, stem, violations);
|
|
131
|
+
}
|
|
132
|
+
return { violations, coverage: { status: 'checked', routes } };
|
|
125
133
|
}
|