@starci/eslint-canon-be 3.18.4 → 3.19.1

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 (211) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/dist/comments.js +1 -1
  4. package/dist/explicit-surface.js +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/jwt-alg.js +1 -1
  7. package/dist/lib/edition.d.ts +1 -1
  8. package/dist/lib/edition.js +1 -1
  9. package/dist/lib/hfs-view.d.ts +5 -0
  10. package/dist/lib/hfs.d.ts +0 -6
  11. package/dist/lib/hfs.js +7 -5
  12. package/dist/lib/runtime-root.d.ts +6 -1
  13. package/dist/lib/runtime-root.js +8 -2
  14. package/dist/lib/subject-values.js +1 -1
  15. package/dist/module-layering.js +2 -2
  16. package/dist/project-graph.js +1 -1
  17. package/dist/schema-authority.js +66 -2
  18. package/dist/third-party-owner.js +1 -1
  19. package/package.json +3 -1
  20. package/runtime/bundle.json +1 -190
  21. package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
  22. package/runtime/scripts/hfs/project-graph.mjs +6 -6
  23. package/runtime/scripts/hfs/project-rule.mjs +3 -3
  24. package/runtime/config.example.yaml +0 -194
  25. package/runtime/engine/by-code-unit.mjs +0 -12
  26. package/runtime/engine/config.mjs +0 -461
  27. package/runtime/engine/invalid-config.mjs +0 -15
  28. package/runtime/engine/model-config.mjs +0 -112
  29. package/runtime/engine/orca-config.mjs +0 -34
  30. package/runtime/engine/plain-object.mjs +0 -5
  31. package/runtime/engine/release-config.mjs +0 -32
  32. package/runtime/engine/removed-vocabulary.mjs +0 -27
  33. package/runtime/engine/resources-config.mjs +0 -59
  34. package/runtime/engine/runtime-root.mjs +0 -138
  35. package/runtime/engine/secrets.mjs +0 -202
  36. package/runtime/engine/sonar-config.mjs +0 -24
  37. package/runtime/engine/temp-root.mjs +0 -26
  38. package/runtime/engine/yaml.mjs +0 -161
  39. package/runtime/knowledge/grammars/index.yaml +0 -114
  40. package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
  41. package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
  42. package/runtime/knowledge/hfs/rules.yaml +0 -6760
  43. package/runtime/knowledge/hfs/slots.yaml +0 -2783
  44. package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
  45. package/runtime/knowledge/sonar-gate.yaml +0 -151
  46. package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
  47. package/runtime/modules/models/registry.yaml +0 -221
  48. package/runtime/modules/models/runtimes.yaml +0 -556
  49. package/runtime/modules/models/tiers.yaml +0 -66
  50. package/runtime/scripts/api/git/cat-file.mjs +0 -4
  51. package/runtime/scripts/api/git/config-get.mjs +0 -9
  52. package/runtime/scripts/api/git/diff.mjs +0 -4
  53. package/runtime/scripts/api/git/lib.mjs +0 -80
  54. package/runtime/scripts/api/git/ls-files.mjs +0 -5
  55. package/runtime/scripts/api/git/ls-tree.mjs +0 -4
  56. package/runtime/scripts/api/git/merge-base.mjs +0 -8
  57. package/runtime/scripts/api/git/remote.mjs +0 -4
  58. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
  59. package/runtime/scripts/api/git/show.mjs +0 -5
  60. package/runtime/scripts/api/git/tag.mjs +0 -4
  61. package/runtime/scripts/hfs/allows.mjs +0 -77
  62. package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
  63. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
  64. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
  65. package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
  66. package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
  67. package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
  68. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
  69. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
  70. package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
  71. package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
  72. package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
  73. package/runtime/scripts/hfs/architecture/config.mjs +0 -407
  74. package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
  75. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
  76. package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
  77. package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
  78. package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
  79. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
  80. package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
  81. package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
  82. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
  83. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
  84. package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
  85. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
  86. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
  87. package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
  88. package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
  89. package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
  90. package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
  91. package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
  92. package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
  93. package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
  94. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
  95. package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
  96. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
  97. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
  98. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
  99. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
  100. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
  101. package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
  102. package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
  103. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
  104. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
  105. package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
  106. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
  107. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
  108. package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
  109. package/runtime/scripts/hfs/architecture/index.mjs +0 -402
  110. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
  111. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
  112. package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
  113. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
  114. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
  115. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
  116. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
  117. package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
  118. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
  119. package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
  120. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
  121. package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
  122. package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
  123. package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
  124. package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
  125. package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
  126. package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
  127. package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
  128. package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
  129. package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
  130. package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
  131. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
  132. package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
  133. package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
  134. package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
  135. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
  136. package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
  137. package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
  138. package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
  139. package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
  140. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
  141. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
  142. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
  143. package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
  144. package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
  145. package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
  146. package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
  147. package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
  148. package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
  149. package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
  150. package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
  151. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
  152. package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
  153. package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
  154. package/runtime/scripts/hfs/edition-slots.mjs +0 -80
  155. package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
  156. package/runtime/scripts/hfs/linear-text.mjs +0 -30
  157. package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
  158. package/runtime/scripts/hfs/param-names.mjs +0 -13
  159. package/runtime/scripts/hfs/path-findings.mjs +0 -167
  160. package/runtime/scripts/hfs/repo-identity.mjs +0 -89
  161. package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
  162. package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
  163. package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
  164. package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
  165. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
  166. package/runtime/scripts/hfs/rules/read.mjs +0 -45
  167. package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
  168. package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
  169. package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
  170. package/runtime/scripts/hfs/slot-classify.mjs +0 -69
  171. package/runtime/scripts/hfs/slot-errors.mjs +0 -12
  172. package/runtime/scripts/hfs/slot-imports.mjs +0 -98
  173. package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
  174. package/runtime/scripts/hfs/slot-match.mjs +0 -164
  175. package/runtime/scripts/hfs/slot-path.mjs +0 -6
  176. package/runtime/scripts/hfs/slot-required.mjs +0 -95
  177. package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
  178. package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
  179. package/runtime/scripts/hfs/slots.mjs +0 -306
  180. package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
  181. package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
  182. package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
  183. package/runtime/scripts/hfs/view.mjs +0 -180
  184. package/runtime/scripts/lib/declaration-surface.mjs +0 -166
  185. package/runtime/scripts/lib/dockerfile.mjs +0 -164
  186. package/runtime/scripts/lib/env.mjs +0 -18
  187. package/runtime/scripts/lib/event-contract.mjs +0 -102
  188. package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
  189. package/runtime/scripts/lib/git.mjs +0 -35
  190. package/runtime/scripts/lib/glob.mjs +0 -32
  191. package/runtime/scripts/lib/grammar-lint.mjs +0 -57
  192. package/runtime/scripts/lib/i18n.mjs +0 -82
  193. package/runtime/scripts/lib/in-order.mjs +0 -90
  194. package/runtime/scripts/lib/json-clone.mjs +0 -70
  195. package/runtime/scripts/lib/json.mjs +0 -44
  196. package/runtime/scripts/lib/language.mjs +0 -233
  197. package/runtime/scripts/lib/list.mjs +0 -26
  198. package/runtime/scripts/lib/mutation-fence.mjs +0 -20
  199. package/runtime/scripts/lib/package-at.mjs +0 -62
  200. package/runtime/scripts/lib/path-key.mjs +0 -124
  201. package/runtime/scripts/lib/read-text.mjs +0 -47
  202. package/runtime/scripts/lib/regex.mjs +0 -3
  203. package/runtime/scripts/lib/rule-packs.mjs +0 -243
  204. package/runtime/scripts/lib/same-text.mjs +0 -4
  205. package/runtime/scripts/lib/secret-patterns.mjs +0 -230
  206. package/runtime/scripts/lib/sops-envelope.mjs +0 -212
  207. package/runtime/scripts/lib/stack-services.mjs +0 -191
  208. package/runtime/scripts/lib/ts-analysis.mjs +0 -39
  209. package/runtime/scripts/lib/ts-ast.mjs +0 -63
  210. package/runtime/scripts/lib/walk.mjs +0 -45
  211. package/runtime/scripts/lib/yaml-cached.mjs +0 -14
@@ -1,127 +0,0 @@
1
- import { RenderGraph } from './render-graph.mjs';
2
- /**
3
- * R356 `surface-nesting` (FE_SURFACE_NESTING), the whole-program half of the one-file card laws (R340, R351, R354, R348, R366).
4
- * ESLint judges one file; an app draws a screen across several, so the check walks the render graph (render-graph.mts) from every
5
- * app component and reports, at the inner element, what stands wrongly inside what once every component is replaced by what it
6
- * draws and every `children` by what its caller handed it:
7
- *
8
- * card-in-card a card inside a card (surface in surface is banned totally, owner decision 2026-11-01);
9
- * card-in-pane a card inside `Pane surface`;
10
- * card-in-overlay a card inside a Dialog, Drawer, AlertDialog or Popover;
11
- * table-in-card a `DataTable` inside a card (a table stands on the page);
12
- * grid-outside-panes a `PaneGrid` inside a card or a Page whose chrome is not `panes`;
13
- * heading-over-card a `Heading`, or a region `Section`, whose only neighbour or child is one card (a card carries its own label);
14
- * label-in-grid a labelled card repeated by a `.map` in a `Grid kind="cards"` (a repeated tile has no label).
15
- *
16
- * A finding carries `crossFile: true` when the two elements are drawn in different files, which is what one-file lint cannot see.
17
- */
18
- export const SURFACE_NESTING_RULE_IDS = ['FE_SURFACE_NESTING'];
19
- const RULE = 'FE_SURFACE_NESTING';
20
- /** The grammar vocabulary this check reads, in one place so a rename in the grammar is one edit here. */
21
- export const SURFACE_VOCABULARY = Object.freeze({
22
- cards: new Set(['SurfaceCard']),
23
- overlays: new Set(['Dialog', 'Drawer', 'AlertDialog', 'Popover']),
24
- tables: new Set(['DataTable']),
25
- headings: new Set(['Heading']),
26
- sections: new Set(['Section']),
27
- paneGrids: new Set(['PaneGrid']),
28
- pane: 'Pane',
29
- page: 'Page',
30
- grids: new Set(['Grid']),
31
- });
32
- const grammarName = (element) => (element.tag.kind === 'grammar' ? element.tag.name : null);
33
- const isGrammarIn = (element, names) => {
34
- const name = grammarName(element);
35
- return name !== null && names.has(name);
36
- };
37
- const isTrue = (element, attribute) => {
38
- const found = element.attributes.get(attribute);
39
- return found !== undefined && found.text !== 'false' && found.text !== null;
40
- };
41
- /** The card an element is, or draws at its root through one app component: the one wrapper level the audit allows. */
42
- const cardOf = (graph, element) => {
43
- if (isGrammarIn(element, SURFACE_VOCABULARY.cards))
44
- return element;
45
- const root = element.tag.kind === 'component' ? graph.rootOf(element) : null;
46
- return root && isGrammarIn(root, SURFACE_VOCABULARY.cards) ? root : null;
47
- };
48
- const describe = (element) => (element.tag.kind === 'component' ? `${element.tag.name} (${element.tag.file})` : element.tag.name);
49
- const chainOf = (ancestors, stack) => `${ancestors.map(entry => entry.element.tag.name).join(' > ')}${stack.length > 1 ? ` via ${stack.map(entry => entry.split('#')[1]).join(' > ')}` : ''}`;
50
- export function checkSurfaceNesting(input) {
51
- const graph = new RenderGraph(input.context.ts, input.graph);
52
- const found = new Map();
53
- const report = (element, outer, kind, message, ancestors, stack) => {
54
- const where = graph.locate(element);
55
- const key = `${where.path}:${where.line}:${where.column}:${kind}`;
56
- if (found.has(key))
57
- return;
58
- found.set(key, {
59
- ruleId: RULE, ...where, kind, crossFile: outer !== null && outer.file !== element.file,
60
- message: `${message} (${chainOf(ancestors, stack)}). A card carries its own label and stands on the page or on a canvas pane; a table stands on the page; a grid stands in Page chrome="panes" (contexts/ui/components/card.md).`,
61
- });
62
- };
63
- const visitor = {
64
- enter(element, ancestors, stack) {
65
- const name = grammarName(element);
66
- const nearestCard = [...ancestors].reverse().find(entry => isGrammarIn(entry.element, SURFACE_VOCABULARY.cards));
67
- if (name !== null && SURFACE_VOCABULARY.cards.has(name)) {
68
- const inPane = [...ancestors].reverse().find(entry => grammarName(entry.element) === SURFACE_VOCABULARY.pane && isTrue(entry.element, 'surface'));
69
- const inOverlay = [...ancestors].reverse().find(entry => isGrammarIn(entry.element, SURFACE_VOCABULARY.overlays));
70
- if (nearestCard)
71
- report(element, nearestCard.element, 'card-in-card', `${name} is drawn inside ${describe(nearestCard.element)}: surface in surface is banned`, ancestors, stack);
72
- else if (inPane)
73
- report(element, inPane.element, 'card-in-pane', `${name} is drawn inside Pane surface`, ancestors, stack);
74
- else if (inOverlay)
75
- report(element, inOverlay.element, 'card-in-overlay', `${name} is drawn inside ${describe(inOverlay.element)}: an overlay is a surface already`, ancestors, stack);
76
- }
77
- if (name !== null && SURFACE_VOCABULARY.tables.has(name) && nearestCard) {
78
- report(element, nearestCard.element, 'table-in-card', `${name} is drawn inside ${describe(nearestCard.element)}`, ancestors, stack);
79
- }
80
- if (name !== null && SURFACE_VOCABULARY.paneGrids.has(name)) {
81
- const frame = [...ancestors].reverse().find(entry => {
82
- const frameName = grammarName(entry.element);
83
- return frameName === SURFACE_VOCABULARY.pane || frameName === SURFACE_VOCABULARY.page || SURFACE_VOCABULARY.cards.has(frameName ?? '');
84
- });
85
- const frameName = frame ? grammarName(frame.element) : null;
86
- if (frame && frameName !== SURFACE_VOCABULARY.pane) {
87
- const chrome = frame.element.attributes.get('chrome');
88
- const open = frameName === SURFACE_VOCABULARY.page && (chrome === undefined ? hasSpread(frame.element) : chrome.text === null);
89
- const panes = frameName === SURFACE_VOCABULARY.page && chrome?.text === 'panes';
90
- if (!open && !panes)
91
- report(element, frame.element, 'grid-outside-panes', `${name} is drawn inside ${describe(frame.element)}`, ancestors, stack);
92
- }
93
- }
94
- if (element.repeated) {
95
- const inGrid = [...ancestors].reverse().find(entry => isGrammarIn(entry.element, SURFACE_VOCABULARY.grids));
96
- const card = inGrid?.element.attributes.get('kind')?.text === 'cards' ? cardOf(graph, element) : null;
97
- if (inGrid && card && card.attributes.has('label')) {
98
- report(element, inGrid.element, 'label-in-grid', `${describe(element)} repeats a labelled card in a Grid kind="cards": a repeated tile has no label`, ancestors, stack);
99
- }
100
- }
101
- },
102
- parent(element, drawn, ancestors, stack) {
103
- if (!isGrammarIn(element, SURFACE_VOCABULARY.sections) || element.attributes.get('kind')?.text === 'list' || drawn.length !== 1)
104
- return;
105
- const only = drawn[0];
106
- if (cardOf(graph, only))
107
- report(only, element, 'heading-over-card', `${describe(only)} is the only thing in a Section: the card has two titles`, ancestors, stack);
108
- },
109
- siblings(elements, ancestors, stack) {
110
- for (let index = 0; index < elements.length - 1; index += 1) {
111
- const heading = elements[index];
112
- if (!isGrammarIn(heading, SURFACE_VOCABULARY.headings))
113
- continue;
114
- const next = elements[index + 1];
115
- const after = elements[index + 2];
116
- if (!cardOf(graph, next) || (after && cardOf(graph, after)))
117
- continue;
118
- report(next, heading, 'heading-over-card', `${describe(next)} stands directly under a ${heading.tag.name}, so the card has two titles`, ancestors, stack);
119
- }
120
- },
121
- };
122
- const components = graph.allComponents();
123
- for (const component of components)
124
- graph.walkFrom(component, visitor);
125
- return { violations: [...found.values()], coverage: { status: 'checked', components: components.length } };
126
- }
127
- const hasSpread = (element) => element.attributes.has('...');
@@ -1,88 +0,0 @@
1
- /**
2
- * The lint surface: which architecture-machine findings an ESLint rule judges instead of `starci app check`.
3
- * Single source of truth. Each enforcer id is the rules.yaml enforcer; `codes` are the exact violation.ruleId strings its
4
- * check file emits on source files. plugins: 'be' = back-end profile repos, 'fe' = front-end profile, graph checks run for both.
5
- */
6
- import fs from 'node:fs';
7
- import path from 'node:path';
8
- const BE = ['be'];
9
- const FE = ['fe'];
10
- const BOTH = ['be', 'fe'];
11
- const enforcer = (id, plugins, codes, description, extra = {}) => Object.freeze({ id, plugins: Object.freeze(plugins), codes: Object.freeze(codes), description, ...extra });
12
- export const LINT_ENFORCERS = Object.freeze([
13
- enforcer('duplicate-code', BOTH, ['HFS_DUPLICATE_CODE'], 'A block of production code never repeats elsewhere in the owner graph.'),
14
- enforcer('duplicate-symbol', BOTH, ['HFS_DUPLICATE_SYMBOL'], 'A symbol name is declared once across the production source.'),
15
- enforcer('alias-reexport', BOTH, ['HFS_ALIAS_REEXPORT'], 'An owner entry re-exports a symbol under its own name, never through a const alias.'),
16
- // cross-app-duplicate emits only FE_CROSS_APP_DUPLICATE today; HFS_DUPLICATE_CODE is named in its comment only.
17
- enforcer('cross-app-duplicate', FE, ['FE_CROSS_APP_DUPLICATE'], 'A file is never copied between apps; shared code lives in a package.'),
18
- enforcer('dead-exports', BOTH, ['HFS_UNUSED_EXPORT', 'HFS_UNUSED_FILE'], 'Every owner export and every production file is reached by a root.'),
19
- enforcer('tier-direction', BOTH, ['BE_TIER_DIRECTION', 'FE_TIER_DIRECTION'], 'An import goes only to a tier the slot matrix allows.'),
20
- enforcer('owner-cycle', BOTH, ['ARCH_OWNER_CYCLE'], 'Owners never import each other in a cycle.'),
21
- enforcer('feature-imports-feature', BE, ['BE_FEATURE_IMPORTS_FEATURE'], 'A feature never imports another feature.'),
22
- enforcer('kind-isolation', BE, ['BE_KIND_ISOLATION'], 'A feature of one trigger kind never imports a feature of another kind; the kinds meet through the event bus.'),
23
- enforcer('app-isolation', FE, ['FE_APP_ISOLATION'], 'An app never imports another app.'),
24
- enforcer('feature-layout', BE, ['BE_FEATURE_LAYOUT_INVALID'], 'A feature file sits in the folder its role names.'),
25
- enforcer('application-never-imports-transport', BE, ['BE_APPLICATION_IMPORTS_TRANSPORT', 'BE_APPLICATION_TRANSPORT_FRAMEWORK'], 'Application code never imports transport code, directly or through a chain.'),
26
- enforcer('owner-export-bypass', BOTH, ['ARCH_OWNER_EXPORT_BYPASS', 'ARCH_OWNER_EXPORT_STAR'], 'Another owner is imported only through its index entry, and an entry never uses export star.'),
27
- enforcer('feature-not-composed', BE, ['BE_FEATURE_NOT_COMPOSED'], 'Every feature owner is composed into an app.'),
28
- enforcer('owner-reachable', FE, ['FE_OWNER_REACHABLE', 'FE_HREF_RESOLVES'], 'Every owner is mounted by a route and every href resolves to a route.'),
29
- enforcer('app-composition-only', BE, ['BE_APP_COMPOSITION_ONLY', 'BE_APP_BUSINESS_ROLE'], 'An app only composes modules and holds no business role.'),
30
- enforcer('entrypoint-only-in-apps', BE, ['BE_ENTRYPOINT_ONLY_IN_APPS'], 'NestFactory and bootstrap live only in an app main file.'),
31
- enforcer('schema-owner', BE, ['BE_SCHEMA_OWNER'], 'Each entity array is registered by one owner across all apps.'),
32
- enforcer('sql-returning', BE, ['BE_SQL_RETURNING_SHAPE'], 'An UPDATE or DELETE with RETURNING is wrapped in a CTE SELECT, because EntityManager.query returns it as [rows, count].'),
33
- enforcer('context-owner', BE, ['BE_CONTEXT_OWNER'], 'An app composes only the contexts (connections) it owns; the migration apps compose all of them.'),
34
- enforcer('context-coupling', BE, ['BE_CONTEXT_COUPLING'], 'Contexts are never coupled by a relation, a foreign key or an import; only by events.'),
35
- enforcer('context-transaction', BE, ['BE_CONTEXT_TRANSACTION'], 'One transaction touches one context connection.'),
36
- enforcer('context-platform-tables', BE, ['BE_CONTEXT_PLATFORM_TABLES'], 'A per-connection platform capability registers its tables on every connection that uses it.'),
37
- enforcer('error-code-unique', BE, ['BE_ERROR_HOME'], 'An error code is declared once in the repository.'),
38
- enforcer('error-masked', BE, ['BE_ERROR_MASKED'], 'Every app wires the error filter that masks internal errors.'),
39
- enforcer('default-deny-app-guard', BE, ['BE_DEFAULT_DENY'], 'Every app registers the default-deny guard before any other guard.'),
40
- // BE_MODULE_SHAPE is emitted by both register-once and module-per-transport.
41
- enforcer('register-once', BE, ['BE_MODULE_SHAPE'], 'A module is registered once and imported by one module.', { via: 'registerOnce' }),
42
- enforcer('module-per-transport', BE, ['BE_MODULE_SHAPE'], 'An app imports transport modules only.', { via: 'modulePerTransport' }),
43
- enforcer('module-registration', BE, ['BE_MODULE_HANDLER_REGISTRATION', 'BE_MODULE_PROVIDER_REREGISTRATION'], 'Every handler is registered by a module and no provider is registered twice.'),
44
- enforcer('background-unowned', BE, ['BE_BACKGROUND_UNOWNED'], 'Every background job is reachable from a worker app.'),
45
- enforcer('test-world-files', BE, ['BE_TEST_TOPOLOGY'], 'The test world files match the stack declaration.'),
46
- enforcer('unit-spec-providers', BE, ['BE_SPEC_QUALITY'], 'A unit spec provides exactly the dependencies its service constructor takes.'),
47
- enforcer('transport-owner', FE, ['FE_TRANSPORT_OWNER'], 'One client and one outcome type own the transport of the repository.'),
48
- enforcer('swr-data-lifecycle', FE, ['FE_SWR_KEY_IDENTITY', 'FE_SWR_MUTATION_RESOURCE_IDENTITY'], 'SWR keys and mutations share one resource identity.'),
49
- enforcer('route-files-thin', FE, ['FE_ROUTE_FILES_THIN'], 'A route file only mounts one feature owner.'),
50
- enforcer('route-adapter', FE, ['FE_ROUTE_ONE_PAGE', 'FE_ROUTE_DRAWING_DECISION', 'FE_ROUTE_CLIENT_BOUNDARY', 'FE_ROUTE_CLIENT_HOOK', 'FE_ROUTE_DEFAULT_EXPORT'], 'A page route is a server adapter that mounts one pages-tier component.'),
51
- enforcer('client-reaches-server', FE, ['FE_CLIENT_REACHES_SERVER'], 'Client code never reaches server-only code through any import chain.'),
52
- enforcer('hooks-are-hooks', FE, ['FE_HOOKS_ARE_HOOKS'], 'A hooks folder holds hooks only, one shared file per domain.'),
53
- enforcer('hook-location', FE, ['FE_CUSTOM_HOOK_LOCATION', 'FE_BLOCK_PRODUCT_HOOK_DEFINITION', 'FE_COMPONENT_DEEP_HOOK_IMPORT'], 'A custom hook is defined in the hooks folder and imported through its entry.'),
54
- enforcer('connection-map', BE, ['BE_CONNECTION_DUPLICATE'], 'Each database connection is declared once and matches the connection map.'),
55
- enforcer('injection-token-exported', BE, ['BE_RAW_INJECT'], 'An injection token is exported by its owner and never injected raw.'),
56
- enforcer('sql-owner', BE, ['BE_SQL_TABLE_OWNER'], 'A SQL table is touched only by the owner of its entity.'),
57
- enforcer('readonly-boundary', BE, ['BE_READONLY_BOUNDARY'], 'Messages and injected classes crossing a boundary are readonly.'),
58
- enforcer('source-names', BE, ['BE_SOURCE_FORM'], 'Names and forms inside a source file follow its role.'),
59
- enforcer('public-contract-form', BE, ['BE_PUBLIC_CONTRACT_FORM'], 'A public signature is typed by a named contract, never inline or untyped.'),
60
- enforcer('frontend-source-layout', FE, ['FE_SOURCE_LAYOUT_INVALID'], 'A front-end source file sits in a tier folder.'),
61
- enforcer('component-purity', FE, ['FE_COMPONENT_WORLD_OWNERSHIP', 'FE_WORLD_OWNER_RENDER_BOUNDARY', 'FE_CONNECTED_BLOCK_RENDER_PAIR', 'FE_PURE_REACHES_DATA', 'FE_PURE_WORLD_HOOK', 'FE_PURE_WORLD_IMPORT'], 'A pure component reaches no data or world state; its connected entry owns them.'),
62
- // Package-manifest contract findings stay with app check; only source import bypasses belong to lint.
63
- enforcer('grammar-entry', FE, ['ARCH_GRAMMAR_EXPORT_BYPASS'], 'Vendor grammar is reached only through its owner entry.'),
64
- enforcer('i18n-keys', FE, ['FE_I18N_KEYS'], 'Translation keys read by source and keys held by catalogs agree both ways.'),
65
- // The per-path judgements of the slot manifest (scripts/hfs/path-findings.mjs), on a tracked TypeScript file.
66
- enforcer('slot-undeclared', BOTH, ['HFS_SLOT_UNDECLARED', 'HFS_SLOT_AMBIGUOUS', 'HFS_SLOT_NOT_ENABLED'], 'A TypeScript file is owned by exactly one slot of the repository.', { origin: 'repo' }),
67
- enforcer('source-suffix', BE, ['BE_SOURCE_FORM'], 'A source file name is index.ts, main.ts, a migration or <kebab-name>.<suffix>.ts with a suffix of the closed list.', { origin: 'repo' }),
68
- enforcer('spec-placement', BE, ['BE_SPEC_PLACEMENT'], 'A spec file lives in one of the four test layers and nowhere else.', { origin: 'repo' }),
69
- // The two below are emitted into context.errors today, not into violations.
70
- enforcer('package-imports-app', BOTH, ['ARCH_PACKAGE_IMPORTS_APP'], 'A package never imports an app.'),
71
- enforcer('package-export-bypass', BOTH, ['ARCH_PACKAGE_EXPORT_BYPASS'], 'A package is imported only through its declared exports.'),
72
- ]);
73
- export const LINT_CODES = new Set(LINT_ENFORCERS.flatMap(e => e.codes));
74
- export const TS_SOURCE = /\.(?:[cm]?tsx?)$/;
75
- /** True when a finding sits on an existing TypeScript file of the repository: the only findings an editor can show on a line. */
76
- function attachesToSource(repositoryRoot, violation) {
77
- const file = violation?.path;
78
- if (typeof file !== 'string' || !TS_SOURCE.test(file))
79
- return false;
80
- return fs.existsSync(path.join(repositoryRoot, ...file.split('/')));
81
- }
82
- /** The finding's code: a machine violation spells it `ruleId`, a repository finding `code`. */
83
- export const codeOf = (finding) => finding?.ruleId ?? finding?.code;
84
- /** Whether `finding` (with its origin and check tags) belongs to `enforcer`. */
85
- export const belongsTo = (enforcer, finding) => enforcer.codes.includes(codeOf(finding))
86
- && (finding.origin ?? 'machine') === (enforcer.origin ?? 'machine') && (enforcer.via === undefined || finding.check === enforcer.via);
87
- /** True when some lint rule owns the finding and it sits on an existing TypeScript file: it is an ESLint report, not a `starci app check` finding. */
88
- export const onLintSurface = (repositoryRoot, finding) => LINT_ENFORCERS.some(enforcer => belongsTo(enforcer, finding)) && attachesToSource(repositoryRoot, finding);
@@ -1,273 +0,0 @@
1
- import { canonical } from './config.mjs';
2
- import { hasAnyFlag } from '../../lib/ts-ast.mjs';
3
- import { entryOf } from './dead-exports.mjs';
4
- export const SYMBOL_RULE_IDS = ['HFS_DUPLICATE_SYMBOL', 'HFS_ALIAS_REEXPORT'];
5
- const lineOf = (sourceFile, node) => sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
6
- /** The modifiers a statement carries (none for a statement that cannot have any). */
7
- const modifiersOf = (ts, statement) => (ts.canHaveModifiers(statement) ? statement.modifiers : undefined) ?? [];
8
- /** The names a source file declares at top level and exports: Map<name, line>. Re-exports from another module declare nothing. */
9
- function addBindingNames(ts, sourceFile, name, into, node) {
10
- if (ts.isIdentifier(name)) {
11
- into.set(name.text, lineOf(sourceFile, node));
12
- return;
13
- }
14
- for (const element of name.elements) {
15
- if (ts.isBindingElement(element))
16
- addBindingNames(ts, sourceFile, element.name, into, node);
17
- }
18
- }
19
- function recordStatementDeclarations(ts, sourceFile, statement, declared, exported) {
20
- const kind = ts.SyntaxKind;
21
- const modifiers = modifiersOf(ts, statement);
22
- const publish = modifiers.some(modifier => modifier.kind === kind.ExportKeyword) && !modifiers.some(modifier => modifier.kind === kind.DefaultKeyword);
23
- const into = publish ? exported : declared;
24
- if (ts.isVariableStatement(statement)) {
25
- for (const declaration of statement.declarationList.declarations)
26
- addBindingNames(ts, sourceFile, declaration.name, into, declaration);
27
- return;
28
- }
29
- const declares = [kind.FunctionDeclaration, kind.ClassDeclaration, kind.EnumDeclaration, kind.TypeAliasDeclaration, kind.InterfaceDeclaration];
30
- const name = statement.name;
31
- if (name && ts.isIdentifier(name) && declares.includes(statement.kind)) {
32
- into.set(name.text, lineOf(sourceFile, statement));
33
- }
34
- }
35
- function exposeLocalExports(localLists, declared, exported) {
36
- for (const element of localLists) {
37
- const local = (element.propertyName ?? element.name).text;
38
- if (declared.has(local))
39
- exported.set(element.name.text, declared.get(local));
40
- }
41
- }
42
- function declaredExports(ts, sourceFile) {
43
- const declared = new Map();
44
- const exported = new Map();
45
- const localLists = [];
46
- for (const statement of sourceFile.statements) {
47
- if (ts.isExportDeclaration(statement)) {
48
- if (!statement.moduleSpecifier && statement.exportClause && ts.isNamedExports(statement.exportClause))
49
- localLists.push(...statement.exportClause.elements);
50
- continue;
51
- }
52
- recordStatementDeclarations(ts, sourceFile, statement, declared, exported);
53
- }
54
- // `export { local }` of a name declared in this file makes that declaration exported.
55
- exposeLocalExports(localLists, declared, exported);
56
- return exported;
57
- }
58
- /** The declaration an export of an entry resolves to: its repository-relative file and its own name, or null. */
59
- function declaringFile(ts, checker, graph, symbol) {
60
- const resolved = hasAnyFlag(symbol.flags, ts.SymbolFlags.Alias) ? checker.getAliasedSymbol(symbol) : symbol;
61
- for (const declaration of resolved?.declarations ?? []) {
62
- const rel = graph.abs(canonical(declaration.getSourceFile().fileName));
63
- if (rel)
64
- return { rel, name: resolved.getName() };
65
- }
66
- return null;
67
- }
68
- function declarationIndex(ts, graph) {
69
- const declarations = new Map(); // name -> Map<rel, line>
70
- for (const [rel, node] of graph.files) {
71
- for (const [name, line] of declaredExports(ts, node.sourceFile)) {
72
- if (name === 'default')
73
- continue;
74
- let byFile = declarations.get(name);
75
- if (!byFile) {
76
- byFile = new Map();
77
- declarations.set(name, byFile);
78
- }
79
- byFile.set(rel, line);
80
- }
81
- }
82
- return declarations;
83
- }
84
- function duplicateViolation(scan, symbol, owner, entry) {
85
- const { ts, checker, graph, declarations, seen } = scan;
86
- const declaration = declaringFile(ts, checker, graph, symbol);
87
- if (!declaration || declaration.name === 'default')
88
- return null;
89
- const { rel: home, name } = declaration;
90
- const others = [...(declarations.get(name) ?? [])].filter(([rel]) => rel !== home);
91
- if (!others.length || seen.has(`${home}\0${name}`))
92
- return null;
93
- seen.add(`${home}\0${name}`);
94
- const where = others.map(([rel, at]) => `${rel}:${at}`);
95
- return {
96
- ruleId: 'HFS_DUPLICATE_SYMBOL',
97
- path: home, line: declarations.get(name)?.get(home) ?? 1, column: 1, name, owner: owner.root, entry,
98
- otherDeclarations: where,
99
- message: `${name} is exported through the public entry ${entry} (declared in ${home}) and also declared and exported in ${where.join(', ')}; one name, one declaration: rename or delete the copy.`,
100
- };
101
- }
102
- function inspectPublicOwner(ts, context, graph, config, declarations, seen, [key, owner]) {
103
- if (owner.tier === 'app')
104
- return { violations: [], surface: 0 };
105
- const entry = entryOf(graph, config, key, owner);
106
- if (!entry)
107
- return { violations: [], surface: 0 };
108
- const entryFile = graph.files.get(entry);
109
- const checker = context.checkerFor(entryFile.abs);
110
- const moduleSymbol = checker?.getSymbolAtLocation(entryFile.sourceFile);
111
- if (!moduleSymbol)
112
- return { violations: [], surface: 0 };
113
- const violations = [];
114
- const scan = { ts, checker, graph, declarations, seen };
115
- let surface = 0;
116
- for (const symbol of checker.getExportsOfModule(moduleSymbol)) {
117
- surface += 1;
118
- const violation = duplicateViolation(scan, symbol, owner, entry);
119
- if (violation)
120
- violations.push(violation);
121
- }
122
- return { violations, surface };
123
- }
124
- function duplicateSymbols({ context, graph, config }) {
125
- const declarations = declarationIndex(context.ts, graph);
126
- const violations = [];
127
- const seen = new Set();
128
- let surface = 0;
129
- for (const item of graph.ownerRoots) {
130
- const result = inspectPublicOwner(context.ts, context, graph, config, declarations, seen, item);
131
- violations.push(...result.violations);
132
- surface += result.surface;
133
- }
134
- return { violations, surface };
135
- }
136
- const isExported = (ts, statement) => modifiersOf(ts, statement).some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword)
137
- && !modifiersOf(ts, statement).some(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword);
138
- const bareAliasExpression = (ts, expression) => ts.isIdentifier(expression)
139
- || (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.name) && (ts.isIdentifier(expression.expression) || ts.isPropertyAccessExpression(expression.expression)));
140
- /** The declaration `node` (an identifier, a member or a qualified name) resolves to when a repository file declares it as one of `kinds`, else null. */
141
- function repositoryDeclaration(ts, checker, graph, node, kinds) {
142
- let target = node;
143
- if (ts.isPropertyAccessExpression(node))
144
- target = node.name;
145
- else if (ts.isQualifiedName(node))
146
- target = node.right;
147
- const symbol = checker?.getSymbolAtLocation(target);
148
- if (!symbol)
149
- return null;
150
- const resolved = hasAnyFlag(symbol.flags, ts.SymbolFlags.Alias) ? checker.getAliasedSymbol(symbol) : symbol;
151
- const home = (resolved?.declarations ?? []).some(declaration => kinds.includes(declaration.kind) && graph.abs(canonical(declaration.getSourceFile().fileName)));
152
- return home ? resolved.getName() : null;
153
- }
154
- /**
155
- * The exported declarations of one top-level statement that only rename another declaration of the repository:
156
- * `export const Y = X` and `export const Y = X.y` (X or y a function, class, const or enum), `export type Y = X` and
157
- * `export interface Y extends X {}` with no body, no type arguments and no type parameters.
158
- */
159
- function variableAliases(ts, checker, graph, statement, kind) {
160
- const found = [];
161
- for (const declaration of statement.declarationList.declarations) {
162
- if (!ts.isIdentifier(declaration.name) || !declaration.initializer || !bareAliasExpression(ts, declaration.initializer))
163
- continue;
164
- const of = repositoryDeclaration(ts, checker, graph, declaration.initializer, [kind.FunctionDeclaration, kind.ClassDeclaration, kind.VariableDeclaration, kind.EnumDeclaration]);
165
- if (of && of !== declaration.name.text)
166
- found.push({ node: declaration, name: declaration.name.text, of, form: `export const ${declaration.name.text} = ${declaration.initializer.getText()}` });
167
- }
168
- return found;
169
- }
170
- function typeAliasOf(ts, checker, graph, statement, kind) {
171
- if (statement.typeParameters?.length || !ts.isTypeReferenceNode(statement.type) || statement.type.typeArguments?.length)
172
- return [];
173
- const of = repositoryDeclaration(ts, checker, graph, statement.type.typeName, [kind.InterfaceDeclaration, kind.TypeAliasDeclaration, kind.ClassDeclaration, kind.EnumDeclaration]);
174
- return of && of !== statement.name.text
175
- ? [{ node: statement, name: statement.name.text, of, form: `export type ${statement.name.text} = ${statement.type.getText()}` }]
176
- : [];
177
- }
178
- function interfaceAliasOf(ts, checker, graph, statement, kind) {
179
- if (statement.members.length || statement.typeParameters?.length)
180
- return [];
181
- const heritage = (statement.heritageClauses ?? []).flatMap((clause) => clause.types);
182
- const only = heritage[0];
183
- if (heritage.length !== 1 || !only || only.typeArguments?.length || !bareAliasExpression(ts, only.expression))
184
- return [];
185
- const of = repositoryDeclaration(ts, checker, graph, only.expression, [kind.InterfaceDeclaration, kind.TypeAliasDeclaration, kind.ClassDeclaration]);
186
- return of && of !== statement.name.text
187
- ? [{ node: statement, name: statement.name.text, of, form: `export interface ${statement.name.text} extends ${only.expression.getText()} {}` }]
188
- : [];
189
- }
190
- function declarationAliases(ts, checker, graph, statement) {
191
- const kind = ts.SyntaxKind;
192
- if (!checker || !isExported(ts, statement))
193
- return [];
194
- if (ts.isVariableStatement(statement))
195
- return variableAliases(ts, checker, graph, statement, kind);
196
- if (ts.isTypeAliasDeclaration(statement))
197
- return typeAliasOf(ts, checker, graph, statement, kind);
198
- if (ts.isInterfaceDeclaration(statement))
199
- return interfaceAliasOf(ts, checker, graph, statement, kind);
200
- return [];
201
- }
202
- /** The names Next.js reads from a route segment file (layout, page, route, ...): the framework fixes them. */
203
- const NEXT_SEGMENT_EXPORTS = new Set([
204
- 'generateMetadata', 'metadata', 'generateViewport', 'viewport', 'generateStaticParams', 'generateImageMetadata', 'generateSitemaps',
205
- 'dynamic', 'dynamicParams', 'revalidate', 'fetchCache', 'runtime', 'preferredRegion', 'maxDuration',
206
- ]);
207
- const ROUTE_SLOT = 'fe.route';
208
- function isFrameworkName(node, name) {
209
- return node.slot === ROUTE_SLOT && NEXT_SEGMENT_EXPORTS.has(name);
210
- }
211
- function addDeclarationAliasViolations(env, rel, node, statement, point, violations) {
212
- const { ts, checker, graph } = env;
213
- for (const alias of declarationAliases(ts, checker, graph, statement)) {
214
- if (isFrameworkName(node, alias.name))
215
- continue;
216
- const at = point(alias.node);
217
- violations.push({
218
- ruleId: 'HFS_ALIAS_REEXPORT', path: rel, line: at.line + 1, column: at.character + 1, name: alias.name, aliasOf: alias.of,
219
- message: `${alias.form} in ${rel} gives the declaration ${alias.of} a second name: use ${alias.of} where ${alias.name} is used and delete ${alias.name}.`,
220
- });
221
- }
222
- }
223
- function addNamespaceAliasViolation(rel, statement, clause, point, violations) {
224
- const at = point(statement);
225
- violations.push({
226
- ruleId: 'HFS_ALIAS_REEXPORT', path: rel, line: at.line + 1, column: at.character + 1, name: clause.name.text,
227
- message: `export * as ${clause.name.text} in ${rel} publishes a whole module under a second name: export the declarations it holds by their own names.`,
228
- });
229
- }
230
- function addNamedAliasViolations(rel, node, clause, point, violations) {
231
- for (const element of clause.elements) {
232
- if (!element.propertyName || element.propertyName.text === element.name.text || isFrameworkName(node, element.name.text))
233
- continue;
234
- const at = point(element);
235
- violations.push({
236
- ruleId: 'HFS_ALIAS_REEXPORT', path: rel, line: at.line + 1, column: at.character + 1,
237
- name: element.name.text, aliasOf: element.propertyName.text,
238
- message: `export { ${element.propertyName.text} as ${element.name.text} } in ${rel} gives one declaration a second name: rename the declaration to ${element.name.text}, or import and export it as ${element.propertyName.text}.`,
239
- });
240
- }
241
- }
242
- function addExportAliasViolations(ts, rel, node, statement, point, violations) {
243
- if (!ts.isExportDeclaration(statement) || !statement.exportClause)
244
- return;
245
- const clause = statement.exportClause;
246
- if (ts.isNamespaceExport(clause)) {
247
- addNamespaceAliasViolation(rel, statement, clause, point, violations);
248
- return;
249
- }
250
- addNamedAliasViolations(rel, node, clause, point, violations);
251
- }
252
- function addStatementAliasViolations(context, graph, rel, node, statement, checker, violations) {
253
- const point = (target) => node.sourceFile.getLineAndCharacterOfPosition(target.getStart(node.sourceFile));
254
- addDeclarationAliasViolations({ ts: context.ts, checker, graph }, rel, node, statement, point, violations);
255
- addExportAliasViolations(context.ts, rel, node, statement, point, violations);
256
- }
257
- function aliasReexports({ context, graph }) {
258
- const violations = [];
259
- for (const [rel, node] of graph.files) {
260
- const checker = context.checkerFor(node.abs);
261
- for (const statement of node.sourceFile.statements)
262
- addStatementAliasViolations(context, graph, rel, node, statement, checker, violations);
263
- }
264
- return { violations };
265
- }
266
- export function checkSymbols(input) {
267
- const duplicates = duplicateSymbols(input);
268
- const aliases = aliasReexports(input);
269
- return {
270
- violations: [...duplicates.violations, ...aliases.violations],
271
- coverage: { status: 'checked', publicNames: duplicates.surface, duplicates: duplicates.violations.length, aliases: aliases.violations.length },
272
- };
273
- }