@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.
Files changed (164) hide show
  1. package/CHANGELOG.md +16 -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,7 +2,6 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { byCodeUnit } from '../../lib/list.mjs';
4
4
  import { escapeRegExp } from '../../lib/regex.mjs';
5
-
6
5
  /**
7
6
  * R106 `i18n-keys` (FE_I18N_KEYS). The catalogs of an app (`apps/<app>/src/modules/i18n/messages/<locale>.json`, slot fe.modules.i18n) and
8
7
  * the source that reads them agree, both ways. The key sets of the locales agree with each other (FE_I18N_CATALOG, `starci app check`); this
@@ -20,180 +19,195 @@ import { escapeRegExp } from '../../lib/regex.mjs';
20
19
  * Reads the source of the program and the JSON catalogs on disk; the wording of a translation is the product owner's.
21
20
  */
22
21
  export const I18N_KEYS_RULE_IDS = ['FE_I18N_KEYS'];
23
-
24
22
  const RULE = 'FE_I18N_KEYS';
25
23
  const MODULES = new Set(['next-intl', 'next-intl/server']);
26
24
  const FACTORIES = new Set(['useTranslations', 'getTranslations']);
27
25
  const READERS = new Set(['rich', 'raw', 'markup']);
28
26
  const APP_SOURCE = /^apps\/([^/]+)\/src\//u;
29
-
30
27
  const leavesOf = (value, prefix = '') => (value !== null && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length
31
- ? Object.entries(value).flatMap(([key, child]) => leavesOf(child, prefix ? `${prefix}.${key}` : key))
32
- : [prefix]);
33
-
28
+ ? Object.entries(value).flatMap(([key, child]) => leavesOf(child, prefix ? `${prefix}.${key}` : key))
29
+ : [prefix]);
34
30
  const readCatalog = (root, rel) => {
35
- try { return new Set(leavesOf(JSON.parse(fs.readFileSync(path.join(root, rel), 'utf8'))).filter(Boolean)); } catch { return null; }
31
+ try {
32
+ return new Set(leavesOf(JSON.parse(fs.readFileSync(path.join(root, rel), 'utf8'))).filter(Boolean));
33
+ }
34
+ catch {
35
+ return null;
36
+ }
36
37
  };
37
-
38
38
  /** True when the key `full` is a leaf of `leaves` or a namespace above one (an object read by `rich`, `raw` or a nested `t`). */
39
39
  const held = (leaves, full) => leaves.has(full) || [...leaves].some(leaf => leaf.startsWith(`${full}.`));
40
-
41
40
  // A pattern that is only wildcards (`${a}`, `${a}.${b}`) names nothing: it would read every key, so it reads none.
42
41
  const tailMatches = (pattern, leafSegments) => pattern.some(segment => segment !== '*' && segment !== '') && pattern.length <= leafSegments.length
43
- && pattern.every((segment, index) => {
44
- const leaf = leafSegments[leafSegments.length - pattern.length + index];
45
- return segment instanceof RegExp ? segment.test(leaf) : segment === '*' || segment === leaf;
46
- });
47
-
42
+ && pattern.every((segment, index) => {
43
+ const leaf = leafSegments[leafSegments.length - pattern.length + index];
44
+ return segment instanceof RegExp ? segment.test(leaf) : segment === '*' || segment === leaf;
45
+ });
48
46
  function catalogsPerApp(config, graph) {
49
- const catalogs = new Map();
50
- const seen = new Set();
51
- for (const file of graph.files.values()) {
52
- const app = APP_SOURCE.exec(file.rel)?.[1];
53
- if (!app || seen.has(app)) continue;
54
- seen.add(app);
55
- const dir = `apps/${app}/src/modules/i18n/messages/`;
56
- let names = [];
57
- try { names = fs.readdirSync(path.join(config.root, dir)).filter(name => name.endsWith('.json')).sort(byCodeUnit); } catch { /* the app has no catalog directory: FE_I18N_PLACEMENT's finding */ }
58
- if (names.length) catalogs.set(dir, names.map(name => ({ rel: `${dir}${name}`, locale: name.slice(0, -5) })));
59
- }
60
- return catalogs;
47
+ const catalogs = new Map();
48
+ const seen = new Set();
49
+ for (const file of graph.files.values()) {
50
+ const app = APP_SOURCE.exec(file.rel)?.[1];
51
+ if (!app || seen.has(app))
52
+ continue;
53
+ seen.add(app);
54
+ const dir = `apps/${app}/src/modules/i18n/messages/`;
55
+ let names = [];
56
+ try {
57
+ names = fs.readdirSync(path.join(config.root, dir)).filter(name => name.endsWith('.json')).sort(byCodeUnit);
58
+ }
59
+ catch { /* the app has no catalog directory: FE_I18N_PLACEMENT's finding */ }
60
+ if (names.length)
61
+ catalogs.set(dir, names.map(name => ({ rel: `${dir}${name}`, locale: name.slice(0, -5) })));
62
+ }
63
+ return catalogs;
61
64
  }
62
-
63
65
  /** Each interpolation can fill part or all of a segment; the template's static fragments keep their literal spelling. */
64
66
  function templatePatternOf(node) {
65
- const pattern = [];
66
- for (const segment of [node.head.text, ...node.templateSpans.map(span => span.literal.text)].join('\u0000').split('.')) {
67
- if (!segment.includes('\u0000')) { pattern.push(segment); continue; }
68
- const parts = segment.split('\u0000');
69
- pattern.push(parts.every(part => part === '') ? '*' : new RegExp(`^${parts.map((part) => escapeRegExp(part)).join('.*')}$`, 'su'));
70
- }
71
- return pattern;
67
+ const pattern = [];
68
+ for (const segment of [node.head.text, ...node.templateSpans.map(span => span.literal.text)].join('\u0000').split('.')) {
69
+ if (!segment.includes('\u0000')) {
70
+ pattern.push(segment);
71
+ continue;
72
+ }
73
+ const parts = segment.split('\u0000');
74
+ pattern.push(parts.every(part => part === '') ? '*' : new RegExp(`^${parts.map((part) => escapeRegExp(part)).join('.*')}$`, 'su'));
75
+ }
76
+ return pattern;
72
77
  }
73
-
74
78
  function patternsOf(ts, files) {
75
- const patterns = [];
76
- for (const file of files) {
77
- const visit = node => {
78
- if (ts.isStringLiteralLike(node)) patterns.push(node.text.split('.'));
79
- else if (ts.isTemplateExpression(node)) patterns.push(templatePatternOf(node));
80
- ts.forEachChild(node, visit);
81
- };
82
- visit(file.sourceFile);
83
- }
84
- return patterns;
79
+ const patterns = [];
80
+ for (const file of files) {
81
+ const visit = (node) => {
82
+ if (ts.isStringLiteralLike(node))
83
+ patterns.push(node.text.split('.'));
84
+ else if (ts.isTemplateExpression(node))
85
+ patterns.push(templatePatternOf(node));
86
+ ts.forEachChild(node, visit);
87
+ };
88
+ visit(file.sourceFile);
89
+ }
90
+ return patterns;
85
91
  }
86
-
87
92
  function translationFactories(ts, file) {
88
- const factories = new Set();
89
- for (const statement of file.sourceFile.statements) {
90
- if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier) || !MODULES.has(statement.moduleSpecifier.text)) continue;
91
- const named = statement.importClause?.namedBindings;
92
- if (!named || !ts.isNamedImports(named)) continue;
93
- for (const element of named.elements) {
94
- if (!element.isTypeOnly && FACTORIES.has((element.propertyName ?? element.name).text)) factories.add(element.name.text);
93
+ const factories = new Set();
94
+ for (const statement of file.sourceFile.statements) {
95
+ if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier) || !MODULES.has(statement.moduleSpecifier.text))
96
+ continue;
97
+ const named = statement.importClause?.namedBindings;
98
+ if (!named || !ts.isNamedImports(named))
99
+ continue;
100
+ for (const element of named.elements) {
101
+ if (!element.isTypeOnly && FACTORIES.has((element.propertyName ?? element.name).text))
102
+ factories.add(element.name.text);
103
+ }
95
104
  }
96
- }
97
- return factories;
105
+ return factories;
98
106
  }
99
-
100
107
  function namespaceForCall(ts, file, init, factories) {
101
- let expression = init;
102
- if (ts.isAwaitExpression(expression)) expression = expression.expression;
103
- if (!ts.isCallExpression(expression) || !ts.isIdentifier(expression.expression) || !factories.has(expression.expression.text)) return null;
104
- const [first] = expression.arguments;
105
- if (first === undefined) return '';
106
- if (ts.isStringLiteralLike(first)) return first.text;
107
- if (!ts.isObjectLiteralExpression(first)) return null;
108
- const property = first.properties.find(candidate => ts.isPropertyAssignment(candidate) && candidate.name.getText(file.sourceFile) === 'namespace');
109
- if (!property) return '';
110
- return ts.isStringLiteralLike(property.initializer) ? property.initializer.text : null;
108
+ let expression = init;
109
+ if (ts.isAwaitExpression(expression))
110
+ expression = expression.expression;
111
+ if (!ts.isCallExpression(expression) || !ts.isIdentifier(expression.expression) || !factories.has(expression.expression.text))
112
+ return null;
113
+ const [first] = expression.arguments;
114
+ if (first === undefined)
115
+ return '';
116
+ if (ts.isStringLiteralLike(first))
117
+ return first.text;
118
+ if (!ts.isObjectLiteralExpression(first))
119
+ return null;
120
+ const property = first.properties.find((candidate) => ts.isPropertyAssignment(candidate) && candidate.name.getText(file.sourceFile) === 'namespace');
121
+ if (!property)
122
+ return '';
123
+ return ts.isStringLiteralLike(property.initializer) ? property.initializer.text : null;
111
124
  }
112
-
113
125
  function translatorNamespaces(ts, file, factories) {
114
- const namespaces = new Map();
115
- const collect = node => {
116
- if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer) {
117
- const namespace = namespaceForCall(ts, file, node.initializer, factories);
118
- if (namespace !== null) namespaces.set(node, namespace);
119
- }
120
- ts.forEachChild(node, collect);
121
- };
122
- collect(file.sourceFile);
123
- return namespaces;
126
+ const namespaces = new Map();
127
+ const collect = (node) => {
128
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer) {
129
+ const namespace = namespaceForCall(ts, file, node.initializer, factories);
130
+ if (namespace !== null)
131
+ namespaces.set(node, namespace);
132
+ }
133
+ ts.forEachChild(node, collect);
134
+ };
135
+ collect(file.sourceFile);
136
+ return namespaces;
124
137
  }
125
-
126
138
  function keysOf(ts, argument) {
127
- if (ts.isConditionalExpression(argument)) return [...keysOf(ts, argument.whenTrue), ...keysOf(ts, argument.whenFalse)];
128
- if (ts.isParenthesizedExpression(argument) || ts.isAsExpression(argument) || ts.isSatisfiesExpression(argument)) return keysOf(ts, argument.expression);
129
- return ts.isStringLiteralLike(argument) ? [argument] : [];
139
+ if (ts.isConditionalExpression(argument))
140
+ return [...keysOf(ts, argument.whenTrue), ...keysOf(ts, argument.whenFalse)];
141
+ if (ts.isParenthesizedExpression(argument) || ts.isAsExpression(argument) || ts.isSatisfiesExpression(argument))
142
+ return keysOf(ts, argument.expression);
143
+ return ts.isStringLiteralLike(argument) ? [argument] : [];
130
144
  }
131
-
132
145
  function reportCallKeys(reads, node) {
133
- const { ts, file, checker, namespaces, loaded, app, report } = reads;
134
- const callee = node.expression;
135
- let owner = ts.isIdentifier(callee) ? callee : null;
136
- if (ts.isPropertyAccessExpression(callee) && READERS.has(callee.name.text) && ts.isIdentifier(callee.expression)) owner = callee.expression;
137
- const [first] = node.arguments;
138
- const declaration = owner ? checker.getSymbolAtLocation(owner)?.valueDeclaration : null;
139
- if (!owner || first === undefined || !namespaces.has(declaration)) return;
140
- for (const literal of keysOf(ts, first)) {
141
- const namespace = namespaces.get(declaration);
142
- const full = namespace ? `${namespace}.${literal.text}` : literal.text;
143
- const lacking = loaded.filter(catalog => !held(catalog.leaves, full)).map(catalog => catalog.locale);
144
- if (lacking.length) report(file, literal, `${file.rel} reads "${full}" and ${lacking.join(', ')} ${lacking.length === 1 ? 'holds' : 'hold'} no such key; add it to every catalog of ${app} or read a key that exists`, { key: full, locales: lacking });
145
- }
146
+ const { ts, file, checker, namespaces, loaded, app, report } = reads;
147
+ const callee = node.expression;
148
+ let owner = ts.isIdentifier(callee) ? callee : null;
149
+ if (ts.isPropertyAccessExpression(callee) && READERS.has(callee.name.text) && ts.isIdentifier(callee.expression))
150
+ owner = callee.expression;
151
+ const [first] = node.arguments;
152
+ const declaration = owner ? checker.getSymbolAtLocation(owner)?.valueDeclaration : null;
153
+ if (!owner || first === undefined || !declaration || !namespaces.has(declaration))
154
+ return;
155
+ for (const literal of keysOf(ts, first)) {
156
+ const namespace = namespaces.get(declaration);
157
+ const full = namespace ? `${namespace}.${literal.text}` : literal.text;
158
+ const lacking = loaded.filter(catalog => !held(catalog.leaves, full)).map(catalog => catalog.locale);
159
+ if (lacking.length)
160
+ report(file, literal, `${file.rel} reads "${full}" and ${lacking.join(', ')} ${lacking.length === 1 ? 'holds' : 'hold'} no such key; add it to every catalog of ${app} or read a key that exists`, { key: full, locales: lacking });
161
+ }
146
162
  }
147
-
148
163
  function reportTranslationReads(ts, file, checker, namespaces, loaded, app, report) {
149
- const reads = { ts, file, checker, namespaces, loaded, app, report };
150
- const read = node => {
151
- if (ts.isCallExpression(node)) reportCallKeys(reads, node);
152
- ts.forEachChild(node, read);
153
- };
154
- read(file.sourceFile);
164
+ const reads = { ts, file, checker, namespaces, loaded, app, report };
165
+ const read = (node) => {
166
+ if (ts.isCallExpression(node))
167
+ reportCallKeys(reads, node);
168
+ ts.forEachChild(node, read);
169
+ };
170
+ read(file.sourceFile);
155
171
  }
156
-
157
172
  function reportUnusedCatalogKeys(primary, loaded, patterns, app, violations) {
158
- const every = new Set(loaded.flatMap(catalog => [...catalog.leaves]));
159
- for (const leaf of [...every].sort(byCodeUnit)) {
160
- const segments = leaf.split('.');
161
- if (patterns.some(pattern => tailMatches(pattern, segments))) continue;
162
- violations.push({ ruleId: RULE, path: primary.rel, line: 1, column: 1, message: `${primary.rel} holds the key "${leaf}" and no source of ${app} or the shared packages reads it; delete the key from every catalog`, key: leaf });
163
- }
173
+ const every = new Set(loaded.flatMap(catalog => [...catalog.leaves]));
174
+ for (const leaf of [...every].sort(byCodeUnit)) {
175
+ const segments = leaf.split('.');
176
+ if (patterns.some(pattern => tailMatches(pattern, segments)))
177
+ continue;
178
+ violations.push({ ruleId: RULE, path: primary.rel, line: 1, column: 1, message: `${primary.rel} holds the key "${leaf}" and no source of ${app} or the shared packages reads it; delete the key from every catalog`, key: leaf });
179
+ }
164
180
  }
165
-
166
181
  export function checkI18nKeys({ config, graph, context }) {
167
- const ts = context.ts;
168
- const violations = [];
169
- const report = (file, node, message, extra = {}) => {
170
- const at = file.sourceFile.getLineAndCharacterOfPosition(node.getStart(file.sourceFile));
171
- violations.push({ ruleId: RULE, path: file.rel, line: at.line + 1, column: at.character + 1, message, ...extra });
172
- };
173
-
174
- const catalogsByApp = catalogsPerApp(config, graph);
175
-
176
- let apps = 0;
177
- for (const [dir, catalogs] of catalogsByApp) {
178
- const app = /^apps\/([^/]+)\//u.exec(dir)?.[1];
179
- const loaded = catalogs.map(catalog => ({ ...catalog, leaves: readCatalog(config.root, catalog.rel) })).filter(catalog => catalog.leaves);
180
- if (!app || !loaded.length) continue;
181
- apps += 1;
182
- const own = [...graph.files.values()].filter(file => file.rel.startsWith(`apps/${app}/src/`));
183
- const shared = [...graph.files.values()].filter(file => /^packages\/[^/]+\/src\//u.test(file.rel));
184
- const patterns = patternsOf(ts, [...own, ...shared]);
185
-
186
- for (const file of own) {
187
- const factories = translationFactories(ts, file);
188
- if (!factories.size) continue;
189
- const checker = context.checkerFor(file.sourceFile.fileName);
190
- const namespaces = translatorNamespaces(ts, file, factories);
191
- if (!namespaces.size) continue;
192
- reportTranslationReads(ts, file, checker, namespaces, loaded, app, report);
182
+ const ts = context.ts;
183
+ const violations = [];
184
+ const report = (file, node, message, extra = {}) => {
185
+ const at = file.sourceFile.getLineAndCharacterOfPosition(node.getStart(file.sourceFile));
186
+ violations.push({ ruleId: RULE, path: file.rel, line: at.line + 1, column: at.character + 1, message, ...extra });
187
+ };
188
+ const catalogsByApp = catalogsPerApp(config, graph);
189
+ let apps = 0;
190
+ for (const [dir, catalogs] of catalogsByApp) {
191
+ const app = /^apps\/([^/]+)\//u.exec(dir)?.[1];
192
+ const loaded = catalogs.map(catalog => ({ ...catalog, leaves: readCatalog(config.root, catalog.rel) })).filter((catalog) => Boolean(catalog.leaves));
193
+ if (!app || !loaded.length)
194
+ continue;
195
+ apps += 1;
196
+ const own = [...graph.files.values()].filter(file => file.rel.startsWith(`apps/${app}/src/`));
197
+ const shared = [...graph.files.values()].filter(file => /^packages\/[^/]+\/src\//u.test(file.rel));
198
+ const patterns = patternsOf(ts, [...own, ...shared]);
199
+ for (const file of own) {
200
+ const factories = translationFactories(ts, file);
201
+ if (!factories.size)
202
+ continue;
203
+ const checker = context.checkerFor(file.sourceFile.fileName);
204
+ const namespaces = translatorNamespaces(ts, file, factories);
205
+ if (!namespaces.size)
206
+ continue;
207
+ reportTranslationReads(ts, file, checker, namespaces, loaded, app, report);
208
+ }
209
+ const [primary] = [...loaded].sort((a, b) => a.locale.localeCompare(b.locale));
210
+ reportUnusedCatalogKeys(primary, loaded, patterns, app, violations);
193
211
  }
194
-
195
- const [primary] = [...loaded].sort((a, b) => a.locale.localeCompare(b.locale));
196
- reportUnusedCatalogKeys(primary, loaded, patterns, app, violations);
197
- }
198
- return { violations, coverage: { status: 'checked', apps } };
212
+ return { violations, coverage: { status: 'checked', apps } };
199
213
  }