@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
|
@@ -3,7 +3,6 @@ import { isComposeGroup, machineKit } from './machine-ast.mjs';
|
|
|
3
3
|
import { treeOf } from './required-files.mjs';
|
|
4
4
|
import { byCodeUnit } from '../../lib/list.mjs';
|
|
5
5
|
import { trimTrailingSlashes } from '../trailing-slashes.mjs';
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* R45 `module-per-transport` (BE_MODULE_SHAPE, BE-CONVENTION 1.2 and 1.6). A feature has one Nest module for its
|
|
9
8
|
* application (`<f>.module.ts` at the feature root) and exactly one module per transport folder
|
|
@@ -23,205 +22,211 @@ import { trimTrailingSlashes } from '../trailing-slashes.mjs';
|
|
|
23
22
|
* other kind lists none of its modules.
|
|
24
23
|
*/
|
|
25
24
|
export const MODULE_PER_TRANSPORT_RULE_IDS = ['BE_MODULE_SHAPE'];
|
|
26
|
-
|
|
27
25
|
const RULE = 'BE_MODULE_SHAPE';
|
|
28
|
-
|
|
29
26
|
function featureOwnerOf(resolver, rel) {
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
const owner = resolver.ownerOf(rel);
|
|
28
|
+
return owner && resolver.slot(owner.slot)?.tier === 'feature' ? owner : null;
|
|
32
29
|
}
|
|
33
|
-
|
|
34
30
|
function modulePlaceOf(resolver, rel) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
31
|
+
const owner = featureOwnerOf(resolver, rel);
|
|
32
|
+
if (!owner)
|
|
33
|
+
return null;
|
|
34
|
+
const composedBy = resolver.slot(owner.slot)?.composedBy;
|
|
35
|
+
const below = rel.slice(owner.root.length + 1).split('/');
|
|
36
|
+
const feature = path.posix.basename(owner.root);
|
|
37
|
+
if (composedBy)
|
|
38
|
+
return { root: owner.root, feature, protocol: null, below, composed: { composedBy } };
|
|
39
|
+
return { root: owner.root, feature, protocol: below[0] === 'transport' && below.length > 2 ? below[1] ?? null : null, below, composed: null };
|
|
40
|
+
}
|
|
44
41
|
function composedModulePath(rel) {
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
const dir = path.posix.dirname(rel);
|
|
43
|
+
return `${dir}/${path.posix.basename(dir)}.module.ts`;
|
|
47
44
|
}
|
|
48
|
-
|
|
49
45
|
function composedByProtocol(resolver) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
46
|
+
const composedBy = new Map();
|
|
47
|
+
for (const slot of resolver.slots()) {
|
|
48
|
+
if (!slot.composedBy || slot.owner)
|
|
49
|
+
continue;
|
|
50
|
+
composedBy.set(path.posix.basename(trimTrailingSlashes(slot.path)), slot.composedBy);
|
|
51
|
+
}
|
|
52
|
+
return composedBy;
|
|
53
|
+
}
|
|
58
54
|
/** The module a feature file may declare: the application module, the transport module of its folder, or a cli folder's module. */
|
|
59
55
|
function ownModuleOf(place, rel, composedModuleOf) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
if (place.composed)
|
|
57
|
+
return composedModuleOf(rel);
|
|
58
|
+
return place.protocol === null
|
|
59
|
+
? `${place.root}/${place.feature}.module.ts`
|
|
60
|
+
: `${place.root}/transport/${place.protocol}/${place.feature}-${place.protocol}.module.ts`;
|
|
64
61
|
}
|
|
65
|
-
|
|
66
62
|
const DEFINITION_FILE = /\.module-definition\.[cm]?tsx?$/u;
|
|
67
|
-
const definitionOf = modulePath => modulePath.replace(/\.module\.([cm]?tsx?)$/u, '.module-definition.$1');
|
|
68
|
-
|
|
63
|
+
const definitionOf = (modulePath) => modulePath.replace(/\.module\.([cm]?tsx?)$/u, '.module-definition.$1');
|
|
69
64
|
function reportTransportFileShapes(tree, placeOf, plain, composedModuleOf) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
65
|
+
let transportModules = 0;
|
|
66
|
+
for (const rel of [...tree.files].sort(byCodeUnit)) {
|
|
67
|
+
const place = placeOf(rel);
|
|
68
|
+
if (!place)
|
|
69
|
+
continue;
|
|
70
|
+
const base = path.posix.basename(rel);
|
|
71
|
+
if (DEFINITION_FILE.test(base) && rel !== definitionOf(ownModuleOf(place, rel, composedModuleOf)))
|
|
72
|
+
plain(rel, `${rel} is a module-definition that is not beside a module of feature ${place.feature}; the definition of a module is its sibling ${path.posix.basename(definitionOf(ownModuleOf(place, rel, composedModuleOf)))}, one per application module, transport module or cli folder.`, { feature: place.feature });
|
|
73
|
+
if (place.protocol && /\.module\.[cm]?tsx?$/u.test(base)) {
|
|
74
|
+
const expected = `${place.feature}-${place.protocol}.module.ts`;
|
|
75
|
+
if (place.below.length !== 3 || base !== expected)
|
|
76
|
+
plain(rel, `${rel} is a second module of the ${place.protocol} transport of ${place.feature}; a transport folder has exactly one module, transport/${place.protocol}/${expected}, never one module per operation. List the operation's providers in that module and delete this file.`, { feature: place.feature, protocol: place.protocol });
|
|
77
|
+
else
|
|
78
|
+
transportModules += 1;
|
|
79
|
+
}
|
|
80
80
|
}
|
|
81
|
-
|
|
82
|
-
return transportModules;
|
|
81
|
+
return transportModules;
|
|
83
82
|
}
|
|
84
|
-
|
|
85
83
|
function isNestModuleClass(ts, kit, checker, statement) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
const own = place.protocol === null
|
|
99
|
-
? `${place.root}/${place.feature}.module.ts`
|
|
100
|
-
: `${place.root}/transport/${place.protocol}/${place.feature}-${place.protocol}.module.ts`;
|
|
101
|
-
if (file.rel !== own) report(file, statement.name, `${statement.name.text} is a Nest module declared in ${file.rel}; a feature declares exactly its application module (${place.feature}.module.ts) and one module per transport folder (${place.feature}-<protocol>.module.ts), never a module per operation.`, { feature: place.feature });
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function reportConfigurableModuleUses(file, checker, kit, ts, place, env) {
|
|
105
|
-
const own = ownModuleOf(place, file.rel, env.composedModuleOf);
|
|
106
|
-
const isDefinition = file.rel === definitionOf(own);
|
|
107
|
-
kit.walk(file.sourceFile, node => {
|
|
108
|
-
if (ts.isNewExpression(node) && kit.isImportOf(checker, node.expression, 'ConfigurableModuleBuilder', '@nestjs/common') && !isDefinition) {
|
|
109
|
-
env.report(file, node, `ConfigurableModuleBuilder builds the module definition of one module; in feature ${place.feature} it is written only in ${path.posix.basename(definitionOf(own))}, beside ${path.posix.basename(own)}.`, { feature: place.feature });
|
|
110
|
-
} else if (ts.isHeritageClause(node) && file.rel !== own) {
|
|
111
|
-
for (const type of node.types) if (kit.isImportOf(checker, type.expression, 'ConfigurableModuleClass', '@nestjs/common')) {
|
|
112
|
-
env.report(file, type, `ConfigurableModuleClass is extended by the module of its own definition only (${path.posix.basename(own)}); feature ${place.feature} declares no other configurable module.`, { feature: place.feature });
|
|
113
|
-
}
|
|
84
|
+
return kit.decorators(statement).some(decorator => {
|
|
85
|
+
const call = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
|
|
86
|
+
return kit.isImportOf(checker, call, 'Module', '@nestjs/common');
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function reportModuleClassLocation(file, name, place, composedModuleOf, report) {
|
|
90
|
+
if (place.composed) {
|
|
91
|
+
const own = composedModuleOf(file.rel);
|
|
92
|
+
if (file.rel !== own)
|
|
93
|
+
report(file, name, `${name.text} is a Nest module declared in ${file.rel}; every folder of ${place.root} holds exactly one static module named after it (${own}), never a module per command.`, { feature: place.feature });
|
|
94
|
+
return;
|
|
114
95
|
}
|
|
115
|
-
|
|
116
|
-
|
|
96
|
+
const own = place.protocol === null
|
|
97
|
+
? `${place.root}/${place.feature}.module.ts`
|
|
98
|
+
: `${place.root}/transport/${place.protocol}/${place.feature}-${place.protocol}.module.ts`;
|
|
99
|
+
if (file.rel !== own)
|
|
100
|
+
report(file, name, `${name.text} is a Nest module declared in ${file.rel}; a feature declares exactly its application module (${place.feature}.module.ts) and one module per transport folder (${place.feature}-<protocol>.module.ts), never a module per operation.`, { feature: place.feature });
|
|
101
|
+
}
|
|
102
|
+
function reportConfigurableModuleUses(file, checker, kit, ts, place, env) {
|
|
103
|
+
const own = ownModuleOf(place, file.rel, env.composedModuleOf);
|
|
104
|
+
const isDefinition = file.rel === definitionOf(own);
|
|
105
|
+
kit.walk(file.sourceFile, node => {
|
|
106
|
+
if (ts.isNewExpression(node) && kit.isImportOf(checker, node.expression, 'ConfigurableModuleBuilder', '@nestjs/common') && !isDefinition) {
|
|
107
|
+
env.report(file, node, `ConfigurableModuleBuilder builds the module definition of one module; in feature ${place.feature} it is written only in ${path.posix.basename(definitionOf(own))}, beside ${path.posix.basename(own)}.`, { feature: place.feature });
|
|
108
|
+
}
|
|
109
|
+
else if (ts.isHeritageClause(node) && file.rel !== own) {
|
|
110
|
+
for (const type of node.types)
|
|
111
|
+
if (kit.isImportOf(checker, type.expression, 'ConfigurableModuleClass', '@nestjs/common')) {
|
|
112
|
+
env.report(file, type, `ConfigurableModuleClass is extended by the module of its own definition only (${path.posix.basename(own)}); feature ${place.feature} declares no other configurable module.`, { feature: place.feature });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
});
|
|
117
117
|
}
|
|
118
|
-
|
|
119
118
|
function moduleClassesInFile(file, checker, place, modules, env) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
119
|
+
const { kit, ts, composedModuleOf, report } = env;
|
|
120
|
+
for (const statement of file.sourceFile.statements) {
|
|
121
|
+
if (!ts.isClassDeclaration(statement) || !statement.name)
|
|
122
|
+
continue;
|
|
123
|
+
if (!isNestModuleClass(ts, kit, checker, statement))
|
|
124
|
+
continue;
|
|
125
|
+
modules.set(statement, { name: statement.name.text, file });
|
|
126
|
+
if (place)
|
|
127
|
+
reportModuleClassLocation(file, statement.name, place, composedModuleOf, report);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
129
130
|
function collectFeatureModules(graph, kit, ts, placeOf, composedModuleOf, report) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
131
|
+
const modules = new Map(); // class declaration -> {name, file}
|
|
132
|
+
const env = { kit, ts, composedModuleOf, report };
|
|
133
|
+
for (const file of graph.files.values()) {
|
|
134
|
+
const checker = kit.checkerOf(file.sourceFile);
|
|
135
|
+
const place = placeOf(file.rel);
|
|
136
|
+
moduleClassesInFile(file, checker, place, modules, env);
|
|
137
|
+
if (place)
|
|
138
|
+
reportConfigurableModuleUses(file, checker, kit, ts, place, env);
|
|
139
|
+
}
|
|
140
|
+
return modules;
|
|
139
141
|
}
|
|
140
|
-
|
|
141
142
|
function reportModuleReference(root, node, app, module, place, composedBy, report) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
143
|
+
if (place.composed) {
|
|
144
|
+
const rootModule = `${place.root}/${place.feature}.module.ts`;
|
|
145
|
+
if (!place.composed.composedBy.includes(app.kind))
|
|
146
|
+
report(root, node, `App ${app.name} is of kind ${app.kind} and lists ${module.name} from ${place.root}; only an app of kind ${place.composed.composedBy.join(', ')} composes that root.`, { app: app.name, module: module.name });
|
|
147
|
+
else if (module.file.rel !== rootModule)
|
|
148
|
+
report(root, node, `App ${app.name} lists ${module.name}, a group module inside ${place.root}; the app lists the root module (${rootModule}), which imports every group module.`, { app: app.name, module: module.name });
|
|
149
|
+
}
|
|
150
|
+
else if (place.protocol === null) {
|
|
151
|
+
report(root, node, `App ${app.name} lists ${module.name}, the application module of feature ${place.feature}; apps import only transport modules (${place.feature}-<protocol>.module.ts), which import the application module themselves.`, { app: app.name, module: module.name });
|
|
152
|
+
}
|
|
153
|
+
else if (!(composedBy.get(place.protocol) ?? []).includes(app.kind)) {
|
|
154
|
+
const allowed = [...composedBy].filter(([, kinds]) => kinds.includes(app.kind)).map(([protocol]) => protocol).sort(byCodeUnit);
|
|
155
|
+
const transports = allowed.length ? `${allowed.join(', ')} transports only` : 'no transport module';
|
|
156
|
+
report(root, node, `App ${app.name} is of kind ${app.kind} and lists ${module.name}, a ${place.protocol} transport module; an app of kind ${app.kind} composes ${transports}.`, { app: app.name, module: module.name, protocol: place.protocol });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
155
159
|
function inspectModuleDeclarations(checker, target, node, root, app, scan, seen) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
160
|
+
const { moduleMap, kit, placeOf, composedBy, report } = scan;
|
|
161
|
+
let references = 0;
|
|
162
|
+
for (const declaration of kit.declarationsOf(checker, target)) {
|
|
163
|
+
const module = moduleMap.get(declaration);
|
|
164
|
+
if (!module)
|
|
165
|
+
continue;
|
|
166
|
+
const place = placeOf(module.file.rel);
|
|
167
|
+
if (!place || seen.has(node))
|
|
168
|
+
continue;
|
|
169
|
+
seen.add(node);
|
|
170
|
+
references += 1;
|
|
171
|
+
reportModuleReference(root, node, app, module, place, composedBy, report);
|
|
172
|
+
}
|
|
173
|
+
return references;
|
|
174
|
+
}
|
|
170
175
|
/** The module references of one composition file: the root's `imports` lists, or every array of a composition group (its module list). */
|
|
171
176
|
function inspectCompositionFile(file, app, scan, seen) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
177
|
+
const { kit, ts } = scan;
|
|
178
|
+
const checker = kit.checkerOf(file.sourceFile);
|
|
179
|
+
const group = isComposeGroup(file.rel);
|
|
180
|
+
let references = 0;
|
|
181
|
+
const judge = (node) => {
|
|
182
|
+
const call = ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === 'register';
|
|
183
|
+
if (ts.isCallExpression(node) && !call)
|
|
184
|
+
return;
|
|
185
|
+
const target = call ? node.expression.expression : node;
|
|
186
|
+
references += inspectModuleDeclarations(checker, target, node, file, app, scan, seen);
|
|
187
|
+
};
|
|
188
|
+
kit.walk(file.sourceFile, node => {
|
|
189
|
+
if (ts.isPropertyAssignment(node) && kit.propertyNameText(node.name) === 'imports' && ts.isArrayLiteralExpression(node.initializer)) {
|
|
190
|
+
for (const element of node.initializer.elements)
|
|
191
|
+
judge(element);
|
|
192
|
+
}
|
|
193
|
+
else if (group && ts.isArrayLiteralExpression(node)) {
|
|
194
|
+
for (const element of node.elements)
|
|
195
|
+
judge(element);
|
|
196
|
+
}
|
|
197
|
+
else if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === 'register')
|
|
198
|
+
judge(node);
|
|
199
|
+
return true;
|
|
200
|
+
});
|
|
201
|
+
return references;
|
|
202
|
+
}
|
|
193
203
|
/** The module references of an app: its root `apps/<app>/src/app.module.ts` and the composition groups of `compose/` it spreads. */
|
|
194
204
|
function inspectAppRoot(app, scan) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
205
|
+
const seen = new Set();
|
|
206
|
+
let references = 0;
|
|
207
|
+
for (const file of scan.kit.appCompositionFiles(app.name))
|
|
208
|
+
references += inspectCompositionFile(file, app, scan, seen);
|
|
209
|
+
return references;
|
|
199
210
|
}
|
|
200
|
-
|
|
201
211
|
function appModuleReferences(apps, scan) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
212
|
+
let references = 0;
|
|
213
|
+
for (const app of apps)
|
|
214
|
+
references += inspectAppRoot(app, scan);
|
|
215
|
+
return references;
|
|
205
216
|
}
|
|
206
|
-
|
|
207
217
|
export function checkModulePerTransport(input) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const modules = collectFeatureModules(graph, kit, ts, placeOf, composedModuleOf, report);
|
|
224
|
-
|
|
225
|
-
const references = appModuleReferences(resolver.repo.apps, { graph, kit, ts, moduleMap: modules, placeOf, composedBy, report });
|
|
226
|
-
return { violations, coverage: { status: 'checked', modules: modules.size, transportModules, appReferences: references } };
|
|
218
|
+
const { config, graph } = input;
|
|
219
|
+
const kit = machineKit(input);
|
|
220
|
+
const { ts, resolver } = kit;
|
|
221
|
+
const violations = [];
|
|
222
|
+
const report = (file, node, message, extra = {}) => violations.push({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, node), message, ...extra });
|
|
223
|
+
const plain = (rel, message, extra = {}) => violations.push({ ruleId: RULE, path: rel, line: 1, column: 1, message, ...extra });
|
|
224
|
+
const placeOf = rel => modulePlaceOf(resolver, rel);
|
|
225
|
+
const composedModuleOf = composedModulePath;
|
|
226
|
+
const composedBy = composedByProtocol(resolver);
|
|
227
|
+
const tree = treeOf(config.root);
|
|
228
|
+
const transportModules = reportTransportFileShapes(tree, placeOf, plain, composedModuleOf);
|
|
229
|
+
const modules = collectFeatureModules(graph, kit, ts, placeOf, composedModuleOf, report);
|
|
230
|
+
const references = appModuleReferences(resolver.repo.apps, { graph, kit, ts, moduleMap: modules, placeOf, composedBy, report });
|
|
231
|
+
return { violations, coverage: { status: 'checked', modules: modules.size, transportModules, appReferences: references } };
|
|
227
232
|
}
|
|
@@ -2,7 +2,6 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
import { canonical, exactKeys, isInside, slash } from './config.mjs';
|
|
5
|
-
|
|
6
5
|
const CONTRACT_SCHEMA = 'starci/next-data-lifecycle@1';
|
|
7
6
|
const SOURCE = /\.[cm]?[jt]sx?$/i;
|
|
8
7
|
const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
|
|
@@ -12,93 +11,116 @@ const SWR_KEYS = new Set(['package', 'major']);
|
|
|
12
11
|
const HOOK_KEYS = new Set(['id', 'path', 'export', 'kind', 'resultBinding', 'identities']);
|
|
13
12
|
const IDENTITY_KEYS = new Set(['id', 'binding', 'gatesRequest', 'resource']);
|
|
14
13
|
function relativeSource(repository, value, label) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
14
|
+
repository = path.resolve(repository);
|
|
15
|
+
if (typeof value !== 'string' || !value.trim() || path.isAbsolute(value))
|
|
16
|
+
throw new Error(`${label} must be a non-empty repository-relative source path.`);
|
|
17
|
+
const relative = slash(value.trim()).replace(/^\.\//, '');
|
|
18
|
+
if (relative.split('/').includes('..') || !SOURCE.test(relative) || /\.d\.[cm]?[jt]s$/i.test(relative)) {
|
|
19
|
+
throw new Error(`${label} must be a production TypeScript or JavaScript source path.`);
|
|
20
|
+
}
|
|
21
|
+
const absolute = path.resolve(repository, ...relative.split('/'));
|
|
22
|
+
if (!isInside(repository, absolute))
|
|
23
|
+
throw new Error(`${label} must stay inside the repository.`);
|
|
24
|
+
for (let current = absolute; current !== repository; current = path.dirname(current)) {
|
|
25
|
+
const stat = fs.lstatSync(current);
|
|
26
|
+
if (stat.isSymbolicLink())
|
|
27
|
+
throw new Error(`${label} must not cross a symbolic-link or junction ancestor.`);
|
|
28
|
+
}
|
|
29
|
+
const stat = fs.lstatSync(absolute);
|
|
30
|
+
if (!stat.isFile() || !isInside(canonical(repository), canonical(absolute)))
|
|
31
|
+
throw new Error(`${label} must be a regular source file inside the repository.`);
|
|
32
|
+
return relative;
|
|
30
33
|
}
|
|
31
|
-
|
|
32
34
|
const CONTRACT_LABEL = 'package.json#starci.codePatterns.next.dataLifecycle';
|
|
33
|
-
|
|
34
35
|
function parseSwr(swr) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
exactKeys(swr, SWR_KEYS, 'dataLifecycle.swr');
|
|
37
|
+
if (swr.package !== 'swr' || !Number.isInteger(swr.major) || swr.major < 1) {
|
|
38
|
+
throw new Error('dataLifecycle.swr must bind package swr and one positive integer major version.');
|
|
39
|
+
}
|
|
39
40
|
}
|
|
40
|
-
|
|
41
41
|
function parseIdentity(identity, identityLabel, seen) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
exactKeys(identity, IDENTITY_KEYS, identityLabel);
|
|
43
|
+
if (typeof identity.id !== 'string' || !identity.id.trim() || seen.ids.has(identity.id.trim()))
|
|
44
|
+
throw new Error(`${identityLabel}.id must be unique and non-empty.`);
|
|
45
|
+
if (typeof identity.binding !== 'string' || !BINDING.test(identity.binding) || seen.bindings.has(identity.binding))
|
|
46
|
+
throw new Error(`${identityLabel}.binding must be a unique identifier or property path.`);
|
|
47
|
+
if (typeof identity.gatesRequest !== 'boolean' || typeof identity.resource !== 'boolean')
|
|
48
|
+
throw new Error(`${identityLabel} must explicitly declare gatesRequest and resource booleans.`);
|
|
49
|
+
seen.ids.add(identity.id.trim());
|
|
50
|
+
seen.bindings.add(identity.binding);
|
|
51
|
+
return { id: identity.id.trim(), binding: identity.binding, gatesRequest: identity.gatesRequest, resource: identity.resource };
|
|
49
52
|
}
|
|
50
|
-
|
|
51
53
|
function parseHook(config, hook, label, ids) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
exactKeys(hook, HOOK_KEYS, label);
|
|
55
|
+
if (typeof hook.id !== 'string' || !hook.id.trim() || ids.has(hook.id.trim()))
|
|
56
|
+
throw new Error(`${label}.id must be unique and non-empty.`);
|
|
57
|
+
ids.add(hook.id.trim());
|
|
58
|
+
const source = relativeSource(config.root, hook.path, `${label}.path`);
|
|
59
|
+
if (typeof hook.export !== 'string' || !/^use[A-Z0-9_$][\w$]*$/.test(hook.export))
|
|
60
|
+
throw new Error(`${label}.export must name one exported use* hook.`);
|
|
61
|
+
if (!['query', 'mutation'].includes(hook.kind))
|
|
62
|
+
throw new Error(`${label}.kind must be query or mutation.`);
|
|
63
|
+
if (hook.resultBinding !== undefined && (typeof hook.resultBinding !== 'string' || !IDENTIFIER.test(hook.resultBinding))) {
|
|
64
|
+
throw new Error(`${label}.resultBinding must be one local identifier.`);
|
|
65
|
+
}
|
|
66
|
+
if (!Array.isArray(hook.identities))
|
|
67
|
+
throw new Error(`${label}.identities must be an array.`);
|
|
68
|
+
const seen = { ids: new Set(), bindings: new Set() };
|
|
69
|
+
const identities = hook.identities.map((identity, identityIndex) => parseIdentity(identity, `${label}.identities[${identityIndex}]`, seen));
|
|
70
|
+
if (hook.kind === 'mutation' && !identities.some((identity) => identity.resource))
|
|
71
|
+
throw new Error(`${label} mutation must declare at least one resource identity.`);
|
|
72
|
+
return { id: hook.id.trim(), path: source, export: hook.export, kind: hook.kind,
|
|
73
|
+
...(hook.resultBinding === undefined ? {} : { resultBinding: hook.resultBinding }), identities };
|
|
67
74
|
}
|
|
68
|
-
|
|
69
75
|
export function parseContract(config) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
// The contract is declared in the app's one package.json (the app root; config.root is the fe side folder).
|
|
77
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(config.packageRoot ?? config.root, 'package.json'), 'utf8'));
|
|
78
|
+
const next = manifest?.starci?.codePatterns?.next;
|
|
79
|
+
const value = next?.dataLifecycle;
|
|
80
|
+
if (value === undefined)
|
|
81
|
+
return null;
|
|
82
|
+
if (next.schema !== 'starci/next-code-pattern-contract@1')
|
|
83
|
+
throw new Error('package.json#starci.codePatterns.next must use starci/next-code-pattern-contract@1.');
|
|
84
|
+
exactKeys(value, TOP_KEYS, CONTRACT_LABEL);
|
|
85
|
+
if (value.schema !== CONTRACT_SCHEMA)
|
|
86
|
+
throw new Error(`dataLifecycle.schema must be ${CONTRACT_SCHEMA}.`);
|
|
87
|
+
parseSwr(value.swr);
|
|
88
|
+
if (!Array.isArray(value.hooks) || value.hooks.length === 0)
|
|
89
|
+
throw new Error('dataLifecycle.hooks must contain at least one declared lifecycle call.');
|
|
90
|
+
const ids = new Set();
|
|
91
|
+
const hooks = value.hooks.map((hook, index) => parseHook(config, hook, `dataLifecycle.hooks[${index}]`, ids));
|
|
92
|
+
return { schema: value.schema, swr: { package: 'swr', major: value.swr.major }, hooks };
|
|
83
93
|
}
|
|
84
|
-
|
|
85
94
|
export function installedSWR(repository) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
const require = createRequire(path.join(repository, 'package.json'));
|
|
96
|
+
let manifest;
|
|
97
|
+
try {
|
|
98
|
+
manifest = require.resolve('swr/package.json');
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
let entry;
|
|
102
|
+
try {
|
|
103
|
+
entry = require.resolve('swr');
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
throw new Error('Installed swr package is unavailable.');
|
|
107
|
+
}
|
|
108
|
+
let current = path.dirname(entry);
|
|
109
|
+
while (isInside(repository, current) && current !== repository) {
|
|
110
|
+
const candidate = path.join(current, 'package.json');
|
|
111
|
+
if (fs.existsSync(candidate)) {
|
|
112
|
+
manifest = candidate;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
current = path.dirname(current);
|
|
116
|
+
}
|
|
96
117
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
118
|
+
if (!manifest)
|
|
119
|
+
throw new Error('Installed swr package.json is unavailable.');
|
|
120
|
+
const actualManifest = canonical(manifest);
|
|
121
|
+
const parsed = JSON.parse(fs.readFileSync(actualManifest, 'utf8'));
|
|
122
|
+
const major = Number.parseInt(String(parsed.version ?? '').split('.')[0] ?? '', 10);
|
|
123
|
+
if (parsed.name !== 'swr' || !Number.isInteger(major))
|
|
124
|
+
throw new Error('Installed swr package identity or version is invalid.');
|
|
125
|
+
return { name: parsed.name, version: parsed.version, major, root: canonical(path.dirname(actualManifest)) };
|
|
104
126
|
}
|