@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
|
@@ -1,153 +1,171 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
|
|
3
2
|
export const keyOf = (ts, property) => (ts.isPropertyAssignment(property) || ts.isShorthandPropertyAssignment(property)) && (ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name)) ? property.name.text : null;
|
|
4
3
|
const exported = (ts, statement) => statement.modifiers?.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword) ?? false;
|
|
5
|
-
|
|
6
4
|
/** The directly defined functions among the declarations of an exported variable statement; other values are not callable. */
|
|
7
5
|
function callableVariables(ts, statement) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
const names = [];
|
|
7
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
8
|
+
const initializer = declaration.initializer;
|
|
9
|
+
if (ts.isIdentifier(declaration.name) && initializer && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer)))
|
|
10
|
+
names.push(declaration.name.text);
|
|
11
|
+
}
|
|
12
|
+
return names;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
/** The callable exports of one statement: an overload signature has no body and collapses into its implementation. */
|
|
17
15
|
function callableExports(ts, statement) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
if (!exported(ts, statement))
|
|
17
|
+
return [];
|
|
18
|
+
if (ts.isFunctionDeclaration(statement))
|
|
19
|
+
return statement.name && statement.body ? [statement.name.text] : [];
|
|
20
|
+
return ts.isVariableStatement(statement) ? callableVariables(ts, statement) : [];
|
|
21
21
|
}
|
|
22
|
-
|
|
23
22
|
/**
|
|
24
23
|
* The callable subset of a function subject's exports. Constants, enums, objects, types, `export ... from` re-exports and overload
|
|
25
24
|
* signatures do not change which functions the spec must provide; a class or a default-export assignment keeps the class-provider
|
|
26
25
|
* check (null), as does a module with no callable export.
|
|
27
26
|
*/
|
|
28
27
|
export function functionSubjectExports(ts, sourceFile) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
const names = [];
|
|
29
|
+
for (const statement of sourceFile.statements) {
|
|
30
|
+
if (ts.isClassDeclaration(statement) || ts.isExportAssignment(statement))
|
|
31
|
+
return null;
|
|
32
|
+
for (const name of callableExports(ts, statement))
|
|
33
|
+
if (!names.includes(name))
|
|
34
|
+
names.push(name);
|
|
35
|
+
}
|
|
36
|
+
return names.length ? names : null;
|
|
35
37
|
}
|
|
36
|
-
|
|
37
38
|
const decoratorsOf = (ts, node) => (ts.canHaveDecorators(node) ? ts.getDecorators(node) ?? [] : []);
|
|
38
|
-
|
|
39
39
|
/** A value object: an undecorated class whose constructor parameters carry no injection token, so Nest never builds it. */
|
|
40
40
|
function isValueObjectClass(ts, declaration) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
if (decoratorsOf(ts, declaration).length > 0)
|
|
42
|
+
return false;
|
|
43
|
+
const constructors = declaration.members.filter((member) => ts.isConstructorDeclaration(member));
|
|
44
|
+
return constructors.every(constructor => constructor.parameters.every(parameter => decoratorsOf(ts, parameter).length === 0));
|
|
44
45
|
}
|
|
45
|
-
|
|
46
46
|
/** The names of the value-object classes a module exports, or null when it exports a class that is not one (or none). */
|
|
47
47
|
export function valueObjectSubjects(ts, sourceFile) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
const classes = sourceFile.statements.filter((statement) => ts.isClassDeclaration(statement) && Boolean(statement.name) && exported(ts, statement));
|
|
49
|
+
if (!classes.length || !classes.every(declaration => isValueObjectClass(ts, declaration)))
|
|
50
|
+
return null;
|
|
51
|
+
return classes.map(declaration => declaration.name.text);
|
|
51
52
|
}
|
|
52
|
-
|
|
53
53
|
/** The value of one literal object property. */
|
|
54
54
|
export const propertyValue = (ts, object, key) => {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const property = object.properties.find(item => keyOf(ts, item) === key);
|
|
56
|
+
return property && ts.isPropertyAssignment(property) ? property.initializer : null;
|
|
57
57
|
};
|
|
58
|
-
|
|
59
58
|
/** A literal value object maps every exported function to its real sibling import. */
|
|
60
59
|
function realFunctions(ts, value, names, imports, rel, serviceRel) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
if (!value || !ts.isObjectLiteralExpression(value) || value.properties.length !== names.length)
|
|
61
|
+
return false;
|
|
62
|
+
const remaining = new Set(names);
|
|
63
|
+
for (const property of value.properties) {
|
|
64
|
+
const key = keyOf(ts, property);
|
|
65
|
+
const identifier = ts.isShorthandPropertyAssignment(property) ? property.name : ts.isPropertyAssignment(property) ? property.initializer : undefined;
|
|
66
|
+
if (key === null || !remaining.delete(key) || !identifier || !ts.isIdentifier(identifier))
|
|
67
|
+
return false;
|
|
68
|
+
const binding = imports.get(identifier.text);
|
|
69
|
+
if (!binding || binding.name !== key || !binding.module.startsWith('.'))
|
|
70
|
+
return false;
|
|
71
|
+
const target = path.posix.normalize(path.posix.join(path.posix.dirname(rel), binding.module)).replace(/\.[cm]?[jt]s$/u, '');
|
|
72
|
+
if (target !== serviceRel.replace(/\.ts$/u, ''))
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return remaining.size === 0;
|
|
73
76
|
}
|
|
74
|
-
|
|
75
77
|
/** Every node satisfying a predicate, within one spec. */
|
|
76
78
|
function matchingNodes(ts, root, predicate) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
const found = [];
|
|
80
|
+
const visit = (node) => {
|
|
81
|
+
if (predicate(node))
|
|
82
|
+
found.push(node);
|
|
83
|
+
ts.forEachChild(node, visit);
|
|
84
|
+
};
|
|
85
|
+
visit(root);
|
|
86
|
+
return found;
|
|
84
87
|
}
|
|
85
|
-
|
|
86
88
|
/** The declared variable initialized by an expression, including its await and call chain. */
|
|
87
89
|
function initializedVariable(ts, expression) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
let cursor = expression;
|
|
91
|
+
let compiled = false;
|
|
92
|
+
let awaited = false;
|
|
93
|
+
while (cursor.parent && (ts.isAwaitExpression(cursor.parent) || ts.isPropertyAccessExpression(cursor.parent) || ts.isCallExpression(cursor.parent))) {
|
|
94
|
+
cursor = cursor.parent;
|
|
95
|
+
if (ts.isAwaitExpression(cursor))
|
|
96
|
+
awaited = true;
|
|
97
|
+
if (ts.isCallExpression(cursor) && ts.isPropertyAccessExpression(cursor.expression) && cursor.expression.name.text === 'compile')
|
|
98
|
+
compiled = true;
|
|
99
|
+
}
|
|
100
|
+
if (!compiled || !awaited)
|
|
101
|
+
return null;
|
|
102
|
+
const declaration = cursor.parent;
|
|
103
|
+
return declaration && ts.isVariableDeclaration(declaration) && ts.isIdentifier(declaration.name) ? declaration.name.text : null;
|
|
99
104
|
}
|
|
100
|
-
|
|
101
105
|
/** The subject variable receiving module.get, whether declared there or assigned in beforeEach. */
|
|
102
106
|
function retrievedVariable(ts, call) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
let cursor = call;
|
|
108
|
+
while (cursor.parent && (ts.isAwaitExpression(cursor.parent) || ts.isParenthesizedExpression(cursor.parent)))
|
|
109
|
+
cursor = cursor.parent;
|
|
110
|
+
const parent = cursor.parent;
|
|
111
|
+
if (parent && ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name))
|
|
112
|
+
return parent.name.text;
|
|
113
|
+
if (parent && ts.isBinaryExpression(parent) && parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isIdentifier(parent.left))
|
|
114
|
+
return parent.left.text;
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
/** The `.text` of a node's `name`, when the node has an identifier-like name. */
|
|
118
|
+
function nameTextOf(node) {
|
|
119
|
+
// reason: a loose compiler-API node; only declarations carry a `name`, and its `.text` is read when it is a string
|
|
120
|
+
const name = node?.name;
|
|
121
|
+
return typeof name?.text === 'string' ? name.text : undefined;
|
|
109
122
|
}
|
|
110
|
-
|
|
111
123
|
/** A helper returning the retrieved subject is followed to the variable receiving its result. */
|
|
112
124
|
function retrievedSubjects(ts, read, sourceFile) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
125
|
+
const direct = retrievedVariable(ts, read);
|
|
126
|
+
if (direct)
|
|
127
|
+
return [direct];
|
|
128
|
+
if (!read.parent || !ts.isReturnStatement(read.parent))
|
|
129
|
+
return [];
|
|
130
|
+
let helper = read.parent;
|
|
131
|
+
while (helper.parent && !ts.isFunctionLike(helper))
|
|
132
|
+
helper = helper.parent;
|
|
133
|
+
const name = nameTextOf(helper) ?? nameTextOf(helper.parent);
|
|
134
|
+
if (!name)
|
|
135
|
+
return [];
|
|
136
|
+
return matchingNodes(ts, sourceFile, node => ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === name)
|
|
137
|
+
.map(node => retrievedVariable(ts, node)).filter((variable) => Boolean(variable));
|
|
122
138
|
}
|
|
123
|
-
|
|
124
139
|
/** The same compiled module retrieves the matching token and its result actually calls a subject function. */
|
|
125
140
|
function retrievedSubjectUsed(ts, call, token, names) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
141
|
+
const moduleName = initializedVariable(ts, call);
|
|
142
|
+
if (!moduleName)
|
|
143
|
+
return false;
|
|
144
|
+
const sourceFile = call.getSourceFile();
|
|
145
|
+
const reads = matchingNodes(ts, sourceFile, node => {
|
|
146
|
+
if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression))
|
|
147
|
+
return false;
|
|
148
|
+
const member = node.expression;
|
|
149
|
+
const first = node.arguments[0];
|
|
150
|
+
return ts.isIdentifier(member.expression) && member.expression.text === moduleName && member.name.text === 'get'
|
|
151
|
+
&& node.arguments.length === 1 && first !== undefined && ts.isIdentifier(first) && first.text === token.text;
|
|
152
|
+
});
|
|
153
|
+
return reads.some(read => {
|
|
154
|
+
const subjects = retrievedSubjects(ts, read, sourceFile);
|
|
155
|
+
return matchingNodes(ts, sourceFile, node => ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)
|
|
156
|
+
&& ts.isIdentifier(node.expression.expression) && subjects.includes(node.expression.expression.text) && names.includes(node.expression.name.text)).length > 0;
|
|
157
|
+
});
|
|
140
158
|
}
|
|
141
|
-
|
|
142
159
|
/** A pure function service has exactly one real subject value provider, retrieved and exercised through Nest. */
|
|
143
160
|
export function checkFunctionSubject({ ts, rel, serviceRel, imports, call, list, names, report }) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
161
|
+
const provider = list.elements[0];
|
|
162
|
+
const shape = provider && ts.isObjectLiteralExpression(provider) && provider.properties.length === 2;
|
|
163
|
+
const token = shape ? propertyValue(ts, provider, 'provide') : null;
|
|
164
|
+
const value = shape ? propertyValue(ts, provider, 'useValue') : null;
|
|
165
|
+
if (list.elements.length !== 1 || !token || !ts.isIdentifier(token) || !realFunctions(ts, value, names, imports, rel, serviceRel)) {
|
|
166
|
+
report(provider ?? list, `${rel}: a function-only subject needs exactly one { provide: TOKEN, useValue: { ...realFunctions } } provider containing every callable export imported from ./${path.posix.basename(serviceRel, '.ts')}.`);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (!retrievedSubjectUsed(ts, call, token, names))
|
|
170
|
+
report(list, `${rel}: retrieve the function subject with moduleRef.get(TOKEN) from this compiled testing module and exercise a function on the returned subject.`);
|
|
153
171
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { canonical } from './config.mjs';
|
|
2
2
|
import { relativePath } from './typescript.mjs';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* The file and owner graph the HFS architecture checks share. Every production source file the TypeScript context
|
|
6
5
|
* loaded becomes a node classified by the slot manifest (config.hfs is the resolver of scripts/hfs/slots.mjs);
|
|
@@ -17,57 +16,62 @@ import { relativePath } from './typescript.mjs';
|
|
|
17
16
|
*/
|
|
18
17
|
// Every production source file the TypeScript context loaded, as a graph.files node keyed by its repository-relative path.
|
|
19
18
|
const collectFiles = (config, context, resolver) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
19
|
+
const files = new Map();
|
|
20
|
+
const absolute = new Map();
|
|
21
|
+
for (const sourceFile of context.files) {
|
|
22
|
+
const file = canonical(sourceFile.fileName);
|
|
23
|
+
const rel = relativePath(config.root, file);
|
|
24
|
+
if (rel.startsWith('..'))
|
|
25
|
+
continue;
|
|
26
|
+
const classified = resolver.classifyPath(rel);
|
|
27
|
+
files.set(rel, {
|
|
28
|
+
abs: file,
|
|
29
|
+
rel,
|
|
30
|
+
slot: classified.slot ?? null,
|
|
31
|
+
status: classified.status,
|
|
32
|
+
tier: classified.slot ? resolver.tierOf(rel) : null,
|
|
33
|
+
owner: classified.slot ? resolver.ownerOf(rel) : null,
|
|
34
|
+
sourceFile,
|
|
35
|
+
});
|
|
36
|
+
absolute.set(file, rel);
|
|
37
|
+
}
|
|
38
|
+
return { files, absolute };
|
|
39
39
|
};
|
|
40
|
-
|
|
41
40
|
// Every import, re-export and type-only import between two graphed files, as rel-path edges.
|
|
42
41
|
const collectEdges = (context, absolute) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
const edges = [];
|
|
43
|
+
for (const [file, list] of context.edges) {
|
|
44
|
+
const from = absolute.get(file);
|
|
45
|
+
if (!from)
|
|
46
|
+
continue;
|
|
47
|
+
for (const edge of list) {
|
|
48
|
+
const to = absolute.get(edge.to);
|
|
49
|
+
if (!to || to === from)
|
|
50
|
+
continue;
|
|
51
|
+
edges.push({ from, to, runtime: edge.runtime, line: edge.line, column: edge.column, specifier: edge.specifier, reexport: Boolean(edge.reexport), edge });
|
|
52
|
+
}
|
|
51
53
|
}
|
|
52
|
-
|
|
53
|
-
return edges;
|
|
54
|
+
return edges;
|
|
54
55
|
};
|
|
55
|
-
|
|
56
56
|
export function buildHfsGraph(config, context) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
57
|
+
const resolver = config.hfs;
|
|
58
|
+
const { files, absolute } = collectFiles(config, context, resolver);
|
|
59
|
+
const edges = collectEdges(context, absolute);
|
|
60
|
+
const unit = (rel) => {
|
|
61
|
+
const node = files.get(rel);
|
|
62
|
+
if (!node)
|
|
63
|
+
return null;
|
|
64
|
+
if (node.owner)
|
|
65
|
+
return `${node.owner.slot}:${node.owner.root}`;
|
|
66
|
+
const classified = resolver.classifyPath(rel);
|
|
67
|
+
return classified.slot ? `${classified.slot}:${classified.root}` : null;
|
|
68
|
+
};
|
|
69
|
+
const ownerRoots = new Map();
|
|
70
|
+
for (const node of files.values())
|
|
71
|
+
if (node.owner) {
|
|
72
|
+
const key = `${node.owner.slot}:${node.owner.root}`;
|
|
73
|
+
if (!ownerRoots.has(key))
|
|
74
|
+
ownerRoots.set(key, { slot: node.owner.slot, root: node.owner.root, tier: resolver.slot(node.owner.slot)?.tier ?? '' }); // the owner slot came from resolver.ownerOf, so the manifest holds it
|
|
75
|
+
}
|
|
76
|
+
return { profile: resolver.repo.profile, resolver, files, edges, unit, ownerRoots, abs: (file) => absolute.get(file) ?? null };
|
|
73
77
|
}
|
|
@@ -2,7 +2,6 @@ import path from 'node:path';
|
|
|
2
2
|
import { machineKit } from './machine-ast.mjs';
|
|
3
3
|
import { treeOf } from './required-files.mjs';
|
|
4
4
|
import { byCodeUnit } from '../../lib/list.mjs';
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* R56 `hooks-are-hooks` (FE_HOOKS_ARE_HOOKS), the repository half of the eslint rule `hooks-folder-holds-hooks-only`, which
|
|
8
7
|
* judges one file at a time and leaves to the machine what needs the whole tree. Per domain folder of hooks
|
|
@@ -14,95 +13,106 @@ import { byCodeUnit } from '../../lib/list.mjs';
|
|
|
14
13
|
* in two files of the domain is a helper copied instead of shared; it lives once in `<domain>.shared.ts`.
|
|
15
14
|
*/
|
|
16
15
|
export const HOOKS_ARE_HOOKS_RULE_IDS = ['FE_HOOKS_ARE_HOOKS'];
|
|
17
|
-
|
|
18
16
|
const RULE = 'FE_HOOKS_ARE_HOOKS';
|
|
19
17
|
const HOOKS_SLOT = 'fe.hooks';
|
|
20
18
|
const HOOK_NAME = /^use[A-Z0-9]/u;
|
|
21
19
|
const SHARED = /\.shared\.[cm]?tsx?$/u;
|
|
22
|
-
|
|
23
20
|
const sharedFilesOf = (tree, resolver, domains) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
21
|
+
const shared = new Map(); // domain root -> [file]
|
|
22
|
+
for (const rel of [...tree.files].sort(byCodeUnit)) {
|
|
23
|
+
const classified = resolver.classifyPath(rel);
|
|
24
|
+
if (classified.slot !== HOOKS_SLOT || !classified.root)
|
|
25
|
+
continue;
|
|
26
|
+
domains.add(classified.root);
|
|
27
|
+
const base = path.posix.basename(rel);
|
|
28
|
+
if (/\.spec\.[cm]?tsx?$/u.test(base) || !SHARED.test(base))
|
|
29
|
+
continue;
|
|
30
|
+
let list = shared.get(classified.root);
|
|
31
|
+
if (!list) {
|
|
32
|
+
list = [];
|
|
33
|
+
shared.set(classified.root, list);
|
|
34
|
+
}
|
|
35
|
+
list.push({ rel, base });
|
|
36
|
+
}
|
|
37
|
+
return shared;
|
|
35
38
|
};
|
|
36
|
-
|
|
37
39
|
const reportSharedFileViolations = (shared, violations) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
for (const [root, list] of shared) {
|
|
41
|
+
const domain = path.posix.basename(root);
|
|
42
|
+
const at = (item, message) => violations.push({ ruleId: RULE, path: item.rel, line: 1, column: 1, domain, message });
|
|
43
|
+
for (const item of list) {
|
|
44
|
+
if (item.base.replace(/\.[cm]?tsx?$/u, '') !== `${domain}.shared` || path.posix.dirname(item.rel) !== root) {
|
|
45
|
+
at(item, `${item.rel} is a shared file that is not ${root}/${domain}.shared.ts; a hooks domain has one shared file for its non-hook helpers, named after the domain. Move the helpers into it.`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
for (const item of list.filter(entry => entry.base.replace(/\.[cm]?tsx?$/u, '') === `${domain}.shared` && path.posix.dirname(entry.rel) === root).slice(1)) {
|
|
49
|
+
at(item, `${item.rel} is a second shared file of hooks domain ${domain}; a domain has exactly one, ${domain}.shared.ts. Merge the helpers into it.`);
|
|
50
|
+
}
|
|
48
51
|
}
|
|
49
|
-
}
|
|
50
52
|
};
|
|
51
|
-
|
|
52
53
|
const helperDeclarationsOf = (statement, ts) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
const found = [];
|
|
55
|
+
if (ts.isFunctionDeclaration(statement) && statement.name)
|
|
56
|
+
found.push([statement.name.text, statement.name]);
|
|
57
|
+
if (ts.isVariableStatement(statement)) {
|
|
58
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
59
|
+
const init = declaration.initializer;
|
|
60
|
+
if (ts.isIdentifier(declaration.name) && init && (ts.isArrowFunction(init) || ts.isFunctionExpression(init)))
|
|
61
|
+
found.push([declaration.name.text, declaration.name]);
|
|
62
|
+
}
|
|
59
63
|
}
|
|
60
|
-
|
|
61
|
-
return found;
|
|
64
|
+
return found;
|
|
62
65
|
};
|
|
63
|
-
|
|
64
66
|
const recordDeclaredHelper = (declared, root, name, file, node) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
if (HOOK_NAME.test(name))
|
|
68
|
+
return;
|
|
69
|
+
let byName = declared.get(root);
|
|
70
|
+
if (!byName) {
|
|
71
|
+
byName = new Map();
|
|
72
|
+
declared.set(root, byName);
|
|
73
|
+
}
|
|
74
|
+
let list = byName.get(name);
|
|
75
|
+
if (!list) {
|
|
76
|
+
list = [];
|
|
77
|
+
byName.set(name, list);
|
|
78
|
+
}
|
|
79
|
+
list.push({ file, node });
|
|
70
80
|
};
|
|
71
|
-
|
|
72
81
|
const declaredHelpersOf = (graph, resolver, ts) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
const declared = new Map(); // domain root -> name -> [{file, node}]
|
|
83
|
+
for (const file of graph.files.values()) {
|
|
84
|
+
if (file.slot !== HOOKS_SLOT)
|
|
85
|
+
continue;
|
|
86
|
+
const root = resolver.classifyPath(file.rel).root ?? ''; // a file in the hooks slot was placed by that slot, so its root exists
|
|
87
|
+
for (const statement of file.sourceFile.statements) {
|
|
88
|
+
for (const [name, node] of helperDeclarationsOf(statement, ts))
|
|
89
|
+
recordDeclaredHelper(declared, root, name, file, node);
|
|
90
|
+
}
|
|
79
91
|
}
|
|
80
|
-
|
|
81
|
-
return declared;
|
|
92
|
+
return declared;
|
|
82
93
|
};
|
|
83
|
-
|
|
84
94
|
const reportDuplicateHelpers = (declared, violations, kit) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
for (const [root, byName] of declared) {
|
|
96
|
+
const domain = path.posix.basename(root);
|
|
97
|
+
for (const [name, list] of byName) {
|
|
98
|
+
if (list.length < 2)
|
|
99
|
+
continue;
|
|
100
|
+
for (const item of list.slice(1)) {
|
|
101
|
+
const others = list.map(entry => entry.file.rel).filter(rel => rel !== item.file.rel).sort(byCodeUnit);
|
|
102
|
+
violations.push({ ruleId: RULE, path: item.file.rel, ...kit.at(item.file.rel, item.file.sourceFile, item.node), domain, helper: name,
|
|
103
|
+
message: `${name} is declared again in hooks domain ${domain} (also in ${others.join(', ')}); a helper the hooks share is written once, in ${domain}.shared.ts.` });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
94
106
|
}
|
|
95
|
-
}
|
|
96
107
|
};
|
|
97
|
-
|
|
98
108
|
export function checkHooksAreHooks(input) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
const { config, graph } = input;
|
|
110
|
+
const kit = machineKit(input);
|
|
111
|
+
const { ts, resolver } = kit;
|
|
112
|
+
const violations = [];
|
|
113
|
+
const domains = new Set();
|
|
114
|
+
const shared = sharedFilesOf(treeOf(config.root), resolver, domains);
|
|
115
|
+
reportSharedFileViolations(shared, violations);
|
|
116
|
+
reportDuplicateHelpers(declaredHelpersOf(graph, resolver, ts), violations, kit);
|
|
117
|
+
return { violations, coverage: { status: 'checked', domains: domains.size } };
|
|
108
118
|
}
|