@starci/eslint-canon-be 3.18.3 → 3.19.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/dist/comments.js +1 -1
- package/dist/explicit-surface.js +1 -1
- package/dist/index.js +1 -1
- package/dist/jwt-alg.js +1 -1
- package/dist/lib/edition.d.ts +1 -1
- package/dist/lib/edition.js +1 -1
- package/dist/lib/hfs.d.ts +0 -6
- package/dist/lib/hfs.js +7 -5
- package/dist/lib/runtime-root.d.ts +6 -1
- package/dist/lib/runtime-root.js +8 -2
- package/dist/lib/subject-values.js +1 -1
- package/dist/module-layering.js +2 -2
- package/dist/project-graph.js +1 -1
- package/dist/third-party-owner.js +1 -1
- package/package.json +3 -1
- package/runtime/bundle.json +1 -190
- package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
- package/runtime/scripts/hfs/project-graph.mjs +6 -6
- package/runtime/scripts/hfs/project-rule.mjs +3 -3
- package/runtime/config.example.yaml +0 -194
- package/runtime/engine/by-code-unit.mjs +0 -12
- package/runtime/engine/config.mjs +0 -461
- package/runtime/engine/invalid-config.mjs +0 -15
- package/runtime/engine/model-config.mjs +0 -112
- package/runtime/engine/orca-config.mjs +0 -34
- package/runtime/engine/plain-object.mjs +0 -5
- package/runtime/engine/release-config.mjs +0 -32
- package/runtime/engine/removed-vocabulary.mjs +0 -27
- package/runtime/engine/resources-config.mjs +0 -59
- package/runtime/engine/runtime-root.mjs +0 -138
- package/runtime/engine/secrets.mjs +0 -202
- package/runtime/engine/sonar-config.mjs +0 -24
- package/runtime/engine/temp-root.mjs +0 -26
- package/runtime/engine/yaml.mjs +0 -161
- package/runtime/knowledge/grammars/index.yaml +0 -114
- package/runtime/knowledge/hfs/canon-pins.yaml +0 -716
- package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
- package/runtime/knowledge/hfs/rules.yaml +0 -6760
- package/runtime/knowledge/hfs/slots.yaml +0 -2783
- package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
- package/runtime/knowledge/sonar-gate.yaml +0 -151
- package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
- package/runtime/modules/models/registry.yaml +0 -221
- package/runtime/modules/models/runtimes.yaml +0 -556
- package/runtime/modules/models/tiers.yaml +0 -66
- package/runtime/scripts/api/git/cat-file.mjs +0 -4
- package/runtime/scripts/api/git/config-get.mjs +0 -9
- package/runtime/scripts/api/git/diff.mjs +0 -4
- package/runtime/scripts/api/git/lib.mjs +0 -80
- package/runtime/scripts/api/git/ls-files.mjs +0 -5
- package/runtime/scripts/api/git/ls-tree.mjs +0 -4
- package/runtime/scripts/api/git/merge-base.mjs +0 -8
- package/runtime/scripts/api/git/remote.mjs +0 -4
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
- package/runtime/scripts/api/git/show.mjs +0 -5
- package/runtime/scripts/api/git/tag.mjs +0 -4
- package/runtime/scripts/hfs/allows.mjs +0 -77
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
- package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
- package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
- package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
- package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
- package/runtime/scripts/hfs/architecture/config.mjs +0 -407
- package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
- package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
- package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
- package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
- package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
- package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
- package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
- package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
- package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
- package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
- package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
- package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
- package/runtime/scripts/hfs/architecture/index.mjs +0 -402
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
- package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
- package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
- package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
- package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
- package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
- package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
- package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
- package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
- package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
- package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
- package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
- package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
- package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
- package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
- package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
- package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
- package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
- package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
- package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
- package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
- package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
- package/runtime/scripts/hfs/edition-slots.mjs +0 -80
- package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
- package/runtime/scripts/hfs/linear-text.mjs +0 -30
- package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
- package/runtime/scripts/hfs/param-names.mjs +0 -13
- package/runtime/scripts/hfs/path-findings.mjs +0 -167
- package/runtime/scripts/hfs/repo-identity.mjs +0 -89
- package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
- package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
- package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
- package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
- package/runtime/scripts/hfs/rules/read.mjs +0 -45
- package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
- package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
- package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
- package/runtime/scripts/hfs/slot-classify.mjs +0 -69
- package/runtime/scripts/hfs/slot-errors.mjs +0 -12
- package/runtime/scripts/hfs/slot-imports.mjs +0 -98
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
- package/runtime/scripts/hfs/slot-match.mjs +0 -164
- package/runtime/scripts/hfs/slot-path.mjs +0 -6
- package/runtime/scripts/hfs/slot-required.mjs +0 -95
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
- package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
- package/runtime/scripts/hfs/slots.mjs +0 -306
- package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
- package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
- package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
- package/runtime/scripts/hfs/view.mjs +0 -180
- package/runtime/scripts/lib/declaration-surface.mjs +0 -166
- package/runtime/scripts/lib/dockerfile.mjs +0 -164
- package/runtime/scripts/lib/env.mjs +0 -18
- package/runtime/scripts/lib/event-contract.mjs +0 -102
- package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
- package/runtime/scripts/lib/git.mjs +0 -35
- package/runtime/scripts/lib/glob.mjs +0 -32
- package/runtime/scripts/lib/grammar-lint.mjs +0 -57
- package/runtime/scripts/lib/i18n.mjs +0 -82
- package/runtime/scripts/lib/in-order.mjs +0 -90
- package/runtime/scripts/lib/json-clone.mjs +0 -70
- package/runtime/scripts/lib/json.mjs +0 -44
- package/runtime/scripts/lib/language.mjs +0 -233
- package/runtime/scripts/lib/list.mjs +0 -26
- package/runtime/scripts/lib/mutation-fence.mjs +0 -20
- package/runtime/scripts/lib/package-at.mjs +0 -62
- package/runtime/scripts/lib/path-key.mjs +0 -124
- package/runtime/scripts/lib/read-text.mjs +0 -47
- package/runtime/scripts/lib/regex.mjs +0 -3
- package/runtime/scripts/lib/rule-packs.mjs +0 -243
- package/runtime/scripts/lib/same-text.mjs +0 -4
- package/runtime/scripts/lib/secret-patterns.mjs +0 -230
- package/runtime/scripts/lib/sops-envelope.mjs +0 -212
- package/runtime/scripts/lib/stack-services.mjs +0 -191
- package/runtime/scripts/lib/ts-analysis.mjs +0 -39
- package/runtime/scripts/lib/ts-ast.mjs +0 -63
- package/runtime/scripts/lib/walk.mjs +0 -45
- package/runtime/scripts/lib/yaml-cached.mjs +0 -14
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { machineKit } from './machine-ast.mjs';
|
|
2
|
-
/**
|
|
3
|
-
* R41 `default-deny-app-guard` (BE_DEFAULT_DENY). Every api app root provides its `APP_GUARD` entries in the order
|
|
4
|
-
* throttler -> CSRF origin guard -> CredentialGuard -> AuthGuard, each exactly once, so no request reaches a handler before it was
|
|
5
|
-
* rate-limited, origin-checked, credential-authenticated and admitted. A guard is classified by structure, never by name or folder alone
|
|
6
|
-
* (BE-CONVENTION 1.7 names the roles, not a library):
|
|
7
|
-
* - throttler: a class of @nestjs/throttler or one that extends it, or a guard that reads through a Reflector the
|
|
8
|
-
* per-door metadata (the `@RateLimit(tier)` decorator) that a SetMetadata call of its own capability writes;
|
|
9
|
-
* - CSRF origin guard: a guard declared in platform/http-security that reads the request origin or referer header;
|
|
10
|
-
* - CredentialGuard: the `CredentialGuard` class declared in domain/identity;
|
|
11
|
-
* - AuthGuard: the `AuthGuard` class declared in domain/identity.
|
|
12
|
-
* Other guards are permitted between them; a missing, repeated or reordered one of the three is a finding.
|
|
13
|
-
*/
|
|
14
|
-
export const DEFAULT_DENY_RULE_IDS = ['BE_DEFAULT_DENY'];
|
|
15
|
-
const RULE = 'BE_DEFAULT_DENY';
|
|
16
|
-
const ORDER = ['throttler', 'csrf', 'credential', 'auth'];
|
|
17
|
-
const ORIGIN_HEADERS = new Set(['origin', 'referer', 'referrer']);
|
|
18
|
-
const METADATA_READERS = new Set(['get', 'getAll', 'getAllAndMerge', 'getAllAndOverride']);
|
|
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' };
|
|
20
|
-
const keySymbol = (kit, checker, node) => (node ? kit.aliased(checker, kit.symbolAt(checker, node)) ?? null : null);
|
|
21
|
-
const extendsThrottlerType = (kit, checker, declaration, type, depth) => {
|
|
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));
|
|
25
|
-
};
|
|
26
|
-
function extendsThrottler(kit, declaration, depth = 0) {
|
|
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));
|
|
35
|
-
}
|
|
36
|
-
const collectSetMetadataKeys = (kit, file, keys) => {
|
|
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
|
-
};
|
|
50
|
-
/** The symbols a SetMetadata call of the owner writes as metadata keys: what its door decorators (`@RateLimit(tier)`) attach. */
|
|
51
|
-
const writtenKeys = (kit, graph, owner, cache) => {
|
|
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;
|
|
62
|
-
};
|
|
63
|
-
/** True when the class reads a request origin or referer header (the origin/referer allowlist of the CSRF guard). */
|
|
64
|
-
const readsOrigin = (kit, declaration) => {
|
|
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;
|
|
78
|
-
};
|
|
79
|
-
const isMetadataRead = (ts, node) => ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && METADATA_READERS.has(node.expression.name.text);
|
|
80
|
-
/** True when the class reads, through a metadata getter, a key its own capability's SetMetadata decorators write. */
|
|
81
|
-
const readsDoorMetadata = (kit, graph, keyCache, declaration, owner) => {
|
|
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;
|
|
96
|
-
};
|
|
97
|
-
const classifyDeclaration = (kit, graph, keyCache, declaration) => {
|
|
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;
|
|
111
|
-
};
|
|
112
|
-
const classify = (kit, graph, keyCache, checker, node) => {
|
|
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;
|
|
126
|
-
};
|
|
127
|
-
const roleMessages = (app, roles, anchor) => {
|
|
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;
|
|
137
|
-
};
|
|
138
|
-
const orderMessages = (app, roles) => {
|
|
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;
|
|
155
|
-
};
|
|
156
|
-
export function checkDefaultDeny(input) {
|
|
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 } };
|
|
175
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { treeOf } from './required-files.mjs';
|
|
4
|
-
import { documentLanguageHits, isDocument, isLocalizedDataFile } from '../../lib/language.mjs';
|
|
5
|
-
import { byCodeUnit } from '../../lib/list.mjs';
|
|
6
|
-
/**
|
|
7
|
-
* R96 `doc-language` (HFS_DOC_NOT_ENGLISH). Every Markdown and YAML document under knowledge/, docs/, src/ and apps/ is English:
|
|
8
|
-
* prose, patterns and examples alike, and a code fence inside Markdown counts because an example is read exactly like the
|
|
9
|
-
* prose around it. Detection is structural on characters (scripts/lib/language.mjs), never a word list.
|
|
10
|
-
*
|
|
11
|
-
* The one exception is data, decided by placement: a YAML file that sits in a slot carrying localized text (a message
|
|
12
|
-
* catalog slot or an i18n fixtures slot, listed in scripts/lib/language.mjs) may hold another language. Markdown is never data, so a README
|
|
13
|
-
* inside a catalog slot is judged like any other document. No comment pragma, no path pattern.
|
|
14
|
-
*/
|
|
15
|
-
export const DOC_LANGUAGE_RULE_IDS = ['HFS_DOC_NOT_ENGLISH'];
|
|
16
|
-
const RULE = 'HFS_DOC_NOT_ENGLISH';
|
|
17
|
-
/** The top-level folders whose documents this check reads. */
|
|
18
|
-
const DOCUMENT_ROOTS = Object.freeze(['knowledge', 'docs', 'src', 'apps']);
|
|
19
|
-
export function checkDocLanguage({ config, graph }) {
|
|
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
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return { violations, coverage: { status: 'checked', files } };
|
|
45
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { braceVariants, globExpression } from '../../lib/glob.mjs';
|
|
2
|
-
/**
|
|
3
|
-
* The entity registry (persistence.md BE-PERSISTENCE-3): the one file whose slot plays `role: entity-registry`
|
|
4
|
-
* (`be.platform.database.entities`, lite's `src/modules/platform/database/entities.ts`). It lists every capability's `<c>Entities`
|
|
5
|
-
* array as `PRIMARY_ENTITIES`, so it is the one platform file that imports domain and platform capability barrels, and only for
|
|
6
|
-
* that name; and it is imported by deep path only from the files its slot's `importedBy` names (app composition and the test world).
|
|
7
|
-
* The tier matrix (tiers.mjs), the public-entry check (owners.mjs) and the lint rule `import-owner-entry` read it here.
|
|
8
|
-
*/
|
|
9
|
-
export const ENTITY_REGISTRY_ROLE = 'entity-registry';
|
|
10
|
-
/** The tiers whose capabilities contribute an entity list to the registry. */
|
|
11
|
-
const CONTRIBUTING_TIERS = new Set(['domain', 'platform']);
|
|
12
|
-
/** The entity list a capability exports: `<c>Entities`, `<c>` its folder name in camelCase. */
|
|
13
|
-
export const entityListName = (capability) => `${capability.replace(/-([a-z0-9])/g, (_, next) => next.toUpperCase())}Entities`;
|
|
14
|
-
/** The slot of `file` (side-relative or absolute) when it plays the entity-registry role, else null. */
|
|
15
|
-
export function registrySlot(resolver, file) {
|
|
16
|
-
const slot = resolver?.slotOf?.(file);
|
|
17
|
-
return slot?.role === ENTITY_REGISTRY_ROLE ? slot : null;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Whether `file` is one of the importers the registry slot admits by deep path (`importedBy`, side-relative patterns); an app-wide
|
|
21
|
-
* resolver answers for a side-prefixed path (`be/apps/...`), which is read without its side folder.
|
|
22
|
-
*/
|
|
23
|
-
export function registryImporter(resolver, slot, file) {
|
|
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)));
|
|
27
|
-
}
|
|
28
|
-
/** The names an import declaration binds by name; null for a default, namespace or side-effect import and for any re-export. */
|
|
29
|
-
function namedImports(declaration) {
|
|
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);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Whether an owner-graph edge (side-relative `from` and `to`, `edge.declaration` the TypeScript statement) is the registry naming a
|
|
38
|
-
* capability's entity list: it leaves the registry, imports the public entry (`index.ts`) of a domain or platform capability, and
|
|
39
|
-
* binds that capability's `<c>Entities` and nothing else.
|
|
40
|
-
*/
|
|
41
|
-
export function registryListImport(resolver, edge) {
|
|
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);
|
|
51
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { machineKit } from './machine-ast.mjs';
|
|
3
|
-
import { isTestWorldSlot } from '../test-world-slot.mjs';
|
|
4
|
-
/**
|
|
5
|
-
* R33 `entrypoint-only-in-apps` (BE_ENTRYPOINT_ONLY_IN_APPS). A process starts in `apps/<app>/src/main.ts` only:
|
|
6
|
-
* `NestFactory.create*` (from @nestjs/core) and a top-level `bootstrap()` call anywhere else are entrypoints hiding in a
|
|
7
|
-
* library, a feature, a spec helper or another file of an app.
|
|
8
|
-
*
|
|
9
|
-
* The test world (slot be.tests.world) is the test COMPOSITION ROOT, like an app's main.ts: use-test-world.ts boots the
|
|
10
|
-
* real apps with NestFactory the way main.ts does in production, so it is an entrypoint owner too. A spec
|
|
11
|
-
* (*.integration-spec.ts, *.contract-spec.ts, *.e2e-spec.ts) does not compose: it calls useTestWorld(...) only, and the
|
|
12
|
-
* other test slots stay refused.
|
|
13
|
-
*/
|
|
14
|
-
export const ENTRYPOINT_RULE_IDS = ['BE_ENTRYPOINT_ONLY_IN_APPS'];
|
|
15
|
-
const RULE = 'BE_ENTRYPOINT_ONLY_IN_APPS';
|
|
16
|
-
const TRANSPARENT = ['isVoidExpression', 'isAwaitExpression', 'isParenthesizedExpression', 'isNonNullExpression'];
|
|
17
|
-
const isTransparent = (ts, node) => TRANSPARENT.some(test => ts[test](node));
|
|
18
|
-
/** The identifier a top-level statement calls: `bootstrap()`, `void bootstrap()`, `bootstrap().catch(...)`. */
|
|
19
|
-
function calledIdentifier(ts, expression) {
|
|
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
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const isNestFactoryCreate = (kit, ts, checker, node) => ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text.startsWith('create')
|
|
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);
|
|
38
|
-
/** Counts the NestFactory.create* calls of an entrypoint owner and reports them in any other file. */
|
|
39
|
-
function inspectFactoryCalls(kit, file, isMain, report) {
|
|
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;
|
|
52
|
-
}
|
|
53
|
-
function inspectBootstrapCalls(ts, file, report) {
|
|
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
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
export function checkEntrypoints(input) {
|
|
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 } };
|
|
75
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { machineKit, upperSnake } from './machine-ast.mjs';
|
|
3
|
-
/**
|
|
4
|
-
* R38 error codes (BE_ERROR_HOME, machine half; the eslint half judges the error classes). The string value of every
|
|
5
|
-
* member of a `<C>ErrorCode` enum in a capability's `errors/<c>.error.ts` is a string literal shaped
|
|
6
|
-
* `<CAPABILITY>_<WHAT>` (UPPER_SNAKE of the owning capability, no `_ERROR` or `_EXCEPTION` suffix) and unique across the
|
|
7
|
-
* whole repository, so a code names one refusal and one capability for the client and the log.
|
|
8
|
-
*/
|
|
9
|
-
export const ERROR_CODE_RULE_IDS = ['BE_ERROR_HOME'];
|
|
10
|
-
const RULE = 'BE_ERROR_HOME';
|
|
11
|
-
// Judge each member of one <C>ErrorCode enum; returns how many string-literal codes it held.
|
|
12
|
-
const checkEnumCodes = (statement, { file, capability, shape, kit, ts, seen, violations }) => {
|
|
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);
|
|
30
|
-
}
|
|
31
|
-
return checked;
|
|
32
|
-
};
|
|
33
|
-
export function checkErrorCodes(input) {
|
|
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
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return { violations, coverage: { status: 'checked', enums, codes } };
|
|
54
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { machineKit } from './machine-ast.mjs';
|
|
2
|
-
/**
|
|
3
|
-
* R39 `error-masked` (BE_ERROR_MASKED). Every api app root provides exactly one `APP_FILTER`, its class declared in
|
|
4
|
-
* platform/errors (the one ExceptionFilter that masks everything that is not a DomainError), and every GraphQL module
|
|
5
|
-
* registration of the program passes the `formatError` platform/errors exports. Filters and format functions defined
|
|
6
|
-
* anywhere else, a second filter, or a GraphQL registration without `formatError` leak internal errors to the client.
|
|
7
|
-
*/
|
|
8
|
-
export const ERROR_MASKED_RULE_IDS = ['BE_ERROR_MASKED'];
|
|
9
|
-
const RULE = 'BE_ERROR_MASKED';
|
|
10
|
-
const inErrorsOf = (kit) => (checker, node) => kit.declarationsOf(checker, node).map(kit.ownerOfDeclaration).some(owner => owner?.tier === 'platform' && owner.name === 'errors');
|
|
11
|
-
function appFilterViolations(kit, inErrors, app, root) {
|
|
12
|
-
const violations = [];
|
|
13
|
-
const filters = kit.providersOf(root, 'APP_FILTER', '@nestjs/core');
|
|
14
|
-
const anchor = filters[0]?.node ?? root.sourceFile.statements[0] ?? root.sourceFile;
|
|
15
|
-
if (filters.length !== 1) {
|
|
16
|
-
violations.push({ ruleId: RULE, ...kit.at(root.rel, root.sourceFile, anchor), app: app.name,
|
|
17
|
-
message: `App ${app.name} provides ${filters.length} APP_FILTER entries; an api app provides exactly one, the ExceptionFilter of platform/errors.` });
|
|
18
|
-
}
|
|
19
|
-
for (const filter of filters) {
|
|
20
|
-
if (!filter.useClass || !inErrors(filter.checker, filter.useClass)) {
|
|
21
|
-
violations.push({ ruleId: RULE, ...kit.at(root.rel, root.sourceFile, filter.node), app: app.name,
|
|
22
|
-
message: 'The APP_FILTER must be `useClass` of the filter declared in platform/errors; any other filter can let an undeclared error reach the client unmasked.' });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return violations;
|
|
26
|
-
}
|
|
27
|
-
const isGraphqlRegistration = (kit, checker, node) => kit.ts.isCallExpression(node) && kit.ts.isPropertyAccessExpression(node.expression)
|
|
28
|
-
&& ['forRoot', 'forRootAsync'].includes(node.expression.name.text)
|
|
29
|
-
&& kit.isImportOf(checker, node.expression.expression, 'GraphQLModule', '@nestjs/graphql');
|
|
30
|
-
/**
|
|
31
|
-
* The formatter a `formatError` value names: the value itself, or the callee of an arrow whose body only calls it (an arrow that
|
|
32
|
-
* binds the errors service, `(formatted, error) => formatGraphqlError(errors, formatted, error)`).
|
|
33
|
-
*/
|
|
34
|
-
function formatterOf(ts, value) {
|
|
35
|
-
if (value && ts.isArrowFunction(value) && ts.isCallExpression(value.body))
|
|
36
|
-
return value.body.expression;
|
|
37
|
-
return value;
|
|
38
|
-
}
|
|
39
|
-
function passesMaskedFormatError(kit, inErrors, checker, call) {
|
|
40
|
-
const { ts } = kit;
|
|
41
|
-
let masked = false;
|
|
42
|
-
for (const argument of call.arguments) {
|
|
43
|
-
kit.walk(argument, (inner) => {
|
|
44
|
-
if ((ts.isPropertyAssignment(inner) || ts.isShorthandPropertyAssignment(inner)) && kit.propertyNameText(inner.name) === 'formatError'
|
|
45
|
-
&& inErrors(checker, formatterOf(ts, kit.valueOfProperty(inner))))
|
|
46
|
-
masked = true;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
return masked;
|
|
50
|
-
}
|
|
51
|
-
export function checkErrorMasked(input) {
|
|
52
|
-
const { config, graph } = input;
|
|
53
|
-
const kit = machineKit(input);
|
|
54
|
-
const violations = [];
|
|
55
|
-
const inErrors = inErrorsOf(kit);
|
|
56
|
-
let apps = 0;
|
|
57
|
-
for (const app of config.apps.filter((item) => item.kind === 'api')) {
|
|
58
|
-
const root = kit.appRoot(app.name);
|
|
59
|
-
if (!root)
|
|
60
|
-
continue;
|
|
61
|
-
apps += 1;
|
|
62
|
-
violations.push(...appFilterViolations(kit, inErrors, app, root));
|
|
63
|
-
}
|
|
64
|
-
let graphql = 0;
|
|
65
|
-
for (const file of graph.files.values()) {
|
|
66
|
-
const checker = kit.checkerOf(file.sourceFile);
|
|
67
|
-
kit.walk(file.sourceFile, (node) => {
|
|
68
|
-
if (!isGraphqlRegistration(kit, checker, node))
|
|
69
|
-
return;
|
|
70
|
-
graphql += 1;
|
|
71
|
-
if (!passesMaskedFormatError(kit, inErrors, checker, node)) {
|
|
72
|
-
violations.push({ ruleId: RULE, ...kit.at(file.rel, file.sourceFile, node),
|
|
73
|
-
message: `GraphQLModule.${node.expression.name.text} must pass the \`formatError\` exported by platform/errors; without it a resolver error reaches the client with its internal message.` });
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
return { violations, coverage: { status: 'checked', apps, graphqlRegistrations: graphql } };
|
|
78
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { treeOf } from './required-files.mjs';
|
|
2
|
-
import { allowsFile } from '../allows.mjs';
|
|
3
|
-
import { isFeTestPath } from '../rules/fe-no-tests.mjs';
|
|
4
|
-
import { byCodeUnit } from '../../lib/list.mjs';
|
|
5
|
-
/**
|
|
6
|
-
* R94 `fe-slot-allows` (FE_SLOT_FILE_ROLE). A front-end slot that owns a whole directory (`fe.route`, `fe.feature`,
|
|
7
|
-
* `fe.components`, `fe.hooks`, `fe.modules.api`) also says what its instances hold (`allows` in knowledge/hfs/slots.yaml).
|
|
8
|
-
* Every tracked file of such a slot is matched against the `requires` and `allows` entries of its slot; a file no entry names is a
|
|
9
|
-
* finding - `page.tsx` in a hooks domain, a `[lang]` segment under `app/`, a stray file beside a component or at a feature
|
|
10
|
-
* root. A file that sits where the slot expects a folder (`hooks/useX.ts`, so the "domain" is a file name) is one too.
|
|
11
|
-
* Files no slot owns are HFS_PATH_NO_SLOT's (`starci app check`), so together every front-end file is placed by exactly one slot and
|
|
12
|
-
* named by it. A test path (a `.spec.tsx` or `.test.tsx` beside a component, a test directory or test tooling) is FE_NO_TESTS's
|
|
13
|
-
* (R97 FE_NO_TESTS): that rule is the one finding of such a file, so this check leaves it alone, as
|
|
14
|
-
* HFS_PATH_NO_SLOT does (scripts/hfs/path-findings.mjs).
|
|
15
|
-
*/
|
|
16
|
-
export const FE_SLOT_ALLOWS_RULE_IDS = ['FE_SLOT_FILE_ROLE'];
|
|
17
|
-
const RULE = 'FE_SLOT_FILE_ROLE';
|
|
18
|
-
export function checkFeSlotAllows({ config, graph }) {
|
|
19
|
-
const resolver = graph.resolver;
|
|
20
|
-
const tree = treeOf(config.root);
|
|
21
|
-
const violations = [];
|
|
22
|
-
let files = 0;
|
|
23
|
-
const report = (file, message, extra = {}) => violations.push({ ruleId: RULE, path: file, line: 1, column: 1, message, ...extra });
|
|
24
|
-
for (const file of [...tree.files].sort(byCodeUnit)) {
|
|
25
|
-
if (isFeTestPath(file))
|
|
26
|
-
continue; // FE_NO_TESTS's, the one finding of that file
|
|
27
|
-
const classified = resolver.classifyPath(file);
|
|
28
|
-
if (classified.status !== 'owned')
|
|
29
|
-
continue;
|
|
30
|
-
const slot = resolver.slot(classified.slot);
|
|
31
|
-
if (!slot?.allows?.length)
|
|
32
|
-
continue;
|
|
33
|
-
files += 1;
|
|
34
|
-
if (slot.owner === true && classified.root === classified.path) {
|
|
35
|
-
report(file, `${file} sits where slot ${slot.id} expects a folder (${slot.path}); it holds ${slot.allows.join(', ')} inside a folder of its own. Move it into one.`, { slot: slot.id });
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
const verdict = allowsFile(resolver, file);
|
|
39
|
-
if (!verdict || verdict.allowed)
|
|
40
|
-
continue;
|
|
41
|
-
report(file, `${file} is not allowed in ${verdict.slot} (${verdict.root}); that slot holds only ${verdict.allows.join(', ')}. Rename it to an allowed role or move it to the slot it belongs to.`, { slot: verdict.slot });
|
|
42
|
-
}
|
|
43
|
-
return { violations, coverage: { status: 'checked', files } };
|
|
44
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { treeOf } from './required-files.mjs';
|
|
3
|
-
import { allowsFile } from '../allows.mjs';
|
|
4
|
-
import { byCodeUnit } from '../../lib/list.mjs';
|
|
5
|
-
/**
|
|
6
|
-
* R29 `feature-shape` (BE_FEATURE_SHAPE). A feature root holds `index.ts`, `<feature>.module.ts`, `application/`,
|
|
7
|
-
* `transport/<protocol>/` and `messages/` only, and each of those folders holds only what its slot `allows` (knowledge/hfs/
|
|
8
|
-
* slots.yaml: be.feature, be.feature.application, be.feature.application.support, be.transport.*,
|
|
9
|
-
* be.feature.messages). Every tracked file below a feature root is classified by the slot resolver and matched against
|
|
10
|
-
* the `requires` and `allows` entries of the slot that owns it; a directory that no slot owns (an unknown protocol under
|
|
11
|
-
* `transport/`, a `graphql/` folder under `application/`) is refused because its files fall back to the feature root slot.
|
|
12
|
-
*/
|
|
13
|
-
export const FEATURE_SHAPE_RULE_IDS = ['BE_FEATURE_SHAPE'];
|
|
14
|
-
const RULE = 'BE_FEATURE_SHAPE';
|
|
15
|
-
// {message, extra} for one feature file the slot answer refuses, or null when it sits where a slot allows it.
|
|
16
|
-
const featureFileFinding = (file, owner, verdict) => {
|
|
17
|
-
const feature = path.posix.basename(owner.root);
|
|
18
|
-
if (verdict.slot === owner.slot) {
|
|
19
|
-
// A file the feature root slot itself allows is in place (the cli feature root allows its <group>/ folders); any other file
|
|
20
|
-
// deeper than the root sits in a directory no slot claims.
|
|
21
|
-
// A directory entry (`transport/`, `application/`) is held by its own slots: below it, only those slots admit a file.
|
|
22
|
-
if (verdict.allowed && !String(verdict.entry ?? '').endsWith('/'))
|
|
23
|
-
return null;
|
|
24
|
-
if (verdict.relative.includes('/')) {
|
|
25
|
-
const folder = verdict.relative.split('/')[0] ?? '';
|
|
26
|
-
return { message: `${file} sits in ${owner.root}/${folder}/, which no slot owns; a feature root holds only ${verdict.allows.join(', ')}, and transport/ holds one folder per protocol a slot names. Move it to application/ or a transport/<protocol>/ folder, or delete it.`,
|
|
27
|
-
extra: { feature, folder } };
|
|
28
|
-
}
|
|
29
|
-
if (verdict.allowed)
|
|
30
|
-
return null;
|
|
31
|
-
return { message: `${file} is not allowed at the root of feature ${feature}; the root holds only ${verdict.allows.join(', ')}. Move it under application/ or transport/<protocol>/.`, extra: { feature } };
|
|
32
|
-
}
|
|
33
|
-
if (verdict.allowed)
|
|
34
|
-
return null;
|
|
35
|
-
const where = `${verdict.slot} (${verdict.root})`;
|
|
36
|
-
const forbidden = verdict.forbiddenBy ? ` ${verdict.forbiddenBy} is forbidden there;` : '';
|
|
37
|
-
return { message: `${file} is not allowed in ${where};${forbidden} that folder holds only ${verdict.allows.join(', ')}. Rename it to an allowed role or move it to the folder its role belongs to.`, extra: { feature, slot: verdict.slot } };
|
|
38
|
-
};
|
|
39
|
-
export function checkFeatureShape({ config, graph }) {
|
|
40
|
-
const resolver = graph.resolver;
|
|
41
|
-
const tree = treeOf(config.root);
|
|
42
|
-
const violations = [];
|
|
43
|
-
const features = new Set();
|
|
44
|
-
let files = 0;
|
|
45
|
-
const report = (file, message, extra = {}) => violations.push({ ruleId: RULE, path: file, line: 1, column: 1, message, ...extra });
|
|
46
|
-
for (const file of [...tree.files].sort(byCodeUnit)) {
|
|
47
|
-
const owner = resolver.ownerOf(file);
|
|
48
|
-
if (!owner || resolver.slot(owner.slot)?.tier !== 'feature')
|
|
49
|
-
continue;
|
|
50
|
-
features.add(owner.root);
|
|
51
|
-
files += 1;
|
|
52
|
-
const verdict = allowsFile(resolver, file);
|
|
53
|
-
if (!verdict)
|
|
54
|
-
continue;
|
|
55
|
-
const finding = featureFileFinding(file, owner, verdict);
|
|
56
|
-
if (finding)
|
|
57
|
-
report(file, finding.message, finding.extra);
|
|
58
|
-
}
|
|
59
|
-
return { violations, coverage: { status: 'checked', features: features.size, files } };
|
|
60
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// framework-pinned.mjs - the Next.js files that only load from a source root (the directory holding
|
|
2
|
-
// app/). Authored once in knowledge/patterns/fe/folder.yaml FE-FOLDER-1 (frameworkPinnedRootFiles), never
|
|
3
|
-
// hard-coded here (a supervisor ruling). Read by the architecture
|
|
4
|
-
// check (FE_SOURCE_LAYOUT_INVALID).
|
|
5
|
-
//
|
|
6
|
-
// An unreadable or malformed list is a broken install, not "no pinned files": the reader throws
|
|
7
|
-
// ARCH_KNOWLEDGE_UNAVAILABLE so the caller reports an error instead of judging with a different contract.
|
|
8
|
-
import fs from 'node:fs';
|
|
9
|
-
import { fileURLToPath } from 'node:url';
|
|
10
|
-
import { parseYaml } from '../../../engine/yaml.mjs';
|
|
11
|
-
export const FRAMEWORK_PINNED_KNOWLEDGE = fileURLToPath(new URL('../../../knowledge/patterns/fe/folder.yaml', import.meta.url));
|
|
12
|
-
const cache = new Map(); // only the installed knowledge file is cached; an explicit file is re-read
|
|
13
|
-
const EXACT_NAME = /^[^\\/*?[\]{}\s]+$/;
|
|
14
|
-
function unavailable(file, detail) {
|
|
15
|
-
return new Error(`ARCH_KNOWLEDGE_UNAVAILABLE: ${file} ${detail}`);
|
|
16
|
-
}
|
|
17
|
-
function load(file) {
|
|
18
|
-
const cached = cache.get(file);
|
|
19
|
-
if (cached)
|
|
20
|
-
return cached;
|
|
21
|
-
// reason: parsed-YAML boundary; the rule row is validated field by field below.
|
|
22
|
-
let rule;
|
|
23
|
-
try {
|
|
24
|
-
rule = parseYaml(fs.readFileSync(file, 'utf8'))?.rules?.find((item) => item?.id === 'FE-FOLDER-1');
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
throw unavailable(file, `cannot be read (${error.message ?? error}).`);
|
|
28
|
-
}
|
|
29
|
-
const list = rule?.frameworkPinnedRootFiles;
|
|
30
|
-
if (!Array.isArray(list) || !list.length || list.some((name) => typeof name !== 'string' || !EXACT_NAME.test(name))) {
|
|
31
|
-
throw unavailable(file, 'FE-FOLDER-1 frameworkPinnedRootFiles must be a nonempty list of exact file names.');
|
|
32
|
-
}
|
|
33
|
-
const loaded = { files: new Set(list) };
|
|
34
|
-
if (file === FRAMEWORK_PINNED_KNOWLEDGE)
|
|
35
|
-
cache.set(file, loaded);
|
|
36
|
-
return loaded;
|
|
37
|
-
}
|
|
38
|
-
/** Exact basenames Next.js loads only from the source root. */
|
|
39
|
-
export function frameworkPinnedRootFiles(file = FRAMEWORK_PINNED_KNOWLEDGE) {
|
|
40
|
-
return load(file).files;
|
|
41
|
-
}
|