@starci/eslint-canon-be 3.8.19 → 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 +12 -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,5 +1,4 @@
|
|
|
1
1
|
import { machineKit } from './machine-ast.mjs';
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* R41 `default-deny-app-guard` (BE_DEFAULT_DENY). Every api app root provides its `APP_GUARD` entries in the order
|
|
5
4
|
* throttler -> CSRF origin guard -> CredentialGuard -> AuthGuard, each exactly once, so no request reaches a handler before it was
|
|
@@ -13,144 +12,164 @@ import { machineKit } from './machine-ast.mjs';
|
|
|
13
12
|
* Other guards are permitted between them; a missing, repeated or reordered one of the three is a finding.
|
|
14
13
|
*/
|
|
15
14
|
export const DEFAULT_DENY_RULE_IDS = ['BE_DEFAULT_DENY'];
|
|
16
|
-
|
|
17
15
|
const RULE = 'BE_DEFAULT_DENY';
|
|
18
16
|
const ORDER = ['throttler', 'csrf', 'credential', 'auth'];
|
|
19
17
|
const ORIGIN_HEADERS = new Set(['origin', 'referer', 'referrer']);
|
|
20
18
|
const METADATA_READERS = new Set(['get', 'getAll', 'getAllAndMerge', 'getAllAndOverride']);
|
|
21
19
|
const LABEL = { throttler: 'the throttler guard', csrf: 'the CSRF origin guard of platform/http-security', credential: 'CredentialGuard of domain/identity', auth: 'AuthGuard of domain/identity' };
|
|
22
|
-
|
|
23
20
|
const keySymbol = (kit, checker, node) => (node ? kit.aliased(checker, kit.symbolAt(checker, node)) ?? null : null);
|
|
24
|
-
|
|
25
21
|
const extendsThrottlerType = (kit, checker, declaration, type, depth) => {
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
if (kit.isImportOf(checker, type.expression, 'ThrottlerGuard', '@nestjs/throttler'))
|
|
23
|
+
return true;
|
|
24
|
+
return kit.declarationsOf(checker, type.expression).some(parent => parent !== declaration && extendsThrottler(kit, parent, depth + 1));
|
|
28
25
|
};
|
|
29
|
-
|
|
30
26
|
function extendsThrottler(kit, declaration, depth = 0) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
const ts = kit.ts;
|
|
28
|
+
if (!ts.isClassDeclaration(declaration) || depth > 8)
|
|
29
|
+
return false;
|
|
30
|
+
const checker = kit.checkerOf(declaration.getSourceFile());
|
|
31
|
+
if (!checker)
|
|
32
|
+
return false;
|
|
33
|
+
const types = (declaration.heritageClauses ?? []).flatMap(clause => [...clause.types]);
|
|
34
|
+
return types.some(type => extendsThrottlerType(kit, checker, declaration, type, depth));
|
|
36
35
|
}
|
|
37
|
-
|
|
38
36
|
const collectSetMetadataKeys = (kit, file, keys) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
const { ts } = kit;
|
|
38
|
+
const checker = kit.checkerOf(file.sourceFile);
|
|
39
|
+
if (!checker)
|
|
40
|
+
return;
|
|
41
|
+
kit.walk(file.sourceFile, (node) => {
|
|
42
|
+
if (ts.isCallExpression(node) && kit.isImportOf(checker, node.expression, 'SetMetadata', '@nestjs/common')) {
|
|
43
|
+
const key = keySymbol(kit, checker, node.arguments[0]);
|
|
44
|
+
if (key)
|
|
45
|
+
keys.add(key);
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
});
|
|
49
49
|
};
|
|
50
|
-
|
|
51
50
|
/** The symbols a SetMetadata call of the owner writes as metadata keys: what its door decorators (`@RateLimit(tier)`) attach. */
|
|
52
51
|
const writtenKeys = (kit, graph, owner, cache) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
const cached = cache.get(owner.root);
|
|
53
|
+
if (cached)
|
|
54
|
+
return cached;
|
|
55
|
+
const keys = new Set();
|
|
56
|
+
for (const file of graph.files.values()) {
|
|
57
|
+
if (file.owner?.root === owner.root)
|
|
58
|
+
collectSetMetadataKeys(kit, file, keys);
|
|
59
|
+
}
|
|
60
|
+
cache.set(owner.root, keys);
|
|
61
|
+
return keys;
|
|
60
62
|
};
|
|
61
|
-
|
|
62
63
|
/** True when the class reads a request origin or referer header (the origin/referer allowlist of the CSRF guard). */
|
|
63
64
|
const readsOrigin = (kit, declaration) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
const { ts } = kit;
|
|
66
|
+
let found = false;
|
|
67
|
+
kit.walk(declaration, (node) => {
|
|
68
|
+
let name = null;
|
|
69
|
+
if (ts.isPropertyAccessExpression(node))
|
|
70
|
+
name = node.name.text;
|
|
71
|
+
else if (ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression))
|
|
72
|
+
name = node.argumentExpression.text;
|
|
73
|
+
if (name && ORIGIN_HEADERS.has(name.toLowerCase()))
|
|
74
|
+
found = true;
|
|
75
|
+
return !found;
|
|
76
|
+
});
|
|
77
|
+
return found;
|
|
74
78
|
};
|
|
75
|
-
|
|
76
79
|
const isMetadataRead = (ts, node) => ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && METADATA_READERS.has(node.expression.name.text);
|
|
77
|
-
|
|
78
80
|
/** True when the class reads, through a metadata getter, a key its own capability's SetMetadata decorators write. */
|
|
79
81
|
const readsDoorMetadata = (kit, graph, keyCache, declaration, owner) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
const checker = kit.checkerOf(declaration.getSourceFile());
|
|
83
|
+
if (!checker)
|
|
84
|
+
return false;
|
|
85
|
+
const keys = writtenKeys(kit, graph, owner, keyCache);
|
|
86
|
+
let found = false;
|
|
87
|
+
kit.walk(declaration, (node) => {
|
|
88
|
+
if (isMetadataRead(kit.ts, node)) {
|
|
89
|
+
const key = keySymbol(kit, checker, node.arguments[0]);
|
|
90
|
+
if (key && keys.has(key))
|
|
91
|
+
found = true;
|
|
92
|
+
}
|
|
93
|
+
return !found;
|
|
94
|
+
});
|
|
95
|
+
return found;
|
|
92
96
|
};
|
|
93
|
-
|
|
94
97
|
const classifyDeclaration = (kit, graph, keyCache, declaration) => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
const ts = kit.ts;
|
|
99
|
+
const owner = kit.ownerOfDeclaration(declaration);
|
|
100
|
+
if (owner?.tier === 'platform' && owner.name === 'http-security' && ts.isClassDeclaration(declaration)) {
|
|
101
|
+
if (readsOrigin(kit, declaration))
|
|
102
|
+
return 'csrf';
|
|
103
|
+
if (readsDoorMetadata(kit, graph, keyCache, declaration, owner))
|
|
104
|
+
return 'throttler';
|
|
105
|
+
}
|
|
106
|
+
if (owner?.tier === 'domain' && owner.name === 'identity' && ts.isClassDeclaration(declaration) && declaration.name?.text === 'AuthGuard')
|
|
107
|
+
return 'auth';
|
|
108
|
+
if (owner?.tier === 'domain' && owner.name === 'identity' && ts.isClassDeclaration(declaration) && declaration.name?.text === 'CredentialGuard')
|
|
109
|
+
return 'credential';
|
|
110
|
+
return null;
|
|
104
111
|
};
|
|
105
|
-
|
|
106
112
|
const classify = (kit, graph, keyCache, checker, node) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
if (!node)
|
|
114
|
+
return null;
|
|
115
|
+
if (kit.importBinding(checker, node)?.module === '@nestjs/throttler')
|
|
116
|
+
return 'throttler';
|
|
117
|
+
const declarations = kit.declarationsOf(checker, node);
|
|
118
|
+
if (declarations.some(declaration => extendsThrottler(kit, declaration)))
|
|
119
|
+
return 'throttler';
|
|
120
|
+
for (const declaration of declarations) {
|
|
121
|
+
const role = classifyDeclaration(kit, graph, keyCache, declaration);
|
|
122
|
+
if (role)
|
|
123
|
+
return role;
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
116
126
|
};
|
|
117
|
-
|
|
118
127
|
const roleMessages = (app, roles, anchor) => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
128
|
+
const out = [];
|
|
129
|
+
for (const role of ORDER) {
|
|
130
|
+
const entries = roles.filter(item => item.role === role);
|
|
131
|
+
if (entries.length === 0)
|
|
132
|
+
out.push({ node: anchor, message: `App ${app.name} does not provide ${LABEL[role]} as an APP_GUARD; an api app is denied by default: throttler, then CSRF origin guard, then CredentialGuard, then AuthGuard.` });
|
|
133
|
+
else if (entries.length > 1 && entries[1])
|
|
134
|
+
out.push({ node: entries[1].guard.node, message: `App ${app.name} provides ${LABEL[role]} more than once as an APP_GUARD.` });
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
126
137
|
};
|
|
127
|
-
|
|
128
138
|
const orderMessages = (app, roles) => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
const indexes = ORDER.map(role => roles.findIndex(item => item.role === role));
|
|
140
|
+
if (!indexes.every(index => index >= 0))
|
|
141
|
+
return [];
|
|
142
|
+
const out = [];
|
|
143
|
+
for (let i = 1; i < indexes.length; i += 1) {
|
|
144
|
+
const index = indexes[i];
|
|
145
|
+
const previous = indexes[i - 1];
|
|
146
|
+
const role = ORDER[i];
|
|
147
|
+
const before = ORDER[i - 1];
|
|
148
|
+
const entry = index === undefined ? undefined : roles[index];
|
|
149
|
+
if (index === undefined || previous === undefined || role === undefined || before === undefined || entry === undefined)
|
|
150
|
+
continue;
|
|
151
|
+
if (index < previous)
|
|
152
|
+
out.push({ node: entry.guard.node, message: `App ${app.name} provides ${LABEL[role]} before ${LABEL[before]}; the APP_GUARD order is throttler, CSRF origin guard, CredentialGuard, AuthGuard.` });
|
|
153
|
+
}
|
|
154
|
+
return out;
|
|
136
155
|
};
|
|
137
|
-
|
|
138
156
|
export function checkDefaultDeny(input) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
157
|
+
const { config } = input;
|
|
158
|
+
const kit = machineKit(input);
|
|
159
|
+
const violations = [];
|
|
160
|
+
const keyCache = new Map();
|
|
161
|
+
let apps = 0;
|
|
162
|
+
for (const app of config.apps.filter(item => item.kind === 'api')) {
|
|
163
|
+
const root = kit.appRoot(app.name);
|
|
164
|
+
if (!root)
|
|
165
|
+
continue;
|
|
166
|
+
apps += 1;
|
|
167
|
+
const guards = kit.providersOf(root, 'APP_GUARD', '@nestjs/core');
|
|
168
|
+
const roles = guards.map(guard => ({ guard, role: classify(kit, input.graph, keyCache, guard.checker, guard.useClass) }));
|
|
169
|
+
const anchor = guards[0]?.node ?? root.sourceFile.statements[0] ?? root.sourceFile;
|
|
170
|
+
const messages = [...roleMessages(app, roles, anchor), ...orderMessages(app, roles)];
|
|
171
|
+
for (const { node, message } of messages)
|
|
172
|
+
violations.push({ ruleId: RULE, path: root.rel, ...kit.at(root.rel, root.sourceFile, node), app: app.name, message });
|
|
173
|
+
}
|
|
174
|
+
return { violations, coverage: { status: 'checked', apps } };
|
|
156
175
|
}
|
|
@@ -3,7 +3,6 @@ import path from 'node:path';
|
|
|
3
3
|
import { treeOf } from './required-files.mjs';
|
|
4
4
|
import { documentLanguageHits, isDocument, isLocalizedDataFile } from '../../lib/language.mjs';
|
|
5
5
|
import { byCodeUnit } from '../../lib/list.mjs';
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* R96 `doc-language` (HFS_DOC_NOT_ENGLISH). Every Markdown and YAML document under knowledge/, docs/, src/ and apps/ is English:
|
|
9
8
|
* prose, patterns and examples alike, and a code fence inside Markdown counts because an example is read exactly like the
|
|
@@ -14,27 +13,33 @@ import { byCodeUnit } from '../../lib/list.mjs';
|
|
|
14
13
|
* inside a catalog slot is judged like any other document. No comment pragma, no path pattern.
|
|
15
14
|
*/
|
|
16
15
|
export const DOC_LANGUAGE_RULE_IDS = ['HFS_DOC_NOT_ENGLISH'];
|
|
17
|
-
|
|
18
16
|
const RULE = 'HFS_DOC_NOT_ENGLISH';
|
|
19
17
|
/** The top-level folders whose documents this check reads. */
|
|
20
18
|
const DOCUMENT_ROOTS = Object.freeze(['knowledge', 'docs', 'src', 'apps']);
|
|
21
|
-
|
|
22
19
|
export function checkDocLanguage({ config, graph }) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
const resolver = graph.resolver;
|
|
21
|
+
const tree = treeOf(config.root);
|
|
22
|
+
const violations = [];
|
|
23
|
+
let files = 0;
|
|
24
|
+
for (const file of [...tree.files].sort(byCodeUnit)) {
|
|
25
|
+
if (!DOCUMENT_ROOTS.includes(file.split('/')[0] ?? '') || !isDocument(file) || file.split('/').includes('node_modules'))
|
|
26
|
+
continue;
|
|
27
|
+
const classified = resolver.classifyPath(file);
|
|
28
|
+
const dataSlot = classified.status === 'owned' ? classified.slot : null;
|
|
29
|
+
if (dataSlot !== null && isLocalizedDataFile(file, dataSlot))
|
|
30
|
+
continue;
|
|
31
|
+
let text;
|
|
32
|
+
try {
|
|
33
|
+
text = fs.readFileSync(path.join(config.root, ...file.split('/')), 'utf8');
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
files += 1;
|
|
39
|
+
for (const hit of documentLanguageHits(file, text)) {
|
|
40
|
+
violations.push({ ruleId: RULE, path: file, line: hit.line, column: hit.column,
|
|
41
|
+
message: `${file}:${hit.line} carries a Vietnamese letter. Documents are English (prose, patterns, examples and code fences); only YAML data in a message-catalog or i18n-fixtures slot may hold another language. Write the line in English.` });
|
|
42
|
+
}
|
|
37
43
|
}
|
|
38
|
-
|
|
39
|
-
return { violations, coverage: { status: 'checked', files } };
|
|
44
|
+
return { violations, coverage: { status: 'checked', files } };
|
|
40
45
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { braceVariants, globExpression } from '../../lib/glob.mjs';
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* The entity registry (persistence.md BE-PERSISTENCE-3): the one file whose slot plays `role: entity-registry`
|
|
5
4
|
* (`be.platform.database.entities`, lite's `src/modules/platform/database/entities.ts`). It lists every capability's `<c>Entities`
|
|
@@ -8,46 +7,45 @@ import { braceVariants, globExpression } from '../../lib/glob.mjs';
|
|
|
8
7
|
* The tier matrix (tiers.mjs), the public-entry check (owners.mjs) and the lint rule `import-owner-entry` read it here.
|
|
9
8
|
*/
|
|
10
9
|
export const ENTITY_REGISTRY_ROLE = 'entity-registry';
|
|
11
|
-
|
|
12
10
|
/** The tiers whose capabilities contribute an entity list to the registry. */
|
|
13
11
|
const CONTRIBUTING_TIERS = new Set(['domain', 'platform']);
|
|
14
|
-
|
|
15
12
|
/** The entity list a capability exports: `<c>Entities`, `<c>` its folder name in camelCase. */
|
|
16
|
-
export const entityListName = capability => `${capability.replace(/-([a-z0-9])/g, (_, next) => next.toUpperCase())}Entities`;
|
|
17
|
-
|
|
13
|
+
export const entityListName = (capability) => `${capability.replace(/-([a-z0-9])/g, (_, next) => next.toUpperCase())}Entities`;
|
|
18
14
|
/** The slot of `file` (side-relative or absolute) when it plays the entity-registry role, else null. */
|
|
19
15
|
export function registrySlot(resolver, file) {
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
const slot = resolver?.slotOf?.(file);
|
|
17
|
+
return slot?.role === ENTITY_REGISTRY_ROLE ? slot : null;
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
/**
|
|
25
20
|
* Whether `file` is one of the importers the registry slot admits by deep path (`importedBy`, side-relative patterns); an app-wide
|
|
26
21
|
* resolver answers for a side-prefixed path (`be/apps/...`), which is read without its side folder.
|
|
27
22
|
*/
|
|
28
23
|
export function registryImporter(resolver, slot, file) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
const side = resolver?.sideOf?.(file);
|
|
25
|
+
const rel = side ? file.slice(side.length + 1) : file;
|
|
26
|
+
return (slot.importedBy ?? []).some(pattern => braceVariants(pattern).some((variant) => globExpression(variant).test(rel)));
|
|
32
27
|
}
|
|
33
|
-
|
|
34
28
|
/** The names an import declaration binds by name; null for a default, namespace or side-effect import and for any re-export. */
|
|
35
29
|
function namedImports(declaration) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
const clause = declaration?.importClause;
|
|
31
|
+
const bindings = clause?.namedBindings;
|
|
32
|
+
if (!clause || clause.name || !Array.isArray(bindings?.elements) || !bindings.elements.length)
|
|
33
|
+
return null;
|
|
34
|
+
return bindings.elements.map(element => (element.propertyName ?? element.name).text);
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
/**
|
|
42
37
|
* Whether an owner-graph edge (side-relative `from` and `to`, `edge.declaration` the TypeScript statement) is the registry naming a
|
|
43
38
|
* capability's entity list: it leaves the registry, imports the public entry (`index.ts`) of a domain or platform capability, and
|
|
44
39
|
* binds that capability's `<c>Entities` and nothing else.
|
|
45
40
|
*/
|
|
46
41
|
export function registryListImport(resolver, edge) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
if (!registrySlot(resolver, edge.from))
|
|
43
|
+
return false;
|
|
44
|
+
const owner = resolver.ownerOf(edge.to);
|
|
45
|
+
const tier = owner ? resolver.slot(owner.slot)?.tier : undefined;
|
|
46
|
+
if (!owner || !CONTRIBUTING_TIERS.has(tier ?? '') || edge.to !== `${owner.root}/index.ts`)
|
|
47
|
+
return false;
|
|
48
|
+
const names = namedImports(edge.edge?.declaration ?? edge.declaration);
|
|
49
|
+
const listName = entityListName(owner.root.split('/').at(-1) ?? '');
|
|
50
|
+
return names !== null && names.every(name => name === listName);
|
|
53
51
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { machineKit } from './machine-ast.mjs';
|
|
3
3
|
import { isTestWorldSlot } from '../test-world-slot.mjs';
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* R33 `entrypoint-only-in-apps` (BE_ENTRYPOINT_ONLY_IN_APPS). A process starts in `apps/<app>/src/main.ts` only:
|
|
7
6
|
* `NestFactory.create*` (from @nestjs/core) and a top-level `bootstrap()` call anywhere else are entrypoints hiding in a
|
|
@@ -13,61 +12,64 @@ import { isTestWorldSlot } from '../test-world-slot.mjs';
|
|
|
13
12
|
* other test slots stay refused.
|
|
14
13
|
*/
|
|
15
14
|
export const ENTRYPOINT_RULE_IDS = ['BE_ENTRYPOINT_ONLY_IN_APPS'];
|
|
16
|
-
|
|
17
15
|
const RULE = 'BE_ENTRYPOINT_ONLY_IN_APPS';
|
|
18
|
-
|
|
19
16
|
const TRANSPARENT = ['isVoidExpression', 'isAwaitExpression', 'isParenthesizedExpression', 'isNonNullExpression'];
|
|
20
|
-
|
|
17
|
+
const isTransparent = (ts, node) => TRANSPARENT.some(test => ts[test](node));
|
|
21
18
|
/** The identifier a top-level statement calls: `bootstrap()`, `void bootstrap()`, `bootstrap().catch(...)`. */
|
|
22
19
|
function calledIdentifier(ts, expression) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
let current = expression;
|
|
21
|
+
for (;;) {
|
|
22
|
+
if (isTransparent(ts, current))
|
|
23
|
+
current = current.expression;
|
|
24
|
+
else if (ts.isCallExpression(current)) {
|
|
25
|
+
if (ts.isIdentifier(current.expression))
|
|
26
|
+
return current.expression;
|
|
27
|
+
current = current.expression;
|
|
28
|
+
}
|
|
29
|
+
else if (ts.isPropertyAccessExpression(current))
|
|
30
|
+
current = current.expression;
|
|
31
|
+
else
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
32
34
|
}
|
|
33
|
-
|
|
34
35
|
const isNestFactoryCreate = (kit, ts, checker, node) => ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text.startsWith('create')
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const isMainFile = file => (Boolean(file.slot?.startsWith('be.app.')) && path.posix.basename(file.rel) === 'main.ts') || isTestWorldSlot(file.slot);
|
|
38
|
-
|
|
36
|
+
&& kit.isImportOf(checker, node.expression.expression, 'NestFactory', '@nestjs/core');
|
|
37
|
+
const isMainFile = (file) => (Boolean(file.slot?.startsWith('be.app.')) && path.posix.basename(file.rel) === 'main.ts') || isTestWorldSlot(file.slot);
|
|
39
38
|
/** Counts the NestFactory.create* calls of an entrypoint owner and reports them in any other file. */
|
|
40
39
|
function inspectFactoryCalls(kit, file, isMain, report) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
const { ts } = kit;
|
|
41
|
+
const checker = kit.checkerOf(file.sourceFile);
|
|
42
|
+
let entrypoints = 0;
|
|
43
|
+
kit.walk(file.sourceFile, (node) => {
|
|
44
|
+
if (!isNestFactoryCreate(kit, ts, checker, node))
|
|
45
|
+
return;
|
|
46
|
+
if (isMain)
|
|
47
|
+
entrypoints += 1;
|
|
48
|
+
else
|
|
49
|
+
report(node, `NestFactory.${node.expression.name.text}() starts a process outside apps/<app>/src/main.ts; entrypoints live in an app's main.ts only.`);
|
|
50
|
+
});
|
|
51
|
+
return entrypoints;
|
|
50
52
|
}
|
|
51
|
-
|
|
52
53
|
function inspectBootstrapCalls(ts, file, report) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
for (const statement of file.sourceFile.statements) {
|
|
55
|
+
if (!ts.isExpressionStatement(statement))
|
|
56
|
+
continue;
|
|
57
|
+
if (calledIdentifier(ts, statement.expression)?.text === 'bootstrap') {
|
|
58
|
+
report(statement, "A top-level bootstrap() call starts a process outside apps/<app>/src/main.ts; entrypoints live in an app's main.ts only.");
|
|
59
|
+
}
|
|
57
60
|
}
|
|
58
|
-
}
|
|
59
61
|
}
|
|
60
|
-
|
|
61
62
|
export function checkEntrypoints(input) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
const { graph } = input;
|
|
64
|
+
const kit = machineKit(input);
|
|
65
|
+
const violations = [];
|
|
66
|
+
let entrypoints = 0;
|
|
67
|
+
for (const file of graph.files.values()) {
|
|
68
|
+
const isMain = isMainFile(file);
|
|
69
|
+
const report = (node, message) => violations.push({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, node), message });
|
|
70
|
+
entrypoints += inspectFactoryCalls(kit, file, isMain, report);
|
|
71
|
+
if (!isMain)
|
|
72
|
+
inspectBootstrapCalls(kit.ts, file, report);
|
|
73
|
+
}
|
|
74
|
+
return { violations, coverage: { status: 'checked', entrypoints } };
|
|
73
75
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { machineKit, upperSnake } from './machine-ast.mjs';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* R38 error codes (BE_ERROR_HOME, machine half; the eslint half judges the error classes). The string value of every
|
|
6
5
|
* member of a `<C>ErrorCode` enum in a capability's `errors/<c>.error.ts` is a string literal shaped
|
|
@@ -8,45 +7,48 @@ import { machineKit, upperSnake } from './machine-ast.mjs';
|
|
|
8
7
|
* whole repository, so a code names one refusal and one capability for the client and the log.
|
|
9
8
|
*/
|
|
10
9
|
export const ERROR_CODE_RULE_IDS = ['BE_ERROR_HOME'];
|
|
11
|
-
|
|
12
10
|
const RULE = 'BE_ERROR_HOME';
|
|
13
|
-
|
|
14
11
|
// Judge each member of one <C>ErrorCode enum; returns how many string-literal codes it held.
|
|
15
12
|
const checkEnumCodes = (statement, { file, capability, shape, kit, ts, seen, violations }) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
let checked = 0;
|
|
14
|
+
for (const member of statement.members) {
|
|
15
|
+
const report = (message) => { violations.push({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, member), message }); };
|
|
16
|
+
const name = kit.propertyNameText(member.name) ?? '?';
|
|
17
|
+
const value = member.initializer && ts.isStringLiteralLike(member.initializer) ? member.initializer.text : null;
|
|
18
|
+
if (value === null) {
|
|
19
|
+
report(`${statement.name.text}.${name} must be a string literal code (\`${capability}_<WHAT>\`); a computed or numeric code cannot be checked or told apart in a log.`);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
checked += 1;
|
|
23
|
+
if (!shape.test(value) || /_(?:ERROR|EXCEPTION)$/u.test(value)) {
|
|
24
|
+
report(`${statement.name.text}.${name} = "${value}" must match ${capability}_<WHAT> in UPPER_SNAKE with the capability prefix and no _ERROR or _EXCEPTION suffix.`);
|
|
25
|
+
}
|
|
26
|
+
if (seen.has(value))
|
|
27
|
+
report(`Error code "${value}" is already declared in ${seen.get(value)}; a code is unique across the repository.`);
|
|
28
|
+
else
|
|
29
|
+
seen.set(value, file.rel);
|
|
25
30
|
}
|
|
26
|
-
|
|
27
|
-
else seen.set(value, file.rel);
|
|
28
|
-
}
|
|
29
|
-
return checked;
|
|
31
|
+
return checked;
|
|
30
32
|
};
|
|
31
|
-
|
|
32
33
|
export function checkErrorCodes(input) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
34
|
+
const { graph } = input;
|
|
35
|
+
const kit = machineKit(input);
|
|
36
|
+
const { ts } = kit;
|
|
37
|
+
const violations = [];
|
|
38
|
+
const seen = new Map();
|
|
39
|
+
let enums = 0;
|
|
40
|
+
let codes = 0;
|
|
41
|
+
const files = [...graph.files.values()].filter((file) => file.slot === 'be.errors' && file.owner !== null && path.posix.basename(file.rel).endsWith('.error.ts'))
|
|
42
|
+
.sort((a, b) => a.rel.localeCompare(b.rel));
|
|
43
|
+
for (const file of files) {
|
|
44
|
+
const capability = upperSnake(path.posix.basename(file.owner.root));
|
|
45
|
+
const shape = new RegExp(`^${capability}_[A-Z0-9]+(?:_[A-Z0-9]+)*$`, 'u');
|
|
46
|
+
for (const statement of file.sourceFile.statements) {
|
|
47
|
+
if (!ts.isEnumDeclaration(statement) || !statement.name.text.endsWith('ErrorCode'))
|
|
48
|
+
continue;
|
|
49
|
+
enums += 1;
|
|
50
|
+
codes += checkEnumCodes(statement, { file, capability, shape, kit, ts, seen, violations });
|
|
51
|
+
}
|
|
49
52
|
}
|
|
50
|
-
|
|
51
|
-
return { violations, coverage: { status: 'checked', enums, codes } };
|
|
53
|
+
return { violations, coverage: { status: 'checked', enums, codes } };
|
|
52
54
|
}
|