@starci/eslint-canon-be 3.8.20 → 3.9.2
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 +16 -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,341 +2,359 @@ import path from 'node:path';
|
|
|
2
2
|
import { relativePath, unwrapExpression } from './typescript.mjs';
|
|
3
3
|
import { anyDescendant, nodeDecorators, normalizedSymbol, normalizedSymbolValue, valueSymbol, violation } from './ast-walks.mjs';
|
|
4
4
|
import { hasAnyFlag, isConstVariable, sourceLocation } from '../../lib/ts-ast.mjs';
|
|
5
|
-
|
|
6
5
|
export const READONLY_BOUNDARY_RULE_ID = 'BE_READONLY_BOUNDARY';
|
|
7
|
-
|
|
8
6
|
export function canonical(file) {
|
|
9
|
-
|
|
7
|
+
return path.resolve(file);
|
|
10
8
|
}
|
|
11
|
-
|
|
12
9
|
export function modifiers(ts, node) {
|
|
13
|
-
|
|
10
|
+
return ts.canHaveModifiers(node) ? ts.getModifiers(node) ?? [] : node.modifiers ?? [];
|
|
14
11
|
}
|
|
15
|
-
|
|
16
12
|
export function hasModifier(ts, node, kind) {
|
|
17
|
-
|
|
13
|
+
return modifiers(ts, node).some(modifier => modifier.kind === kind);
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
export function isPublicMember(ts, node) {
|
|
21
|
-
|
|
16
|
+
return !hasModifier(ts, node, ts.SyntaxKind.PrivateKeyword) && !hasModifier(ts, node, ts.SyntaxKind.ProtectedKeyword);
|
|
22
17
|
}
|
|
23
|
-
|
|
24
18
|
function readonlyMember(ts, node) {
|
|
25
|
-
|
|
19
|
+
return hasModifier(ts, node, ts.SyntaxKind.ReadonlyKeyword);
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function propertyName(ts, node) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
const name = node.name;
|
|
23
|
+
if (ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isPrivateIdentifier(name))
|
|
24
|
+
return name.text;
|
|
25
|
+
return null;
|
|
32
26
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
27
|
+
function thisOriginStatus(ts, checker, input, seen = new Set(), depth = 0) {
|
|
28
|
+
if (!input || depth > 8)
|
|
29
|
+
return 'no';
|
|
30
|
+
const expression = unwrapExpression(ts, input);
|
|
31
|
+
if (expression.kind === ts.SyntaxKind.ThisKeyword)
|
|
32
|
+
return 'yes';
|
|
33
|
+
const symbol = normalizedSymbol(ts, checker, expression);
|
|
34
|
+
if (!symbol || seen.has(symbol))
|
|
35
|
+
return 'no';
|
|
36
|
+
const declarations = symbol.getDeclarations?.() ?? [];
|
|
37
|
+
const [only] = declarations;
|
|
38
|
+
if (declarations.length !== 1 || !only || !ts.isVariableDeclaration(only) || !only.initializer)
|
|
39
|
+
return 'no';
|
|
40
|
+
const origin = thisOriginStatus(ts, checker, only.initializer, new Set(seen).add(symbol), depth + 1);
|
|
41
|
+
if (origin === 'no')
|
|
42
|
+
return 'no';
|
|
43
|
+
return isConstVariable(ts, only) ? origin : 'unavailable';
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
function instanceAssignmentTarget(ts, checker, input) {
|
|
46
|
+
const expression = unwrapExpression(ts, input);
|
|
47
|
+
if (!ts.isPropertyAccessExpression(expression) && !ts.isElementAccessExpression(expression))
|
|
48
|
+
return { instance: false };
|
|
49
|
+
const owner = thisOriginStatus(ts, checker, expression.expression);
|
|
50
|
+
if (owner === 'no')
|
|
51
|
+
return { instance: false };
|
|
52
|
+
if (owner === 'unavailable')
|
|
53
|
+
return { instance: true, name: null, supported: false };
|
|
54
|
+
if (ts.isPropertyAccessExpression(expression))
|
|
55
|
+
return { instance: true, name: expression.name.text, supported: true };
|
|
56
|
+
if (ts.isStringLiteralLike(expression.argumentExpression))
|
|
57
|
+
return { instance: true, name: expression.argumentExpression.text, supported: true };
|
|
58
|
+
return { instance: true, name: null, supported: false };
|
|
56
59
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
60
|
+
function expressionOrigin(ts, checker, input, seen = new Set(), depth = 0) {
|
|
61
|
+
if (!input || depth > 8)
|
|
62
|
+
return null;
|
|
63
|
+
const expression = unwrapExpression(ts, input);
|
|
64
|
+
const shorthand = ts.isShorthandPropertyAssignment(expression) ? checker.getShorthandAssignmentValueSymbol?.(expression) : null;
|
|
65
|
+
const symbol = normalizedSymbolValue(ts, checker, shorthand) ?? normalizedSymbol(ts, checker, expression);
|
|
66
|
+
if (!symbol || seen.has(symbol))
|
|
67
|
+
return symbol;
|
|
68
|
+
const declarations = symbol.getDeclarations?.() ?? [];
|
|
69
|
+
const [only] = declarations;
|
|
70
|
+
if (declarations.length === 1 && only && ts.isVariableDeclaration(only) && only.initializer
|
|
71
|
+
&& isConstVariable(ts, only)) {
|
|
72
|
+
return expressionOrigin(ts, checker, only.initializer, new Set(seen).add(symbol), depth + 1);
|
|
73
|
+
}
|
|
74
|
+
return symbol;
|
|
70
75
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return hasAnyFlag(type.flags, primitive) && !hasAnyFlag(type.flags, ts.TypeFlags.Any | ts.TypeFlags.Unknown);
|
|
76
|
+
const expressionReferencesOrigin = (ts, checker, expression, expected) => anyDescendant(ts, expression, node => expressionOrigin(ts, checker, node) === expected);
|
|
77
|
+
function isSafePrimitiveProjection(ts, checker, input, expected) {
|
|
78
|
+
const expression = unwrapExpression(ts, input);
|
|
79
|
+
if (!ts.isPropertyAccessExpression(expression) && !ts.isElementAccessExpression(expression))
|
|
80
|
+
return false;
|
|
81
|
+
if (expressionOrigin(ts, checker, expression.expression) !== expected)
|
|
82
|
+
return false;
|
|
83
|
+
const type = checker.getTypeAtLocation(expression);
|
|
84
|
+
const primitive = ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike | ts.TypeFlags.BooleanLike
|
|
85
|
+
| ts.TypeFlags.BigIntLike | ts.TypeFlags.ESSymbolLike | ts.TypeFlags.Null | ts.TypeFlags.Undefined
|
|
86
|
+
| ts.TypeFlags.Void | ts.TypeFlags.Never;
|
|
87
|
+
return hasAnyFlag(type.flags, primitive) && !hasAnyFlag(type.flags, ts.TypeFlags.Any | ts.TypeFlags.Unknown);
|
|
84
88
|
}
|
|
85
|
-
|
|
86
89
|
function assignmentPatternHasInstanceTarget(ts, checker, expression) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
let found = false;
|
|
91
|
+
const visit = (node) => {
|
|
92
|
+
if (found)
|
|
93
|
+
return;
|
|
94
|
+
const target = instanceAssignmentTarget(ts, checker, node);
|
|
95
|
+
if (target.instance) {
|
|
96
|
+
found = true;
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
ts.forEachChild(node, visit);
|
|
100
|
+
};
|
|
101
|
+
visit(expression);
|
|
102
|
+
return found;
|
|
99
103
|
}
|
|
100
|
-
|
|
101
104
|
function globalLibraryIdentifier(ts, checker, node, expected) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
&&
|
|
105
|
+
if (!ts.isIdentifier(node) || node.text !== expected)
|
|
106
|
+
return false;
|
|
107
|
+
const symbol = normalizedSymbol(ts, checker, node);
|
|
108
|
+
const declarations = symbol?.getDeclarations?.() ?? [];
|
|
109
|
+
return declarations.length > 0 && declarations.every(declaration => declaration.getSourceFile().isDeclarationFile
|
|
110
|
+
&& /(?:^|[/\\])lib\.[^/\\]+\.d\.ts$/i.test(declaration.getSourceFile().fileName));
|
|
107
111
|
}
|
|
108
|
-
|
|
109
112
|
function instanceMutationCall(ts, checker, node) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|| method === '
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression))
|
|
114
|
+
return null;
|
|
115
|
+
const owner = node.expression.expression;
|
|
116
|
+
const method = node.expression.name.text;
|
|
117
|
+
const known = (method === 'assign' || method === 'defineProperty') && globalLibraryIdentifier(ts, checker, owner, 'Object')
|
|
118
|
+
|| method === 'set' && globalLibraryIdentifier(ts, checker, owner, 'Reflect');
|
|
119
|
+
if (!known || thisOriginStatus(ts, checker, node.arguments[0]) === 'no')
|
|
120
|
+
return null;
|
|
121
|
+
return { node, values: node.arguments.slice(method === 'assign' ? 1 : 2) };
|
|
117
122
|
}
|
|
118
|
-
|
|
119
123
|
const isFunctionBoundary = (ts, node) => ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node)
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
|| ts.isArrowFunction(node) || ts.isMethodDeclaration(node);
|
|
122
125
|
/** The instance assignment a `<left> = <origin-derived>` expression performs, or null when its target is no instance member. */
|
|
123
126
|
function instanceAssignment(ts, checker, node) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
const target = instanceAssignmentTarget(ts, checker, node.left);
|
|
128
|
+
if (target.instance) {
|
|
129
|
+
return { node, name: target.name, supported: target.supported && node.operatorToken.kind === ts.SyntaxKind.EqualsToken };
|
|
130
|
+
}
|
|
131
|
+
return assignmentPatternHasInstanceTarget(ts, checker, node.left) ? { node, name: null, supported: false } : null;
|
|
129
132
|
}
|
|
130
|
-
|
|
131
133
|
/** The assignment or mutation call at `node` that stores the constructor parameter on the instance, or null. */
|
|
132
134
|
function constructorFinding(ts, checker, node, parameterSymbol) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
135
|
+
if (ts.isBinaryExpression(node) && expressionReferencesOrigin(ts, checker, node.right, parameterSymbol)
|
|
136
|
+
&& !isSafePrimitiveProjection(ts, checker, node.right, parameterSymbol)) {
|
|
137
|
+
return instanceAssignment(ts, checker, node);
|
|
138
|
+
}
|
|
139
|
+
const mutation = instanceMutationCall(ts, checker, node);
|
|
140
|
+
return mutation?.values.some(argument => expressionReferencesOrigin(ts, checker, argument, parameterSymbol))
|
|
141
|
+
? { node, name: null, supported: false }
|
|
142
|
+
: null;
|
|
141
143
|
}
|
|
142
|
-
|
|
143
144
|
function constructorAssignments(ts, checker, constructor, parameter) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
145
|
+
if (!constructor.body)
|
|
146
|
+
return [];
|
|
147
|
+
const parameterSymbol = normalizedSymbol(ts, checker, parameter.name);
|
|
148
|
+
const assignments = [];
|
|
149
|
+
const visit = (node) => {
|
|
150
|
+
if (node !== constructor.body && isFunctionBoundary(ts, node))
|
|
151
|
+
return;
|
|
152
|
+
const finding = constructorFinding(ts, checker, node, parameterSymbol);
|
|
153
|
+
if (finding)
|
|
154
|
+
assignments.push(finding);
|
|
155
|
+
else
|
|
156
|
+
ts.forEachChild(node, visit);
|
|
157
|
+
};
|
|
158
|
+
visit(constructor.body);
|
|
159
|
+
return assignments;
|
|
155
160
|
}
|
|
156
|
-
|
|
157
161
|
function checkReadonlyProperty(config, context, sourceFile, node, label, violations) {
|
|
158
|
-
|
|
159
|
-
|
|
162
|
+
if (!readonlyMember(context.ts, node))
|
|
163
|
+
violations.push(violation(config, sourceFile, node.name ?? node, READONLY_BOUNDARY_RULE_ID, `${label} must be readonly; execution state must not mutate an injected dependency or received message.`));
|
|
160
164
|
}
|
|
161
|
-
|
|
162
165
|
function classValuesForSymbol(ts, symbol, localFiles) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
166
|
+
return (symbol?.getDeclarations?.() ?? []).flatMap((declaration) => {
|
|
167
|
+
if (ts.isClassDeclaration(declaration))
|
|
168
|
+
return [declaration];
|
|
169
|
+
if (ts.isVariableDeclaration(declaration) && declaration.initializer) {
|
|
170
|
+
const initializer = unwrapExpression(ts, declaration.initializer);
|
|
171
|
+
if (ts.isClassExpression(initializer))
|
|
172
|
+
return [initializer];
|
|
173
|
+
}
|
|
174
|
+
return [];
|
|
175
|
+
}).filter(declaration => localFiles.has(canonical(declaration.getSourceFile().fileName)));
|
|
171
176
|
}
|
|
172
|
-
|
|
173
177
|
export function messageClass(config, context, checker, decorator, localFiles, reasons) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
178
|
+
const expression = decorator.expression;
|
|
179
|
+
const messageArgument = context.ts.isCallExpression(expression) ? expression.arguments[0] : undefined;
|
|
180
|
+
if (!messageArgument) {
|
|
181
|
+
reasons.push(`${relativePath(config.root, decorator.getSourceFile().fileName)} has a handler decorator without a static message class`);
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
const symbol = valueSymbol(context.ts, checker, messageArgument);
|
|
185
|
+
const declarations = classValuesForSymbol(context.ts, symbol, localFiles);
|
|
186
|
+
if (declarations.length !== 1) {
|
|
187
|
+
reasons.push(`${relativePath(config.root, decorator.getSourceFile().fileName)} cannot resolve one local message class from its handler decorator`);
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
return declarations[0] ?? null;
|
|
186
191
|
}
|
|
187
|
-
|
|
188
192
|
function inspectMessageConstructor(state, constructor) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
const { config, context, checker, sourceFile, violations, reasons } = state;
|
|
194
|
+
const ts = context.ts;
|
|
195
|
+
for (const parameter of constructor.parameters) {
|
|
196
|
+
if (modifiers(ts, parameter).some(modifier => [ts.SyntaxKind.PublicKeyword,
|
|
197
|
+
ts.SyntaxKind.PrivateKeyword, ts.SyntaxKind.ProtectedKeyword, ts.SyntaxKind.ReadonlyKeyword].includes(modifier.kind))) {
|
|
198
|
+
checkReadonlyProperty(config, context, sourceFile, parameter, `Message field ${propertyName(ts, parameter) ?? '(computed)'}`, violations);
|
|
199
|
+
}
|
|
195
200
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
201
|
+
if (!constructor.body)
|
|
202
|
+
return;
|
|
203
|
+
const inspectAssign = (node) => {
|
|
204
|
+
if (node !== constructor.body && (ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node)))
|
|
205
|
+
return;
|
|
206
|
+
if (instanceMutationCall(ts, checker, node)) {
|
|
207
|
+
reasons.push(`${relativePath(config.root, sourceFile.fileName)} constructs message fields through an unsupported instance mutation`);
|
|
208
|
+
}
|
|
209
|
+
else if (ts.isBinaryExpression(node) && assignmentPatternHasInstanceTarget(ts, checker, node.left)
|
|
210
|
+
&& !instanceAssignmentTarget(ts, checker, node.left).supported) {
|
|
211
|
+
reasons.push(`${relativePath(config.root, sourceFile.fileName)} constructs message fields through an unsupported instance assignment`);
|
|
212
|
+
}
|
|
213
|
+
else
|
|
214
|
+
ts.forEachChild(node, inspectAssign);
|
|
215
|
+
};
|
|
216
|
+
inspectAssign(constructor.body);
|
|
208
217
|
}
|
|
209
|
-
|
|
210
218
|
function inspectMessageMembers(state) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
219
|
+
const { config, context, declaration, violations, reasons } = state;
|
|
220
|
+
const ts = context.ts;
|
|
221
|
+
const sourceFile = declaration.getSourceFile();
|
|
222
|
+
const classState = { ...state, sourceFile };
|
|
223
|
+
for (const member of declaration.members) {
|
|
224
|
+
if (ts.isPropertyDeclaration(member) && !hasModifier(ts, member, ts.SyntaxKind.StaticKeyword)) {
|
|
225
|
+
checkReadonlyProperty(config, context, sourceFile, member, `Message field ${propertyName(ts, member) ?? '(computed)'}`, violations);
|
|
226
|
+
}
|
|
227
|
+
if (ts.isSetAccessorDeclaration(member))
|
|
228
|
+
violations.push(violation(config, sourceFile, member.name, READONLY_BOUNDARY_RULE_ID, `Message field ${propertyName(ts, member) ?? '(computed)'} cannot expose a setter.`));
|
|
229
|
+
if (ts.isIndexSignatureDeclaration(member))
|
|
230
|
+
reasons.push(`${relativePath(config.root, sourceFile.fileName)} has a message index signature whose mutation boundary cannot be proved`);
|
|
231
|
+
if (ts.isConstructorDeclaration(member))
|
|
232
|
+
inspectMessageConstructor(classState, member);
|
|
218
233
|
}
|
|
219
|
-
if (ts.isSetAccessorDeclaration(member)) violations.push(violation(config, sourceFile, member.name, READONLY_BOUNDARY_RULE_ID,
|
|
220
|
-
`Message field ${propertyName(ts, member) ?? '(computed)'} cannot expose a setter.`));
|
|
221
|
-
if (ts.isIndexSignatureDeclaration(member)) reasons.push(`${relativePath(config.root, sourceFile.fileName)} has a message index signature whose mutation boundary cannot be proved`);
|
|
222
|
-
if (ts.isConstructorDeclaration(member)) inspectMessageConstructor(classState, member);
|
|
223
|
-
}
|
|
224
234
|
}
|
|
225
|
-
|
|
226
235
|
function classCarriesState(ts, declaration) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
236
|
+
return declaration.members.some(member => (ts.isPropertyDeclaration(member) && !hasModifier(ts, member, ts.SyntaxKind.StaticKeyword))
|
|
237
|
+
|| ts.isSetAccessorDeclaration(member) || ts.isIndexSignatureDeclaration(member)
|
|
238
|
+
|| (ts.isConstructorDeclaration(member) && member.parameters.length > 0));
|
|
230
239
|
}
|
|
231
|
-
|
|
232
240
|
function classInstanceType(ts, checker, declaration) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
241
|
+
const symbol = declaration.name ? normalizedSymbol(ts, checker, declaration.name) : null;
|
|
242
|
+
if (symbol && ts.isClassDeclaration(declaration))
|
|
243
|
+
return checker.getDeclaredTypeOfSymbol(symbol);
|
|
244
|
+
const value = checker.getTypeAtLocation(declaration);
|
|
245
|
+
const constructor = checker.getSignaturesOfType(value, ts.SignatureKind.Construct)[0];
|
|
246
|
+
return constructor ? checker.getReturnTypeOfSignature(constructor) : value;
|
|
238
247
|
}
|
|
239
|
-
|
|
240
248
|
function inspectMessageBases(state) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
const { config, context, checker, declaration, localFiles, sourceFile, reasons } = state;
|
|
250
|
+
const ts = context.ts;
|
|
251
|
+
const type = classInstanceType(ts, checker, declaration);
|
|
252
|
+
// reason: a class symbol's declared type is an interface type; the construct-signature fallback is read the same way.
|
|
253
|
+
for (const base of type && checker.getBaseTypes ? checker.getBaseTypes(type) : []) {
|
|
254
|
+
const declarations = (base.symbol?.getDeclarations?.() ?? []).filter((item) => ts.isClassDeclaration(item)) ?? [];
|
|
255
|
+
const [base0] = declarations;
|
|
256
|
+
if (declarations.length !== 1 || !base0) {
|
|
257
|
+
reasons.push(`${relativePath(config.root, sourceFile.fileName)} inherits message fields from a class outside the checked production program`);
|
|
258
|
+
}
|
|
259
|
+
else if (localFiles.has(canonical(base0.getSourceFile().fileName))) {
|
|
260
|
+
visitMessageClass({ ...state, declaration: base0, sourceFile: base0.getSourceFile() });
|
|
261
|
+
}
|
|
262
|
+
else if (classCarriesState(ts, base0)) {
|
|
263
|
+
reasons.push(`${relativePath(config.root, sourceFile.fileName)} inherits message state from a class outside the checked production program`);
|
|
264
|
+
}
|
|
252
265
|
}
|
|
253
|
-
}
|
|
254
266
|
}
|
|
255
|
-
|
|
256
267
|
function visitMessageClass(state) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
268
|
+
const { declaration, visited } = state;
|
|
269
|
+
const key = `${canonical(declaration.getSourceFile().fileName)}:${declaration.pos}`;
|
|
270
|
+
if (visited.has(key))
|
|
271
|
+
return;
|
|
272
|
+
visited.add(key);
|
|
273
|
+
const classState = { ...state, sourceFile: declaration.getSourceFile() };
|
|
274
|
+
inspectMessageMembers(classState);
|
|
275
|
+
inspectMessageBases(classState);
|
|
264
276
|
}
|
|
265
|
-
|
|
266
277
|
export function checkMessageReadonly(config, context, checker, declaration, localFiles, violations, reasons) {
|
|
267
|
-
|
|
278
|
+
visitMessageClass({ config, context, checker, declaration, localFiles, visited: new Set(), violations, reasons });
|
|
268
279
|
}
|
|
269
|
-
|
|
270
280
|
function inspectInjectedParameter(state, member, parameter) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
ts.SyntaxKind.
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
281
|
+
const { config, context, checker, sourceFile, classKind, properties, framework, violations, reasons } = state;
|
|
282
|
+
const ts = context.ts;
|
|
283
|
+
const explicitInject = nodeDecorators(ts, parameter).some(decorator => framework.decoratorKind(ts, checker, decorator, framework.targets) === 'Inject');
|
|
284
|
+
if (!classKind && !explicitInject)
|
|
285
|
+
return;
|
|
286
|
+
const parameterProperty = modifiers(ts, parameter).some(modifier => [ts.SyntaxKind.PublicKeyword, ts.SyntaxKind.PrivateKeyword,
|
|
287
|
+
ts.SyntaxKind.ProtectedKeyword, ts.SyntaxKind.ReadonlyKeyword].includes(modifier.kind));
|
|
288
|
+
if (parameterProperty) {
|
|
289
|
+
checkReadonlyProperty(config, context, sourceFile, parameter, `Injected dependency ${propertyName(ts, parameter) ?? '(computed)'}`, violations);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
for (const assignment of constructorAssignments(ts, checker, member, parameter)) {
|
|
293
|
+
if (!assignment.supported || !assignment.name) {
|
|
294
|
+
reasons.push(`${relativePath(config.root, sourceFile.fileName)}:${sourceLocation(sourceFile, assignment.node).line} stores an injected dependency through an unsupported instance assignment`);
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
const property = properties.get(assignment.name);
|
|
298
|
+
if (!property)
|
|
299
|
+
reasons.push(`${relativePath(config.root, sourceFile.fileName)} assigns injected dependency ${assignment.name} without a declared field`);
|
|
300
|
+
else
|
|
301
|
+
checkReadonlyProperty(config, context, sourceFile, property, `Injected dependency ${assignment.name}`, violations);
|
|
285
302
|
}
|
|
286
|
-
const property = properties.get(assignment.name);
|
|
287
|
-
if (!property) reasons.push(`${relativePath(config.root, sourceFile.fileName)} assigns injected dependency ${assignment.name} without a declared field`);
|
|
288
|
-
else checkReadonlyProperty(config, context, sourceFile, property, `Injected dependency ${assignment.name}`, violations);
|
|
289
|
-
}
|
|
290
303
|
}
|
|
291
|
-
|
|
292
304
|
function inspectInjectedConstructor(state, member) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
305
|
+
for (const parameter of member.parameters) {
|
|
306
|
+
inspectInjectedParameter(state, member, parameter);
|
|
307
|
+
}
|
|
296
308
|
}
|
|
297
|
-
|
|
298
309
|
function inspectInjectedMembers(state) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
310
|
+
const { config, context, checker, declaration, framework, violations } = state;
|
|
311
|
+
const ts = context.ts;
|
|
312
|
+
const sourceFile = declaration.getSourceFile();
|
|
313
|
+
const classState = { ...state, sourceFile };
|
|
314
|
+
for (const member of declaration.members) {
|
|
315
|
+
if (ts.isPropertyDeclaration(member)) {
|
|
316
|
+
const injected = nodeDecorators(ts, member).some(decorator => framework.decoratorKind(ts, checker, decorator, framework.targets) === 'Inject');
|
|
317
|
+
if (injected)
|
|
318
|
+
checkReadonlyProperty(config, context, sourceFile, member, `Injected property ${propertyName(ts, member) ?? '(computed)'}`, violations);
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (!ts.isConstructorDeclaration(member))
|
|
322
|
+
continue;
|
|
323
|
+
inspectInjectedConstructor(classState, member);
|
|
308
324
|
}
|
|
309
|
-
if (!ts.isConstructorDeclaration(member)) continue;
|
|
310
|
-
inspectInjectedConstructor(classState, member);
|
|
311
|
-
}
|
|
312
325
|
}
|
|
313
|
-
|
|
314
326
|
function inspectInjectedBases(state) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
+
const { config, context, checker, declaration, localFiles, reasons } = state;
|
|
328
|
+
const ts = context.ts;
|
|
329
|
+
const sourceFile = declaration.getSourceFile();
|
|
330
|
+
const type = classInstanceType(ts, checker, declaration);
|
|
331
|
+
// reason: a class symbol's declared type is an interface type; the construct-signature fallback is read the same way.
|
|
332
|
+
for (const base of type && checker.getBaseTypes ? checker.getBaseTypes(type) : []) {
|
|
333
|
+
const declarations = (base.symbol?.getDeclarations?.() ?? []).filter((item) => ts.isClassDeclaration(item)) ?? [];
|
|
334
|
+
const [base0] = declarations;
|
|
335
|
+
if (declarations.length !== 1 || !base0) {
|
|
336
|
+
reasons.push(`${relativePath(config.root, sourceFile.fileName)} inherits an injected constructor from a class outside the checked production program`);
|
|
337
|
+
}
|
|
338
|
+
else if (localFiles.has(canonical(base0.getSourceFile().fileName))) {
|
|
339
|
+
checkInjectedClass({ ...state, declaration: base0 });
|
|
340
|
+
}
|
|
341
|
+
else if (classCarriesState(ts, base0)) {
|
|
342
|
+
reasons.push(`${relativePath(config.root, sourceFile.fileName)} inherits an injected constructor from a class outside the checked production program`);
|
|
343
|
+
}
|
|
327
344
|
}
|
|
328
|
-
}
|
|
329
345
|
}
|
|
330
|
-
|
|
331
346
|
export function checkInjectedClass({ config, context, checker, declaration, classKind, targets, decoratorKind, localFiles, violations, reasons, visited = new Set() }) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
347
|
+
const ts = context.ts;
|
|
348
|
+
const classKey = `${canonical(declaration.getSourceFile().fileName)}:${declaration.pos}`;
|
|
349
|
+
if (visited.has(classKey))
|
|
350
|
+
return;
|
|
351
|
+
visited.add(classKey);
|
|
352
|
+
const properties = new Map(declaration.members.filter((member) => ts.isPropertyDeclaration(member))
|
|
353
|
+
.map((member) => [propertyName(ts, member), member])
|
|
354
|
+
.filter((entry) => Boolean(entry[0])));
|
|
355
|
+
const state = { config, context, checker, declaration, classKind, properties, targets, decoratorKind,
|
|
356
|
+
framework: { targets, decoratorKind }, localFiles, violations, reasons, visited };
|
|
357
|
+
inspectInjectedMembers(state);
|
|
358
|
+
if (classKind)
|
|
359
|
+
inspectInjectedBases(state);
|
|
342
360
|
}
|