@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.
Files changed (164) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +1 -1
  3. package/runtime/bundle.json +192 -0
  4. package/runtime/engine/by-code-unit.mjs +6 -6
  5. package/runtime/engine/model-config.mjs +98 -76
  6. package/runtime/engine/orca-config.mjs +22 -17
  7. package/runtime/engine/release-config.mjs +22 -18
  8. package/runtime/engine/removed-vocabulary.mjs +21 -20
  9. package/runtime/engine/resources-config.mjs +42 -35
  10. package/runtime/engine/runtime-root.mjs +11 -13
  11. package/runtime/engine/secrets.mjs +170 -102
  12. package/runtime/engine/sonar-config.mjs +16 -13
  13. package/runtime/engine/temp-root.mjs +3 -9
  14. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  15. package/runtime/knowledge/hfs/rules.yaml +6 -6
  16. package/runtime/knowledge/hfs/slots.yaml +2 -2
  17. package/runtime/knowledge/sonar-gate.yaml +1 -1
  18. package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
  19. package/runtime/scripts/api/git/cat-file.mjs +0 -1
  20. package/runtime/scripts/api/git/config-get.mjs +1 -2
  21. package/runtime/scripts/api/git/diff.mjs +0 -1
  22. package/runtime/scripts/api/git/lib.mjs +32 -32
  23. package/runtime/scripts/api/git/ls-files.mjs +0 -1
  24. package/runtime/scripts/api/git/ls-tree.mjs +0 -1
  25. package/runtime/scripts/api/git/merge-base.mjs +2 -3
  26. package/runtime/scripts/api/git/remote.mjs +0 -1
  27. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
  28. package/runtime/scripts/api/git/show.mjs +0 -1
  29. package/runtime/scripts/hfs/allows.mjs +37 -38
  30. package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
  31. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
  32. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
  33. package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
  34. package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
  35. package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
  36. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
  37. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
  38. package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
  39. package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
  40. package/runtime/scripts/hfs/architecture/config.mjs +302 -268
  41. package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
  42. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
  43. package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
  44. package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
  45. package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
  46. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
  47. package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
  48. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
  49. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
  50. package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
  51. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
  52. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
  53. package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
  54. package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
  55. package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
  56. package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
  57. package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
  58. package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
  59. package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
  60. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
  61. package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
  62. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
  63. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
  64. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
  65. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
  66. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
  67. package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
  68. package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
  69. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
  70. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
  71. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
  72. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
  73. package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
  74. package/runtime/scripts/hfs/architecture/index.mjs +272 -272
  75. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
  76. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
  77. package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
  78. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
  79. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
  80. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
  81. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
  82. package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
  83. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
  84. package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
  85. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
  86. package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
  87. package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
  88. package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
  89. package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
  90. package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
  91. package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
  92. package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
  93. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
  94. package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
  95. package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
  96. package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
  97. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
  98. package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
  99. package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
  100. package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
  101. package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
  102. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
  103. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
  104. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
  105. package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
  106. package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
  107. package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
  108. package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
  109. package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
  110. package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
  111. package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
  112. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
  113. package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
  114. package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
  115. package/runtime/scripts/hfs/edition-slots.mjs +43 -40
  116. package/runtime/scripts/hfs/linear-text.mjs +20 -20
  117. package/runtime/scripts/hfs/param-names.mjs +6 -11
  118. package/runtime/scripts/hfs/path-findings.mjs +120 -100
  119. package/runtime/scripts/hfs/repo-identity.mjs +55 -42
  120. package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
  121. package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
  122. package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
  123. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
  124. package/runtime/scripts/hfs/rules/read.mjs +19 -15
  125. package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
  126. package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
  127. package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
  128. package/runtime/scripts/hfs/slot-classify.mjs +42 -38
  129. package/runtime/scripts/hfs/slot-errors.mjs +8 -7
  130. package/runtime/scripts/hfs/slot-imports.mjs +70 -63
  131. package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
  132. package/runtime/scripts/hfs/slot-match.mjs +122 -111
  133. package/runtime/scripts/hfs/slot-path.mjs +0 -2
  134. package/runtime/scripts/hfs/slot-required.mjs +65 -59
  135. package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
  136. package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
  137. package/runtime/scripts/hfs/slots.mjs +175 -152
  138. package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
  139. package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
  140. package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
  141. package/runtime/scripts/hfs/view.mjs +38 -40
  142. package/runtime/scripts/lib/dockerfile.mjs +131 -114
  143. package/runtime/scripts/lib/env.mjs +3 -6
  144. package/runtime/scripts/lib/event-contract.mjs +73 -78
  145. package/runtime/scripts/lib/git.mjs +15 -16
  146. package/runtime/scripts/lib/glob.mjs +23 -14
  147. package/runtime/scripts/lib/grammar-lint.mjs +33 -37
  148. package/runtime/scripts/lib/i18n.mjs +32 -35
  149. package/runtime/scripts/lib/in-order.mjs +57 -38
  150. package/runtime/scripts/lib/json-clone.mjs +45 -36
  151. package/runtime/scripts/lib/json.mjs +26 -14
  152. package/runtime/scripts/lib/language.mjs +133 -129
  153. package/runtime/scripts/lib/list.mjs +9 -14
  154. package/runtime/scripts/lib/mutation-fence.mjs +10 -5
  155. package/runtime/scripts/lib/path-key.mjs +53 -38
  156. package/runtime/scripts/lib/read-text.mjs +30 -17
  157. package/runtime/scripts/lib/regex.mjs +1 -2
  158. package/runtime/scripts/lib/same-text.mjs +0 -1
  159. package/runtime/scripts/lib/sops-envelope.mjs +148 -120
  160. package/runtime/scripts/lib/stack-services.mjs +128 -129
  161. package/runtime/scripts/lib/ts-analysis.mjs +28 -26
  162. package/runtime/scripts/lib/ts-ast.mjs +36 -42
  163. package/runtime/scripts/lib/walk.mjs +33 -27
  164. 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
- return path.resolve(file);
7
+ return path.resolve(file);
10
8
  }
11
-
12
9
  export function modifiers(ts, node) {
13
- return ts.canHaveModifiers(node) ? ts.getModifiers(node) ?? [] : node.modifiers ?? [];
10
+ return ts.canHaveModifiers(node) ? ts.getModifiers(node) ?? [] : node.modifiers ?? [];
14
11
  }
15
-
16
12
  export function hasModifier(ts, node, kind) {
17
- return modifiers(ts, node).some(modifier => modifier.kind === kind);
13
+ return modifiers(ts, node).some(modifier => modifier.kind === kind);
18
14
  }
19
-
20
15
  export function isPublicMember(ts, node) {
21
- return !hasModifier(ts, node, ts.SyntaxKind.PrivateKeyword) && !hasModifier(ts, node, ts.SyntaxKind.ProtectedKeyword);
16
+ return !hasModifier(ts, node, ts.SyntaxKind.PrivateKeyword) && !hasModifier(ts, node, ts.SyntaxKind.ProtectedKeyword);
22
17
  }
23
-
24
18
  function readonlyMember(ts, node) {
25
- return hasModifier(ts, node, ts.SyntaxKind.ReadonlyKeyword);
19
+ return hasModifier(ts, node, ts.SyntaxKind.ReadonlyKeyword);
26
20
  }
27
-
28
21
  function propertyName(ts, node) {
29
- const name = node.name;
30
- if (ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isPrivateIdentifier(name)) return name.text;
31
- return null;
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
- function thisOriginStatus(ts, checker, expression, seen = new Set(), depth = 0) {
35
- if (!expression || depth > 8) return 'no';
36
- expression = unwrapExpression(ts, expression);
37
- if (expression.kind === ts.SyntaxKind.ThisKeyword) return 'yes';
38
- const symbol = normalizedSymbol(ts, checker, expression);
39
- if (!symbol || seen.has(symbol)) return 'no';
40
- const declarations = symbol.getDeclarations?.() ?? [];
41
- if (declarations.length !== 1 || !ts.isVariableDeclaration(declarations[0]) || !declarations[0].initializer) return 'no';
42
- const origin = thisOriginStatus(ts, checker, declarations[0].initializer, new Set(seen).add(symbol), depth + 1);
43
- if (origin === 'no') return 'no';
44
- return isConstVariable(ts, declarations[0]) ? origin : 'unavailable';
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
- function instanceAssignmentTarget(ts, checker, expression) {
48
- expression = unwrapExpression(ts, expression);
49
- if (!ts.isPropertyAccessExpression(expression) && !ts.isElementAccessExpression(expression)) return { instance: false };
50
- const owner = thisOriginStatus(ts, checker, expression.expression);
51
- if (owner === 'no') return { instance: false };
52
- if (owner === 'unavailable') return { instance: true, name: null, supported: false };
53
- if (ts.isPropertyAccessExpression(expression)) return { instance: true, name: expression.name.text, supported: true };
54
- if (ts.isStringLiteralLike(expression.argumentExpression)) return { instance: true, name: expression.argumentExpression.text, supported: true };
55
- return { instance: true, name: null, supported: false };
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
- function expressionOrigin(ts, checker, expression, seen = new Set(), depth = 0) {
59
- if (!expression || depth > 8) return null;
60
- expression = unwrapExpression(ts, expression);
61
- const shorthand = ts.isShorthandPropertyAssignment(expression) ? checker.getShorthandAssignmentValueSymbol?.(expression) : null;
62
- const symbol = normalizedSymbolValue(ts, checker, shorthand) ?? normalizedSymbol(ts, checker, expression);
63
- if (!symbol || seen.has(symbol)) return symbol;
64
- const declarations = symbol.getDeclarations?.() ?? [];
65
- if (declarations.length === 1 && ts.isVariableDeclaration(declarations[0]) && declarations[0].initializer
66
- && isConstVariable(ts, declarations[0])) {
67
- return expressionOrigin(ts, checker, declarations[0].initializer, new Set(seen).add(symbol), depth + 1);
68
- }
69
- return symbol;
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
- const expressionReferencesOrigin = (ts, checker, expression, expected) =>
73
- anyDescendant(ts, expression, node => expressionOrigin(ts, checker, node) === expected);
74
-
75
- function isSafePrimitiveProjection(ts, checker, expression, expected) {
76
- expression = unwrapExpression(ts, expression);
77
- if (!ts.isPropertyAccessExpression(expression) && !ts.isElementAccessExpression(expression)) return false;
78
- if (expressionOrigin(ts, checker, expression.expression) !== expected) return false;
79
- const type = checker.getTypeAtLocation(expression);
80
- const primitive = ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike | ts.TypeFlags.BooleanLike
81
- | ts.TypeFlags.BigIntLike | ts.TypeFlags.ESSymbolLike | ts.TypeFlags.Null | ts.TypeFlags.Undefined
82
- | ts.TypeFlags.Void | ts.TypeFlags.Never;
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
- let found = false;
88
- const visit = node => {
89
- if (found) return;
90
- const target = instanceAssignmentTarget(ts, checker, node);
91
- if (target.instance) {
92
- found = true;
93
- return;
94
- }
95
- ts.forEachChild(node, visit);
96
- };
97
- visit(expression);
98
- return found;
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
- if (!ts.isIdentifier(node) || node.text !== expected) return false;
103
- const symbol = normalizedSymbol(ts, checker, node);
104
- const declarations = symbol?.getDeclarations?.() ?? [];
105
- return declarations.length > 0 && declarations.every(declaration => declaration.getSourceFile().isDeclarationFile
106
- && /(?:^|[/\\])lib\.[^/\\]+\.d\.ts$/i.test(declaration.getSourceFile().fileName));
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
- if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression)) return null;
111
- const owner = node.expression.expression;
112
- const method = node.expression.name.text;
113
- const known = (method === 'assign' || method === 'defineProperty') && globalLibraryIdentifier(ts, checker, owner, 'Object')
114
- || method === 'set' && globalLibraryIdentifier(ts, checker, owner, 'Reflect');
115
- if (!known || thisOriginStatus(ts, checker, node.arguments[0]) === 'no') return null;
116
- return { node, values: node.arguments.slice(method === 'assign' ? 1 : 2) };
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
- || ts.isArrowFunction(node) || ts.isMethodDeclaration(node);
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
- const target = instanceAssignmentTarget(ts, checker, node.left);
125
- if (target.instance) {
126
- return { node, name: target.name, supported: target.supported && node.operatorToken.kind === ts.SyntaxKind.EqualsToken };
127
- }
128
- return assignmentPatternHasInstanceTarget(ts, checker, node.left) ? { node, name: null, supported: false } : null;
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
- if (ts.isBinaryExpression(node) && expressionReferencesOrigin(ts, checker, node.right, parameterSymbol)
134
- && !isSafePrimitiveProjection(ts, checker, node.right, parameterSymbol)) {
135
- return instanceAssignment(ts, checker, node);
136
- }
137
- const mutation = instanceMutationCall(ts, checker, node);
138
- return mutation?.values.some(argument => expressionReferencesOrigin(ts, checker, argument, parameterSymbol))
139
- ? { node, name: null, supported: false }
140
- : null;
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
- if (!constructor.body) return [];
145
- const parameterSymbol = normalizedSymbol(ts, checker, parameter.name);
146
- const assignments = [];
147
- const visit = node => {
148
- if (node !== constructor.body && isFunctionBoundary(ts, node)) return;
149
- const finding = constructorFinding(ts, checker, node, parameterSymbol);
150
- if (finding) assignments.push(finding);
151
- else ts.forEachChild(node, visit);
152
- };
153
- visit(constructor.body);
154
- return assignments;
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
- if (!readonlyMember(context.ts, node)) violations.push(violation(config, sourceFile, node.name ?? node, READONLY_BOUNDARY_RULE_ID,
159
- `${label} must be readonly; execution state must not mutate an injected dependency or received message.`));
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
- return (symbol?.getDeclarations?.() ?? []).flatMap(declaration => {
164
- if (ts.isClassDeclaration(declaration)) return [declaration];
165
- if (ts.isVariableDeclaration(declaration) && declaration.initializer) {
166
- const initializer = unwrapExpression(ts, declaration.initializer);
167
- if (ts.isClassExpression(initializer)) return [initializer];
168
- }
169
- return [];
170
- }).filter(declaration => localFiles.has(canonical(declaration.getSourceFile().fileName)));
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
- const expression = decorator.expression;
175
- if (!context.ts.isCallExpression(expression) || expression.arguments.length < 1) {
176
- reasons.push(`${relativePath(config.root, decorator.getSourceFile().fileName)} has a handler decorator without a static message class`);
177
- return null;
178
- }
179
- const symbol = valueSymbol(context.ts, checker, expression.arguments[0]);
180
- const declarations = classValuesForSymbol(context.ts, symbol, localFiles);
181
- if (declarations.length !== 1) {
182
- reasons.push(`${relativePath(config.root, decorator.getSourceFile().fileName)} cannot resolve one local message class from its handler decorator`);
183
- return null;
184
- }
185
- return declarations[0];
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
- const { config, context, checker, sourceFile, violations, reasons } = state;
190
- const ts = context.ts;
191
- for (const parameter of constructor.parameters) {
192
- if (modifiers(ts, parameter).some(modifier => [ts.SyntaxKind.PublicKeyword,
193
- ts.SyntaxKind.PrivateKeyword, ts.SyntaxKind.ProtectedKeyword, ts.SyntaxKind.ReadonlyKeyword].includes(modifier.kind))) {
194
- checkReadonlyProperty(config, context, sourceFile, parameter, `Message field ${propertyName(ts, parameter) ?? '(computed)'}`, violations);
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
- if (!constructor.body) return;
198
- const inspectAssign = node => {
199
- if (node !== constructor.body && (ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node))) return;
200
- if (instanceMutationCall(ts, checker, node)) {
201
- reasons.push(`${relativePath(config.root, sourceFile.fileName)} constructs message fields through an unsupported instance mutation`);
202
- } else if (ts.isBinaryExpression(node) && assignmentPatternHasInstanceTarget(ts, checker, node.left)
203
- && !instanceAssignmentTarget(ts, checker, node.left).supported) {
204
- reasons.push(`${relativePath(config.root, sourceFile.fileName)} constructs message fields through an unsupported instance assignment`);
205
- } else ts.forEachChild(node, inspectAssign);
206
- };
207
- inspectAssign(constructor.body);
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
- const { config, context, declaration, violations, reasons } = state;
212
- const ts = context.ts;
213
- const sourceFile = declaration.getSourceFile();
214
- const classState = { ...state, sourceFile };
215
- for (const member of declaration.members) {
216
- if (ts.isPropertyDeclaration(member) && !hasModifier(ts, member, ts.SyntaxKind.StaticKeyword)) {
217
- checkReadonlyProperty(config, context, sourceFile, member, `Message field ${propertyName(ts, member) ?? '(computed)'}`, violations);
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
- return declaration.members.some(member => (ts.isPropertyDeclaration(member) && !hasModifier(ts, member, ts.SyntaxKind.StaticKeyword))
228
- || ts.isSetAccessorDeclaration(member) || ts.isIndexSignatureDeclaration(member)
229
- || (ts.isConstructorDeclaration(member) && member.parameters.length > 0));
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
- const symbol = declaration.name ? normalizedSymbol(ts, checker, declaration.name) : null;
234
- if (symbol && ts.isClassDeclaration(declaration)) return checker.getDeclaredTypeOfSymbol(symbol);
235
- const value = checker.getTypeAtLocation(declaration);
236
- const constructor = checker.getSignaturesOfType(value, ts.SignatureKind.Construct)[0];
237
- return constructor ? checker.getReturnTypeOfSignature(constructor) : value;
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
- const { config, context, checker, declaration, localFiles, sourceFile, reasons } = state;
242
- const ts = context.ts;
243
- const type = classInstanceType(ts, checker, declaration);
244
- for (const base of type && checker.getBaseTypes ? checker.getBaseTypes(type) : []) {
245
- const declarations = (base.symbol?.getDeclarations?.() ?? []).filter(item => ts.isClassDeclaration(item)) ?? [];
246
- if (declarations.length !== 1) {
247
- reasons.push(`${relativePath(config.root, sourceFile.fileName)} inherits message fields from a class outside the checked production program`);
248
- } else if (localFiles.has(canonical(declarations[0].getSourceFile().fileName))) {
249
- visitMessageClass({ ...state, declaration: declarations[0], sourceFile: declarations[0].getSourceFile() });
250
- } else if (classCarriesState(ts, declarations[0])) {
251
- reasons.push(`${relativePath(config.root, sourceFile.fileName)} inherits message state from a class outside the checked production program`);
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
- const { declaration, visited } = state;
258
- const key = `${canonical(declaration.getSourceFile().fileName)}:${declaration.pos}`;
259
- if (visited.has(key)) return;
260
- visited.add(key);
261
- const classState = { ...state, sourceFile: declaration.getSourceFile() };
262
- inspectMessageMembers(classState);
263
- inspectMessageBases(classState);
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
- visitMessageClass({ config, context, checker, declaration, localFiles, visited: new Set(), violations, reasons });
278
+ visitMessageClass({ config, context, checker, declaration, localFiles, visited: new Set(), violations, reasons });
268
279
  }
269
-
270
280
  function inspectInjectedParameter(state, member, parameter) {
271
- const { config, context, checker, sourceFile, classKind, properties, framework, violations, reasons } = state;
272
- const ts = context.ts;
273
- const explicitInject = nodeDecorators(ts, parameter).some(decorator => framework.decoratorKind(ts, checker, decorator, framework.targets) === 'Inject');
274
- if (!classKind && !explicitInject) return;
275
- const parameterProperty = modifiers(ts, parameter).some(modifier => [ts.SyntaxKind.PublicKeyword, ts.SyntaxKind.PrivateKeyword,
276
- ts.SyntaxKind.ProtectedKeyword, ts.SyntaxKind.ReadonlyKeyword].includes(modifier.kind));
277
- if (parameterProperty) {
278
- checkReadonlyProperty(config, context, sourceFile, parameter, `Injected dependency ${propertyName(ts, parameter) ?? '(computed)'}`, violations);
279
- return;
280
- }
281
- for (const assignment of constructorAssignments(ts, checker, member, parameter)) {
282
- if (!assignment.supported || !assignment.name) {
283
- reasons.push(`${relativePath(config.root, sourceFile.fileName)}:${sourceLocation(sourceFile, assignment.node).line} stores an injected dependency through an unsupported instance assignment`);
284
- continue;
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
- for (const parameter of member.parameters) {
294
- inspectInjectedParameter(state, member, parameter);
295
- }
305
+ for (const parameter of member.parameters) {
306
+ inspectInjectedParameter(state, member, parameter);
307
+ }
296
308
  }
297
-
298
309
  function inspectInjectedMembers(state) {
299
- const { config, context, checker, declaration, framework, violations } = state;
300
- const ts = context.ts;
301
- const sourceFile = declaration.getSourceFile();
302
- const classState = { ...state, sourceFile };
303
- for (const member of declaration.members) {
304
- if (ts.isPropertyDeclaration(member)) {
305
- const injected = nodeDecorators(ts, member).some(decorator => framework.decoratorKind(ts, checker, decorator, framework.targets) === 'Inject');
306
- if (injected) checkReadonlyProperty(config, context, sourceFile, member, `Injected property ${propertyName(ts, member) ?? '(computed)'}`, violations);
307
- continue;
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
- const { config, context, checker, declaration, localFiles, reasons } = state;
316
- const ts = context.ts;
317
- const sourceFile = declaration.getSourceFile();
318
- const type = classInstanceType(ts, checker, declaration);
319
- for (const base of type && checker.getBaseTypes ? checker.getBaseTypes(type) : []) {
320
- const declarations = (base.symbol?.getDeclarations?.() ?? []).filter(item => ts.isClassDeclaration(item)) ?? [];
321
- if (declarations.length !== 1) {
322
- reasons.push(`${relativePath(config.root, sourceFile.fileName)} inherits an injected constructor from a class outside the checked production program`);
323
- } else if (localFiles.has(canonical(declarations[0].getSourceFile().fileName))) {
324
- checkInjectedClass({ ...state, declaration: declarations[0] });
325
- } else if (classCarriesState(ts, declarations[0])) {
326
- reasons.push(`${relativePath(config.root, sourceFile.fileName)} inherits an injected constructor from a class outside the checked production program`);
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
- const ts = context.ts;
333
- const classKey = `${canonical(declaration.getSourceFile().fileName)}:${declaration.pos}`;
334
- if (visited.has(classKey)) return;
335
- visited.add(classKey);
336
- const properties = new Map(declaration.members.filter(member => ts.isPropertyDeclaration(member))
337
- .map(member => [propertyName(ts, member), member]).filter(([name]) => name));
338
- const state = { config, context, checker, declaration, classKind, properties, targets, decoratorKind,
339
- framework: { targets, decoratorKind }, localFiles, violations, reasons, visited };
340
- inspectInjectedMembers(state);
341
- if (classKind) inspectInjectedBases(state);
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
  }