@starci/eslint-canon-be 3.8.20 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -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
|
@@ -43,9 +43,7 @@ import { globExpression } from '../../lib/glob.mjs';
|
|
|
43
43
|
import { stagedConsumerSources } from './staged-consumers.mjs';
|
|
44
44
|
import { bindingsOf } from './dead-exports-bindings.mjs';
|
|
45
45
|
import { operationContractRoots } from './operation-contract-roots.mjs';
|
|
46
|
-
|
|
47
46
|
export const DEAD_EXPORT_RULE_IDS = ['HFS_UNUSED_EXPORT', 'HFS_UNUSED_FILE'];
|
|
48
|
-
|
|
49
47
|
const PACKAGE_ENTRIES = ['src/index.ts', 'src/index.tsx', 'index.ts', 'index.tsx'];
|
|
50
48
|
const OWNER_ENTRIES = ['index.ts', 'index.tsx'];
|
|
51
49
|
const CHAIN_DEPTH = 6;
|
|
@@ -53,310 +51,370 @@ const CHAIN_DEPTH = 6;
|
|
|
53
51
|
const UNJUDGED_TIERS = new Set(['none', 'e2e', 'fixtures']);
|
|
54
52
|
const CONFIG_EXTENSIONS = ['', '.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '/index.ts', '/index.tsx', '/index.js'];
|
|
55
53
|
const CONFIG_STRING = /['"`](\.{1,2}\/[^'"`\s]+)['"`]/g;
|
|
56
|
-
|
|
57
54
|
/** The public entry file (repository-relative) of an owner unit, or null when the owner has none in the graph. */
|
|
58
55
|
export function entryOf(graph, config, key, owner) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
const declared = config.owners?.find(item => item.id === key)?.entry;
|
|
57
|
+
if (declared && graph.files.has(declared))
|
|
58
|
+
return declared;
|
|
59
|
+
for (const candidate of owner.tier === 'package' ? PACKAGE_ENTRIES : OWNER_ENTRIES) {
|
|
60
|
+
const rel = owner.root ? `${owner.root}/${candidate}` : candidate;
|
|
61
|
+
if (graph.files.has(rel))
|
|
62
|
+
return rel;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
66
65
|
}
|
|
67
|
-
|
|
68
66
|
/** The additional public entry files (repository-relative, in the graph) the slot manifest declares for the owner (slot field `entries`, on the slot that holds its entry file). */
|
|
69
67
|
function extraEntries(graph, entry) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
const found = graph.resolver.classifyPath(entry);
|
|
69
|
+
const names = found.slot ? graph.resolver.slot(found.slot)?.entries ?? [] : [];
|
|
70
|
+
// an entry holding `*` (one file per operation) names every graph file it matches
|
|
71
|
+
const matches = (name) => [...graph.files.keys()].filter(rel => globExpression(`${found.root}/${name}`).test(rel));
|
|
72
|
+
return names.flatMap((name) => (name.includes('*') ? matches(name) : [`${found.root}/${name}`].filter(rel => graph.files.has(rel))));
|
|
75
73
|
}
|
|
76
|
-
|
|
77
74
|
const addExportName = (found, sourceFile, name, node) => {
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
if (found.has(name))
|
|
76
|
+
return;
|
|
77
|
+
found.set(name, sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1);
|
|
80
78
|
};
|
|
81
|
-
|
|
82
79
|
const addBindingNames = (ts, found, sourceFile, name, node) => {
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
if (name.kind === ts.SyntaxKind.Identifier)
|
|
81
|
+
addExportName(found, sourceFile, name.text, node);
|
|
82
|
+
else
|
|
83
|
+
for (const element of name.elements)
|
|
84
|
+
if (element.kind === ts.SyntaxKind.BindingElement)
|
|
85
|
+
addBindingNames(ts, found, sourceFile, element.name, node);
|
|
85
86
|
};
|
|
86
|
-
|
|
87
87
|
const addExportDeclarationNames = (ts, statement, add) => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
if (statement.exportClause?.kind === ts.SyntaxKind.NamedExports) {
|
|
89
|
+
for (const element of statement.exportClause.elements)
|
|
90
|
+
add(element.name.text, element);
|
|
91
|
+
}
|
|
92
|
+
else if (statement.exportClause?.kind === ts.SyntaxKind.NamespaceExport)
|
|
93
|
+
add(statement.exportClause.name.text, statement);
|
|
91
94
|
};
|
|
92
|
-
|
|
93
95
|
const addStatementNames = (ts, found, sourceFile, statement) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
96
|
+
const kind = ts.SyntaxKind;
|
|
97
|
+
const add = (name, node) => addExportName(found, sourceFile, name, node);
|
|
98
|
+
if (ts.isExportDeclaration(statement))
|
|
99
|
+
return addExportDeclarationNames(ts, statement, add);
|
|
100
|
+
if (ts.isExportAssignment(statement))
|
|
101
|
+
return add('default', statement);
|
|
102
|
+
const declaring = statement; // reason: only declaration statements carry modifiers and a name; both are read as optional
|
|
103
|
+
const modifiers = declaring.modifiers ?? [];
|
|
104
|
+
if (!modifiers.some(modifier => modifier.kind === kind.ExportKeyword))
|
|
105
|
+
return undefined;
|
|
106
|
+
if (modifiers.some(modifier => modifier.kind === kind.DefaultKeyword))
|
|
107
|
+
return add('default', statement);
|
|
108
|
+
if (ts.isVariableStatement(statement)) {
|
|
109
|
+
for (const declaration of statement.declarationList.declarations)
|
|
110
|
+
addBindingNames(ts, found, sourceFile, declaration.name, declaration);
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
return declaring.name && ts.isIdentifier(declaring.name) ? add(declaring.name.text, statement) : undefined;
|
|
106
114
|
};
|
|
107
|
-
|
|
108
115
|
/** The exported names of an entry source file, each with the line of its declaration. */
|
|
109
116
|
export function exportedNames(ts, sourceFile) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
117
|
+
const found = new Map();
|
|
118
|
+
for (const statement of sourceFile.statements)
|
|
119
|
+
addStatementNames(ts, found, sourceFile, statement);
|
|
120
|
+
return found;
|
|
113
121
|
}
|
|
114
|
-
|
|
115
|
-
const withoutSlash = value => value.replace(/\/$/, '');
|
|
116
|
-
|
|
122
|
+
const withoutSlash = (value) => value.replace(/\/$/, '');
|
|
117
123
|
const addConfigTextRoots = (graph, directory, text, roots) => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
for (const match of text.matchAll(CONFIG_STRING)) {
|
|
125
|
+
const target = path.posix.join(directory, match[1] ?? '');
|
|
126
|
+
const hit = CONFIG_EXTENSIONS.map(extension => `${target}${extension}`).find(candidate => graph.files.has(candidate));
|
|
127
|
+
if (hit)
|
|
128
|
+
roots.add(hit);
|
|
129
|
+
}
|
|
123
130
|
};
|
|
124
|
-
|
|
125
131
|
const addAppConfigRoots = (graph, config, app, roots) => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
const directory = `apps/${app.name}`;
|
|
133
|
+
let names = [];
|
|
134
|
+
try {
|
|
135
|
+
names = fs.readdirSync(path.join(config.root, ...directory.split('/')));
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
for (const name of names) {
|
|
141
|
+
if (graph.resolver.classifyPath(`${directory}/${name}`).slot !== 'fe.app.next' || !/\.[cm]?[jt]sx?$/.test(name))
|
|
142
|
+
continue;
|
|
143
|
+
let text = '';
|
|
144
|
+
try {
|
|
145
|
+
text = fs.readFileSync(path.join(config.root, ...directory.split('/'), name), 'utf8');
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
addConfigTextRoots(graph, directory, text, roots);
|
|
151
|
+
}
|
|
135
152
|
};
|
|
136
|
-
|
|
137
153
|
const addFrameworkConfigRoots = (graph, config, roots) => {
|
|
138
|
-
|
|
154
|
+
for (const app of config.apps ?? [])
|
|
155
|
+
addAppConfigRoots(graph, config, app, roots);
|
|
139
156
|
};
|
|
140
|
-
|
|
141
157
|
/** Roots are required app files, registered operation contracts, routes, package entries and config-named files. */
|
|
142
158
|
function rootFiles(graph, config, context) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
159
|
+
const roots = new Set();
|
|
160
|
+
for (const [rel, node] of graph.files) {
|
|
161
|
+
if (node.tier === 'route') {
|
|
162
|
+
roots.add(rel);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (!node.owner || node.tier !== 'app')
|
|
166
|
+
continue;
|
|
167
|
+
const slot = graph.resolver.slot(node.owner.slot);
|
|
168
|
+
const inside = rel.slice(withoutSlash(node.owner.root).length + 1);
|
|
169
|
+
if ((slot?.requires ?? []).includes(inside))
|
|
170
|
+
roots.add(rel);
|
|
171
|
+
}
|
|
172
|
+
for (const [key, owner] of graph.ownerRoots) {
|
|
173
|
+
if (owner.tier !== 'package')
|
|
174
|
+
continue;
|
|
175
|
+
const entry = entryOf(graph, config, key, owner);
|
|
176
|
+
if (entry)
|
|
177
|
+
roots.add(entry);
|
|
178
|
+
}
|
|
179
|
+
// A framework config of an app (slot fe.app.next) names sources by string, never by import.
|
|
180
|
+
addFrameworkConfigRoots(graph, config, roots);
|
|
181
|
+
for (const entry of operationContractRoots(context, graph, config))
|
|
182
|
+
roots.add(entry);
|
|
183
|
+
return roots;
|
|
160
184
|
}
|
|
161
|
-
|
|
162
185
|
const unusedFileViolation = (rel, node) => ({
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
186
|
+
ruleId: 'HFS_UNUSED_FILE',
|
|
187
|
+
path: rel, line: 1, column: 1,
|
|
188
|
+
slot: node.slot, owner: node.owner?.root ?? null,
|
|
189
|
+
message: `${rel} is not reached from any root (an app main.ts or app.module.ts, a registered operation contract, a route file, a package entry): nothing consumes it. Delete the file, or import it where it is used (a spec alone does not count).`,
|
|
167
190
|
});
|
|
168
|
-
|
|
169
191
|
/** HFS_UNUSED_FILE: production files no root reaches through runtime or type-only imports and re-exports. */
|
|
170
192
|
function deadFiles(graph, config, context) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
193
|
+
const roots = rootFiles(graph, config, context);
|
|
194
|
+
const forward = edgeIndex(graph.edges, edge => edge.from);
|
|
195
|
+
const reached = new Set(roots);
|
|
196
|
+
const queue = [...roots];
|
|
197
|
+
while (queue.length) {
|
|
198
|
+
const current = queue.shift();
|
|
199
|
+
if (current === undefined)
|
|
200
|
+
break;
|
|
201
|
+
for (const { to } of forward.get(current) ?? [])
|
|
202
|
+
if (!reached.has(to)) {
|
|
203
|
+
reached.add(to);
|
|
204
|
+
queue.push(to);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const judgedFiles = [...graph.files]
|
|
208
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
209
|
+
.filter(([, node]) => !(node.tier === null || UNJUDGED_TIERS.has(node.tier) || node.tier === 'route'));
|
|
210
|
+
const violations = judgedFiles.filter(([rel]) => !reached.has(rel)).map(([rel, node]) => unusedFileViolation(rel, node));
|
|
211
|
+
return { violations, judged: judgedFiles.length, roots: roots.size };
|
|
181
212
|
}
|
|
182
|
-
|
|
183
213
|
/** The unit spec of a webhook, gateway, subscription or SSE controller door: a door has no service of its own, so its spec is the only unit spec of its kind. */
|
|
184
214
|
const DOOR_SPEC = /^src\/features\/(?:webhooks|realtime)\/.+\.(?:webhook|gateway|subscription|controller)\.spec\.ts$/u;
|
|
185
215
|
const BUILDER_CONSUMER = /^src\/tests\/fixtures\/builders\/.+\.builder\.ts$/u;
|
|
186
216
|
/** The test world slots (knowledge/hfs/slots.yaml): their files wire the real capabilities of the e2e run. */
|
|
187
217
|
const WORLD_SLOTS = new Set(['be.tests.world', 'be.tests.world.kit']);
|
|
188
|
-
|
|
189
218
|
/** Whether `rel` is a test file that counts as a consumer of any owner: a unit role spec, a fixture builder, a world file. */
|
|
190
219
|
function testConsumer(graph, rel) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
220
|
+
const params = graph.resolver.ruleParams() ?? {};
|
|
221
|
+
const specs = [...(params.unitRoles ?? []).map((role) => role.spec), ...(params.logicRoles ?? []).map((role) => `${role}.spec`)];
|
|
222
|
+
if (/^(?:src|apps)\//u.test(rel) && specs.some(spec => rel.endsWith(`.${spec}.ts`)))
|
|
223
|
+
return true;
|
|
224
|
+
if (DOOR_SPEC.test(rel))
|
|
225
|
+
return true;
|
|
226
|
+
if (BUILDER_CONSUMER.test(rel))
|
|
227
|
+
return true;
|
|
228
|
+
const classified = graph.resolver.classifyPath(rel);
|
|
229
|
+
return classified.slot !== undefined && WORLD_SLOTS.has(classified.slot) && classified.status !== 'forbidden' && /\.tsx?$/u.test(rel);
|
|
198
230
|
}
|
|
199
231
|
/** The slot of integration specs and the slot of the integrations they pair with by folder (knowledge/hfs/slots.yaml). */
|
|
200
232
|
const INTEGRATION_SPEC_SLOT = 'be.tests.integration';
|
|
201
233
|
const INTEGRATION_SLOT = 'be.integrations';
|
|
202
|
-
|
|
203
234
|
/** The provider an integration spec pairs with (its `<capability>` folder), or null when `rel` is no integration spec. */
|
|
204
235
|
function integrationSpecProvider(graph, rel) {
|
|
205
|
-
|
|
206
|
-
|
|
236
|
+
const classified = graph.resolver.classifyPath(rel);
|
|
237
|
+
return classified.slot === INTEGRATION_SPEC_SLOT && classified.status !== 'forbidden' ? classified.bindings?.capability ?? null : null;
|
|
207
238
|
}
|
|
208
|
-
|
|
209
239
|
/** Whether `to` belongs to the integration of `provider` (slot be.integrations, its `<provider>` binding). */
|
|
210
240
|
function inIntegrationOf(graph, to, provider) {
|
|
211
|
-
|
|
212
|
-
|
|
241
|
+
const owner = graph.resolver.ownerOf(to);
|
|
242
|
+
return owner?.slot === INTEGRATION_SLOT && owner.bindings?.provider === provider;
|
|
213
243
|
}
|
|
214
|
-
|
|
215
244
|
/** The pseudo edges of one test consumer file: its import/export declarations that resolve to graph files it may reach. */
|
|
216
245
|
function consumerFileEdges({ ts, options, graph, config }, rel, provider, indexedText) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
246
|
+
const abs = path.join(config.root, ...rel.split('/'));
|
|
247
|
+
let text = indexedText;
|
|
248
|
+
if (text === undefined) {
|
|
249
|
+
try {
|
|
250
|
+
text = fs.readFileSync(abs, 'utf8');
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const sourceFile = ts.createSourceFile(abs, text, ts.ScriptTarget.Latest, true);
|
|
257
|
+
const edges = [];
|
|
258
|
+
for (const statement of sourceFile.statements) {
|
|
259
|
+
if (!(ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement)) || !statement.moduleSpecifier || !ts.isStringLiteralLike(statement.moduleSpecifier))
|
|
260
|
+
continue;
|
|
261
|
+
const resolved = ts.resolveModuleName(statement.moduleSpecifier.text, abs, options, ts.sys).resolvedModule?.resolvedFileName;
|
|
262
|
+
const to = resolved ? graph.abs(canonical(resolved)) : null;
|
|
263
|
+
if (to && (provider === null || inIntegrationOf(graph, to, provider)))
|
|
264
|
+
edges.push({ from: rel, to, edge: { declaration: statement }, reexport: false });
|
|
265
|
+
}
|
|
266
|
+
return edges;
|
|
231
267
|
}
|
|
232
|
-
|
|
233
268
|
/**
|
|
234
269
|
* Pseudo edges (read from disk and staged index sources, outside the production program) to graph files: from the unit role specs, the fixture builders and
|
|
235
270
|
* the test world files to anything, and from an integration spec only to the integration of its own provider folder.
|
|
236
271
|
*/
|
|
237
272
|
function testConsumerEdges({ context, graph, config }) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
273
|
+
const resolution = { ts: context.ts, options: context.projects?.[0]?.options ?? {}, graph, config };
|
|
274
|
+
// Live lint keeps tracked disk consumers; staged snapshots add the consumers present in the same commit.
|
|
275
|
+
const staged = stagedConsumerSources(config.root, file => testConsumer(graph, file) || integrationSpecProvider(graph, file) !== null);
|
|
276
|
+
const consumers = [...[...treeOf(config.root).files].map((file) => ({ file })), ...staged]
|
|
277
|
+
.map(source => ({ ...source, any: testConsumer(graph, source.file) }))
|
|
278
|
+
.map(({ file, text, any }) => ({ file, text, provider: any ? null : integrationSpecProvider(graph, file), any }))
|
|
279
|
+
.filter(({ any, provider }) => any || provider !== null)
|
|
280
|
+
.sort((a, b) => a.file.localeCompare(b.file));
|
|
281
|
+
return consumers.flatMap(({ file: rel, text, provider }) => consumerFileEdges(resolution, rel, provider, text));
|
|
247
282
|
}
|
|
248
|
-
|
|
249
|
-
const edgeIndex = edges => {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
283
|
+
/** The edges grouped by an end of the edge (`to` unless a selector says otherwise), in edge order. */
|
|
284
|
+
const edgeIndex = (edges, keyOf = edge => edge.to) => {
|
|
285
|
+
const grouped = new Map();
|
|
286
|
+
for (const edge of edges) {
|
|
287
|
+
const key = keyOf(edge);
|
|
288
|
+
let list = grouped.get(key);
|
|
289
|
+
if (!list) {
|
|
290
|
+
list = [];
|
|
291
|
+
grouped.set(key, list);
|
|
292
|
+
}
|
|
293
|
+
list.push(edge);
|
|
294
|
+
}
|
|
295
|
+
return grouped;
|
|
256
296
|
};
|
|
257
|
-
|
|
258
297
|
const unitOfFile = (graph, rel) => {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
298
|
+
const known = graph.unit(rel);
|
|
299
|
+
if (known)
|
|
300
|
+
return known;
|
|
301
|
+
const classified = graph.resolver.classifyPath(rel);
|
|
302
|
+
const owner = classified.slot ? graph.resolver.ownerOf(rel) : null;
|
|
303
|
+
return owner ? `${owner.slot}:${owner.root}` : null;
|
|
264
304
|
};
|
|
265
|
-
|
|
266
305
|
const consumeReexportedName = (context, result, edge, pair, depth, visiting) => {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
306
|
+
if (pair.exported === null) {
|
|
307
|
+
result.names.add(pair.imported);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
// A re-export by name: the name is used when the re-exporting file's own export is used further on.
|
|
311
|
+
const reexporter = edge.from;
|
|
312
|
+
if (visiting.has(reexporter) || depth >= CHAIN_DEPTH) {
|
|
313
|
+
result.names.add(pair.imported);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (!(context.edgesTo.get(reexporter)?.length)) {
|
|
317
|
+
// nobody imports the re-exporting file: a framework entry (route file) uses it, an unused owner entry does not
|
|
318
|
+
const holder = context.graph.files.get(reexporter);
|
|
319
|
+
if (!holder?.owner || context.graph.resolver.slot(holder.owner.slot)?.tier === 'app')
|
|
320
|
+
result.names.add(pair.imported);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const next = consumedNames(context, reexporter, null, depth + 1, new Set([...visiting, reexporter]));
|
|
324
|
+
if (next.all || next.names.has(pair.exported))
|
|
325
|
+
result.names.add(pair.imported);
|
|
279
326
|
};
|
|
280
|
-
|
|
281
327
|
/** What the importers of `file` take from it; edges from inside `ownerKey` are skipped when given. */
|
|
282
328
|
const consumedNames = (context, file, ownerKey, depth, visiting) => {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
329
|
+
const result = { all: false, names: new Set() };
|
|
330
|
+
for (const edge of context.edgesTo.get(file) ?? []) {
|
|
331
|
+
if (ownerKey && unitOfFile(context.graph, edge.from) === ownerKey)
|
|
332
|
+
continue;
|
|
333
|
+
const bindings = bindingsOf(context, edge.edge.declaration);
|
|
334
|
+
if (bindings.all) {
|
|
335
|
+
result.all = true;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
for (const pair of bindings.pairs)
|
|
339
|
+
consumeReexportedName(context, result, edge, pair, depth, visiting);
|
|
340
|
+
}
|
|
341
|
+
return result;
|
|
291
342
|
};
|
|
292
|
-
|
|
293
343
|
/** Adds to `used` the entry exports reached by a consumer outside the owner that imports a file the entry re-exports by name. */
|
|
294
344
|
const addReexportedUses = (context, key, publicEntry, used) => {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
345
|
+
const { graph } = context;
|
|
346
|
+
for (const edge of graph.edges) {
|
|
347
|
+
if (edge.from !== publicEntry || !edge.reexport || graph.unit(edge.to) !== key)
|
|
348
|
+
continue;
|
|
349
|
+
const reexport = bindingsOf(context, edge.edge.declaration);
|
|
350
|
+
const inner = consumedNames(context, edge.to, key, 0, new Set([publicEntry, edge.to]));
|
|
351
|
+
if (reexport.all)
|
|
352
|
+
continue;
|
|
353
|
+
for (const pair of reexport.pairs)
|
|
354
|
+
if ((inner.all || inner.names.has(pair.imported)) && pair.exported !== null)
|
|
355
|
+
used.names.add(pair.exported);
|
|
356
|
+
}
|
|
303
357
|
};
|
|
304
|
-
|
|
305
358
|
const unusedExportViolation = (publicEntry, name, line, owner) => ({
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
359
|
+
ruleId: 'HFS_UNUSED_EXPORT',
|
|
360
|
+
path: publicEntry, line, column: 1,
|
|
361
|
+
name, owner: owner.root, slot: owner.slot,
|
|
362
|
+
message: `${publicEntry} exports ${name}, but no production file outside ${owner.root || 'the repository root'} imports it; remove the export (only a unit role spec, a fixture builder, a test world file, or an integration spec of this integration's own provider folder counts besides production files).`,
|
|
310
363
|
});
|
|
311
|
-
|
|
312
364
|
/** Adds to `used` what another declared entry of the same owner imports from `publicEntry`: that entry's signature makes it public. */
|
|
313
365
|
const addSiblingEntryUses = (context, publicEntry, declared, used) => {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
366
|
+
for (const edge of context.edgesTo.get(publicEntry) ?? []) {
|
|
367
|
+
if (edge.reexport || edge.from === publicEntry || !declared.has(edge.from))
|
|
368
|
+
continue;
|
|
369
|
+
const bindings = bindingsOf(context, edge.edge.declaration);
|
|
370
|
+
if (bindings.all)
|
|
371
|
+
used.all = true;
|
|
372
|
+
for (const pair of bindings.pairs)
|
|
373
|
+
used.names.add(pair.imported);
|
|
374
|
+
}
|
|
320
375
|
};
|
|
321
|
-
|
|
322
376
|
/** The unused-export violations and the export count of one public entry of an owner (`declared`: its slot's extra entries). */
|
|
323
377
|
const publicEntryExports = (context, key, owner, publicEntry, declared) => {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
.
|
|
331
|
-
|
|
378
|
+
const entryFile = context.graph.files.get(publicEntry);
|
|
379
|
+
if (!entryFile)
|
|
380
|
+
return { violations: [], exports: 0 };
|
|
381
|
+
const names = exportedNames(context.ts, entryFile.sourceFile);
|
|
382
|
+
const used = consumedNames(context, publicEntry, key, 0, new Set([publicEntry]));
|
|
383
|
+
addReexportedUses(context, key, publicEntry, used);
|
|
384
|
+
if (declared.has(publicEntry))
|
|
385
|
+
addSiblingEntryUses(context, publicEntry, declared, used);
|
|
386
|
+
const violations = [...names]
|
|
387
|
+
.filter(([name]) => !(used.all || used.names.has(name)))
|
|
388
|
+
.map(([name, line]) => unusedExportViolation(publicEntry, name, line, owner));
|
|
389
|
+
return { violations, exports: names.size };
|
|
332
390
|
};
|
|
333
|
-
|
|
334
391
|
const ownerExportFindings = (context, config) => {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
392
|
+
const { graph } = context;
|
|
393
|
+
const violations = [];
|
|
394
|
+
let owners = 0;
|
|
395
|
+
let exports = 0;
|
|
396
|
+
for (const [key, owner] of graph.ownerRoots) {
|
|
397
|
+
if (owner.tier === 'app')
|
|
398
|
+
continue;
|
|
399
|
+
const entry = entryOf(graph, config, key, owner);
|
|
400
|
+
if (!entry)
|
|
401
|
+
continue;
|
|
402
|
+
owners += 1;
|
|
403
|
+
const declared = new Set(extraEntries(graph, entry));
|
|
404
|
+
for (const publicEntry of [entry, ...declared]) {
|
|
405
|
+
const found = publicEntryExports(context, key, owner, publicEntry, declared);
|
|
406
|
+
exports += found.exports;
|
|
407
|
+
violations.push(...found.violations);
|
|
408
|
+
}
|
|
349
409
|
}
|
|
350
|
-
|
|
351
|
-
return { violations, owners, exports };
|
|
410
|
+
return { violations, owners, exports };
|
|
352
411
|
};
|
|
353
|
-
|
|
354
412
|
export function checkDeadExports({ context, graph, config }) {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
413
|
+
const edgesTo = edgeIndex([...graph.edges, ...testConsumerEdges({ context, graph, config })]);
|
|
414
|
+
const analysis = { ...context, graph, edgesTo, namespaceCheckers: new WeakMap(), namespaceUses: new WeakMap() };
|
|
415
|
+
const exports = ownerExportFindings(analysis, config);
|
|
416
|
+
const files = deadFiles(graph, config, context);
|
|
417
|
+
const dead = exports.violations.length;
|
|
418
|
+
exports.violations.push(...files.violations);
|
|
419
|
+
return { violations: exports.violations, coverage: { status: 'checked', owners: exports.owners, exports: exports.exports, dead, files: files.judged, roots: files.roots, unusedFiles: files.violations.length } };
|
|
362
420
|
}
|