@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
|
@@ -2,317 +2,319 @@ import { relativePath, UNPROVEN_FRAMEWORK, unwrapExpression } from './typescript
|
|
|
2
2
|
import { constructedDecoratorKind, mutableDecoratorKind, nodeDecorators, tracedFrameworkKinds, violation } from './ast-walks.mjs';
|
|
3
3
|
import { byCodeUnit } from '../../lib/list.mjs';
|
|
4
4
|
function locateSource(h, config, context, sourceFile, roots, state) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
5
|
+
const { featureRoots, moduleRoots, localFiles } = roots;
|
|
6
|
+
const { canonical, frameworkTargets, locatedRoot, sourceRole, exportedDeclarations, SPECIAL_BASENAMES } = h;
|
|
7
|
+
const fileName = canonical(sourceFile.fileName);
|
|
8
|
+
const featureRoot = locatedRoot(featureRoots, fileName);
|
|
9
|
+
const moduleRoot = locatedRoot(moduleRoots, fileName);
|
|
10
|
+
const ownerRoot = featureRoot ?? moduleRoot;
|
|
11
|
+
if (!ownerRoot)
|
|
12
|
+
return null;
|
|
13
|
+
state.checkedFiles += 1;
|
|
14
|
+
const checker = context.checkerFor(fileName);
|
|
15
|
+
if (!checker)
|
|
16
|
+
return null;
|
|
17
|
+
if (!state.frameworkByChecker.has(checker))
|
|
18
|
+
state.frameworkByChecker.set(checker, frameworkTargets(config, context, checker, localFiles));
|
|
19
|
+
const framework = state.frameworkByChecker.get(checker) ?? frameworkTargets(config, context, checker, localFiles);
|
|
20
|
+
const relativeToOwner = relativePath(ownerRoot, fileName);
|
|
21
|
+
const parts = relativeToOwner.split('/');
|
|
22
|
+
const directories = parts.slice(0, -1).map(part => part.toLowerCase());
|
|
23
|
+
const applicationIndex = directories.indexOf('application');
|
|
24
|
+
const transportIndex = directories.indexOf('transport');
|
|
25
|
+
const inApplication = applicationIndex >= 0;
|
|
26
|
+
const inTransport = transportIndex >= 0;
|
|
27
|
+
const role = sourceRole(context.ts, sourceFile);
|
|
28
|
+
const relative = relativePath(config.root, fileName);
|
|
29
|
+
const migrationName = /^\d{10,}-[A-Z][A-Za-z0-9]*$/.test(role.base);
|
|
30
|
+
const persistencePath = !role.spec && (migrationName || directories.includes('migrations'));
|
|
31
|
+
const special = SPECIAL_BASENAMES.has(role.base.toLowerCase()) || migrationName
|
|
32
|
+
|| ['constants', 'enums', 'errors', 'migrations'].some(folder => directories.includes(folder));
|
|
33
|
+
const publicDeclarations = exportedDeclarations(context.ts, checker, sourceFile);
|
|
34
|
+
return { config, context, sourceFile, fileName, featureRoot, moduleRoot, checker, framework, directories, transportIndex,
|
|
35
|
+
inApplication, inTransport, role, relative, migrationName, persistencePath, special, publicDeclarations };
|
|
31
36
|
}
|
|
32
|
-
|
|
33
37
|
function reportSourceName(h, info, state) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const { kebabSourceBase, SOURCE_NAME_RULE_ID } = h;
|
|
39
|
+
const { config, sourceFile, migrationName, role, relative } = info;
|
|
40
|
+
if (!migrationName && !kebabSourceBase(role.base))
|
|
41
|
+
state.violations.push(violation(config, sourceFile, sourceFile, SOURCE_NAME_RULE_ID, `Source basename ${role.base} must use kebab-case segments plus an explicit role suffix.`));
|
|
42
|
+
if (!role.role && !info.special)
|
|
43
|
+
state.namingReasons.push(`${relative} has no statically identifiable source role`);
|
|
39
44
|
}
|
|
40
|
-
|
|
41
45
|
function reportFeatureRoleConflicts(h, info, state) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
const { SOURCE_LAYOUT_RULE_ID, APPLICATION_ROLES, TRANSPORT_ROLES } = h;
|
|
47
|
+
const { config, sourceFile, role, directories, inApplication, inTransport, transportIndex } = info;
|
|
48
|
+
const { violations } = state;
|
|
49
|
+
if (inApplication && inTransport)
|
|
50
|
+
violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, 'A feature source cannot belong to both application and transport layers.'));
|
|
51
|
+
if (role.role && APPLICATION_ROLES.has(role.role) && !inApplication)
|
|
52
|
+
violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, `${role.role} source belongs under the feature application/ layer.`));
|
|
53
|
+
if (role.role && TRANSPORT_ROLES.has(role.role) && !inTransport)
|
|
54
|
+
violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, `${role.role} source belongs under the feature transport/<protocol>/ layer.`));
|
|
55
|
+
if (inApplication && role.role && TRANSPORT_ROLES.has(role.role))
|
|
56
|
+
violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, `Transport role ${role.role} cannot live in application/.`));
|
|
57
|
+
if (inTransport && role.role && APPLICATION_ROLES.has(role.role))
|
|
58
|
+
violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, `Application role ${role.role} cannot live in transport/.`));
|
|
59
|
+
if (inTransport && transportIndex >= directories.length - 1)
|
|
60
|
+
violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, 'Feature transport source must name a protocol below transport/.'));
|
|
57
61
|
}
|
|
58
|
-
|
|
59
62
|
/** A non-index source whose role is neither one of the layer's own roles nor one the other layer or the schema owns. */
|
|
60
63
|
function unselectedLayerRole(role, layerRoles, otherRoles) {
|
|
61
|
-
|
|
64
|
+
return role.base !== 'index' && (!role.role || !layerRoles.has(role.role)) && !(role.role && (otherRoles.has(role.role) || role.role === 'entity'));
|
|
62
65
|
}
|
|
63
|
-
|
|
64
66
|
function reportFeatureRoleSelection(h, info, state) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
const { APPLICATION_ROLES, TRANSPORT_ROLES, APPLICATION_LAYER_ROLES, TRANSPORT_LAYER_ROLES } = h;
|
|
68
|
+
const { role, relative, directories, inApplication, inTransport, persistencePath } = info;
|
|
69
|
+
const topLevelFeatureFile = directories.length === 1 && (role.base === 'index' || role.role === 'module' || role.spec);
|
|
70
|
+
if (inApplication && unselectedLayerRole(role, APPLICATION_LAYER_ROLES, TRANSPORT_ROLES)) {
|
|
71
|
+
state.layoutReasons.push(`${relative} role ${role.role ?? '(unclassified)'} is not a selected application-layer role`);
|
|
72
|
+
}
|
|
73
|
+
if (inTransport && unselectedLayerRole(role, TRANSPORT_LAYER_ROLES, APPLICATION_ROLES)) {
|
|
74
|
+
state.layoutReasons.push(`${relative} role ${role.role ?? '(unclassified)'} is not a selected transport-layer role`);
|
|
75
|
+
}
|
|
76
|
+
if (inApplication || inTransport || topLevelFeatureFile)
|
|
77
|
+
return;
|
|
78
|
+
if (role.role && role.role !== 'entity' && !APPLICATION_ROLES.has(role.role) && !TRANSPORT_ROLES.has(role.role)) {
|
|
79
|
+
state.layoutReasons.push(`${relative} role ${role.role} has no statically selected feature layer`);
|
|
80
|
+
}
|
|
81
|
+
if (!role.role && !persistencePath)
|
|
82
|
+
state.layoutReasons.push(`${relative} has no statically selected feature layer`);
|
|
79
83
|
}
|
|
80
|
-
|
|
81
84
|
function reportFeatureSchemaPlacement(h, info, state) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
const { SOURCE_LAYOUT_RULE_ID } = h;
|
|
86
|
+
const { config, sourceFile, role, persistencePath } = info;
|
|
87
|
+
if (persistencePath)
|
|
88
|
+
state.violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, 'Migration source cannot be owned by a feature; place it under the declared persistence module.'));
|
|
89
|
+
if (role.role === 'entity')
|
|
90
|
+
state.violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, 'Entity source cannot be owned by a feature; place schema under the declared persistence module.'));
|
|
88
91
|
}
|
|
89
|
-
|
|
90
92
|
function reportFeatureLayout(h, info, state) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
if (!info.featureRoot)
|
|
94
|
+
return;
|
|
95
|
+
reportFeatureRoleConflicts(h, info, state);
|
|
96
|
+
reportFeatureRoleSelection(h, info, state);
|
|
97
|
+
reportFeatureSchemaPlacement(h, info, state);
|
|
95
98
|
}
|
|
96
|
-
|
|
97
99
|
function inspectClassPlacement(h, info, declaration, kinds, state) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
'TypeORM entities and migrations cannot be owned by a feature; place schema under its declared persistence module.'));
|
|
100
|
+
const { implementsFramework, SOURCE_LAYOUT_RULE_ID } = h;
|
|
101
|
+
const { config, context, sourceFile, featureRoot, inTransport, directories, transportIndex, checker, framework } = info;
|
|
102
|
+
const { ts } = context;
|
|
103
|
+
const graphQlDto = kinds.some(kind => kind === 'ArgsType' || kind === 'InputType' || kind === 'ObjectType');
|
|
104
|
+
if (graphQlDto && (!featureRoot || !inTransport || directories[transportIndex + 1] !== 'graphql')) {
|
|
105
|
+
state.violations.push(violation(config, sourceFile, declaration.name ?? declaration, SOURCE_LAYOUT_RULE_ID, 'GraphQL DTO classes belong under a feature transport/graphql/ boundary.'));
|
|
106
|
+
}
|
|
107
|
+
const persistenceSchema = kinds.includes('Entity') || kinds.includes('ViewEntity')
|
|
108
|
+
|| implementsFramework(ts, checker, declaration, framework.bySymbol, 'MigrationInterface');
|
|
109
|
+
if (persistenceSchema && featureRoot)
|
|
110
|
+
state.violations.push(violation(config, sourceFile, declaration.name ?? declaration, SOURCE_LAYOUT_RULE_ID, 'TypeORM entities and migrations cannot be owned by a feature; place schema under its declared persistence module.'));
|
|
110
111
|
}
|
|
111
|
-
|
|
112
112
|
function inspectClassName(h, info, declaration, state) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
113
|
+
const { implementedPortNames, SOURCE_NAME_RULE_ID, CLASS_ROLE_SUFFIX, NON_CLASS_ROLES } = h;
|
|
114
|
+
const { config, sourceFile, role, relative, checker } = info;
|
|
115
|
+
const { ts } = info.context;
|
|
116
|
+
const { publicDeclarations } = info;
|
|
117
|
+
const classSuffix = role.role && !NON_CLASS_ROLES.has(role.role) ? CLASS_ROLE_SUFFIX.get(role.role) : null;
|
|
118
|
+
const nameNode = declaration.name;
|
|
119
|
+
if (publicDeclarations.has(declaration) && !nameNode)
|
|
120
|
+
state.namingReasons.push(`${relative} exports an anonymous class whose role name cannot be proved`);
|
|
121
|
+
else if (publicDeclarations.has(declaration) && nameNode && classSuffix && !nameNode.text.endsWith(classSuffix)
|
|
122
|
+
&& !implementedPortNames(ts, checker, declaration).some(port => nameNode.text.endsWith(port))) {
|
|
123
|
+
state.violations.push(violation(config, sourceFile, nameNode, SOURCE_NAME_RULE_ID, `Exported class ${nameNode.text} must end in ${classSuffix} for a ${role.role} source file, or in the name of the port it implements.`));
|
|
124
|
+
}
|
|
125
|
+
else if (publicDeclarations.has(declaration) && nameNode && role.role && !NON_CLASS_ROLES.has(role.role) && !classSuffix) {
|
|
126
|
+
state.namingReasons.push(`${relative} declares exported class ${nameNode.text} with unclassified file role ${role.role}`);
|
|
127
|
+
}
|
|
126
128
|
}
|
|
127
|
-
|
|
128
129
|
function inspectClass(h, info, declaration, state) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
130
|
+
const { decoratorKind } = h;
|
|
131
|
+
const { ts } = info.context;
|
|
132
|
+
const { checker, framework } = info;
|
|
133
|
+
const declarationDecorators = nodeDecorators(ts, declaration);
|
|
134
|
+
const kinds = declarationDecorators.map(decorator => decoratorKind(ts, checker, decorator, framework.bySymbol)).filter((kind) => Boolean(kind));
|
|
135
|
+
inspectClassPlacement(h, info, declaration, kinds, state);
|
|
136
|
+
inspectClassName(h, info, declaration, state);
|
|
136
137
|
}
|
|
137
|
-
|
|
138
138
|
function inspectClasses(h, info, state) {
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
const declarations = info.sourceFile.statements.filter((statement) => info.context.ts.isClassDeclaration(statement));
|
|
140
|
+
for (const declaration of declarations)
|
|
141
|
+
inspectClass(h, info, declaration, state);
|
|
141
142
|
}
|
|
142
|
-
|
|
143
143
|
function inspectClassValue(h, info, declaration, state) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
144
|
+
const { classValueStatus, SOURCE_NAME_RULE_ID, CLASS_ROLE_SUFFIX, NON_CLASS_ROLES } = h;
|
|
145
|
+
const { config, sourceFile, relative, role, checker, publicDeclarations } = info;
|
|
146
|
+
const { ts } = info.context;
|
|
147
|
+
if (!publicDeclarations.has(declaration) || !declaration.initializer)
|
|
148
|
+
return;
|
|
149
|
+
const classValue = classValueStatus(ts, checker, declaration.initializer);
|
|
150
|
+
if (classValue.status === 'unavailable') {
|
|
151
|
+
state.namingReasons.push(`${relative} exports a class-valued declaration whose role identity is not statically proved`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (classValue.status !== 'class')
|
|
155
|
+
return;
|
|
156
|
+
const classSuffix = role.role && !NON_CLASS_ROLES.has(role.role) ? CLASS_ROLE_SUFFIX.get(role.role) : null;
|
|
157
|
+
if (!classSuffix || !ts.isIdentifier(declaration.name)) {
|
|
158
|
+
state.namingReasons.push(`${relative} exports a class-valued declaration without a statically selected class role`);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const names = [declaration.name.text, ...classValue.names];
|
|
162
|
+
const invalid = names.find(name => !name.endsWith(classSuffix));
|
|
163
|
+
if (invalid)
|
|
164
|
+
state.violations.push(violation(config, sourceFile, declaration.name, SOURCE_NAME_RULE_ID, `Exported class value ${invalid} must end in ${classSuffix} for a ${role.role} source file.`));
|
|
163
165
|
}
|
|
164
|
-
|
|
165
166
|
function inspectClassValues(h, info, state) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
const { ts } = info.context;
|
|
168
|
+
const { sourceFile } = info;
|
|
169
|
+
for (const statement of sourceFile.statements)
|
|
170
|
+
if (ts.isVariableStatement(statement)) {
|
|
171
|
+
for (const declaration of statement.declarationList.declarations)
|
|
172
|
+
inspectClassValue(h, info, declaration, state);
|
|
173
|
+
}
|
|
171
174
|
}
|
|
172
|
-
|
|
173
175
|
function inspectEnumMembers(h, info, statement, state) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
176
|
+
const { SOURCE_NAME_RULE_ID } = h;
|
|
177
|
+
const { config, sourceFile } = info;
|
|
178
|
+
const { ts } = info.context;
|
|
179
|
+
for (const member of statement.members) {
|
|
180
|
+
const name = ts.isIdentifier(member.name) || ts.isStringLiteralLike(member.name) ? member.name.text : null;
|
|
181
|
+
const initializer = member.initializer && unwrapExpression(ts, member.initializer);
|
|
182
|
+
if (!name || !/^[A-Z][A-Za-z0-9]*$/.test(name) || !initializer || !ts.isStringLiteralLike(initializer)) {
|
|
183
|
+
state.violations.push(violation(config, sourceFile, member.name, SOURCE_NAME_RULE_ID, 'Enum members must use PascalCase names with explicit static string values.'));
|
|
184
|
+
}
|
|
183
185
|
}
|
|
184
|
-
}
|
|
185
186
|
}
|
|
186
|
-
|
|
187
187
|
function inspectObjectContract(h, info, statement, state) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
188
|
+
const { objectContractStatus, companionInterfaceAllowed, SOURCE_NAME_RULE_ID, TRANSPORT_OBJECT_SUFFIX } = h;
|
|
189
|
+
const { config, sourceFile, role, checker, publicDeclarations } = info;
|
|
190
|
+
const { ts } = info.context;
|
|
191
|
+
// an object contract is an interface or an object type alias, so any other statement has no contract name to judge
|
|
192
|
+
if (!ts.isInterfaceDeclaration(statement) && !ts.isTypeAliasDeclaration(statement))
|
|
193
|
+
return;
|
|
194
|
+
const contractStatus = objectContractStatus(ts, checker, statement);
|
|
195
|
+
const transportSuffix = role.role === null ? undefined : TRANSPORT_OBJECT_SUFFIX.get(role.role);
|
|
196
|
+
if (contractStatus === 'object' && publicDeclarations.has(statement) && transportSuffix && !role.spec
|
|
197
|
+
&& !statement.name.text.endsWith(transportSuffix) && !companionInterfaceAllowed(ts, sourceFile, statement.name.text)) {
|
|
198
|
+
state.violations.push(violation(config, sourceFile, statement.name, SOURCE_NAME_RULE_ID, `Public object contract ${statement.name.text} in a ${role.role} source file must end in ${transportSuffix}.`));
|
|
199
|
+
}
|
|
198
200
|
}
|
|
199
|
-
|
|
200
201
|
function inspectEnumAndContract(h, info, statement, state) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
202
|
+
const { hasModifier, SOURCE_NAME_RULE_ID } = h;
|
|
203
|
+
const { config, sourceFile } = info;
|
|
204
|
+
const { ts } = info.context;
|
|
205
|
+
if (ts.isEnumDeclaration(statement)) {
|
|
206
|
+
if (hasModifier(ts, statement, ts.SyntaxKind.ConstKeyword) || !/^[A-Z][A-Za-z0-9]*$/.test(statement.name.text)) {
|
|
207
|
+
state.violations.push(violation(config, sourceFile, statement.name, SOURCE_NAME_RULE_ID, 'Enums must be non-const declarations with PascalCase names.'));
|
|
208
|
+
}
|
|
209
|
+
inspectEnumMembers(h, info, statement, state);
|
|
208
210
|
}
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
inspectObjectContract(h, info, statement, state);
|
|
211
|
+
inspectObjectContract(h, info, statement, state);
|
|
212
212
|
}
|
|
213
|
-
|
|
214
213
|
function inspectEnumsAndContracts(h, info, state) {
|
|
215
|
-
|
|
214
|
+
for (const statement of info.sourceFile.statements)
|
|
215
|
+
inspectEnumAndContract(h, info, statement, state);
|
|
216
216
|
}
|
|
217
|
-
|
|
218
217
|
function inspectDynamicDecorator(info, dynamic, state) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
218
|
+
const detail = `${info.relative} uses a mutable or constructed ${dynamic} decorator identity`;
|
|
219
|
+
if (['Entity', 'ViewEntity', 'ArgsType', 'InputType', 'ObjectType', 'multiple framework', 'unproven framework'].includes(dynamic))
|
|
220
|
+
state.layoutReasons.push(detail);
|
|
221
|
+
if (!['Entity', 'ViewEntity'].includes(dynamic))
|
|
222
|
+
state.namingReasons.push(detail);
|
|
222
223
|
}
|
|
223
|
-
|
|
224
224
|
function inspectDecorator(h, info, node, decorator, state) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
225
|
+
const { graphqlField, graphqlArgument, decoratorKind, TRACE_NEW } = h;
|
|
226
|
+
const { ts } = info.context;
|
|
227
|
+
const { checker, framework } = info;
|
|
228
|
+
const kind = decoratorKind(ts, checker, decorator, framework.bySymbol);
|
|
229
|
+
if (!kind) {
|
|
230
|
+
const dynamic = mutableDecoratorKind(ts, checker, decorator, framework.bySymbol)
|
|
231
|
+
?? constructedDecoratorKind(ts, checker, decorator, framework.bySymbol, TRACE_NEW);
|
|
232
|
+
if (dynamic)
|
|
233
|
+
inspectDynamicDecorator(info, dynamic, state);
|
|
234
|
+
}
|
|
235
|
+
if (kind === 'Mutation' || kind === 'Query')
|
|
236
|
+
graphqlField({ config: info.config, context: info.context, sourceFile: info.sourceFile,
|
|
237
|
+
node, decorator, kind, namingReasons: state.namingReasons, violations: state.violations });
|
|
238
|
+
if (kind === 'Args')
|
|
239
|
+
graphqlArgument(info.config, info.context, info.sourceFile, node, decorator, state.namingReasons, state.violations);
|
|
237
240
|
}
|
|
238
|
-
|
|
239
241
|
function inspectNodeDecorators(h, info, node, state) {
|
|
240
|
-
|
|
242
|
+
for (const decorator of nodeDecorators(info.context.ts, node))
|
|
243
|
+
inspectDecorator(h, info, node, decorator, state);
|
|
241
244
|
}
|
|
242
|
-
|
|
243
245
|
function inspectEnumCalls(h, info, node, state) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
246
|
+
const { graphqlEnumRegistration, selectedCallKind, callsNamedHelper } = h;
|
|
247
|
+
const { ts } = info.context;
|
|
248
|
+
const { checker, framework } = info;
|
|
249
|
+
if (!ts.isCallExpression(node))
|
|
250
|
+
return;
|
|
251
|
+
if (selectedCallKind(ts, checker, node, framework.bySymbol) === 'registerEnumType') {
|
|
252
|
+
graphqlEnumRegistration(info.config, info.context, info.sourceFile, node, state.namingReasons, state.violations);
|
|
253
|
+
}
|
|
254
|
+
else if (callsNamedHelper(ts, checker, node, 'createEnumType')) {
|
|
255
|
+
state.namingReasons.push(`${info.relative} calls a project GraphQL enum adapter whose emitted type name is not statically proved`);
|
|
256
|
+
}
|
|
253
257
|
}
|
|
254
|
-
|
|
255
258
|
function inspectConstructedSource(h, info, node, state) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
259
|
+
const { SOURCE_LAYOUT_RULE_ID, TRACE_NEW } = h;
|
|
260
|
+
const { ts } = info.context;
|
|
261
|
+
const { checker, framework, publicDeclarations, featureRoot } = info;
|
|
262
|
+
const exportedFactoryCall = ts.isCallExpression(node) && ts.isVariableDeclaration(node.parent) && publicDeclarations.has(node.parent);
|
|
263
|
+
if ((ts.isNewExpression(node) || exportedFactoryCall) && featureRoot) {
|
|
264
|
+
const constructed = tracedFrameworkKinds(ts, checker, node, framework.bySymbol, TRACE_NEW);
|
|
265
|
+
if (constructed.has('EntitySchema'))
|
|
266
|
+
state.violations.push(violation(info.config, info.sourceFile, node.expression, SOURCE_LAYOUT_RULE_ID, 'TypeORM EntitySchema cannot be owned by a feature; place schema under its declared persistence module.'));
|
|
267
|
+
if (constructed.has(UNPROVEN_FRAMEWORK))
|
|
268
|
+
state.layoutReasons.push(`${info.relative} has a constructed provider identity beyond the bounded static trace`);
|
|
269
|
+
}
|
|
266
270
|
}
|
|
267
|
-
|
|
268
271
|
function visitSourceNode(h, info, node, state) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
272
|
+
inspectNodeDecorators(h, info, node, state);
|
|
273
|
+
inspectEnumCalls(h, info, node, state);
|
|
274
|
+
inspectConstructedSource(h, info, node, state);
|
|
275
|
+
info.context.ts.forEachChild(node, child => visitSourceNode(h, info, child, state));
|
|
273
276
|
}
|
|
274
|
-
|
|
275
277
|
function inspectSourceFile(h, config, context, sourceFile, roots, state) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
278
|
+
const info = locateSource(h, config, context, sourceFile, roots, state);
|
|
279
|
+
if (!info)
|
|
280
|
+
return;
|
|
281
|
+
reportSourceName(h, info, state);
|
|
282
|
+
reportFeatureLayout(h, info, state);
|
|
283
|
+
inspectClasses(h, info, state);
|
|
284
|
+
inspectClassValues(h, info, state);
|
|
285
|
+
inspectEnumsAndContracts(h, info, state);
|
|
286
|
+
visitSourceNode(h, info, sourceFile, state);
|
|
284
287
|
}
|
|
285
|
-
|
|
286
288
|
function coverageFor(state) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
289
|
+
for (const framework of state.frameworkByChecker.values()) {
|
|
290
|
+
state.layoutReasons.push(...framework.reasons);
|
|
291
|
+
state.namingReasons.push(...framework.reasons.filter(reason => reason.includes('@nestjs/graphql')));
|
|
292
|
+
}
|
|
293
|
+
if (state.checkedFiles === 0) {
|
|
294
|
+
state.layoutReasons.push('the checked TypeScript program contains no configured backend feature or module source');
|
|
295
|
+
state.namingReasons.push('the checked TypeScript program contains no configured backend feature or module source');
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
files: state.checkedFiles,
|
|
299
|
+
layout: state.layoutReasons.length
|
|
300
|
+
? { status: 'unavailable', reason: 'one or more backend source placement relations are not statically proved', details: [...new Set(state.layoutReasons)].sort(byCodeUnit) }
|
|
301
|
+
: { status: 'checked' },
|
|
302
|
+
naming: state.namingReasons.length
|
|
303
|
+
? { status: 'unavailable', reason: 'one or more backend source naming relations are not statically proved', details: [...new Set(state.namingReasons)].sort(byCodeUnit) }
|
|
304
|
+
: { status: 'checked' },
|
|
305
|
+
};
|
|
304
306
|
}
|
|
305
|
-
|
|
306
307
|
/** Check the adopted domain-first backend source layout without inferring semantic ownership from folder names alone. */
|
|
307
308
|
export function createBackendSourceShapeChecker(helpers) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
309
|
+
const { absoluteRoots, canonical } = helpers;
|
|
310
|
+
return function checkBackendSourceShape(config, context) {
|
|
311
|
+
const featureRoots = absoluteRoots(config.root, config.backend.features);
|
|
312
|
+
const moduleRoots = absoluteRoots(config.root, config.backend.modules);
|
|
313
|
+
const localFiles = new Set(context.files.map(file => canonical(file.fileName)));
|
|
314
|
+
const state = { frameworkByChecker: new Map(), violations: [], layoutReasons: [], namingReasons: [], checkedFiles: 0 };
|
|
315
|
+
const roots = { featureRoots, moduleRoots, localFiles };
|
|
316
|
+
for (const sourceFile of context.files)
|
|
317
|
+
inspectSourceFile(helpers, config, context, sourceFile, roots, state);
|
|
318
|
+
return { violations: state.violations, coverage: coverageFor(state) };
|
|
319
|
+
};
|
|
318
320
|
}
|