@starci/eslint-canon-be 3.18.3 → 3.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/comments.js +1 -1
- package/dist/explicit-surface.js +1 -1
- package/dist/index.js +1 -1
- package/dist/jwt-alg.js +1 -1
- package/dist/lib/edition.d.ts +1 -1
- package/dist/lib/edition.js +1 -1
- package/dist/lib/hfs.d.ts +0 -6
- package/dist/lib/hfs.js +7 -5
- package/dist/lib/runtime-root.d.ts +6 -1
- package/dist/lib/runtime-root.js +8 -2
- package/dist/lib/subject-values.js +1 -1
- package/dist/module-layering.js +2 -2
- package/dist/project-graph.js +1 -1
- package/dist/third-party-owner.js +1 -1
- package/package.json +3 -1
- package/runtime/bundle.json +1 -190
- package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
- package/runtime/scripts/hfs/project-graph.mjs +6 -6
- package/runtime/scripts/hfs/project-rule.mjs +3 -3
- package/runtime/config.example.yaml +0 -194
- package/runtime/engine/by-code-unit.mjs +0 -12
- package/runtime/engine/config.mjs +0 -461
- package/runtime/engine/invalid-config.mjs +0 -15
- package/runtime/engine/model-config.mjs +0 -112
- package/runtime/engine/orca-config.mjs +0 -34
- package/runtime/engine/plain-object.mjs +0 -5
- package/runtime/engine/release-config.mjs +0 -32
- package/runtime/engine/removed-vocabulary.mjs +0 -27
- package/runtime/engine/resources-config.mjs +0 -59
- package/runtime/engine/runtime-root.mjs +0 -138
- package/runtime/engine/secrets.mjs +0 -202
- package/runtime/engine/sonar-config.mjs +0 -24
- package/runtime/engine/temp-root.mjs +0 -26
- package/runtime/engine/yaml.mjs +0 -161
- package/runtime/knowledge/grammars/index.yaml +0 -114
- package/runtime/knowledge/hfs/canon-pins.yaml +0 -716
- package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
- package/runtime/knowledge/hfs/rules.yaml +0 -6760
- package/runtime/knowledge/hfs/slots.yaml +0 -2783
- package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
- package/runtime/knowledge/sonar-gate.yaml +0 -151
- package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
- package/runtime/modules/models/registry.yaml +0 -221
- package/runtime/modules/models/runtimes.yaml +0 -556
- package/runtime/modules/models/tiers.yaml +0 -66
- package/runtime/scripts/api/git/cat-file.mjs +0 -4
- package/runtime/scripts/api/git/config-get.mjs +0 -9
- package/runtime/scripts/api/git/diff.mjs +0 -4
- package/runtime/scripts/api/git/lib.mjs +0 -80
- package/runtime/scripts/api/git/ls-files.mjs +0 -5
- package/runtime/scripts/api/git/ls-tree.mjs +0 -4
- package/runtime/scripts/api/git/merge-base.mjs +0 -8
- package/runtime/scripts/api/git/remote.mjs +0 -4
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
- package/runtime/scripts/api/git/show.mjs +0 -5
- package/runtime/scripts/api/git/tag.mjs +0 -4
- package/runtime/scripts/hfs/allows.mjs +0 -77
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
- package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
- package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
- package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
- package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
- package/runtime/scripts/hfs/architecture/config.mjs +0 -407
- package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
- package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
- package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
- package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
- package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
- package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
- package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
- package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
- package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
- package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
- package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
- package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
- package/runtime/scripts/hfs/architecture/index.mjs +0 -402
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
- package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
- package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
- package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
- package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
- package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
- package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
- package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
- package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
- package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
- package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
- package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
- package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
- package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
- package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
- package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
- package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
- package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
- package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
- package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
- package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
- package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
- package/runtime/scripts/hfs/edition-slots.mjs +0 -80
- package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
- package/runtime/scripts/hfs/linear-text.mjs +0 -30
- package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
- package/runtime/scripts/hfs/param-names.mjs +0 -13
- package/runtime/scripts/hfs/path-findings.mjs +0 -167
- package/runtime/scripts/hfs/repo-identity.mjs +0 -89
- package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
- package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
- package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
- package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
- package/runtime/scripts/hfs/rules/read.mjs +0 -45
- package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
- package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
- package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
- package/runtime/scripts/hfs/slot-classify.mjs +0 -69
- package/runtime/scripts/hfs/slot-errors.mjs +0 -12
- package/runtime/scripts/hfs/slot-imports.mjs +0 -98
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
- package/runtime/scripts/hfs/slot-match.mjs +0 -164
- package/runtime/scripts/hfs/slot-path.mjs +0 -6
- package/runtime/scripts/hfs/slot-required.mjs +0 -95
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
- package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
- package/runtime/scripts/hfs/slots.mjs +0 -306
- package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
- package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
- package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
- package/runtime/scripts/hfs/view.mjs +0 -180
- package/runtime/scripts/lib/declaration-surface.mjs +0 -166
- package/runtime/scripts/lib/dockerfile.mjs +0 -164
- package/runtime/scripts/lib/env.mjs +0 -18
- package/runtime/scripts/lib/event-contract.mjs +0 -102
- package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
- package/runtime/scripts/lib/git.mjs +0 -35
- package/runtime/scripts/lib/glob.mjs +0 -32
- package/runtime/scripts/lib/grammar-lint.mjs +0 -57
- package/runtime/scripts/lib/i18n.mjs +0 -82
- package/runtime/scripts/lib/in-order.mjs +0 -90
- package/runtime/scripts/lib/json-clone.mjs +0 -70
- package/runtime/scripts/lib/json.mjs +0 -44
- package/runtime/scripts/lib/language.mjs +0 -233
- package/runtime/scripts/lib/list.mjs +0 -26
- package/runtime/scripts/lib/mutation-fence.mjs +0 -20
- package/runtime/scripts/lib/package-at.mjs +0 -62
- package/runtime/scripts/lib/path-key.mjs +0 -124
- package/runtime/scripts/lib/read-text.mjs +0 -47
- package/runtime/scripts/lib/regex.mjs +0 -3
- package/runtime/scripts/lib/rule-packs.mjs +0 -243
- package/runtime/scripts/lib/same-text.mjs +0 -4
- package/runtime/scripts/lib/secret-patterns.mjs +0 -230
- package/runtime/scripts/lib/sops-envelope.mjs +0 -212
- package/runtime/scripts/lib/stack-services.mjs +0 -191
- package/runtime/scripts/lib/ts-analysis.mjs +0 -39
- package/runtime/scripts/lib/ts-ast.mjs +0 -63
- package/runtime/scripts/lib/walk.mjs +0 -45
- package/runtime/scripts/lib/yaml-cached.mjs +0 -14
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { normalizedSymbolValue } from './ast-walks.mjs';
|
|
3
|
-
import { unwrapExpression } from './typescript.mjs';
|
|
4
|
-
/** Feature composition may inject block renders into a pure view without making the view a world owner. */
|
|
5
|
-
export class BlockRenderAnalysis {
|
|
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
|
-
}
|
|
112
|
-
}
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { canonical, isInside } from './config.mjs';
|
|
4
|
-
import { readJsonFile as readJson } from '../../lib/json.mjs';
|
|
5
|
-
import { exportTargetStrings, isUnshadowedCommonJsRequire, relativePath } from './typescript.mjs';
|
|
6
|
-
import { byCodeUnit } from '../../lib/list.mjs';
|
|
7
|
-
import { sameOrUnder } from '../../lib/path-key.mjs';
|
|
8
|
-
function grammarExport(manifest, packageName, specifier) {
|
|
9
|
-
const key = specifier === packageName ? '.' : `.${specifier.slice(packageName.length)}`;
|
|
10
|
-
const value = manifest?.exports?.[key];
|
|
11
|
-
const targets = exportTargetStrings(value);
|
|
12
|
-
return targets.length > 0 && targets.every(target => target.startsWith('./') && !target.includes('\\') && !target.split('/').includes('..'));
|
|
13
|
-
}
|
|
14
|
-
function grammarExportTargets(manifest, packageRoot, packageName, specifier) {
|
|
15
|
-
const key = specifier === packageName ? '.' : `.${specifier.slice(packageName.length)}`;
|
|
16
|
-
return exportTargetStrings(manifest?.exports?.[key]).filter(target => target.startsWith('./') && !target.includes('\\') && !target.split('/').includes('..'))
|
|
17
|
-
.map(target => canonical(path.resolve(packageRoot, target)));
|
|
18
|
-
}
|
|
19
|
-
function literalModules(ts, sourceFile, checker) {
|
|
20
|
-
const modules = [];
|
|
21
|
-
const visit = (node) => {
|
|
22
|
-
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier && ts.isStringLiteralLike(node.moduleSpecifier)) {
|
|
23
|
-
modules.push({ node: node.moduleSpecifier, specifier: node.moduleSpecifier.text });
|
|
24
|
-
}
|
|
25
|
-
else if (ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)
|
|
26
|
-
&& node.moduleReference.expression && ts.isStringLiteralLike(node.moduleReference.expression)) {
|
|
27
|
-
modules.push({ node: node.moduleReference.expression, specifier: node.moduleReference.expression.text });
|
|
28
|
-
}
|
|
29
|
-
else if (ts.isCallExpression(node) && node.arguments.length > 0 && node.arguments[0] !== undefined && ts.isStringLiteralLike(node.arguments[0])
|
|
30
|
-
&& (node.expression.kind === ts.SyntaxKind.ImportKeyword || isUnshadowedCommonJsRequire(ts, checker, node.expression))) {
|
|
31
|
-
modules.push({ node: node.arguments[0], specifier: node.arguments[0].text });
|
|
32
|
-
}
|
|
33
|
-
ts.forEachChild(node, visit);
|
|
34
|
-
};
|
|
35
|
-
visit(sourceFile);
|
|
36
|
-
return modules;
|
|
37
|
-
}
|
|
38
|
-
function cssImports(content) {
|
|
39
|
-
const imports = [];
|
|
40
|
-
const withoutComments = content.replace(/\/\*[\s\S]*?\*\//g, match => match.replace(/[^\r\n]/g, ' '));
|
|
41
|
-
const pattern = new RegExp([String.raw `@import\s+(?:url\(\s*(?:(["'])`, String.raw `(.*?)\1|([^\s)]+))\s*\)|(["'])(.*?)\4)`].join(''), 'gi');
|
|
42
|
-
for (const match of withoutComments.matchAll(pattern)) {
|
|
43
|
-
const specifier = match[2] ?? match[3] ?? match[5];
|
|
44
|
-
if (specifier === undefined || match.index === undefined)
|
|
45
|
-
continue; // one alternative of the pattern always matches
|
|
46
|
-
imports.push({ specifier, index: match.index });
|
|
47
|
-
}
|
|
48
|
-
return imports;
|
|
49
|
-
}
|
|
50
|
-
function installRootFor(config) {
|
|
51
|
-
return config.packageRoot ?? config.root;
|
|
52
|
-
}
|
|
53
|
-
function installedPackageRoot(installRoot, packageName, from) {
|
|
54
|
-
for (let dir = from; isInside(installRoot, dir); dir = path.dirname(dir)) {
|
|
55
|
-
const candidate = path.join(dir, 'node_modules', ...packageName.split('/'));
|
|
56
|
-
if (fs.existsSync(path.join(candidate, 'package.json')))
|
|
57
|
-
return candidate;
|
|
58
|
-
if (dir === installRoot || path.dirname(dir) === dir)
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
return path.join(installRoot, 'node_modules', ...packageName.split('/'));
|
|
62
|
-
}
|
|
63
|
-
function grammarConsumers(config, grammar, local, installRoot) {
|
|
64
|
-
return grammar.consumerManifests.map((relative) => {
|
|
65
|
-
const root = path.dirname(path.join(config.root, ...relative.split('/')));
|
|
66
|
-
const packageRoot = local?.root ?? installedPackageRoot(installRoot, grammar.package, root);
|
|
67
|
-
return { relative, root, packageRoot, packageManifest: readJson(path.join(packageRoot, 'package.json')),
|
|
68
|
-
manifest: readJson(path.join(config.root, ...relative.split('/'))) ?? {} };
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
function uniqueGrammarInstalls(consumers) {
|
|
72
|
-
return [...new Map(consumers.map((consumer) => [consumer.packageRoot, consumer])).values()];
|
|
73
|
-
}
|
|
74
|
-
function grammarPackageRoot(installs, local, installRoot, packageName) {
|
|
75
|
-
return installs[0]?.packageRoot ?? local?.root ?? path.join(installRoot, 'node_modules', ...packageName.split('/'));
|
|
76
|
-
}
|
|
77
|
-
function addInstallContractProblems(install, installs, grammar, configRoot, problems) {
|
|
78
|
-
const where = installs.length > 1 ? ` (as ${install.relative} resolves it, ${relativePath(configRoot, install.packageRoot)})` : '';
|
|
79
|
-
if (install.packageManifest?.name !== grammar.package)
|
|
80
|
-
problems.push(`installed package ${grammar.package} is unavailable or has a different name${where}`);
|
|
81
|
-
if (!grammarExport(install.packageManifest, grammar.package, grammar.entry))
|
|
82
|
-
problems.push(`${grammar.entry} is not a safe declared package export${where}`);
|
|
83
|
-
if (!grammarExport(install.packageManifest, grammar.package, grammar.styleEntry))
|
|
84
|
-
problems.push(`${grammar.styleEntry} is not a safe declared style export${where}`);
|
|
85
|
-
const actualPeers = Object.keys(install.packageManifest?.peerDependencies ?? {}).sort(byCodeUnit);
|
|
86
|
-
const selectedPeers = [...grammar.peers].sort(byCodeUnit);
|
|
87
|
-
if (JSON.stringify(actualPeers) !== JSON.stringify(selectedPeers)) {
|
|
88
|
-
problems.push(`${grammar.package} peerDependencies must exactly match the selected peers ${selectedPeers.join(', ')}${where}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function addConsumerDependencyProblems(grammar, consumers, problems) {
|
|
92
|
-
for (const consumer of consumers)
|
|
93
|
-
if (!Object.hasOwn(consumer.manifest.dependencies ?? {}, grammar.package)) {
|
|
94
|
-
problems.push(`${consumer.relative} does not declare ${grammar.package} as a runtime dependency`);
|
|
95
|
-
}
|
|
96
|
-
for (const peer of grammar.peers) {
|
|
97
|
-
for (const consumer of consumers)
|
|
98
|
-
if (!Object.hasOwn(consumer.manifest.dependencies ?? {}, peer) && !Object.hasOwn(consumer.manifest.peerDependencies ?? {}, peer)) {
|
|
99
|
-
problems.push(`${consumer.relative} does not declare Grammar peer ${peer}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function addGrammarStyleProblems(config, grammar, problems, styleBypasses) {
|
|
104
|
-
for (const source of grammar.styleSources) {
|
|
105
|
-
const content = fs.readFileSync(path.join(config.root, ...source.split('/')), 'utf8');
|
|
106
|
-
const grammarStyles = cssImports(content).filter(item => item.specifier === grammar.package || item.specifier.startsWith(`${grammar.package}/`));
|
|
107
|
-
if (!grammarStyles.some(item => item.specifier === grammar.styleEntry))
|
|
108
|
-
problems.push(`${source} does not import ${grammar.styleEntry}`);
|
|
109
|
-
for (const imported of grammarStyles)
|
|
110
|
-
if (imported.specifier !== grammar.styleEntry) {
|
|
111
|
-
problems.push(`${source} imports Grammar style ${imported.specifier} outside the selected style entry`);
|
|
112
|
-
styleBypasses.push({ ruleId: 'ARCH_GRAMMAR_EXPORT_BYPASS', path: source,
|
|
113
|
-
line: content.slice(0, imported.index).split(/\r?\n/u).length, column: 1, package: grammar.package, specifier: imported.specifier,
|
|
114
|
-
message: `Style source must use the selected Grammar style entry ${grammar.styleEntry}; ${imported.specifier} is outside that contract.` });
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function grammarOwner(consumers, fileName) {
|
|
119
|
-
return consumers.filter(consumer => isInside(consumer.root, fileName))
|
|
120
|
-
.sort((a, b) => b.root.length - a.root.length)[0] ?? null;
|
|
121
|
-
}
|
|
122
|
-
function sourceEdges(context, sourceFile) {
|
|
123
|
-
return new Map((context.edges.get(path.resolve(sourceFile.fileName)) ?? []).map((edge) => [edge.node.getStart(sourceFile), edge]));
|
|
124
|
-
}
|
|
125
|
-
function grammarReferenceAllowed(reference, sourceFile, owner, edgesByStart, grammar, allowed) {
|
|
126
|
-
if (!allowed.has(reference.specifier))
|
|
127
|
-
return false;
|
|
128
|
-
const edge = edgesByStart.get(reference.node.getStart(sourceFile));
|
|
129
|
-
const expected = grammarExportTargets(owner.packageManifest, owner.packageRoot, grammar.package, reference.specifier);
|
|
130
|
-
return !edge || expected.includes(canonical(edge.to));
|
|
131
|
-
}
|
|
132
|
-
function reportGrammarReference(scan, sourceFile, reference, owner, edgesByStart) {
|
|
133
|
-
const { config, grammar, allowed, violations, makeViolation } = scan;
|
|
134
|
-
if (!sameOrUnder(reference.specifier, grammar.package))
|
|
135
|
-
return;
|
|
136
|
-
if (grammarReferenceAllowed(reference, sourceFile, owner, edgesByStart, grammar, allowed))
|
|
137
|
-
return;
|
|
138
|
-
violations.push(makeViolation(config, sourceFile, reference.node, 'ARCH_GRAMMAR_EXPORT_BYPASS', `Product source must import the selected Grammar code entry ${grammar.entry} or style entry ${grammar.styleEntry}; ${reference.specifier} is outside that contract.`, { specifier: reference.specifier, package: grammar.package }));
|
|
139
|
-
}
|
|
140
|
-
function inspectGrammarSource(scan, sourceFile) {
|
|
141
|
-
const { context, consumers, installs } = scan;
|
|
142
|
-
if (installs.some(install => isInside(install.packageRoot, sourceFile.fileName)))
|
|
143
|
-
return;
|
|
144
|
-
const owner = grammarOwner(consumers, sourceFile.fileName);
|
|
145
|
-
if (!owner)
|
|
146
|
-
return;
|
|
147
|
-
const edgesByStart = sourceEdges(context, sourceFile);
|
|
148
|
-
const references = literalModules(context.ts, sourceFile, context.checkerFor(sourceFile.fileName));
|
|
149
|
-
for (const reference of references)
|
|
150
|
-
reportGrammarReference(scan, sourceFile, reference, owner, edgesByStart);
|
|
151
|
-
}
|
|
152
|
-
function addGrammarContractFinding(config, grammar, manifestFile, problems, violations) {
|
|
153
|
-
if (!problems.length)
|
|
154
|
-
return;
|
|
155
|
-
violations.push({
|
|
156
|
-
ruleId: 'ARCH_GRAMMAR_CONTRACT_INVALID',
|
|
157
|
-
path: fs.existsSync(manifestFile) && isInside(config.root, manifestFile) ? relativePath(config.root, manifestFile) : 'package.json',
|
|
158
|
-
line: 1,
|
|
159
|
-
column: 1,
|
|
160
|
-
package: grammar.package,
|
|
161
|
-
message: `Grammar contract is invalid: ${problems.join('; ')}.`,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
export function checkGrammar(config, context, makeViolation) {
|
|
165
|
-
const grammar = config.frontend.grammar;
|
|
166
|
-
if (!grammar)
|
|
167
|
-
return [];
|
|
168
|
-
const violations = [];
|
|
169
|
-
const local = context.workspaces.find(workspace => workspace.name === grammar.package);
|
|
170
|
-
// Node resolution per consumer: in an npm-workspaces monorepo a consumer whose range differs from the
|
|
171
|
-
// hoisted copy gets its own apps/<app>/node_modules/<package> (one consumer: apps/app on 0.5.0 beside a hoisted
|
|
172
|
-
// 0.4.11). Every consumer is judged against the copy it actually resolves, never the hoisted one alone.
|
|
173
|
-
// An app installs once, at its root (config.packageRoot): a side folder has no node_modules of its own.
|
|
174
|
-
const installRoot = installRootFor(config);
|
|
175
|
-
const consumers = grammarConsumers(config, grammar, local, installRoot);
|
|
176
|
-
const installs = uniqueGrammarInstalls(consumers);
|
|
177
|
-
const packageRoot = grammarPackageRoot(installs, local, installRoot, grammar.package);
|
|
178
|
-
const manifestFile = path.join(packageRoot, 'package.json');
|
|
179
|
-
readJson(manifestFile);
|
|
180
|
-
const contractProblems = [];
|
|
181
|
-
const styleBypasses = [];
|
|
182
|
-
for (const install of installs)
|
|
183
|
-
addInstallContractProblems(install, installs, grammar, config.root, contractProblems);
|
|
184
|
-
addConsumerDependencyProblems(grammar, consumers, contractProblems);
|
|
185
|
-
addGrammarStyleProblems(config, grammar, contractProblems, styleBypasses);
|
|
186
|
-
addGrammarContractFinding(config, grammar, manifestFile, contractProblems, violations);
|
|
187
|
-
const allowed = new Set([grammar.entry, grammar.styleEntry]);
|
|
188
|
-
violations.push(...styleBypasses);
|
|
189
|
-
const scan = { config, context, grammar, consumers, installs, allowed, violations, makeViolation };
|
|
190
|
-
for (const sourceFile of context.files)
|
|
191
|
-
inspectGrammarSource(scan, sourceFile);
|
|
192
|
-
return violations;
|
|
193
|
-
}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { reachableViolation, relativePath } from './typescript.mjs';
|
|
3
|
-
function hasClientDirective(ts, sourceFile) {
|
|
4
|
-
return sourceFile.statements.find(statement => ts.isExpressionStatement(statement)
|
|
5
|
-
&& ts.isStringLiteral(statement.expression) && statement.expression.text === 'use client');
|
|
6
|
-
}
|
|
7
|
-
function bindImportClause(ts, clause, edge, bindings) {
|
|
8
|
-
if (clause.name && !clause.isTypeOnly)
|
|
9
|
-
bindings.set(clause.name.text, edge);
|
|
10
|
-
if (!clause.namedBindings)
|
|
11
|
-
return;
|
|
12
|
-
if (ts.isNamespaceImport(clause.namedBindings))
|
|
13
|
-
bindings.set(clause.namedBindings.name.text, edge);
|
|
14
|
-
if (!ts.isNamedImports(clause.namedBindings))
|
|
15
|
-
return;
|
|
16
|
-
for (const element of clause.namedBindings.elements) {
|
|
17
|
-
if (!element.isTypeOnly && !clause.isTypeOnly)
|
|
18
|
-
bindings.set(element.name.text, edge);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function importBindings(ts, sourceFile, edges) {
|
|
22
|
-
const byStart = new Map(edges.map((edge) => [edge.node.getStart(sourceFile), edge]));
|
|
23
|
-
const bindings = new Map();
|
|
24
|
-
for (const statement of sourceFile.statements) {
|
|
25
|
-
if (!ts.isImportDeclaration(statement) || !statement.importClause || !ts.isStringLiteralLike(statement.moduleSpecifier))
|
|
26
|
-
continue;
|
|
27
|
-
const edge = byStart.get(statement.moduleSpecifier.getStart(sourceFile));
|
|
28
|
-
if (!edge)
|
|
29
|
-
continue;
|
|
30
|
-
bindImportClause(ts, statement.importClause, edge, bindings);
|
|
31
|
-
}
|
|
32
|
-
return bindings;
|
|
33
|
-
}
|
|
34
|
-
function importedNames(ts, sourceFile, moduleName) {
|
|
35
|
-
const names = new Map();
|
|
36
|
-
for (const statement of sourceFile.statements) {
|
|
37
|
-
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteralLike(statement.moduleSpecifier) || statement.moduleSpecifier.text !== moduleName || !statement.importClause || statement.importClause.isTypeOnly)
|
|
38
|
-
continue;
|
|
39
|
-
const named = statement.importClause.namedBindings;
|
|
40
|
-
if (!named || !ts.isNamedImports(named))
|
|
41
|
-
continue;
|
|
42
|
-
for (const element of named.elements)
|
|
43
|
-
if (!element.isTypeOnly)
|
|
44
|
-
names.set(element.name.text, element.propertyName?.text ?? element.name.text);
|
|
45
|
-
}
|
|
46
|
-
return names;
|
|
47
|
-
}
|
|
48
|
-
function jsxRootName(ts, tagName) {
|
|
49
|
-
if (ts.isIdentifier(tagName))
|
|
50
|
-
return tagName.text;
|
|
51
|
-
if (ts.isPropertyAccessExpression(tagName)) {
|
|
52
|
-
let current = tagName;
|
|
53
|
-
while (ts.isPropertyAccessExpression(current))
|
|
54
|
-
current = current.expression;
|
|
55
|
-
return ts.isIdentifier(current) ? current.text : null;
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
function addRouteVariableFunctions(ts, statement, variables) {
|
|
60
|
-
for (const declaration of statement.declarationList.declarations) {
|
|
61
|
-
if (ts.isIdentifier(declaration.name) && declaration.initializer
|
|
62
|
-
&& (ts.isArrowFunction(declaration.initializer) || ts.isFunctionExpression(declaration.initializer)))
|
|
63
|
-
variables.set(declaration.name.text, declaration.initializer);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function recordRouteStatement(ts, statement, state) {
|
|
67
|
-
if (ts.isVariableStatement(statement))
|
|
68
|
-
addRouteVariableFunctions(ts, statement, state.variables);
|
|
69
|
-
if (ts.isFunctionDeclaration(statement) && statement.name)
|
|
70
|
-
state.functions.set(statement.name.text, statement);
|
|
71
|
-
if (ts.isFunctionDeclaration(statement) && statement.modifiers?.some(item => item.kind === ts.SyntaxKind.DefaultKeyword))
|
|
72
|
-
state.directDefault = statement;
|
|
73
|
-
if (ts.isExportAssignment(statement) && !statement.isExportEquals)
|
|
74
|
-
state.exportNode = statement;
|
|
75
|
-
}
|
|
76
|
-
function routeFunction(ts, sourceFile) {
|
|
77
|
-
const state = { variables: new Map(), functions: new Map(), directDefault: null, exportNode: null };
|
|
78
|
-
for (const statement of sourceFile.statements)
|
|
79
|
-
recordRouteStatement(ts, statement, state);
|
|
80
|
-
if (state.directDefault)
|
|
81
|
-
return { fn: state.directDefault, exportNode: state.directDefault };
|
|
82
|
-
if (!state.exportNode || !ts.isIdentifier(state.exportNode.expression))
|
|
83
|
-
return { fn: null, exportNode: state.exportNode };
|
|
84
|
-
return { fn: state.variables.get(state.exportNode.expression.text) ?? state.functions.get(state.exportNode.expression.text) ?? null, exportNode: state.exportNode };
|
|
85
|
-
}
|
|
86
|
-
function routePageRoots(context, sourceFile, featureRoots) {
|
|
87
|
-
const workspace = context.workspaceOf(sourceFile.fileName);
|
|
88
|
-
if (!workspace)
|
|
89
|
-
return featureRoots.map(root => path.join(root, 'pages'));
|
|
90
|
-
const local = featureRoots.filter(root => context.workspaceOf(root) === workspace);
|
|
91
|
-
return (local.length ? local : featureRoots).map(root => path.join(root, 'pages'));
|
|
92
|
-
}
|
|
93
|
-
function routingTermination(ts, statement, navigation) {
|
|
94
|
-
if (ts.isThrowStatement(statement))
|
|
95
|
-
return true;
|
|
96
|
-
if (ts.isBlock(statement)) {
|
|
97
|
-
const last = statement.statements.at(-1);
|
|
98
|
-
return statement.statements.length > 0 && last !== undefined && routingTermination(ts, last, navigation);
|
|
99
|
-
}
|
|
100
|
-
const expression = ts.isExpressionStatement(statement) ? statement.expression : (ts.isReturnStatement(statement) && statement.expression) || null;
|
|
101
|
-
return Boolean(expression && ts.isCallExpression(expression) && ts.isIdentifier(expression.expression)
|
|
102
|
-
&& ['redirect', 'notFound'].includes(navigation.get(expression.expression.text) ?? ''));
|
|
103
|
-
}
|
|
104
|
-
function routingGuard(ts, node, navigation) {
|
|
105
|
-
return ts.isIfStatement(node) && !node.elseStatement && routingTermination(ts, node.thenStatement, navigation);
|
|
106
|
-
}
|
|
107
|
-
function routeNavigationCall(ts, node, navigation) {
|
|
108
|
-
return ts.isCallExpression(node) && ts.isIdentifier(node.expression)
|
|
109
|
-
&& ['redirect', 'notFound'].includes(navigation.get(node.expression.text) ?? '');
|
|
110
|
-
}
|
|
111
|
-
function recordRouteNode(ts, node, state, insideNavigationArgument) {
|
|
112
|
-
if (ts.isJsxSelfClosingElement(node) || ts.isJsxElement(node))
|
|
113
|
-
state.jsx.push(node);
|
|
114
|
-
if (ts.isIfStatement(node) || ts.isSwitchStatement(node) || (ts.isConditionalExpression(node) && !insideNavigationArgument))
|
|
115
|
-
state.decisions.push(node);
|
|
116
|
-
}
|
|
117
|
-
function visitRouteNode(ts, node, state, insideNavigationArgument = false) {
|
|
118
|
-
recordRouteNode(ts, node, state, insideNavigationArgument);
|
|
119
|
-
if (routeNavigationCall(ts, node, state.navigation)) {
|
|
120
|
-
state.adapterCalls.push(node);
|
|
121
|
-
for (const argument of node.arguments)
|
|
122
|
-
visitRouteNode(ts, argument, state, true);
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
ts.forEachChild(node, child => visitRouteNode(ts, child, state, insideNavigationArgument));
|
|
126
|
-
}
|
|
127
|
-
function collectRouteNodes(ts, routeFunction, navigation) {
|
|
128
|
-
const state = { jsx: [], adapterCalls: [], decisions: [], navigation };
|
|
129
|
-
visitRouteNode(ts, routeFunction, state);
|
|
130
|
-
return state;
|
|
131
|
-
}
|
|
132
|
-
function mountedRoutePages(ts, context, sourceFile, featureRoots, bindings, jsx, insideAny) {
|
|
133
|
-
const pages = routePageRoots(context, sourceFile, featureRoots);
|
|
134
|
-
return jsx.filter(node => {
|
|
135
|
-
const opening = ts.isJsxElement(node) ? node.openingElement : node;
|
|
136
|
-
const local = jsxRootName(ts, opening.tagName);
|
|
137
|
-
const edge = local ? bindings.get(local) : null;
|
|
138
|
-
return edge && Boolean(reachableViolation(context.edges, edge, target => insideAny(pages, target), { follow: candidate => candidate.reexport && candidate.runtime }));
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
function reportRouteComposition(at, fn, scan, mountedPages) {
|
|
142
|
-
const { config, context, sourceFile, violations, violation } = at;
|
|
143
|
-
const navigationOnly = scan.jsx.length === 0 && scan.adapterCalls.length === 1;
|
|
144
|
-
if (!navigationOnly && (mountedPages.length !== 1 || scan.jsx.length !== 1)) {
|
|
145
|
-
violations.push(violation(config, sourceFile, fn, 'FE_ROUTE_ONE_PAGE', 'A page.tsx route must mount exactly one pages-tier component, or be a zero-JSX redirect/notFound adapter.', { ts: context.ts }));
|
|
146
|
-
}
|
|
147
|
-
return navigationOnly;
|
|
148
|
-
}
|
|
149
|
-
function reportRouteDecisions(at, decisions, navigation, navigationOnly) {
|
|
150
|
-
if (navigationOnly)
|
|
151
|
-
return;
|
|
152
|
-
const { config, context, sourceFile, violations, violation } = at;
|
|
153
|
-
for (const decision of decisions)
|
|
154
|
-
if (!routingGuard(context.ts, decision, navigation)) {
|
|
155
|
-
violations.push(violation(config, sourceFile, decision, 'FE_ROUTE_DRAWING_DECISION', 'Visual route files may use terminal redirect/notFound guards but cannot select or omit visual composition.', { ts: context.ts }));
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
function reportClientDirective(config, context, sourceFile, violations, violation) {
|
|
159
|
-
const clientDirective = hasClientDirective(context.ts, sourceFile);
|
|
160
|
-
if (clientDirective)
|
|
161
|
-
violations.push(violation(config, sourceFile, clientDirective, 'FE_ROUTE_CLIENT_BOUNDARY', 'A page.tsx route adapter cannot own the client boundary.', { ts: context.ts }));
|
|
162
|
-
}
|
|
163
|
-
function routeHookName(ts, sourceFile, local) {
|
|
164
|
-
return sourceFile.statements.flatMap(statement => ts.isImportDeclaration(statement) && statement.importClause?.namedBindings && ts.isNamedImports(statement.importClause.namedBindings)
|
|
165
|
-
? statement.importClause.namedBindings.elements.filter(item => item.name.text === local).map(item => item.name) : [])[0];
|
|
166
|
-
}
|
|
167
|
-
function reportForbiddenRouteHooks(config, context, sourceFile, navigation, violations, violation) {
|
|
168
|
-
const { ts } = context;
|
|
169
|
-
const forbiddenRouteHooks = new Set(['useRouter', 'usePathname', 'useSearchParams', 'useParams', 'useSelectedLayoutSegment', 'useSelectedLayoutSegments']);
|
|
170
|
-
for (const [local, imported] of navigation)
|
|
171
|
-
if (forbiddenRouteHooks.has(imported)) {
|
|
172
|
-
const identifier = routeHookName(ts, sourceFile, local);
|
|
173
|
-
if (identifier)
|
|
174
|
-
violations.push(violation(config, sourceFile, identifier, 'FE_ROUTE_CLIENT_HOOK', `Server route adapter imports ${imported}.`, { ts }));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
export function checkRoute(config, context, sourceFile, roots, helpers) {
|
|
178
|
-
const { violation, insideAny, importsForSource } = helpers;
|
|
179
|
-
const { ts } = context;
|
|
180
|
-
const violations = [];
|
|
181
|
-
const edges = importsForSource(context, sourceFile.fileName);
|
|
182
|
-
const bindings = importBindings(ts, sourceFile, edges);
|
|
183
|
-
const route = routeFunction(ts, sourceFile);
|
|
184
|
-
if (!route.exportNode || !route.fn) {
|
|
185
|
-
violations.push({ ruleId: 'FE_ROUTE_DEFAULT_EXPORT', path: relativePath(config.root, sourceFile.fileName), line: 1, column: 1,
|
|
186
|
-
message: 'A page.tsx must default-export one local route function.' });
|
|
187
|
-
return violations;
|
|
188
|
-
}
|
|
189
|
-
const navigation = importedNames(ts, sourceFile, 'next/navigation');
|
|
190
|
-
const scan = collectRouteNodes(ts, route.fn, navigation);
|
|
191
|
-
const mountedPages = mountedRoutePages(ts, context, sourceFile, roots.features, bindings, scan.jsx, insideAny);
|
|
192
|
-
const at = { config, context, sourceFile, violations, violation };
|
|
193
|
-
const navigationOnly = reportRouteComposition(at, route.fn, scan, mountedPages);
|
|
194
|
-
reportRouteDecisions(at, scan.decisions, navigation, navigationOnly);
|
|
195
|
-
reportClientDirective(config, context, sourceFile, violations, violation);
|
|
196
|
-
reportForbiddenRouteHooks(config, context, sourceFile, navigation, violations, violation);
|
|
197
|
-
return violations;
|
|
198
|
-
}
|