@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
|
* R39 `error-masked` (BE_ERROR_MASKED). Every api app root provides exactly one `APP_FILTER`, its class declared in
|
|
5
4
|
* platform/errors (the one ExceptionFilter that masks everything that is not a DomainError), and every GraphQL module
|
|
@@ -7,76 +6,73 @@ import { machineKit } from './machine-ast.mjs';
|
|
|
7
6
|
* anywhere else, a second filter, or a GraphQL registration without `formatError` leak internal errors to the client.
|
|
8
7
|
*/
|
|
9
8
|
export const ERROR_MASKED_RULE_IDS = ['BE_ERROR_MASKED'];
|
|
10
|
-
|
|
11
9
|
const RULE = 'BE_ERROR_MASKED';
|
|
12
|
-
|
|
13
|
-
const inErrorsOf = kit => (checker, node) => kit.declarationsOf(checker, node).map(kit.ownerOfDeclaration).some(owner => owner?.tier === 'platform' && owner.name === 'errors');
|
|
14
|
-
|
|
10
|
+
const inErrorsOf = (kit) => (checker, node) => kit.declarationsOf(checker, node).map(kit.ownerOfDeclaration).some(owner => owner?.tier === 'platform' && owner.name === 'errors');
|
|
15
11
|
function appFilterViolations(kit, inErrors, app, root) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
for (const filter of filters) {
|
|
24
|
-
if (!filter.useClass || !inErrors(filter.checker, filter.useClass)) {
|
|
25
|
-
violations.push({ ruleId: RULE, path: root.rel, ...kit.at(root.rel, root.sourceFile, filter.node), app: app.name,
|
|
26
|
-
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.' });
|
|
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.` });
|
|
27
18
|
}
|
|
28
|
-
|
|
29
|
-
|
|
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;
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
const isGraphqlRegistration = (kit, checker, node) => kit.ts.isCallExpression(node) && kit.ts.isPropertyAccessExpression(node.expression)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
&& ['forRoot', 'forRootAsync'].includes(node.expression.name.text)
|
|
29
|
+
&& kit.isImportOf(checker, node.expression.expression, 'GraphQLModule', '@nestjs/graphql');
|
|
36
30
|
/**
|
|
37
31
|
* The formatter a `formatError` value names: the value itself, or the callee of an arrow whose body only calls it (an arrow that
|
|
38
32
|
* binds the errors service, `(formatted, error) => formatGraphqlError(errors, formatted, error)`).
|
|
39
33
|
*/
|
|
40
34
|
function formatterOf(ts, value) {
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
if (value && ts.isArrowFunction(value) && ts.isCallExpression(value.body))
|
|
36
|
+
return value.body.expression;
|
|
37
|
+
return value;
|
|
43
38
|
}
|
|
44
|
-
|
|
45
39
|
function passesMaskedFormatError(kit, inErrors, checker, call) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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;
|
|
55
50
|
}
|
|
56
|
-
|
|
57
51
|
export function checkErrorMasked(input) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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 } };
|
|
82
78
|
}
|
|
@@ -2,7 +2,6 @@ import { treeOf } from './required-files.mjs';
|
|
|
2
2
|
import { allowsFile } from '../allows.mjs';
|
|
3
3
|
import { isFeTestPath } from '../rules/fe-no-tests.mjs';
|
|
4
4
|
import { byCodeUnit } from '../../lib/list.mjs';
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* R94 `fe-slot-allows` (FE_SLOT_FILE_ROLE). A front-end slot that owns a whole directory (`fe.route`, `fe.feature`,
|
|
8
7
|
* `fe.components`, `fe.hooks`, `fe.modules.api`) also says what its instances hold (`allows` in knowledge/hfs/slots.yaml).
|
|
@@ -15,29 +14,31 @@ import { byCodeUnit } from '../../lib/list.mjs';
|
|
|
15
14
|
* HFS_PATH_NO_SLOT does (scripts/hfs/path-findings.mjs).
|
|
16
15
|
*/
|
|
17
16
|
export const FE_SLOT_ALLOWS_RULE_IDS = ['FE_SLOT_FILE_ROLE'];
|
|
18
|
-
|
|
19
17
|
const RULE = 'FE_SLOT_FILE_ROLE';
|
|
20
|
-
|
|
21
18
|
export function checkFeSlotAllows({ config, graph }) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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 });
|
|
37
42
|
}
|
|
38
|
-
|
|
39
|
-
if (!verdict || verdict.allowed) continue;
|
|
40
|
-
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 });
|
|
41
|
-
}
|
|
42
|
-
return { violations, coverage: { status: 'checked', files } };
|
|
43
|
+
return { violations, coverage: { status: 'checked', files } };
|
|
43
44
|
}
|
|
@@ -2,7 +2,6 @@ import path from 'node:path';
|
|
|
2
2
|
import { treeOf } from './required-files.mjs';
|
|
3
3
|
import { allowsFile } from '../allows.mjs';
|
|
4
4
|
import { byCodeUnit } from '../../lib/list.mjs';
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* R29 `feature-shape` (BE_FEATURE_SHAPE). A feature root holds `index.ts`, `<feature>.module.ts`, `application/`,
|
|
8
7
|
* `transport/<protocol>/` and `messages/` only, and each of those folders holds only what its slot `allows` (knowledge/hfs/
|
|
@@ -12,47 +11,50 @@ import { byCodeUnit } from '../../lib/list.mjs';
|
|
|
12
11
|
* `transport/`, a `graphql/` folder under `application/`) is refused because its files fall back to the feature root slot.
|
|
13
12
|
*/
|
|
14
13
|
export const FEATURE_SHAPE_RULE_IDS = ['BE_FEATURE_SHAPE'];
|
|
15
|
-
|
|
16
14
|
const RULE = 'BE_FEATURE_SHAPE';
|
|
17
|
-
|
|
18
15
|
// {message, extra} for one feature file the slot answer refuses, or null when it sits where a slot allows it.
|
|
19
16
|
const featureFileFinding = (file, owner, verdict) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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 } };
|
|
30
32
|
}
|
|
31
|
-
if (verdict.allowed)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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 } };
|
|
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
38
|
};
|
|
39
|
-
|
|
40
39
|
export function checkFeatureShape({ config, graph }) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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 } };
|
|
58
60
|
}
|
|
@@ -8,34 +8,34 @@
|
|
|
8
8
|
import fs from 'node:fs';
|
|
9
9
|
import { fileURLToPath } from 'node:url';
|
|
10
10
|
import { parseYaml } from '../../../engine/yaml.mjs';
|
|
11
|
-
|
|
12
11
|
export const FRAMEWORK_PINNED_KNOWLEDGE = fileURLToPath(new URL('../../../knowledge/patterns/fe/folder.yaml', import.meta.url));
|
|
13
|
-
|
|
14
12
|
const cache = new Map(); // only the installed knowledge file is cached; an explicit file is re-read
|
|
15
13
|
const EXACT_NAME = /^[^\\/*?[\]{}\s]+$/;
|
|
16
|
-
|
|
17
14
|
function unavailable(file, detail) {
|
|
18
|
-
|
|
15
|
+
return new Error(`ARCH_KNOWLEDGE_UNAVAILABLE: ${file} ${detail}`);
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
function load(file) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
rule
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
38
|
/** Exact basenames Next.js loads only from the source root. */
|
|
39
39
|
export function frameworkPinnedRootFiles(file = FRAMEWORK_PINNED_KNOWLEDGE) {
|
|
40
|
-
|
|
40
|
+
return load(file).files;
|
|
41
41
|
}
|
|
@@ -1,104 +1,112 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { normalizedSymbolValue } from './ast-walks.mjs';
|
|
3
3
|
import { unwrapExpression } from './typescript.mjs';
|
|
4
|
-
|
|
5
4
|
/** Feature composition may inject block renders into a pure view without making the view a world owner. */
|
|
6
5
|
export class BlockRenderAnalysis {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
6
|
+
renderer;
|
|
7
|
+
world;
|
|
8
|
+
constructor(renderer) {
|
|
9
|
+
this.renderer = renderer;
|
|
10
|
+
// The renderer is always built by the world analysis, which carries the frontend tier helper.
|
|
11
|
+
this.world = renderer.world;
|
|
12
|
+
}
|
|
13
|
+
featureComposition(expression, expectedFile) {
|
|
14
|
+
const file = expression?.getSourceFile().fileName;
|
|
15
|
+
return Boolean(file && !expectedFile && this.world.insideAny(this.world.roots.features, file)
|
|
16
|
+
&& path.basename(file) === 'index.tsx');
|
|
17
|
+
}
|
|
18
|
+
renderProp(expression, checker, expectedFile) {
|
|
19
|
+
return this.featureComposition(expression, expectedFile) && this.renderValue(expression, checker);
|
|
20
|
+
}
|
|
21
|
+
blockTarget(expression, checker) {
|
|
22
|
+
const functions = this.world.expressionFunctions(expression, checker);
|
|
23
|
+
return functions.length > 0 && functions.every(fn => {
|
|
24
|
+
const file = fn.getSourceFile().fileName;
|
|
25
|
+
return this.world.sourceSet.has(path.resolve(file)) && path.basename(file) === 'index.tsx'
|
|
26
|
+
&& this.world.tierOf(this.world.roots.components, file)?.tier === 'blocks'
|
|
27
|
+
&& this.renderer.functionHasRender(fn, checker);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
callbacksRender(functions, checker, seen) {
|
|
31
|
+
return functions.length > 0 && functions.every(fn => {
|
|
32
|
+
const values = this.renderer.helpers.returnedExpressions(this.world.ts, fn);
|
|
33
|
+
return !this.world.functionUsesWorld(fn, checker) && values.length > 0
|
|
34
|
+
&& values.every(value => this.renderValue(value, checker, seen));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
renderValue(input, checker, seen = new Set()) {
|
|
38
|
+
const ts = this.world.ts;
|
|
39
|
+
const value = unwrapExpression(ts, input);
|
|
40
|
+
if (!value)
|
|
41
|
+
return false;
|
|
42
|
+
if (value.kind === ts.SyntaxKind.NullKeyword || value.kind === ts.SyntaxKind.FalseKeyword)
|
|
43
|
+
return true;
|
|
44
|
+
if (ts.isConditionalExpression(value))
|
|
45
|
+
return this.renderValue(value.whenTrue, checker, seen)
|
|
46
|
+
&& this.renderValue(value.whenFalse, checker, seen);
|
|
47
|
+
if (ts.isBinaryExpression(value) && value.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken)
|
|
48
|
+
return this.renderValue(value.right, checker, seen);
|
|
49
|
+
if (ts.isArrayLiteralExpression(value))
|
|
50
|
+
return value.elements.every(item => this.renderValue(item, checker, seen));
|
|
51
|
+
if (ts.isJsxFragment(value))
|
|
52
|
+
return this.fragmentBlocks(value, checker, seen);
|
|
53
|
+
if (ts.isJsxElement(value) || ts.isJsxSelfClosingElement(value))
|
|
54
|
+
return this.jsxBlock(value, checker, seen);
|
|
55
|
+
if (ts.isCallExpression(value))
|
|
56
|
+
return this.createdBlock(value, checker, seen) || this.mappedBlocks(value, checker, seen);
|
|
57
|
+
if (ts.isArrowFunction(value) || ts.isFunctionExpression(value))
|
|
58
|
+
return this.callbacksRender([value], checker, seen);
|
|
59
|
+
return this.referencedBlocks(value, checker, seen);
|
|
60
|
+
}
|
|
61
|
+
fragmentBlocks(value, checker, seen) {
|
|
62
|
+
const ts = this.world.ts;
|
|
63
|
+
return value.children.every(child => {
|
|
64
|
+
if (ts.isJsxText(child))
|
|
65
|
+
return !child.text.trim();
|
|
66
|
+
return this.renderValue(ts.isJsxExpression(child) ? child.expression : child, checker, seen);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
jsxBlock(value, checker, seen) {
|
|
70
|
+
const ts = this.world.ts;
|
|
71
|
+
const opening = ts.isJsxElement(value) ? value.openingElement : value;
|
|
72
|
+
if (!this.blockTarget(opening.tagName, checker))
|
|
73
|
+
return false;
|
|
74
|
+
const boundary = { hasBoundary: true };
|
|
75
|
+
return this.renderer.jsxChildrenBoundary(value, opening, checker, seen, null, false, boundary)
|
|
76
|
+
&& this.renderer.jsxAttributesBoundary(opening, checker, seen, null, boundary);
|
|
77
|
+
}
|
|
78
|
+
mappedBlocks(value, checker, seen) {
|
|
79
|
+
const ts = this.world.ts;
|
|
80
|
+
const callee = unwrapExpression(ts, value.expression);
|
|
81
|
+
if (!ts.isPropertyAccessExpression(callee) && !ts.isElementAccessExpression(callee))
|
|
82
|
+
return false;
|
|
83
|
+
let name = ts.isPropertyAccessExpression(callee) ? callee.name.text : null;
|
|
84
|
+
if (name === null && ts.isElementAccessExpression(callee) && ts.isStringLiteralLike(callee.argumentExpression))
|
|
85
|
+
name = callee.argumentExpression.text;
|
|
86
|
+
const [mapper] = value.arguments;
|
|
87
|
+
return name === 'map' && mapper !== undefined
|
|
88
|
+
&& this.callbacksRender(this.world.expressionFunctions(mapper, checker), checker, seen);
|
|
89
|
+
}
|
|
90
|
+
createdBlock(value, checker, seen) {
|
|
91
|
+
const ts = this.world.ts;
|
|
92
|
+
if (!this.renderer.isCreateElement(value, checker) || !value.arguments[0]
|
|
93
|
+
|| !this.blockTarget(value.arguments[0], checker))
|
|
94
|
+
return false;
|
|
95
|
+
const boundary = { hasBoundary: true };
|
|
96
|
+
const props = value.arguments[1] ? unwrapExpression(ts, value.arguments[1]) : null;
|
|
97
|
+
return this.renderer.createElementPropsBoundary(props, checker, seen, null, boundary, false)
|
|
98
|
+
&& value.arguments.slice(2).every(child => this.renderer.renderBoundary(child, checker, seen));
|
|
99
|
+
}
|
|
100
|
+
referencedBlocks(value, checker, seen) {
|
|
101
|
+
const ts = this.world.ts;
|
|
102
|
+
const symbol = normalizedSymbolValue(ts, checker, this.renderer.helpers.selectedSymbol(ts, checker, value));
|
|
103
|
+
if (!symbol || seen.has(symbol))
|
|
104
|
+
return false;
|
|
105
|
+
const nextSeen = new Set(seen).add(symbol);
|
|
106
|
+
const values = (symbol.getDeclarations?.() ?? []).flatMap(declaration => ts.isVariableDeclaration(declaration)
|
|
107
|
+
&& declaration.initializer ? [declaration.initializer] : []);
|
|
108
|
+
if (values.length)
|
|
109
|
+
return values.every(item => this.renderValue(item, checker, nextSeen));
|
|
110
|
+
return this.callbacksRender(this.world.expressionFunctions(value, checker), checker, nextSeen);
|
|
111
|
+
}
|
|
104
112
|
}
|