@md-code/follow-architecture 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +1310 -472
- package/dist/args.d.ts +4 -0
- package/dist/args.js +18 -1
- package/dist/bin/follow-architecture.js +3 -3
- package/dist/closure-project.d.ts +4 -0
- package/dist/closure-project.js +132 -0
- package/dist/code-entities/classify.d.ts +11 -0
- package/dist/code-entities/classify.js +45 -0
- package/dist/code-entities/connector.d.ts +8 -0
- package/dist/code-entities/connector.js +119 -0
- package/dist/code-entities/entities.d.ts +9 -0
- package/dist/{code-roles/roles.js → code-entities/entities.js} +98 -61
- package/dist/code-entities/project.d.ts +21 -0
- package/dist/code-entities/project.js +259 -0
- package/dist/code-entities/walk.d.ts +31 -0
- package/dist/code-entities/walk.js +105 -0
- package/dist/config-options.d.ts +23 -0
- package/dist/config-options.js +18 -1
- package/dist/config-project.js +27 -9
- package/dist/config-report.d.ts +1 -1
- package/dist/config-report.js +37 -10
- package/dist/config-rule.d.ts +25 -0
- package/dist/config-rule.js +106 -13
- package/dist/config-state.d.ts +14 -3
- package/dist/config-state.js +197 -24
- package/dist/config.d.ts +25 -0
- package/dist/css/index.d.ts +11 -7
- package/dist/css/index.js +141 -30
- package/dist/css/syntax/css/gate.js +5 -5
- package/dist/css/syntax/css/index.d.ts +1 -1
- package/dist/css/syntax/css/index.js +18 -8
- package/dist/css/syntax/css/reference.d.ts +1 -1
- package/dist/css/syntax/css/reference.js +15 -3
- package/dist/css/syntax/language.d.ts +1 -1
- package/dist/css/syntax/language.js +21 -9
- package/dist/css/syntax/scss/index.d.ts +2 -2
- package/dist/css/syntax/scss/index.js +18 -8
- package/dist/css/syntax/scss/reference.d.ts +1 -1
- package/dist/css/syntax/scss/reference.js +7 -1
- package/dist/css/syntax/styled/document.d.ts +3 -3
- package/dist/css/syntax/styled/document.js +34 -14
- package/dist/css/syntax/styled/markup.d.ts +1 -1
- package/dist/css/syntax/styled/markup.js +22 -14
- package/dist/css/syntax/styled/tags.d.ts +2 -0
- package/dist/css/syntax/styled/tags.js +22 -0
- package/dist/css/syntax/styled/template.js +10 -4
- package/dist/css/syntax/tailwind/tailwind.js +4 -4
- package/dist/css/value/check.d.ts +1 -1
- package/dist/css/value/check.js +1 -1
- package/dist/css/value/expression/arithmetic.d.ts +2 -2
- package/dist/css/value/expression/arithmetic.js +7 -3
- package/dist/css/value/expression/block.d.ts +2 -2
- package/dist/css/value/expression/block.js +4 -3
- package/dist/css/value/expression/conditional.d.ts +2 -2
- package/dist/css/value/expression/conditional.js +1 -1
- package/dist/css/value/expression/index.d.ts +2 -2
- package/dist/css/value/expression/index.js +10 -6
- package/dist/css/value/expression/map.d.ts +2 -2
- package/dist/css/value/expression/map.js +2 -2
- package/dist/css/value/object/index.d.ts +2 -2
- package/dist/css/value/object/index.js +14 -4
- package/dist/css/value/object/members.d.ts +2 -2
- package/dist/css/value/object/node.js +9 -4
- package/dist/css/value/object/path.d.ts +3 -3
- package/dist/css/value/object/path.js +10 -4
- package/dist/css/value/pieces.d.ts +3 -3
- package/dist/css/value/pieces.js +14 -4
- package/dist/css/value/resolve.js +15 -5
- package/dist/css/value/scope.d.ts +3 -2
- package/dist/css/value/scope.js +25 -7
- package/dist/css/value/substitute.js +43 -11
- package/dist/entities/architecture.d.ts +28 -25
- package/dist/entities/ast/assignments-raw.d.ts +1 -1
- package/dist/entities/ast/assignments-raw.js +61 -8
- package/dist/entities/ast/assignments-tagged.d.ts +1 -1
- package/dist/entities/ast/assignments-tagged.js +22 -7
- package/dist/entities/ast/assignments.d.ts +1 -1
- package/dist/entities/ast/assignments.js +6 -4
- package/dist/entities/ast/branches.d.ts +1 -1
- package/dist/entities/ast/calls.d.ts +1 -1
- package/dist/entities/ast/calls.js +19 -3
- package/dist/entities/ast/classes.d.ts +1 -1
- package/dist/entities/ast/classes.js +5 -1
- package/dist/entities/ast/comments.d.ts +3 -2
- package/dist/entities/ast/comments.js +47 -17
- package/dist/entities/ast/declaration.d.ts +1 -1
- package/dist/entities/ast/depth.d.ts +2 -2
- package/dist/entities/ast/depth.js +32 -15
- package/dist/entities/ast/enums.d.ts +1 -1
- package/dist/entities/ast/export-chain.d.ts +15 -0
- package/dist/entities/ast/export-chain.js +171 -0
- package/dist/entities/ast/file-exports.d.ts +1 -1
- package/dist/entities/ast/file-exports.js +26 -3
- package/dist/entities/ast/file-facts.d.ts +6 -3
- package/dist/entities/ast/file-facts.js +33 -4
- package/dist/entities/ast/file-imports.d.ts +1 -1
- package/dist/entities/ast/file-imports.js +26 -3
- package/dist/entities/ast/file.d.ts +2 -2
- package/dist/entities/ast/file.js +2 -1
- package/dist/entities/ast/functions.d.ts +1 -1
- package/dist/entities/ast/functions.js +13 -4
- package/dist/entities/ast/heritage.d.ts +1 -1
- package/dist/entities/ast/heritage.js +9 -1
- package/dist/entities/ast/index.d.ts +6 -3
- package/dist/entities/ast/index.js +82 -26
- package/dist/entities/ast/kind.d.ts +1 -1
- package/dist/entities/ast/kind.js +7 -1
- package/dist/entities/ast/modifiers.d.ts +1 -1
- package/dist/entities/ast/modifiers.js +4 -4
- package/dist/entities/ast/project.js +33 -2
- package/dist/entities/ast/properties.d.ts +1 -1
- package/dist/entities/ast/properties.js +10 -5
- package/dist/entities/ast/resolve.d.ts +1 -1
- package/dist/entities/ast/resolve.js +21 -11
- package/dist/entities/ast/tree.d.ts +4 -2
- package/dist/entities/ast/tree.js +184 -17
- package/dist/entities/ast/types.d.ts +1 -1
- package/dist/entities/ast/types.js +2 -1
- package/dist/entities/ast/usage.d.ts +1 -1
- package/dist/entities/ast/usage.js +1 -1
- package/dist/entities/ast/variables.d.ts +1 -1
- package/dist/entities/context.d.ts +4 -4
- package/dist/entities/facts.d.ts +36 -13
- package/dist/entities/findings.d.ts +3 -3
- package/dist/entities/kinds.d.ts +1 -1
- package/dist/entities/kinds.js +148 -37
- package/dist/entities/location/homes.d.ts +10 -10
- package/dist/entities/location/homes.js +74 -48
- package/dist/entities/location/place.d.ts +1 -1
- package/dist/entities/location/place.js +10 -3
- package/dist/entities/location/where.d.ts +10 -8
- package/dist/entities/location/where.js +89 -30
- package/dist/entities/location.d.ts +3 -3
- package/dist/entities/location.js +17 -17
- package/dist/entities/operators.js +1 -1
- package/dist/entities/overview/data.d.ts +6 -6
- package/dist/entities/overview/decision.d.ts +11 -11
- package/dist/entities/overview/finding.d.ts +10 -10
- package/dist/entities/overview/graph.d.ts +28 -11
- package/dist/entities/overview/input.d.ts +2 -2
- package/dist/entities/overview/summaries.d.ts +17 -15
- package/dist/entities/queries.d.ts +1 -1
- package/dist/entities/queries.js +89 -19
- package/dist/entities/repair.d.ts +1 -1
- package/dist/entities/repair.js +8 -2
- package/dist/entities/schema.d.ts +17 -3
- package/dist/entities/schema.js +74 -16
- package/dist/entities/story.d.ts +5 -5
- package/dist/entities/structure-facts.d.ts +1 -1
- package/dist/entities/token.d.ts +4 -4
- package/dist/entities/tree/build.d.ts +4 -3
- package/dist/entities/tree/build.js +112 -51
- package/dist/entities/tree/entries.d.ts +4 -4
- package/dist/entities/tree/entries.js +41 -16
- package/dist/entities/tree/index.d.ts +2 -2
- package/dist/entities/tree/index.js +1 -1
- package/dist/entities/tree/match.d.ts +2 -2
- package/dist/entities/tree/match.js +26 -12
- package/dist/fa-index.d.ts +16 -0
- package/dist/fa-index.js +165 -0
- package/dist/fa-open.d.ts +51 -0
- package/dist/fa-open.js +242 -0
- package/dist/fa-store.d.ts +22 -0
- package/dist/fa-store.js +232 -0
- package/dist/fa-values.d.ts +37 -0
- package/dist/fa-values.js +104 -0
- package/dist/facts-record.d.ts +45 -0
- package/dist/facts-record.js +297 -0
- package/dist/frameworks/angular/index.d.ts +2 -2
- package/dist/frameworks/angular/index.js +2 -1
- package/dist/frameworks/facet.d.ts +3 -1
- package/dist/frameworks/facet.js +13 -0
- package/dist/frameworks/index.d.ts +1 -1
- package/dist/frameworks/index.js +25 -11
- package/dist/frameworks/react/index.d.ts +2 -2
- package/dist/frameworks/react/index.js +33 -10
- package/dist/frameworks/test/index.d.ts +6 -0
- package/dist/frameworks/test/index.js +157 -0
- package/dist/frameworks/vue/index.d.ts +2 -2
- package/dist/frameworks/vue/index.js +2 -1
- package/dist/ignore.d.ts +3 -0
- package/dist/ignore.js +62 -0
- package/dist/index-file.d.ts +43 -0
- package/dist/index-file.js +218 -0
- package/dist/index-run.d.ts +39 -0
- package/dist/index-run.js +217 -0
- package/dist/index-zone.d.ts +25 -0
- package/dist/index-zone.js +219 -0
- package/dist/main.d.ts +5 -2
- package/dist/main.js +223 -41
- package/dist/nodes/child-entities.d.ts +3 -0
- package/dist/nodes/child-entities.js +12 -0
- package/dist/nodes/children.d.ts +4 -4
- package/dist/nodes/children.js +64 -11
- package/dist/nodes/finally/emit.d.ts +4 -4
- package/dist/nodes/finally/emit.js +26 -10
- package/dist/nodes/finally/entities.d.ts +13 -0
- package/dist/nodes/finally/entities.js +42 -0
- package/dist/nodes/finally/index.d.ts +6 -6
- package/dist/nodes/finally/index.js +8 -8
- package/dist/nodes/finally/queries.d.ts +2 -2
- package/dist/nodes/finally/queries.js +7 -4
- package/dist/nodes/finally/relations-access.d.ts +2 -2
- package/dist/nodes/finally/relations-access.js +22 -18
- package/dist/nodes/finally/relations-edge.d.ts +5 -5
- package/dist/nodes/finally/relations-edge.js +67 -44
- package/dist/nodes/finally/relations-group.d.ts +7 -7
- package/dist/nodes/finally/relations-group.js +28 -25
- package/dist/nodes/finally/relations.d.ts +2 -2
- package/dist/nodes/finally/relations.js +16 -12
- package/dist/nodes/finally/required.d.ts +3 -3
- package/dist/nodes/finally/required.js +9 -7
- package/dist/nodes/finally/violation.d.ts +2 -2
- package/dist/nodes/similar.d.ts +3 -3
- package/dist/nodes/similar.js +78 -56
- package/dist/piece-forms.d.ts +9 -0
- package/dist/piece-forms.js +68 -0
- package/dist/{pipeline-roles.d.ts → pipeline-entities.d.ts} +2 -2
- package/dist/{pipeline-roles.js → pipeline-entities.js} +32 -28
- package/dist/pipeline-facts.d.ts +4 -3
- package/dist/pipeline-facts.js +64 -62
- package/dist/{pipeline-unroled.d.ts → pipeline-unclassified.d.ts} +2 -2
- package/dist/{pipeline-unroled.js → pipeline-unclassified.js} +58 -63
- package/dist/pipeline.d.ts +1 -1
- package/dist/pipeline.js +19 -64
- package/dist/release-file.d.ts +3 -0
- package/dist/release-file.js +13 -0
- package/dist/report/asks.d.ts +3 -3
- package/dist/report/asks.js +16 -6
- package/dist/report/configErrors.d.ts +55 -27
- package/dist/report/configErrors.js +81 -35
- package/dist/report/errorTypes/codes/structure.d.ts +1 -1
- package/dist/report/errorTypes/codes/structure.js +9 -9
- package/dist/report/errorTypes/decision-maker.d.ts +5 -5
- package/dist/report/errorTypes/decision-maker.js +21 -11
- package/dist/report/errorTypes/destinations.d.ts +5 -5
- package/dist/report/errorTypes/destinations.js +52 -34
- package/dist/report/errorTypes/finding-type.d.ts +3 -3
- package/dist/report/errorTypes/index.d.ts +1 -1
- package/dist/report/errorTypes/index.js +17 -7
- package/dist/report/errorTypes/types/fileContents.d.ts +4 -4
- package/dist/report/errorTypes/types/fileContents.js +11 -5
- package/dist/report/errorTypes/types/unknownEntity.d.ts +9 -0
- package/dist/report/errorTypes/types/{unknownRole.js → unknownEntity.js} +12 -7
- package/dist/report/errorTypes/types/wrongAction.d.ts +5 -5
- package/dist/report/errorTypes/types/wrongAction.js +18 -13
- package/dist/report/errorTypes/types/wrongPlacement.d.ts +4 -4
- package/dist/report/errorTypes/types/wrongPlacement.js +19 -9
- package/dist/report/errorTypes/vocabulary/ids.d.ts +2 -2
- package/dist/report/errorTypes/vocabulary/ids.js +3 -3
- package/dist/report/errorTypes/vocabulary/phrases.d.ts +2 -2
- package/dist/report/errorTypes/vocabulary/phrases.js +39 -26
- package/dist/report/errorTypes/vocabulary/places.d.ts +3 -3
- package/dist/report/errorTypes/vocabulary/places.js +13 -13
- package/dist/report/finding-from.d.ts +3 -3
- package/dist/report/finding-from.js +14 -9
- package/dist/report/notices.d.ts +6 -1
- package/dist/report/notices.js +46 -20
- package/dist/report/observed.d.ts +19 -0
- package/dist/report/observed.js +87 -0
- package/dist/report/render-report.d.ts +1 -1
- package/dist/report/render-report.js +33 -30
- package/dist/report/user-report/build/bundle.js +26 -7
- package/dist/report/user-report/build/bundle.prebuilt.js +799 -297
- package/dist/report/user-report/data/collect.d.ts +2 -2
- package/dist/report/user-report/data/collect.js +32 -19
- package/dist/report/user-report/data/entities.d.ts +7 -0
- package/dist/report/user-report/data/{roles.js → entities.js} +27 -22
- package/dist/report/user-report/data/{role-examples.d.ts → entity-examples.d.ts} +3 -3
- package/dist/report/user-report/data/entity-examples.js +136 -0
- package/dist/report/user-report/data/{role-filters.d.ts → entity-filters.d.ts} +2 -2
- package/dist/report/user-report/data/{role-filters.js → entity-filters.js} +7 -7
- package/dist/report/user-report/data/entity-marks.d.ts +5 -0
- package/dist/report/user-report/data/{role-marks.js → entity-marks.js} +11 -11
- package/dist/report/user-report/data/file-tree.d.ts +3 -3
- package/dist/report/user-report/data/file-tree.js +13 -5
- package/dist/report/user-report/data/finding-boundary.d.ts +4 -4
- package/dist/report/user-report/data/finding-boundary.js +2 -2
- package/dist/report/user-report/data/finding-plan.d.ts +5 -5
- package/dist/report/user-report/data/finding-plan.js +10 -10
- package/dist/report/user-report/data/finding-title.d.ts +2 -2
- package/dist/report/user-report/data/finding-title.js +8 -8
- package/dist/report/user-report/data/findings.d.ts +4 -4
- package/dist/report/user-report/data/findings.js +30 -20
- package/dist/report/user-report/data/graph-edges.d.ts +4 -4
- package/dist/report/user-report/data/graph-edges.js +19 -19
- package/dist/report/user-report/data/graph-entities.d.ts +6 -0
- package/dist/report/user-report/data/graph-entities.js +158 -0
- package/dist/report/user-report/data/graph-helpers.d.ts +5 -5
- package/dist/report/user-report/data/graph-helpers.js +15 -15
- package/dist/report/user-report/data/graph.d.ts +5 -4
- package/dist/report/user-report/data/graph.js +28 -21
- package/dist/report/user-report/data/nodes.d.ts +2 -2
- package/dist/report/user-report/data/nodes.js +33 -23
- package/dist/report/user-report/data/rules.d.ts +7 -0
- package/dist/report/user-report/data/{invariants.js → rules.js} +13 -13
- package/dist/report/user-report/data/scan.d.ts +1 -1
- package/dist/report/user-report/data/scan.js +19 -9
- package/dist/report/user-report/html/shell.d.ts +1 -1
- package/dist/report/user-report/html/shell.js +1 -1
- package/dist/report/user-report/index.d.ts +1 -1
- package/dist/report/user-report/index.js +17 -7
- package/dist/report/user-report/shared/describe.d.ts +1 -1
- package/dist/report/user-report/shared/describe.js +6 -6
- package/dist/rules/index.d.ts +7 -0
- package/dist/{invariants → rules}/index.js +85 -57
- package/dist/{invariants → rules}/list-vars.d.ts +2 -2
- package/dist/{invariants → rules}/list-vars.js +9 -3
- package/dist/{invariants → rules}/name.js +2 -2
- package/dist/rules/normalize.d.ts +5 -0
- package/dist/rules/normalize.js +108 -0
- package/dist/{invariants → rules}/vars.d.ts +9 -7
- package/dist/{invariants → rules}/vars.js +5 -5
- package/dist/scan-run.d.ts +20 -0
- package/dist/scan-run.js +130 -0
- package/dist/scripts/audit-report.js +19 -9
- package/dist/usage-index.d.ts +4 -0
- package/dist/usage-index.js +282 -0
- package/dist/usage-mode.d.ts +7 -0
- package/dist/usage-mode.js +16 -0
- package/dist/usage-pass.d.ts +19 -0
- package/dist/usage-pass.js +136 -0
- package/dist/usage-prepare.d.ts +2 -0
- package/dist/usage-prepare.js +22 -0
- package/dist/usage-sweep.d.ts +10 -0
- package/dist/usage-sweep.js +264 -0
- package/dist/utils/aliases.d.ts +22 -0
- package/dist/utils/aliases.js +173 -0
- package/dist/utils/classify.d.ts +2 -2
- package/dist/utils/classify.js +4 -4
- package/dist/utils/configs.js +17 -7
- package/dist/utils/distinct.js +4 -2
- package/dist/utils/files.js +41 -37
- package/dist/utils/fixpoint.js +2 -2
- package/dist/utils/host.d.ts +1 -1
- package/dist/utils/host.js +4 -1
- package/dist/utils/imports.js +83 -19
- package/dist/utils/keyed.js +2 -2
- package/dist/utils/map-record.js +2 -2
- package/dist/utils/packages.d.ts +15 -0
- package/dist/utils/packages.js +207 -0
- package/dist/utils/path-label.js +3 -1
- package/dist/utils/pattern.d.ts +5 -4
- package/dist/utils/pattern.js +55 -15
- package/dist/utils/permission.d.ts +3 -3
- package/dist/utils/permission.js +4 -2
- package/dist/utils/plural.js +2 -2
- package/dist/utils/qualified.js +4 -4
- package/dist/utils/rank.js +2 -2
- package/dist/utils/record.js +1 -1
- package/dist/utils/search.js +7 -2
- package/dist/utils/speak.js +1 -1
- package/dist/utils/split.js +14 -1
- package/dist/utils/template.d.ts +1 -1
- package/dist/utils/template.js +1 -1
- package/dist/utils/tokenize.js +6 -1
- package/dist/utils/typed-field.js +2 -2
- package/dist/utils/verdicts.js +1 -1
- package/entities/operators.ts +1 -1
- package/package.json +101 -90
- package/report/errorTypes/vocabulary/ids.ts +7 -2
- package/report/errorTypes/vocabulary/phrases.ts +47 -27
- package/report/errorTypes/vocabulary/places.ts +21 -16
- package/report/user-report/shared/describe.ts +7 -7
- package/dist/code-roles/classify.d.ts +0 -11
- package/dist/code-roles/classify.js +0 -43
- package/dist/code-roles/connector.d.ts +0 -5
- package/dist/code-roles/connector.js +0 -114
- package/dist/code-roles/project.d.ts +0 -12
- package/dist/code-roles/project.js +0 -122
- package/dist/code-roles/roles.d.ts +0 -8
- package/dist/invariants/index.d.ts +0 -6
- package/dist/invariants/normalize.d.ts +0 -4
- package/dist/invariants/normalize.js +0 -95
- package/dist/nodes/child-roles.d.ts +0 -3
- package/dist/nodes/child-roles.js +0 -12
- package/dist/nodes/finally/roles.d.ts +0 -13
- package/dist/nodes/finally/roles.js +0 -41
- package/dist/report/errorTypes/types/unknownRole.d.ts +0 -9
- package/dist/report/user-report/data/graph-roles.d.ts +0 -5
- package/dist/report/user-report/data/graph-roles.js +0 -71
- package/dist/report/user-report/data/invariants.d.ts +0 -7
- package/dist/report/user-report/data/role-examples.js +0 -94
- package/dist/report/user-report/data/role-marks.d.ts +0 -5
- package/dist/report/user-report/data/roles.d.ts +0 -7
- /package/dist/{invariants → rules}/name.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
# follow-architecture
|
|
1
|
+
# @md-code/follow-architecture
|
|
2
2
|
|
|
3
|
-
ESLint rule + CLI that validates code against a declarative architecture. The plugin
|
|
3
|
+
ESLint rule + CLI that validates code against a declarative architecture. The plugin
|
|
4
|
+
knows nothing about your project — everything (paths, names, rules, fixes) lives in
|
|
5
|
+
`architecture.yaml`.
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
It collects **facts** from the AST (ts-morph, plus one reader per non-TypeScript
|
|
8
|
+
language) and evaluates **filters** (Keystone-GraphQL-style) against them. There are
|
|
9
|
+
no named rule kinds and no semantic predicates inside the plugin: all law lives in
|
|
10
|
+
the YAML.
|
|
6
11
|
|
|
7
|
-
Three chunks are what you AUTHOR, and each
|
|
8
|
-
files — they do not mix:
|
|
12
|
+
Three chunks are what you AUTHOR, and each one answers a different question about
|
|
13
|
+
the same files — they do not mix:
|
|
9
14
|
|
|
10
15
|
| chunk | YAML key | folder | answers |
|
|
11
16
|
| --- | --- | --- | --- |
|
|
12
|
-
| nodes | `nodes` | [nodes/](nodes) | where files may live, what names they may have, and which
|
|
13
|
-
|
|
|
14
|
-
|
|
|
17
|
+
| nodes | `nodes` | [nodes/](nodes) | where files may live, what names they may have, and which entity each child holds |
|
|
18
|
+
| entities | `entities` | [code-entities/](code-entities) | what a piece of code *is* (atom, handler, theme, barrel, …) and what may be done with it — never where it lives |
|
|
19
|
+
| rules | `rules` | [rules/](rules) | what a file may contain |
|
|
15
20
|
|
|
16
|
-
`aliases` maps import sources to paths so the three can resolve imports; it is
|
|
21
|
+
`aliases` maps import sources to repo paths so the three can resolve imports; it is
|
|
17
22
|
the only other key in the file.
|
|
18
23
|
|
|
19
24
|
```mermaid
|
|
@@ -23,136 +28,222 @@ flowchart LR
|
|
|
23
28
|
subgraph F["filter"]
|
|
24
29
|
direction TB
|
|
25
30
|
N["nodes"]
|
|
26
|
-
R["
|
|
27
|
-
I["
|
|
31
|
+
R["entities"]
|
|
32
|
+
I["rules"]
|
|
28
33
|
end
|
|
29
34
|
F --> O["Report"]
|
|
30
35
|
```
|
|
31
36
|
|
|
32
|
-
Everything else in this repository is the engine that answers those questions —
|
|
33
|
-
|
|
37
|
+
Everything else in this repository is the engine that answers those questions — it
|
|
38
|
+
carries no project knowledge.
|
|
34
39
|
|
|
35
|
-
##
|
|
36
|
-
|
|
37
|
-
Pick your runner:
|
|
38
|
-
|
|
39
|
-
<details open>
|
|
40
|
-
<summary><b>bunx</b></summary>
|
|
40
|
+
## Install
|
|
41
41
|
|
|
42
42
|
```sh
|
|
43
|
-
|
|
44
|
-
# exit 1 when findings exist (CI):
|
|
45
|
-
bunx follow-architecture --config architecture.yaml --check
|
|
46
|
-
# interactive, self-contained HTML overview (structure · roles · graph · findings):
|
|
47
|
-
bunx follow-architecture --config architecture.yaml --overview reports/architecture-overview.html
|
|
43
|
+
pnpm add -D @md-code/follow-architecture
|
|
48
44
|
```
|
|
49
45
|
|
|
50
|
-
|
|
46
|
+
| Package | Where it comes from | Why |
|
|
47
|
+
| --- | --- | --- |
|
|
48
|
+
| `@md-code/utils` | `dependencies` | shared repo-root, walk and index helpers (installed for you) |
|
|
49
|
+
| `ts-morph`, `@typescript-eslint/parser` | `dependencies` | every file is read with the TypeScript compiler API |
|
|
50
|
+
| `js-yaml`, `minimatch`, `remeda` | `dependencies` | the architecture file, the globs, the pipeline |
|
|
51
|
+
| `postcss`, `postcss-scss`, `postcss-selector-parser`, `postcss-value-parser`, `stylis`, `css-tree`, `tailwindcss` | `dependencies` | the CSS and class-list facts (a styles contract can be part of the architecture) |
|
|
52
|
+
| `highlight.js` | `dependencies` | code panels in the `--overview` page |
|
|
53
|
+
| `eslint` | peer `>=8.40.0` | the rule is an ESLint rule; bring your own ESLint |
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
Node `>=18`. The interactive overview ships prebuilt inside `dist/`: React,
|
|
56
|
+
`styled-components`, `@md-code/sections` and `esbuild` are `devDependencies` here and
|
|
57
|
+
are never needed by a published install.
|
|
54
58
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
Minimal configuration — one ESLint rule, one YAML file:
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
// eslint.config.js
|
|
63
|
+
const followArchitecture = require("@md-code/follow-architecture");
|
|
64
|
+
|
|
65
|
+
module.exports = [
|
|
66
|
+
{
|
|
67
|
+
files: ["**/*.ts", "**/*.tsx"],
|
|
68
|
+
plugins: { "md-code": followArchitecture },
|
|
69
|
+
rules: {
|
|
70
|
+
// The option is the architecture file's path, relative to the repo root.
|
|
71
|
+
// The rule walks up from each linted file to find it, so the same config
|
|
72
|
+
// works in any package of a monorepo.
|
|
73
|
+
"md-code/follow-architecture": ["error", { config: "architecture.yaml" }],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
];
|
|
61
77
|
```
|
|
62
78
|
|
|
63
|
-
|
|
79
|
+
`require("@md-code/follow-architecture")` **is** the plugin (`{ meta, rules }`); there
|
|
80
|
+
is no `flatConfig` helper to call, and no per-project code in the package.
|
|
64
81
|
|
|
65
|
-
|
|
66
|
-
<summary><b>npx</b></summary>
|
|
82
|
+
## Quick start
|
|
67
83
|
|
|
68
84
|
```sh
|
|
85
|
+
# the report to stdout (exit 1 with findings under --check):
|
|
69
86
|
npx follow-architecture --config architecture.yaml --out reports/follow-architecture.md
|
|
70
|
-
# exit 1 when findings exist (CI):
|
|
71
87
|
npx follow-architecture --config architecture.yaml --check
|
|
72
|
-
|
|
88
|
+
|
|
89
|
+
# the interactive, self-contained HTML overview:
|
|
73
90
|
npx follow-architecture --config architecture.yaml --overview reports/architecture-overview.html
|
|
74
91
|
```
|
|
75
92
|
|
|
76
|
-
|
|
93
|
+
From this repository, build the package once and drive its `bin/` entry:
|
|
77
94
|
|
|
78
|
-
|
|
95
|
+
```sh
|
|
96
|
+
pnpm build
|
|
97
|
+
node dist/bin/follow-architecture.js --config architecture.yaml --out reports/follow-architecture.md
|
|
98
|
+
node dist/bin/follow-architecture.js --config architecture.yaml --check
|
|
99
|
+
node dist/bin/follow-architecture.js --config architecture.yaml --overview
|
|
100
|
+
```
|
|
79
101
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
102
|
+
Run the `bin/` entry, not `dist/main.js`: `main.js` is the module the `bin` script
|
|
103
|
+
calls — `node dist/main.js` exits 0 and prints nothing.
|
|
104
|
+
|
|
105
|
+
A full walk of this monorepo can exhaust Node's default heap, which is why the
|
|
106
|
+
package's own product-lint script raises it
|
|
107
|
+
(`NODE_OPTIONS=--max-old-space-size=13312` in `lint:products`).
|
|
108
|
+
|
|
109
|
+
## Command line
|
|
110
|
+
|
|
111
|
+
```sh
|
|
112
|
+
follow-architecture [--config <path>] [--cwd <dir>] [--ext <.ext>]... [--ignore <glob>]...
|
|
113
|
+
[--ignore-dir <name>]... [--files <path>]... [--out <path>] [--overview [path]]
|
|
114
|
+
[--index <path|off>] [--usage <checker|index>]
|
|
115
|
+
[--barrel-depth <n>] [--check]
|
|
83
116
|
```
|
|
84
117
|
|
|
118
|
+
| Flag | Meaning |
|
|
119
|
+
| --- | --- |
|
|
120
|
+
| `--config <path>` | The architecture file. Default `architecture.yaml` |
|
|
121
|
+
| `--cwd <dir>` | Where the scan begins, and the anchor `--config` is resolved against |
|
|
122
|
+
| `--ext <.ext>` | Add a source extension (repeatable, on top of the built-in list) |
|
|
123
|
+
| `--ignore <glob>` | Repo-relative glob not read (repeatable) |
|
|
124
|
+
| `--ignore-dir <name>` | Do not enter this folder (repeatable, any depth) |
|
|
125
|
+
| `--files <path>` | Check only this file or folder (repeatable). The tree is still walked, so imports resolve across it |
|
|
126
|
+
| `--out <path>` | Write the text report here; without it the report goes to stdout |
|
|
127
|
+
| `--overview [path]` | Write the self-contained HTML overview; alone it writes `architecture-overview.html` at the repo root |
|
|
128
|
+
| `--index <path\|off>` | Where the run's index lives, or `off` for a run that neither reads nor writes one |
|
|
129
|
+
| `--usage <checker\|index>` | Who answers `references`: the type checker (default, exact) or an occurrence index (cheaper, approximate) |
|
|
130
|
+
| `--barrel-depth <n>` | How many barrels a name may pass through while the run looks for the file that DECLARES it (default `8`, integer ≥ 1) |
|
|
131
|
+
| `--check` | Exit 1 when there is at least one finding |
|
|
132
|
+
| `--help`, `-h` | Print the usage line |
|
|
133
|
+
|
|
134
|
+
There is no `--roots`: the scan starts at the repo root (or `--cwd`); `--ignore`,
|
|
135
|
+
`--ignore-dir` and `--ext` narrow what is walked, and `--files` narrows what is
|
|
136
|
+
checked. A flag that takes a value consumes the next argument; `--overview` alone
|
|
137
|
+
takes none. The scan scope is the TOOL's, never the YAML's.
|
|
138
|
+
|
|
139
|
+
### Exit codes
|
|
140
|
+
|
|
141
|
+
| Code | Meaning |
|
|
142
|
+
| --- | --- |
|
|
143
|
+
| `0` | The run finished and (with `--check`) no finding was produced |
|
|
144
|
+
| `1` | `--check` and at least one finding, an unreadable/invalid `architecture.yaml`, or an internal crash |
|
|
145
|
+
|
|
146
|
+
Without `--check` findings never change the exit code — the CLI is a report
|
|
147
|
+
generator; the ESLint rule is what fails a build. A config mistake prints one
|
|
148
|
+
sentence naming what the file claims and what it may claim instead; anything else
|
|
149
|
+
prints `follow-architecture: the run failed for a reason that is not in the
|
|
150
|
+
architecture` with its stack.
|
|
151
|
+
|
|
152
|
+
### Which paths are relative to what
|
|
153
|
+
|
|
154
|
+
| Value | Resolved against |
|
|
155
|
+
| --- | --- |
|
|
156
|
+
| `--config`, `--cwd` | the process working directory |
|
|
157
|
+
| `--out` | the process working directory |
|
|
158
|
+
| `--overview` | the **repo root** (the directory of the resolved `--config`, or `--cwd` when given) |
|
|
159
|
+
| `--index`, rule option `indexPath` | the repo root (absolute paths used as given) |
|
|
160
|
+
| rule option `exportPath` | the repo root |
|
|
161
|
+
| `--files`, `--ignore`, `--ignore-dir` | the repo root |
|
|
162
|
+
|
|
163
|
+
The repo root is where the architecture file lives — the SAME anchor the ESLint rule
|
|
164
|
+
uses — so `--config ../arch.yaml` scans the repo that file describes. An explicit
|
|
165
|
+
`--cwd` overrides that anchor. The root is canonicalised (`fs.realpathSync`) before
|
|
166
|
+
it becomes a path, so the index, its header and every absolute path in it agree even
|
|
167
|
+
when the same directory is reachable under a symlinked spelling.
|
|
168
|
+
|
|
169
|
+
### `--config` discovery
|
|
170
|
+
|
|
171
|
+
`--config <path>` is the only way to name the architecture file; the default is
|
|
172
|
+
`architecture.yaml` in the working directory. The file may be YAML or JSON
|
|
173
|
+
(`architecture.yaml`, `architecture.yml`, `architecture.json`) — the same file the
|
|
174
|
+
ESLint rule reads through its `config` option, and which file was loaded is visible
|
|
175
|
+
in the report and in every finding.
|
|
176
|
+
|
|
85
177
|
## `architecture.yaml`
|
|
86
178
|
|
|
87
|
-
|
|
88
|
-
|
|
179
|
+
Four keys, nothing else:
|
|
180
|
+
|
|
181
|
+
| Key | Answers | Chapter |
|
|
182
|
+
| --- | --- | --- |
|
|
183
|
+
| `aliases` | which repo path an import specifier names | [Aliases](#aliases) |
|
|
184
|
+
| `entities` | what a piece of code IS | [Code entities](#code-entities) |
|
|
185
|
+
| `nodes` | where code lives | [Nodes](#nodes) |
|
|
186
|
+
| `rules` | conditions a file must satisfy | [Rules](#rules) |
|
|
187
|
+
|
|
188
|
+
An unknown key — at the top level or inside an entry — is a config error that names
|
|
189
|
+
the allowed keys with their meanings, never a silent no-op.
|
|
190
|
+
|
|
191
|
+
Abridged from this repository's own file (every key shown is real; the comments and
|
|
192
|
+
the middle of each list are cut):
|
|
193
|
+
|
|
194
|
+
```yaml
|
|
89
195
|
aliases:
|
|
90
|
-
|
|
196
|
+
"@md-code/components": packages/components
|
|
197
|
+
"@md/styles": packages/styles/index.ts
|
|
91
198
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
name: apps/backend # path segment (or prefix); {name} placeholders capture segments
|
|
96
|
-
parent: root
|
|
97
|
-
closed: true # a file directly inside must match one of children
|
|
98
|
-
report: # finding text for "file does not belong here"
|
|
99
|
-
message: "…"
|
|
100
|
-
fix: "…"
|
|
101
|
-
children:
|
|
102
|
-
- index.ts
|
|
103
|
-
- "{kebab-case}.ts" # name template; {kebab-case} matches kebab-case text
|
|
104
|
-
- name: "{kebab-case}"
|
|
105
|
-
forbidden: true # a shape that must NEVER exist
|
|
106
|
-
report: { message: "…", fix: "…" }
|
|
107
|
-
- name: store.ts
|
|
108
|
-
required: true # without it the folder is not this node at all
|
|
109
|
-
|
|
110
|
-
# what a declaration is: a LIST of roles, first `infer` filter that matches wins
|
|
111
|
-
codeRoles:
|
|
112
|
-
- slug: storeModel
|
|
113
|
-
name: store model
|
|
114
|
-
# The chain roots that REACH this role without an import
|
|
115
|
-
# (mobx-state-tree's getRoot/getParent). Each entry is structured:
|
|
116
|
-
# `kind` is the base shape of the chain — call / identifier / methodCall —
|
|
117
|
-
# and `segments` is the callee (or base + leading properties).
|
|
118
|
-
# Per-role on purpose: different roles are reached differently.
|
|
199
|
+
entities:
|
|
200
|
+
- slug: barrel
|
|
201
|
+
name: barrel
|
|
119
202
|
infer:
|
|
120
|
-
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
# what a file may contain
|
|
130
|
-
invariants:
|
|
131
|
-
- id: no-any
|
|
132
|
-
where: ["**/*.ts"] # globs or { node: slug }; empty/omitted = all files
|
|
133
|
-
ignore: ["**/*.test.ts"] # same entry interface: glob or { node: slug }
|
|
134
|
-
when: # optional gate: a plain filter over the file facts
|
|
135
|
-
roles: { any: { equals: orchestrator } } # e.g. "a role is present"
|
|
136
|
-
infer: # a finding when a filter MATCHES the facts
|
|
203
|
+
- exports:
|
|
204
|
+
length: { gt: 0 }
|
|
205
|
+
none:
|
|
206
|
+
or:
|
|
207
|
+
- form: { in: [equals, commonjs] }
|
|
208
|
+
- and:
|
|
209
|
+
- form: { equals: default }
|
|
210
|
+
- from: { isSet: false }
|
|
137
211
|
- kind:
|
|
138
212
|
descendants:
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
213
|
+
none: { is: { in: [FunctionDeclaration, ArrowFunction, ClassDeclaration, VariableDeclaration] } }
|
|
214
|
+
- location: { fileName: { equals: index } }
|
|
215
|
+
actions:
|
|
216
|
+
import: { where: [{ node: root }] }
|
|
217
|
+
mutate: { where: [{ entity: testCode }] }
|
|
218
|
+
declare: { where: [{ entity: barrel }] }
|
|
219
|
+
report:
|
|
220
|
+
description: "A barrel re-exports a module's surface and declares nothing of its own; it is named `index` and a folder has one."
|
|
145
221
|
|
|
146
|
-
|
|
222
|
+
nodes:
|
|
223
|
+
- slug: components-atoms
|
|
224
|
+
name: atoms
|
|
225
|
+
parent: components
|
|
226
|
+
children:
|
|
227
|
+
- "{PascalCase}"
|
|
228
|
+
- { name: index.ts, entity: barrel }
|
|
147
229
|
|
|
148
|
-
|
|
149
|
-
-
|
|
150
|
-
|
|
230
|
+
rules:
|
|
231
|
+
- id: no-hidden-store
|
|
232
|
+
infer:
|
|
233
|
+
- mutable: { equals: true }
|
|
234
|
+
kind:
|
|
235
|
+
ancestors: { none: { is: { in: [FunctionDeclaration, Block, CaseClause, ModuleBlock] } } }
|
|
236
|
+
report:
|
|
237
|
+
code: rewrite
|
|
238
|
+
description: "`{what}` is a module-scope `let`/`var`: a store that outlives every call."
|
|
239
|
+
fix:
|
|
240
|
+
message: "Make it a `const`, or move the changing value into the function that owns it."
|
|
241
|
+
```
|
|
151
242
|
|
|
152
|
-
|
|
243
|
+
### Placeholders
|
|
153
244
|
|
|
154
|
-
A `{…}` in a path pattern is a **capture**,
|
|
155
|
-
|
|
245
|
+
A `{…}` in a path pattern is a **capture**, written IN the convention it asks for —
|
|
246
|
+
the convention is read off the name, so there is no list of known ones:
|
|
156
247
|
|
|
157
248
|
| write | matches |
|
|
158
249
|
| --- | --- |
|
|
@@ -164,476 +255,1223 @@ asks for — the convention is read off the name, so there is no list of known o
|
|
|
164
255
|
| `{PascalCase}`, `{Name}` | `TodoList` |
|
|
165
256
|
| `{Mixed_Name}` (states no convention) | anything but `/` — it captures and enforces nothing |
|
|
166
257
|
|
|
167
|
-
A placeholder may share a segment with literal text, so a test file is declared
|
|
168
|
-
|
|
169
|
-
|
|
258
|
+
A placeholder may share a segment with literal text, so a test file is declared next
|
|
259
|
+
to the code it tests: `{kebab-case}.spec.ts` matches `todo-list.spec.ts` and not
|
|
260
|
+
`todoList.spec.ts`; inside a segment, dots and other text are literal.
|
|
170
261
|
|
|
171
262
|
## Nodes
|
|
172
263
|
|
|
173
|
-
A **node** is a
|
|
264
|
+
A **node** is a place in the tree: a folder, or a file. Nodes reference each other by
|
|
265
|
+
`slug`; a node's path is its parent's path + its `name`. `name` may be a path
|
|
266
|
+
template (`packages/components/atoms`, `atoms/{PascalCase}`) and may start with `@`, which makes
|
|
267
|
+
it an alias specifier instead of a segment — `name: "@md-code/components"` puts the
|
|
268
|
+
node at the package's folder wherever the alias points.
|
|
174
269
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
270
|
+
| Key | Meaning |
|
|
271
|
+
| --- | --- |
|
|
272
|
+
| `slug` | the node's identifier, named by `parent` and by children |
|
|
273
|
+
| `name` | the path segment or path template this node matches |
|
|
274
|
+
| `parent` | the node this one sits under — one slug, or a list of them (one variant per parent) |
|
|
275
|
+
| `children` | the names, patterns and nodes this folder declares |
|
|
276
|
+
| `entity` | which entities this place is a home for (the whole folder, `**`) |
|
|
277
|
+
| `required` | whether this node must exist for its parent to be an instance |
|
|
278
|
+
| `report` | what to say when this node's structure is broken |
|
|
180
279
|
|
|
181
|
-
|
|
182
|
-
- a **string** — a name template (`{kebab-case}`, `*`, `?` work; a name without an extension is a folder, with an extension is a file, and a name may mix both — `{kebab-case}.spec.ts`);
|
|
183
|
-
- an **object** — `{ name, forbidden?, required?, report? }`. `forbidden: true` names a shape that must **never** exist; `required: true` names a shape that must **always** exist.
|
|
280
|
+
Any other key is an error, not a silent no-op.
|
|
184
281
|
|
|
185
|
-
|
|
282
|
+
### Closed lists
|
|
283
|
+
|
|
284
|
+
A node closes exactly what it declares, and nothing else:
|
|
285
|
+
|
|
286
|
+
| declared | the node is closed to |
|
|
287
|
+
| --- | --- |
|
|
288
|
+
| `children:` only | those NAMES — an entry it does not declare is reported with the place it belongs to |
|
|
289
|
+
| `entity:` only | those KINDS — names are free, and a piece of another kind is reported with the home it belongs to |
|
|
290
|
+
| both | both: the names, and the kinds of what they hold |
|
|
291
|
+
| neither | nothing — a folder that only passes structure through |
|
|
186
292
|
|
|
187
|
-
|
|
293
|
+
That is the whole of what a flag used to spell: the list you write is the close. Both
|
|
294
|
+
answers are needed because they catch different mistakes — a molecule in `atoms/` is
|
|
295
|
+
the `entity:` list's finding, a stray file beside the atoms is `children:`'s. A piece
|
|
296
|
+
no entity describes is left to the entity checks: silence there is the absence of a
|
|
297
|
+
question, not permission. The deepest matching node wins, so a nested node's list
|
|
298
|
+
governs its own folder.
|
|
188
299
|
|
|
189
|
-
A node
|
|
300
|
+
A node may also carry `required: true`, which makes the folder an instance of the
|
|
301
|
+
node only when the node itself is present.
|
|
190
302
|
|
|
191
|
-
|
|
192
|
-
|
|
303
|
+
### Children
|
|
304
|
+
|
|
305
|
+
Each entry of `children` is either a name template (`"*.d.ts"`, `"{PascalCase}"`,
|
|
306
|
+
`atoms`) or a spec:
|
|
307
|
+
|
|
308
|
+
| Key | Meaning |
|
|
309
|
+
| --- | --- |
|
|
310
|
+
| `name` | the child's name or path pattern |
|
|
311
|
+
| `node` | borrow another declared node's own pattern |
|
|
312
|
+
| `entity` | which entities this child is a home for |
|
|
313
|
+
| `required` | the child must be present, or the folder is not this node |
|
|
314
|
+
| `forbidden` | the child must be absent |
|
|
315
|
+
| `query` | a filter over the file's facts that recognises the child, whatever it is called |
|
|
316
|
+
| `report` | what to say when this child's rule is broken |
|
|
317
|
+
|
|
318
|
+
A name without an extension is a folder, with an extension a file. Real entries from
|
|
319
|
+
this repo:
|
|
193
320
|
|
|
194
321
|
```yaml
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
322
|
+
- slug: components-atoms
|
|
323
|
+
name: atoms
|
|
324
|
+
parent: components
|
|
325
|
+
children:
|
|
326
|
+
- "{PascalCase}" # one folder per atom
|
|
327
|
+
- { name: index.ts, entity: barrel }
|
|
328
|
+
|
|
329
|
+
- slug: components-atom
|
|
330
|
+
name: "{PascalCase}"
|
|
331
|
+
parent: components-atoms
|
|
332
|
+
entity: [atom, barrel, styleBlock, data, pureFunction, class, constant, sharedTypes, handler, state, testCode]
|
|
203
333
|
```
|
|
204
334
|
|
|
205
|
-
`
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
335
|
+
`atoms/` declares its children and nothing else, so an undeclared folder beside the
|
|
336
|
+
atoms is a finding; an
|
|
337
|
+
atom's own folder declares the kinds it may hold, so a molecule inside it is a
|
|
338
|
+
finding. `query` is how a file is routed when its NAME says nothing: a file that
|
|
339
|
+
matches the child's query but sits elsewhere is told the folder it belongs to.
|
|
340
|
+
|
|
341
|
+
A missing `required` child makes the folder "not an instance of that node" — reported
|
|
342
|
+
once per folder, not per file, and no entity destinations are invented inside it.
|
|
343
|
+
|
|
344
|
+
## Code entities
|
|
345
|
+
|
|
346
|
+
An **entity** says what a piece of code IS, by facts. It never says where the code
|
|
347
|
+
lives: that is the tree's job, and keeping the two apart is what lets a folder move
|
|
348
|
+
without touching a law.
|
|
349
|
+
|
|
350
|
+
An entity carries `slug`, `name`, `infer`, `actions` and `report` — and no location.
|
|
351
|
+
|
|
352
|
+
### A piece of code, not a file
|
|
353
|
+
|
|
354
|
+
`infer` runs over the **candidates** in a file: functions (declarations, arrows,
|
|
355
|
+
expressions, methods, accessors), classes, variable declarations, type declarations,
|
|
356
|
+
and the file's comments. Each candidate carries its own entity, so one file holds
|
|
357
|
+
several at once: `styles.ts` is a `styleBlock` beside a `constant`, `Header.tsx` is an
|
|
358
|
+
`atom` beside a `handler`.
|
|
359
|
+
|
|
360
|
+
`infer` is a list in PRIORITY order: the first entry that matches wins. In this repo
|
|
361
|
+
`handler` comes before `pureFunction`, because a function value has no name of its
|
|
362
|
+
own and would otherwise also match "a declared, named function". An entity without
|
|
363
|
+
`infer` is never inferred.
|
|
364
|
+
|
|
365
|
+
Two subjects are the FILE, not a piece:
|
|
366
|
+
|
|
367
|
+
- **`barrel`** — a file that declares nothing of its own and only re-exports (by
|
|
368
|
+
name, by namespace, wholesale, or as a default that hands on an imported binding).
|
|
369
|
+
It is a place, not a piece, so it is read from the file's `exports` and `kind`.
|
|
370
|
+
- **`entry`** — a module that only wires: it imports what a package offers and calls
|
|
371
|
+
it at the top level, declaring nothing. `bin/*.ts` is the case; a file that declares
|
|
372
|
+
anything at all is not an entry.
|
|
373
|
+
|
|
374
|
+
A module entity has no `name` and no `lines`, and no finding ever names it. That is
|
|
375
|
+
why `imports` and `exports` describe the MODULE: an `imports` filter in `infer` says
|
|
376
|
+
"the file that brings the provider in", and it is asked of the file, never of the
|
|
377
|
+
`const` beside the render. A repo that wants a PIECE judged by what its file brings in
|
|
378
|
+
says so explicitly — `{ file: { imports: { any: { source: { equals: "vscode" } } } } }`
|
|
379
|
+
— which reads the candidate's own `file` fact.
|
|
380
|
+
|
|
381
|
+
`.vue` / `.svelte` single-file components are parsed too: only the `<script>` block is
|
|
382
|
+
handed to the parser and every other line is blanked, so reported line numbers still
|
|
383
|
+
match the file in the editor.
|
|
384
|
+
|
|
385
|
+
### The forms
|
|
386
|
+
|
|
387
|
+
These are this repo's form entities (yours are whatever you declare — the engine has
|
|
388
|
+
no vocabulary of its own):
|
|
389
|
+
|
|
390
|
+
| entity | what the code is | recognised by |
|
|
391
|
+
| --- | --- | --- |
|
|
392
|
+
| `pureFunction` | a DECLARED, NAMED function: `function f() {}`, a method, or an arrow bound by `const f = …` | declaration kind + a name |
|
|
393
|
+
| `handler` | a function VALUE: a JSX attribute, a call argument, an object property, a returned closure | its position, or a `use*` call, or an `on…`/`handle…` name |
|
|
394
|
+
| `class` | a class declaration, or a class expression bound to a name | `kind.own.is` + `name` |
|
|
395
|
+
| `styleBlock` | `const Box = styled.div`…`` — the style half of a component | a `VariableDeclaration` carrying `framework.css.templates` |
|
|
396
|
+
| `data` | an object or array literal a module keeps (a thresholds map, a column list) | initializer kind |
|
|
397
|
+
| `sharedTypes` | an interface, a type alias, or an ambient `export const x: T;` in a `.d.ts` | declaration kind + no initializer |
|
|
398
|
+
| `constant` | a module-scope name for a VALUE: a literal, an alias, a computed value, a `keyframes` tag | `mutable: false` + initializer kind (a function initializer belongs to the form entities above) |
|
|
399
|
+
| `state` | the value a state factory returns (`createContext(…)`, `t.model(…)`) | initializer origin |
|
|
400
|
+
| `atom` / `molecule` / `section` | the UI layers: renders no component / renders imported components / composes molecules for one place | `framework.component`, `framework.links` |
|
|
401
|
+
| `theme` | the one object carrying every token table | initializer origin, or an object literal with the token groups |
|
|
402
|
+
| `testCode` | test code — by what it DOES, not only where it sits | `framework.test.*`, or a path |
|
|
403
|
+
|
|
404
|
+
A pure function and a handler are not two layers of one thing: the first is code you
|
|
405
|
+
can call by name, the second exists only where it was passed to. The FORM is the
|
|
406
|
+
whole definition — whether a function writes or returns is what the code DOES, not
|
|
407
|
+
what kind of code it is.
|
|
408
|
+
|
|
409
|
+
### `infer`
|
|
410
|
+
|
|
411
|
+
A list of filters, ANDed. An entry may also be a bare STRING naming another entity —
|
|
412
|
+
`infer: [action, { lines: { gt: 5 } }]` means "code that is an action AND longer than
|
|
413
|
+
5 lines" — so entities compose with no extra keyword. Filters nest to any depth:
|
|
210
414
|
|
|
211
|
-
|
|
415
|
+
```yaml
|
|
416
|
+
infer:
|
|
417
|
+
- and:
|
|
418
|
+
- kind: { own: { is: { equals: ArrowFunction } } }
|
|
419
|
+
- or:
|
|
420
|
+
- calls: { any: { targetEntity: { equals: action } } }
|
|
421
|
+
- kind: { descendants: { any: { is: { equals: AwaitExpression } } } }
|
|
422
|
+
- not:
|
|
423
|
+
calls: { any: { targetEntity: { equals: pureFunction } } }
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### `actions`
|
|
427
|
+
|
|
428
|
+
`actions` is an open map of the EIGHT relations, and nothing else exists: `import`,
|
|
429
|
+
`export`, `declare`, `call`, `mutate`, `assign`, `read`, `typeImport`. Each entry is
|
|
430
|
+
`{ where, except?, of?, scopeAccess? }`; any other key is an error.
|
|
431
|
+
|
|
432
|
+
- `where` — who may do it: a list of `where` entries (below).
|
|
433
|
+
- `except` — where the allowance stops: the same entries, subtracted.
|
|
434
|
+
- `of` — the fact class this action is checked against, when the name is your own
|
|
435
|
+
(`emit: { of: call }`), so an event-driven design needs no engine change.
|
|
436
|
+
- `scopeAccess` — how the code is reached WITHOUT an import: see below.
|
|
437
|
+
|
|
438
|
+
A `where` entry is one of:
|
|
439
|
+
|
|
440
|
+
| entry | means |
|
|
441
|
+
| --- | --- |
|
|
442
|
+
| `{ entity: x }` | a file that DECLARES that entity — the only entry that names a KIND rather than a place |
|
|
443
|
+
| `{ entity: x, same: true }` | …in the same instance of a repeating node (feature A's action, never feature B's) |
|
|
444
|
+
| `{ entity: x, via: import }` | …that HOLDS it from an import rather than reaching it through an object tree |
|
|
445
|
+
| `{ node: slug }` | any file under that declared node |
|
|
446
|
+
| `{ template: "…" }` | a path built from the tree |
|
|
447
|
+
| `"packages/ui/**"` | a glob (a bare string that names a declared entity is an entity reference instead) |
|
|
448
|
+
| `{ imports: { any: … } }` | any filter over the file's facts |
|
|
212
449
|
|
|
213
|
-
`
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
action (`setHost`). `role: [a, b]` on a node says which roles may be declared in
|
|
218
|
-
that folder, and a finding always names the PIECE it judges (`setHost` is an
|
|
219
|
-
action) together with the relation it broke.
|
|
450
|
+
The `where` mechanism is the SAME one rules use for their `where` / `ignore`
|
|
451
|
+
(`entities/location/where.ts`, one matcher, the same facts), and the same one that
|
|
452
|
+
decides a destination in the report. Paths themselves live in `nodes`, so a `where`
|
|
453
|
+
never restates a folder.
|
|
220
454
|
|
|
221
|
-
A piece no
|
|
222
|
-
|
|
223
|
-
nothing is not asked — silence there is the absence of a question, not
|
|
224
|
-
permission.
|
|
455
|
+
A piece no entity describes is granted nothing: every relation it makes is refused,
|
|
456
|
+
and the finding names that piece.
|
|
225
457
|
|
|
226
|
-
### `
|
|
458
|
+
### `scopeAccess`
|
|
227
459
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
460
|
+
Data a component is GIVEN — a theme, a store, a locale — is never imported by the code
|
|
461
|
+
that renders with it. `actions.import` lists only the places that mount the provider
|
|
462
|
+
and pass the object in; `scopeAccess` lists the chain roots through which everyone
|
|
463
|
+
else reaches the same code, with the SHAPE of the root spelled out:
|
|
231
464
|
|
|
232
465
|
```yaml
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
466
|
+
read:
|
|
467
|
+
where: [{ entity: atom }, { entity: molecule }, { entity: section }, { entity: styleBlock }]
|
|
468
|
+
scopeAccess:
|
|
469
|
+
- { scope: function, type: styled-components.DefaultTheme } # ${(value: DefaultTheme) => value.colors.x}
|
|
470
|
+
- { scope: function, entity: [atom, molecule, section], segments: [useTheme] } # useTheme().colors.x
|
|
471
|
+
- { scope: object, segments: [theme] } # theme.colors.x
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
- `scope` is `function`, `object` or `method` — the spelling of the root.
|
|
475
|
+
- `type` — the door IS a type, and it is the PARAMETER'S TYPE that makes the function
|
|
476
|
+
one, never the name it is spelled with: `${(value: DefaultTheme) => …}` and
|
|
477
|
+
`${({ theme }) => …}` are the same door. The value is `module.Type`; a bare
|
|
478
|
+
`DefaultTheme` is an error, because two packages may each declare one. An entry
|
|
479
|
+
with a `type` needs no `segments`.
|
|
480
|
+
- `entity` — the door belongs to code of these entities only (the hook inside a
|
|
481
|
+
component, not inside a helper). An entry with an `entity` still spells its
|
|
482
|
+
`segments`.
|
|
483
|
+
|
|
484
|
+
An import below those places is then not a new rule to write: it is a relation the
|
|
485
|
+
action refuses, and the finding names both the refusing list and the chains.
|
|
238
486
|
|
|
239
|
-
|
|
240
|
-
- slug: action
|
|
241
|
-
infer: [{ location: { node: feature-actions } }] # WHAT it is
|
|
242
|
-
report: { message: "…", fix: "…" } # said when it is misplaced
|
|
487
|
+
### The theme law
|
|
243
488
|
|
|
244
|
-
|
|
489
|
+
The pattern in full, from this repo: a theme is handed in at the root and read
|
|
490
|
+
through the provider, never imported by the code that renders with it.
|
|
491
|
+
|
|
492
|
+
```yaml
|
|
493
|
+
- slug: theme
|
|
494
|
+
infer:
|
|
495
|
+
- kind: { own: { is: { equals: VariableDeclaration } } }
|
|
496
|
+
- or:
|
|
497
|
+
- kind: { initializer: { origin: { in: [defineTheme, withStatuses] } } }
|
|
498
|
+
- and:
|
|
499
|
+
- kind: { initializer: { is: { equals: ObjectLiteralExpression } } }
|
|
500
|
+
- kind: { initializer: { members: { where: { filter: { name: { in: [colors, shadows, zIndex, …] } }, by: { length: { gte: 8 } } } } } }
|
|
501
|
+
actions:
|
|
245
502
|
import:
|
|
246
|
-
where: [
|
|
247
|
-
|
|
248
|
-
where: [
|
|
249
|
-
scopeAccess:
|
|
250
|
-
- {
|
|
251
|
-
- {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
503
|
+
where: [{ entity: theme }, { entity: themeProvider }, { entity: barrel }, { entity: testCode }]
|
|
504
|
+
read:
|
|
505
|
+
where: [{ entity: theme }, { entity: atom }, { entity: molecule }, { entity: section }, { entity: styleBlock }, { entity: testCode }]
|
|
506
|
+
scopeAccess:
|
|
507
|
+
- { scope: function, type: styled-components.DefaultTheme }
|
|
508
|
+
- { scope: function, entity: [atom, molecule, section, themeProvider], segments: [useTheme] }
|
|
509
|
+
report:
|
|
510
|
+
description: "A theme is the design context of a situation: a component never imports it — it reads the theme it was given."
|
|
511
|
+
fix:
|
|
512
|
+
message: "Delete the import: read `theme` in the styled block's callback or call `useTheme()`."
|
|
255
513
|
```
|
|
256
514
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
515
|
+
Three consequences, all of them free:
|
|
516
|
+
|
|
517
|
+
- a component that imports a theme is a refused relation, not a rule to write;
|
|
518
|
+
- `props.theme` is NOT one of the chains — a component that receives the palette as
|
|
519
|
+
a prop relays it through its signature and cannot be used outside a provider;
|
|
520
|
+
- token tables (`colors`, `zIndexes`) are private to themes: only a theme imports
|
|
521
|
+
one, everyone else reads it as `theme.colors.section`.
|
|
522
|
+
|
|
523
|
+
The edge of the relation: a library import has no target in the tree. A component
|
|
524
|
+
importing `ThemeProvider` from `styled-components` names no repo file, and the
|
|
525
|
+
relation engine judges only edges that land on the repository's own code. A law about
|
|
526
|
+
a library symbol is therefore a RULE over the `imports` fact — that is exactly
|
|
527
|
+
[`no-theme-mount-in-a-component`](#no-theme-mount-in-a-component) below.
|
|
528
|
+
|
|
529
|
+
## Aliases
|
|
530
|
+
|
|
531
|
+
The `aliases` block gives an import specifier a place in the repo — and the SAME one
|
|
532
|
+
function answers every other place the architecture names files, so a specifier is
|
|
533
|
+
never written twice and never resolved two different ways.
|
|
534
|
+
|
|
535
|
+
```yaml
|
|
536
|
+
aliases:
|
|
537
|
+
"@md-code/components": packages/components # a FOLDER: everything under it is the package
|
|
538
|
+
"@md/styles": packages/styles/index.ts # an ENTRY FILE: the package still lives in its folder
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
One alias function answers four consumers, and nothing else reads `aliases`:
|
|
542
|
+
|
|
543
|
+
1. **the import resolver** — `facts.imports[].source`: `@md-code/components/logo` →
|
|
544
|
+
`packages/components/atoms/Logo/index.tsx` (the subpath goes through the package's `exports`);
|
|
545
|
+
2. **node `name`s and `children`** — a name that starts with `@` is an alias
|
|
546
|
+
specifier:
|
|
547
|
+
|
|
548
|
+
```yaml
|
|
549
|
+
- slug: components
|
|
550
|
+
name: "@md-code/components" # the node IS the package folder, wherever the alias points
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
3. **rule `where` / `ignore`** — a glob that starts with `@` is expanded:
|
|
554
|
+
`ignore: ["@md-code/components/**"]` reads as `packages/components/**`;
|
|
555
|
+
4. **`location` filters** — every string inside a `location` subtree:
|
|
556
|
+
`location: { path: { startsWith: "@md/styles/" } }`.
|
|
557
|
+
|
|
558
|
+
A trailing `/` is a PREFIX and keeps its slash; `@pkg/*` means every public source of
|
|
559
|
+
that package; an alias with several places expands to a `{a,b}` brace alternation in a
|
|
560
|
+
glob. A string that starts with `@` and names no alias is a **config error**, not
|
|
561
|
+
silence — without it the pattern would match nothing and the rule would quietly never
|
|
562
|
+
fire. A filter's other strings are values, not places: `equals: "@angular/core"` stays
|
|
563
|
+
as written.
|
|
564
|
+
|
|
565
|
+
### Where a subpath points
|
|
566
|
+
|
|
567
|
+
The value of an alias is a folder or an entry file. A subpath is read from there:
|
|
568
|
+
|
|
569
|
+
- **a package that publishes folders** (`@pkg/button` with `"@pkg": packages/pkg`) is
|
|
570
|
+
`packages/pkg/button` — folder subpaths are folders, exactly as the path reads;
|
|
571
|
+
- **a package that publishes SUBPATHS** (`exports` in its `package.json`, like
|
|
572
|
+
`@md-code/components/chip`) has no such folder. The subpath goes through the
|
|
573
|
+
manifest: `exports["./chip"].types` names the build artifact, and the SOURCE is the
|
|
574
|
+
scanned file whose path ends with that artifact's tail. `typesVersions` is read the
|
|
575
|
+
same way when `exports` has no answer, and a subpath the manifest does not describe
|
|
576
|
+
falls back to the plain folder reading.
|
|
577
|
+
|
|
578
|
+
When a subpath's manifest entry exists but no scanned file mirrors it, the run says so
|
|
579
|
+
once instead of silently resolving nothing.
|
|
580
|
+
|
|
581
|
+
A manifest's `exports` is only consulted when the run knows the scanned files, which
|
|
582
|
+
is the import resolver's case. Config-time consumers (nodes, rules, filters) are read
|
|
583
|
+
before the repo is scanned, so they get the folder reading — which is why a package
|
|
584
|
+
that publishes only subpaths is aliased to its FOLDER.
|
|
585
|
+
|
|
586
|
+
## Rules
|
|
587
|
+
|
|
588
|
+
A **rule** is a per-file condition. Fields:
|
|
589
|
+
|
|
590
|
+
| Key | Meaning |
|
|
591
|
+
| --- | --- |
|
|
592
|
+
| `id` | the rule's identifier, used by findings and `dedupeBy` |
|
|
593
|
+
| `where` | the code the rule applies to: the same `where` entries entities use; omitted = all files |
|
|
594
|
+
| `ignore` | the code it does NOT apply to — the same entries, inverted |
|
|
595
|
+
| `when` | an extra gate: a plain filter over the file facts; the rule runs only when it matches |
|
|
596
|
+
| `infer` | filters that, when they MATCH, are the violation |
|
|
597
|
+
| `report` | what to say: a string, or a spec (below) |
|
|
598
|
+
| `dedupeBy` | the place findings are counted once per (a `where` entry) |
|
|
599
|
+
| `children` | nested rules, evaluated with the same file facts |
|
|
600
|
+
|
|
601
|
+
Any other key is an error naming the allowed keys. There is no legacy-key mapping and
|
|
602
|
+
no second check key: "this must be true" is the same filter under `not:`.
|
|
603
|
+
|
|
604
|
+
Two subjects: the filter is asked of the **file** first; when the file does not
|
|
605
|
+
answer, the SAME filter is asked of every **candidate** in it, and the matching
|
|
606
|
+
candidate supplies the `{what}` and the line of the finding. That is why a rule about
|
|
607
|
+
a module reads `imports` and a rule about a function reads `kind`.
|
|
608
|
+
|
|
609
|
+
`dedupeBy` counts findings per place instead of per file: `dedupeBy: [{ node: feature }]`
|
|
610
|
+
reports a per-folder rule once per feature folder, and a glob once per matched folder.
|
|
611
|
+
File-level findings are then reported once per distinct place across the run.
|
|
612
|
+
|
|
613
|
+
### Before writing a rule: an entity and a node
|
|
614
|
+
|
|
615
|
+
Most architecture laws are not rules. They are answers to two questions the tree and
|
|
616
|
+
the entities already ask:
|
|
617
|
+
|
|
618
|
+
- **"What is this piece?"** is an entity. Write it once, by facts (`infer`), and the
|
|
619
|
+
order of the `entities` list states which kind wins when several match.
|
|
620
|
+
- **"Where does this kind live?"** is a node with `entity:` on it (or on one of its
|
|
621
|
+
children). A piece declared anywhere else is reported with the home it belongs to —
|
|
622
|
+
the finding, the destination and the fix come for free.
|
|
623
|
+
- **"Who may use whom?"** is an `actions.*.where` list. It is also the picture: a box
|
|
624
|
+
that imports nothing but its own kind is a leaf, a box that imports the leaf is the
|
|
625
|
+
layer above it.
|
|
626
|
+
- **"How is it reached without an import?"** is `scopeAccess`.
|
|
627
|
+
- **"Who is the consumer — a folder or a kind of code?"** An action's `where` names
|
|
628
|
+
entities and nodes, never a path. `apps/**` spells a place; the place will move, the
|
|
629
|
+
law will not.
|
|
630
|
+
|
|
631
|
+
A rule is for the rest: a value that must not be typed, a file that must not grow, a
|
|
632
|
+
name that must not repeat. A rule that only says "this kind of code sits in that
|
|
633
|
+
folder" or "this kind may not import that kind" duplicates what the entities and the
|
|
634
|
+
nodes say — and unlike them it cannot be read off the tree.
|
|
635
|
+
|
|
636
|
+
The order is therefore fixed — **entity → home → allowance → rule last**, in names
|
|
637
|
+
that are not any project's:
|
|
638
|
+
|
|
639
|
+
```yaml
|
|
640
|
+
entities:
|
|
641
|
+
# 1. WHAT it is, by facts. Asked first: a panel is also "a component that renders
|
|
642
|
+
# components", so the composition layer comes before the leaf.
|
|
643
|
+
- slug: panel
|
|
644
|
+
infer:
|
|
645
|
+
- framework: { component: { equals: true } }
|
|
646
|
+
- framework: { links: { any: { module: { isSet: true } } } }
|
|
647
|
+
# 3. WHO may use it: a panel may be rendered by another panel or by a screen.
|
|
648
|
+
actions:
|
|
649
|
+
import: { where: [{ entity: panel }, { entity: screen }] }
|
|
650
|
+
- slug: tile
|
|
651
|
+
infer:
|
|
652
|
+
- framework: { component: { equals: true } }
|
|
653
|
+
- not: { framework: { links: { any: { module: { isSet: true } } } } }
|
|
654
|
+
actions:
|
|
655
|
+
import: { where: [{ entity: tile }, { entity: panel }] }
|
|
656
|
+
|
|
657
|
+
nodes:
|
|
658
|
+
# 2. WHERE each kind may be declared. One line to move a folder, and no action
|
|
659
|
+
# changes.
|
|
660
|
+
- slug: ui
|
|
661
|
+
name: ui
|
|
662
|
+
parent: packages
|
|
663
|
+
children:
|
|
664
|
+
- { name: tiles, entity: [tile] }
|
|
665
|
+
- { name: panels, entity: [panel] }
|
|
666
|
+
|
|
667
|
+
rules:
|
|
668
|
+
# 4. Only what the two above cannot say: a tile may not take more than three props.
|
|
669
|
+
- id: small-tiles
|
|
670
|
+
where: [{ entity: tile }]
|
|
671
|
+
infer:
|
|
672
|
+
- framework: { props: { length: { gt: 3 } } }
|
|
673
|
+
report:
|
|
674
|
+
code: rewrite
|
|
675
|
+
description: "`{what}` is a tile with {n} props: a tile takes what it renders, not a bag."
|
|
676
|
+
fix: { message: "Pass the object the tile needs, or let it read what it needs itself." }
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
A tile declared under `panels/` is a finding that names `tiles/`; a tile importing a
|
|
680
|
+
screen is a finding with the exact import; nothing else had to be written. The same
|
|
681
|
+
two lists, read from the other end, are the dependency graph of the overview: what
|
|
682
|
+
imports what, and what nothing imports.
|
|
683
|
+
|
|
684
|
+
### `no-hidden-store`
|
|
685
|
+
|
|
686
|
+
Not every law is a shape of code. One is worth spelling out, because it is the only
|
|
687
|
+
thing this repo states about a file's SCOPE: **at module scope there are only
|
|
688
|
+
constants.** A `let`/`var` bound at module level is a store that outlives every call
|
|
689
|
+
and hides its writers from the reader; bound inside a function or a block it is
|
|
690
|
+
ordinary local work.
|
|
691
|
+
|
|
692
|
+
That is a rule and not an entity — no piece becomes "the thing", so there is nothing
|
|
693
|
+
to classify — written over two facts the engine already has:
|
|
694
|
+
|
|
695
|
+
```yaml
|
|
696
|
+
- id: no-hidden-store
|
|
315
697
|
infer:
|
|
316
|
-
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
698
|
+
- mutable: { equals: true }
|
|
699
|
+
kind:
|
|
700
|
+
ancestors: { none: { is: { in: [FunctionDeclaration, MethodDeclaration, ArrowFunction, FunctionExpression, Constructor, GetAccessor, SetAccessor, Block, CaseClause, ModuleBlock, ForStatement, ForOfStatement, ForInStatement, WhileStatement, DoStatement, ClassDeclaration, ClassExpression] } } }
|
|
701
|
+
report:
|
|
702
|
+
code: rewrite
|
|
703
|
+
description: "`{what}` is a module-scope `let`/`var`: a store that outlives every call, is writable from every importer and is invisible in every signature that reads it."
|
|
704
|
+
fix:
|
|
705
|
+
message: "Make it a `const` — a value computed once, at load — or move the changing value into the function that owns it (a local) or into a state container the UI reads."
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
`mutable` is true for a declaration in a `let`/`var` list, and `kind.ancestors` says
|
|
709
|
+
what the declaration sits inside — no ancestor that opens a scope means module scope.
|
|
710
|
+
A function's own `let` has its `Block` above it and is never asked.
|
|
711
|
+
|
|
712
|
+
### `proper-values`
|
|
713
|
+
|
|
714
|
+
The style reading is what makes a design-token law expressible. This rule asks the
|
|
715
|
+
CSS each component reads to RESOLVE against the provider (the theme) it was handed:
|
|
716
|
+
|
|
717
|
+
```yaml
|
|
718
|
+
- id: proper-values
|
|
719
|
+
where: [{ entity: atom }, { entity: molecule }, { entity: section }]
|
|
720
|
+
ignore: ["packages/**/tests/**", "**/*.test.*"]
|
|
721
|
+
infer:
|
|
722
|
+
# a) the provider's value is wrong for the property (the CSS grammar rejects it)
|
|
723
|
+
- framework:
|
|
724
|
+
css:
|
|
725
|
+
templates:
|
|
726
|
+
any:
|
|
727
|
+
declarations:
|
|
728
|
+
any:
|
|
729
|
+
resolution:
|
|
730
|
+
resolvedValues:
|
|
731
|
+
any:
|
|
732
|
+
valid: { equals: false }
|
|
733
|
+
report:
|
|
734
|
+
code: rewrite
|
|
735
|
+
description: "`{what}` resolves `{prop}` to `{value}` in provider `{provider}`, which the CSS grammar rejects."
|
|
736
|
+
fix:
|
|
737
|
+
message: "Fix the THEME value or the property the component feeds it to — do not hardcode a value."
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
The other two branches are the same shape: a FIXED path some provider does not carry
|
|
741
|
+
(`resolution.unresolved.kind: absent` — the provider is incomplete, not the
|
|
742
|
+
component), and any part that never reaches a concrete value.
|
|
743
|
+
|
|
744
|
+
### `no-theme-mount-in-a-component`
|
|
745
|
+
|
|
746
|
+
The law about a LIBRARY symbol, which is a rule because the import has no repo target:
|
|
747
|
+
|
|
748
|
+
```yaml
|
|
749
|
+
- id: no-theme-mount-in-a-component
|
|
750
|
+
where: [{ entity: atom }, { entity: molecule }, { entity: section }]
|
|
751
|
+
infer:
|
|
752
|
+
- imports:
|
|
753
|
+
any:
|
|
754
|
+
source: { in: [styled-components, styled-components/native] }
|
|
755
|
+
imported: { any: { equals: ThemeProvider } }
|
|
756
|
+
not:
|
|
757
|
+
or:
|
|
758
|
+
- location: { path: { contains: "/tests/" } }
|
|
759
|
+
- location: { fileName: { matches: "*.test.*" } }
|
|
760
|
+
report:
|
|
761
|
+
code: remove
|
|
762
|
+
description: "`{basename}` imports `ThemeProvider` — a component mounts no theme."
|
|
763
|
+
fix:
|
|
764
|
+
message: "Delete the import and the `<ThemeProvider>` it renders: read the theme in the styled block's callback or call `useTheme()`."
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
`imported` is matched, not `named` — `import { ThemeProvider as TP }` renames the
|
|
768
|
+
binding, never the symbol.
|
|
769
|
+
|
|
770
|
+
### Report specs
|
|
771
|
+
|
|
772
|
+
`report` is a string, or an object whose fields the report and the picture share:
|
|
773
|
+
|
|
774
|
+
| field | meaning |
|
|
775
|
+
| --- | --- |
|
|
776
|
+
| `description` (or `message`) | the finding sentence |
|
|
777
|
+
| `fix` | the repair sentence, or `{ message, location }` |
|
|
778
|
+
| `code` (or `ask`) | the repair kind the picture labels: `move`, `remove`, `rewrite`, `merge`, `split`, `delete`, `declare`, `create`, `add`, `rules`, or your own |
|
|
779
|
+
| `path`, `place`, `to`, `from` | the boxes the repair points at, when a rule states them itself |
|
|
780
|
+
|
|
781
|
+
`{…}` placeholders are substituted: path vars (`{file}`, `{basename}`, `{dir}`),
|
|
782
|
+
scalars of `location` (`{fileName}`, `{files}`), captures from node names, and match
|
|
783
|
+
context (`{what}` — the matched candidate's name, `{n}`, `{snippet}`, `{violations}` —
|
|
784
|
+
the items of a list fact that fail an `every`).
|
|
342
785
|
|
|
343
786
|
## The filter engine
|
|
344
787
|
|
|
345
|
-
Every `infer`
|
|
788
|
+
Every `infer`, `when` and `where`-by filter uses one grammar
|
|
789
|
+
([entities/queries.ts](entities/queries.ts)). A filter is:
|
|
346
790
|
|
|
347
791
|
- an **object of entries** — AND of all entries;
|
|
348
792
|
- a **list of filters** — AND of all sub-filters;
|
|
349
793
|
- `null` / omitted — always passes.
|
|
350
794
|
|
|
351
|
-
Each entry is either an **operator** or a **field** of the item — one field at a time,
|
|
352
|
-
`{ name: { equals: "x" } }` → `item.name` must pass it; `{ kind: { own:
|
|
795
|
+
Each entry is either an **operator** or a **field** of the item — one field at a time,
|
|
796
|
+
on every fact: `{ name: { equals: "x" } }` → `item.name` must pass it; `{ kind: { own:
|
|
797
|
+
{ is: { in: […] } } } }` → `item.kind.own.is` must. Dotted keys are paths into a
|
|
798
|
+
nested fact.
|
|
353
799
|
|
|
354
|
-
|
|
800
|
+
| group | operators |
|
|
801
|
+
| --- | --- |
|
|
802
|
+
| scalar | `equals`, `not`, `lt`, `lte`, `gt`, `gte`, `in`, `notIn`, `contains`, `startsWith`, `endsWith`, `isSet`, `matches` |
|
|
803
|
+
| null / empty | `isNull`, `isEmpty` |
|
|
804
|
+
| list | `length`, `at`, `every`, `any`, `none`, `where` (`{ filter, by }` — narrows the list, then applies `by`), `unique` |
|
|
805
|
+
| composition | `and`, `or`, `xor`, `not` |
|
|
806
|
+
| place | `location` — asks the path question with the location vocabulary |
|
|
355
807
|
|
|
356
|
-
|
|
808
|
+
A missing or non-list field simply fails the operator. `$`-prefixed values reference
|
|
809
|
+
another fact in scope, dot-paths included: `{ equals: "$name" }` compares the field to
|
|
810
|
+
the candidate's own `name`.
|
|
357
811
|
|
|
358
|
-
|
|
812
|
+
## Facts
|
|
359
813
|
|
|
360
|
-
|
|
814
|
+
A relation is a **runtime** dependency: `import type` is not one (nothing is bound at
|
|
815
|
+
runtime). Type-only imports are a relation of their own — `typeImport` — so a project
|
|
816
|
+
can allow one and forbid the other: `import` says "this code runs against that file",
|
|
817
|
+
`typeImport` says "this code names a shape from it".
|
|
361
818
|
|
|
362
|
-
|
|
819
|
+
### File facts
|
|
363
820
|
|
|
364
|
-
|
|
821
|
+
| fact | holds |
|
|
822
|
+
| --- | --- |
|
|
823
|
+
| `lines` | the file's lines as ONE array (`lines[0]` is the first, `lines.length` the count) |
|
|
824
|
+
| `imports` | `[{ form, source, resolved, typeOnly, named, defaultName?, namespaceName?, line, piece, imported, declaring }]` — `form` is `statement` / `require` / `dynamic` |
|
|
825
|
+
| `exports` | `[{ form, named, from, source, name, line, piece, declaring, original }]` — `form` is `named` / `namespace` / `star` / `default` / `equals` / `commonjs` |
|
|
826
|
+
| `location` | where the file is: `path`, `dir`, `fileName`, `files` (the folder's own files) |
|
|
827
|
+
| `kind` | the file's own node and every node below it |
|
|
828
|
+
| `candidates` | the entity-enriched candidate facts |
|
|
829
|
+
| `entities` | the flat list of entity names present |
|
|
830
|
+
| `reads` | `[{ module, what, line, piece }]` — whole member paths (`a.b.c`, `a["b"]`) whose root belongs to another module, i.e. a read that is not a call |
|
|
365
831
|
|
|
366
|
-
|
|
832
|
+
`location` is the ONE place fact, in every subject: `{ location: { files: { length: {
|
|
833
|
+
gt: 7 } } } }` is "this folder holds more than seven files", and `{ location: { piece:
|
|
834
|
+
{ isNull: true } } }` is "at module scope".
|
|
367
835
|
|
|
368
|
-
|
|
836
|
+
### The `kind` fact
|
|
837
|
+
|
|
838
|
+
One shape for every structural question about a node, so a rule never needs a second
|
|
839
|
+
vocabulary. A node descriptor is `{ is, name?, line?, …what that node has }`, and
|
|
840
|
+
every facet takes the same filters:
|
|
369
841
|
|
|
370
842
|
| facet | is |
|
|
371
843
|
| --- | --- |
|
|
372
844
|
| `own` | the node itself |
|
|
373
845
|
| `parent` | its syntax parent (may be a `Block` or a `VariableStatement` — syntax, not meaning) |
|
|
374
|
-
| `ancestors` | every enclosing node up to the file |
|
|
846
|
+
| `ancestors` | every enclosing node, up to the file |
|
|
375
847
|
| `children` | its direct children |
|
|
376
848
|
| `siblings` | its siblings |
|
|
377
849
|
| `descendants` | everything below it, flat (`depth: 0` = a direct child; extras: `snippet`, `nested`, `type` on `as` expressions, `members` on object literals) |
|
|
378
|
-
| `initializer` | for a declaration, the value it is initialised with: `{ is, origin, members }` (`origin` is the leftmost identifier chain
|
|
850
|
+
| `initializer` | for a declaration, the value it is initialised with: `{ is, origin, members }` (`origin` is the leftmost identifier chain — `t.model` in `t.model({…})`) |
|
|
851
|
+
| `chain` | the links the engine followed to reach this piece (calls and rendered components) — `kind.chain.length` is the depth a `no-props-drilling` rule asks about |
|
|
852
|
+
|
|
853
|
+
Beside them, the SPELLING of the node: `modifiers` (`["export", "abstract", "const"]`),
|
|
854
|
+
`decorators` (`[{ name, full, line }]`), `assertion` (`as const` / `satisfies X`) and
|
|
855
|
+
`disposable` (`using`).
|
|
379
856
|
|
|
380
|
-
|
|
857
|
+
### Candidate facts
|
|
381
858
|
|
|
382
|
-
|
|
859
|
+
A piece is described with its own facts and nothing else:
|
|
383
860
|
|
|
384
|
-
| fact |
|
|
861
|
+
| fact | holds |
|
|
385
862
|
| --- | --- |
|
|
386
|
-
| `
|
|
387
|
-
| `
|
|
388
|
-
| `
|
|
389
|
-
| `
|
|
390
|
-
| `
|
|
391
|
-
| `
|
|
392
|
-
| `
|
|
393
|
-
| `
|
|
863
|
+
| `name`, `entity` | what it is called and what it got |
|
|
864
|
+
| `location` | `path` (the file) and `piece` (the piece it is nested in — `null` = module scope) |
|
|
865
|
+
| `lines` | the lines it spans, as ONE array |
|
|
866
|
+
| `parameters` | `[{ name, type, typeFile, optional, rest, bindings }]` — `typeFile` is the file declaring the type, resolved by the checker |
|
|
867
|
+
| `calls` | `[{ kind, origin, action, module, target, receiverOnly, bare, arguments, targetEntity }]` — `target` is `{ path, name }` |
|
|
868
|
+
| `assignments` | `[{ line, target, method, value, via, module, onThis, type, param, local, relation }]` — every write in one fact; `via` is `assign` / `call` / `delete` / `freeze` / `seal`, and `relation` is the ONE classification: `mutate` (somebody else's value), `assign` (a value handed in or declared in the repo) or `null` (the piece's own local) |
|
|
869
|
+
| `returns` | `[{ kind, exprKind, origin, members }]` |
|
|
870
|
+
| `branches` | `[{ is, line }]` — the branching the piece contains |
|
|
871
|
+
| `kind` | the facets above |
|
|
872
|
+
| `exported`, `mutable` | is it written with `export`; may the binding be reassigned (`let`/`var`) |
|
|
873
|
+
| `extends`, `implements`, `members`, `constructorParams` | classes |
|
|
874
|
+
| `references`, `implementations` | the checker's answer, not the tree's |
|
|
875
|
+
| `file` | the facts of the file it lives in |
|
|
876
|
+
|
|
877
|
+
A call's `target` is a **location**, the same interface `where` entries use, so a call
|
|
878
|
+
destination is addressed like anything else:
|
|
879
|
+
|
|
880
|
+
```yaml
|
|
881
|
+
# "a function that calls something living in the utils node"
|
|
882
|
+
infer:
|
|
883
|
+
- calls:
|
|
884
|
+
any:
|
|
885
|
+
target:
|
|
886
|
+
location: { node: utils }
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
`targetEntity` is the same question in entity vocabulary: the entity whose home covers
|
|
890
|
+
the target's location. An ambiguous location yields `null` — the engine never guesses.
|
|
394
891
|
|
|
395
|
-
|
|
892
|
+
### `imports`, `exports` and `declaring`
|
|
396
893
|
|
|
397
|
-
|
|
894
|
+
A name is judged where it is DECLARED, not at the module that passes it on. `import {
|
|
895
|
+
codeEditor } from "@md/styles"` names the package's `index.ts`, but the file that
|
|
896
|
+
declares `codeEditor` is the theme file — and that is the file a relation is about. So
|
|
897
|
+
every import and re-export fact carries the answer:
|
|
398
898
|
|
|
399
|
-
|
|
899
|
+
- `imports[].imported` — the names as the target module writes them (`import { X as Y }`
|
|
900
|
+
gives `X`: an alias renames the binding, never the symbol);
|
|
901
|
+
- `imports[].declaring` / `exports[].declaring` — one entry per name, the file that
|
|
902
|
+
DECLARES it, or `null` when the chain does not answer;
|
|
903
|
+
- `exports[].original` — the name before `as`.
|
|
904
|
+
|
|
905
|
+
The chain ([entities/ast/export-chain.ts](entities/ast/export-chain.ts)) follows
|
|
906
|
+
`exports[].from` hop by hop, through aliases. It stops at a CYCLE and at the budget
|
|
907
|
+
`barrelDepth` (the rule option, the CLI's `--barrel-depth`, `8` unless given — a TOOL
|
|
908
|
+
setting: where a name is judged is the law, not a per-repo knob). Both answer `null`,
|
|
909
|
+
and the edge then stays on the module file.
|
|
910
|
+
|
|
911
|
+
An import edge is SPLIT by declaring file: one edge per file a name came from, and the
|
|
912
|
+
module edge remains only for the names that stayed or never resolved. So a filter may
|
|
913
|
+
say what a barrel is for:
|
|
400
914
|
|
|
401
915
|
```yaml
|
|
402
|
-
# "a function that calls something living in the actions node"
|
|
403
916
|
infer:
|
|
404
|
-
-
|
|
917
|
+
- imports:
|
|
405
918
|
any:
|
|
406
|
-
|
|
407
|
-
location: { node: backend-feature-actions }
|
|
919
|
+
declaring: { any: { startsWith: "packages/styles/themes/" } }
|
|
408
920
|
```
|
|
409
921
|
|
|
410
|
-
|
|
922
|
+
### The `framework` namespace
|
|
411
923
|
|
|
412
|
-
|
|
924
|
+
Every fact a reader that is NOT the TypeScript AST contributes lives in ONE namespace,
|
|
925
|
+
`framework`, with one branch per reader. A rule names the reading, never the reader.
|
|
413
926
|
|
|
414
|
-
|
|
927
|
+
`framework.links` is the composition graph: one entry per component a piece RENDERS —
|
|
928
|
+
`{ name, module }`, where `module` is the file that declares the rendered component and
|
|
929
|
+
`null` means "this same file". Without an import map the list is EMPTY, never guessed.
|
|
415
930
|
|
|
416
|
-
|
|
931
|
+
## Facets
|
|
417
932
|
|
|
418
|
-
|
|
933
|
+
The engine knows TypeScript. It does not know React, Vue, Angular, styled-components,
|
|
934
|
+
Tailwind or Vitest — and it must not. A **facet** is the module that knows: a reader of
|
|
935
|
+
the same AST that says what its own world calls the things it sees.
|
|
419
936
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
|
424
|
-
|
|
425
|
-
|
|
|
426
|
-
|
|
|
427
|
-
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
closest one. When no home is in the file's branch — a role allowed in several
|
|
434
|
-
unrelated packages — the home declared FIRST answers, so **the order of the
|
|
435
|
-
nodes that declare a role is its priority list**: put the canonical home first,
|
|
436
|
-
the permissive ones (examples, tests) last.
|
|
437
|
-
| the config file | every instruction names the file the architecture was actually loaded from (`architecture.yaml`, or whatever `--config` pointed at) — never a hardcoded default |
|
|
438
|
-
|
|
439
|
-
When the architecture genuinely has no answer (a role with no declared home, in
|
|
440
|
-
a folder the tree does not declare), the finding says exactly that and names the
|
|
441
|
-
single edit that gives it one — it does not offer an "either … or".
|
|
442
|
-
|
|
443
|
-
### Where the wording lives — `report/errorTypes/`
|
|
444
|
-
|
|
445
|
-
The engine observes and decides **facts**. The report turns facts into
|
|
446
|
-
**language**, once, for every consumer (the CLI text, the linter message, the
|
|
447
|
-
interactive overview). No module outside `report/errorTypes/` writes a sentence
|
|
448
|
-
about a finding.
|
|
937
|
+
| branch | written by | answers |
|
|
938
|
+
| --- | --- | --- |
|
|
939
|
+
| `framework.id` | the component readers, and the test reader where nobody else spoke | whose reading this is: `react` / `vue` / `angular` / `test` |
|
|
940
|
+
| `framework.component`, `framework.props`, `framework.forwarded`, `framework.jsx`, `framework.handler` | the component readers | what the piece renders and hands down; `handler` marks a piece referenced by an event attribute |
|
|
941
|
+
| `framework.links` | the component readers | the components it renders — the composition graph |
|
|
942
|
+
| `framework.css.templates` | the style facet ([css/](css)) | the CSS a tagged template holds |
|
|
943
|
+
| `framework.tailwind.classes` | the style facet | the class list a class attribute holds, each class read as a utility |
|
|
944
|
+
| `framework.test` | the test reader ([frameworks/test/](frameworks/test)) | which runner the file was written for, and what it declares |
|
|
945
|
+
|
|
946
|
+
A rule therefore says `framework.css.templates` or `framework.test.runner` whatever
|
|
947
|
+
read it. There is no second facade beside `framework` — not `css` on the candidate, not
|
|
948
|
+
`test` at the top — so a filter written once keeps working when the reader behind it
|
|
949
|
+
changes.
|
|
449
950
|
|
|
951
|
+
### The registry
|
|
952
|
+
|
|
953
|
+
A framework module lives in `frameworks/<id>/index.ts` and exports a `FrameworkFacet`:
|
|
954
|
+
|
|
955
|
+
```ts
|
|
956
|
+
interface FrameworkFacet {
|
|
957
|
+
id: string; // the word `framework.id` carries
|
|
958
|
+
applies(ctx: FacetContext): boolean; // the cheap gate: read the path / the text
|
|
959
|
+
enrich(candidates: Candidate[], ctx: FacetContext): Candidate[];
|
|
960
|
+
classAttributes?: string[]; // `className`, `class` — the words a class list is written into
|
|
961
|
+
}
|
|
450
962
|
```
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
963
|
+
|
|
964
|
+
`REGISTRY` ([frameworks/index.ts](frameworks/index.ts)) is the list — `react`, `vue`,
|
|
965
|
+
`angular`, `test` — and adding a framework is one module plus one entry, with no change
|
|
966
|
+
to the engine, the pipeline or the report. `applies` is asked first and answers from the
|
|
967
|
+
path or the text; only a file that applies is enriched.
|
|
968
|
+
|
|
969
|
+
`classAttributes` is why the style facet can stay framework-blind: a class list is
|
|
970
|
+
written into `className` in React and `class` in a template, and the css facet asks the
|
|
971
|
+
registry for the union instead of spelling either word.
|
|
972
|
+
|
|
973
|
+
The style facet is deliberately NOT in the registry: `css/` reads structure, not a
|
|
974
|
+
framework — a tagged template is a tagged template in a `.ts`, a `.tsx` or a `.vue`
|
|
975
|
+
file — so no `applies` gate could narrow it. It writes `framework.css` /
|
|
976
|
+
`framework.tailwind` and never `framework.id`.
|
|
977
|
+
|
|
978
|
+
### The style reading
|
|
979
|
+
|
|
980
|
+
A template becomes a fact when its SUBSTITUTED text reads as CSS — `${…}` is replaced
|
|
981
|
+
by blanks and the result goes through the CSS grammar — so SQL, JSON and prose in a
|
|
982
|
+
tagged template stay unread whatever the tag is called. The one exception is a body
|
|
983
|
+
with no text left (`` css`${({ $wide }) => …}` ``): for that case only, and only when
|
|
984
|
+
the tag is a styled-components word, the tag decides.
|
|
985
|
+
|
|
986
|
+
| fact | holds |
|
|
987
|
+
| --- | --- |
|
|
988
|
+
| `framework.css.templates[]` | `tag`, `line`, `startLine`, `comment` (the doc above the declaration), `declarations[]`, `rules[]`, `literals[]`, `vars[]`, `exprs[]` — the whole document reading |
|
|
989
|
+
| `framework.tailwind.classes[]` | one entry per class token: `raw`, `variants`, `utility`, `base`, `value`, `arbitrary`, `negative`, `known`, `properties`, `line` |
|
|
990
|
+
|
|
991
|
+
`known` is the Tailwind engine's answer to "does this project's config know this
|
|
992
|
+
utility", so a rule about a second styling system needs no vocabulary of its own. A
|
|
993
|
+
declaration also carries its RESOLVED value: `resolution.resolvedValues` (the
|
|
994
|
+
provider's answer for a theme token) and `resolution.unresolved` (a path no provider
|
|
995
|
+
declares).
|
|
996
|
+
|
|
997
|
+
### The test reading
|
|
998
|
+
|
|
999
|
+
A test file is a file that imports a test API from a module that RUNS it, or calls one:
|
|
1000
|
+
|
|
1001
|
+
| fact | holds |
|
|
1002
|
+
| --- | --- |
|
|
1003
|
+
| `framework.test.runner` | `vitest` or `jest`, `null` when nobody was imported |
|
|
1004
|
+
| `framework.test.cases` | `it` / `test` calls (`it.each([...])(…)` is ONE case) |
|
|
1005
|
+
| `framework.test.asserts` | `expect` calls |
|
|
1006
|
+
| `framework.test.hooks` | the hooks the file installs, by name |
|
|
1007
|
+
| `framework.test.snapshots` | `toMatchSnapshot` / `toMatchInlineSnapshot` — counted as assertions too |
|
|
1008
|
+
| `framework.test.mocks` | `vi.*` / `jest.*` mock calls |
|
|
1009
|
+
|
|
1010
|
+
A TYPE-only import is a TypeScript reading, not a test: `import type { Mock } from
|
|
1011
|
+
"vitest"` binds nothing at runtime, so the file is not a test file however the type is
|
|
1012
|
+
used; `import { type Mock, describe } from "vitest"` IS one, because a value came along.
|
|
1013
|
+
That is the same rule the engine applies to `import` vs `typeImport`.
|
|
1014
|
+
|
|
1015
|
+
The facts are the FILE's, which is what lets an entity be defined on what a file DOES
|
|
1016
|
+
instead of where it lives:
|
|
1017
|
+
|
|
1018
|
+
```yaml
|
|
1019
|
+
- slug: testCode
|
|
1020
|
+
infer:
|
|
1021
|
+
- or:
|
|
1022
|
+
- location: { path: { matches: "**/*.test.ts*" } }
|
|
1023
|
+
- framework: { test: { runner: { isSet: true } } }
|
|
1024
|
+
- framework: { test: { cases: { gt: 0 } } }
|
|
467
1025
|
```
|
|
468
1026
|
|
|
469
|
-
###
|
|
1027
|
+
### One candidate, several readers
|
|
470
1028
|
|
|
471
|
-
A
|
|
472
|
-
|
|
1029
|
+
A `.tsx` test renders components AND runs tests, so two readers write the same
|
|
1030
|
+
candidate. They do not fight: `attach()` ([frameworks/facet.ts](frameworks/facet.ts))
|
|
1031
|
+
MERGES into `framework`, never replaces it, so the react reading keeps `jsx`/`props`
|
|
1032
|
+
and the test reading sits beside it as `framework.test`. `framework.id` names the
|
|
1033
|
+
file's reading deterministically — the component readers run before the test reader.
|
|
473
1034
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
| `hostable` | can a real node instance host that home today? | 0.07 |
|
|
480
|
-
| `branch` | is that home in the file's own top branch? | 0.05 |
|
|
1035
|
+
A reader that throws is isolated, and reported once: `applies` and `enrich` are each
|
|
1036
|
+
wrapped, so a broken facet cannot take a file's analysis down with it — the file keeps
|
|
1037
|
+
every other fact it had, and the run prints one notice instead of a stack trace per
|
|
1038
|
+
file. A reader may add facts and may fail, but it may never edit the AST facts or hide
|
|
1039
|
+
a file from the rules.
|
|
481
1040
|
|
|
482
|
-
|
|
483
|
-
allowed is forbidden", so a place where the relation is still forbidden is not a
|
|
484
|
-
destination at all, whatever the other signals say. A permission says the move
|
|
485
|
-
would be legal; it never says the move is right (`testCode` may call an action,
|
|
486
|
-
and that says nothing about where production code belongs).
|
|
1041
|
+
### One walk over one file
|
|
487
1042
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
1043
|
+
Loading the syntax, collecting the candidates, attaching the readers' facts, reading
|
|
1044
|
+
the file's facts and classifying them is a single function —
|
|
1045
|
+
[`walkFile`](code-entities/walk.ts) — and one context names everything a consumer may
|
|
1046
|
+
say: `rel`, `arch`, `repoRoot`, `repoFiles`, `aliases`, `project`, `sf`, `text` (the
|
|
1047
|
+
editor's buffer), `usage` (the checker facts), `record` and `depth`. The CLI pipeline,
|
|
1048
|
+
the editor's project index and the report's entity cards call it and nothing else, so
|
|
1049
|
+
the same file classifies the same way everywhere.
|
|
492
1050
|
|
|
493
|
-
|
|
494
|
-
|
|
1051
|
+
## Report
|
|
1052
|
+
|
|
1053
|
+
A finding is written for someone who has to ACT on it, so it carries the same
|
|
1054
|
+
information the graph does:
|
|
1055
|
+
|
|
1056
|
+
| part | what it names |
|
|
1057
|
+
| --- | --- |
|
|
1058
|
+
| the message | the offending line, and everything the rule DOES allow — a closed folder lists its declared children, an action lists the entities and the folders that may do it |
|
|
1059
|
+
| the destination | when the offending code has an entity with a declared home, that home resolved for this file, so "move it" means one path |
|
|
1060
|
+
| the mechanisms | for an action with `scopeAccess`, the chains that reach the same code WITHOUT an import |
|
|
1061
|
+
| `How to fix` | one instruction per offending line, naming the exact file or folder — and nothing at all when the architecture cannot prove a destination |
|
|
1062
|
+
| the config file | every instruction names the file the architecture was actually loaded from |
|
|
1063
|
+
|
|
1064
|
+
Which home answers is decided, not guessed: a home in the file's own BRANCH wins, and
|
|
1065
|
+
among those the closest one. When no home is in the file's branch, the home declared
|
|
1066
|
+
FIRST answers — so **the order of the nodes that declare an entity is its priority
|
|
1067
|
+
list**.
|
|
1068
|
+
|
|
1069
|
+
### Where the wording lives
|
|
1070
|
+
|
|
1071
|
+
The engine observes and decides **facts**; the report turns facts into **language**,
|
|
1072
|
+
once, for every consumer (the CLI text, the linter message, the interactive overview).
|
|
1073
|
+
No module outside `report/errorTypes/` writes a sentence about a finding.
|
|
495
1074
|
|
|
496
|
-
```
|
|
497
|
-
|
|
498
|
-
|
|
1075
|
+
```
|
|
1076
|
+
report/errorTypes/
|
|
1077
|
+
index.ts public surface: describe(), renderToken(), ids
|
|
1078
|
+
decision-maker.ts the only decision maker: which kind of finding, what to say,
|
|
1079
|
+
what can be done
|
|
1080
|
+
destinations.ts where a move goes, and how sure the report is
|
|
1081
|
+
finding-type.ts the interface each finding type implements
|
|
1082
|
+
vocabulary/
|
|
1083
|
+
ids.ts the ids both sides use (the report and the picture)
|
|
1084
|
+
verbs.ts "imports" / "import" / "mutation"
|
|
1085
|
+
phrases.ts a fact → a phrase, a subject, a reason
|
|
1086
|
+
places.ts entity → box, name → node, an entity's declared home
|
|
1087
|
+
types/
|
|
1088
|
+
wrongAction.ts a relation the architecture forbids
|
|
1089
|
+
wrongPlacement.ts the code is in the wrong place (move, or split)
|
|
1090
|
+
unknownEntity.ts nothing declares this kind of code here
|
|
1091
|
+
fileContents.ts the finding judges the file itself
|
|
1092
|
+
codes/
|
|
1093
|
+
structure.ts structure.* — "this entry does not belong in this folder"
|
|
499
1094
|
```
|
|
500
1095
|
|
|
501
1096
|
Each type answers three questions and nothing else:
|
|
502
1097
|
|
|
503
|
-
|
|
|
504
|
-
|
|
1098
|
+
| export | question |
|
|
1099
|
+
| --- | --- |
|
|
505
1100
|
| `classify(ctx, places)` | is this finding of my kind, and what are the facts? |
|
|
506
1101
|
| `message(story, ctx)` | the sentence to print — `null` keeps the engine's |
|
|
507
1102
|
| `fixes(story, ctx)` | **a list** of repairs, cheapest first |
|
|
508
1103
|
|
|
509
|
-
`fixes` is
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
"Delete it." about a file that is perfectly placed.
|
|
1104
|
+
`fixes` is a list because a broken rule usually has more than one honest answer: a
|
|
1105
|
+
forbidden relation can be repaired by removing the usage, by moving the code, or by
|
|
1106
|
+
widening the rule — printing only the first is how a report says "Delete it." about a
|
|
1107
|
+
file that is perfectly placed.
|
|
514
1108
|
|
|
515
1109
|
**The engine emits tokens, not prose.** A refused relation travels as
|
|
516
1110
|
|
|
517
1111
|
```js
|
|
518
1112
|
{ code: "relation.forbidden",
|
|
519
1113
|
fact: { kind: "typeImport", resolved: "…/document/type.ts" },
|
|
520
|
-
subject: { pieces: [],
|
|
521
|
-
why: { code: "allowed",
|
|
1114
|
+
subject: { pieces: [], entities: ["constants"], plural: false },
|
|
1115
|
+
why: { code: "allowed", entities: ["theme"], targetNode: "sharedTypes" },
|
|
522
1116
|
via: null }
|
|
523
1117
|
```
|
|
524
1118
|
|
|
525
|
-
`phrases.
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
|
555
|
-
|
|
556
|
-
|
|
|
557
|
-
|
|
|
558
|
-
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
1119
|
+
`phrases.ts` renders the sentence from it, `wrongAction.ts` renders the repairs, the
|
|
1120
|
+
picture renders the arrow.
|
|
1121
|
+
|
|
1122
|
+
### Where a move goes
|
|
1123
|
+
|
|
1124
|
+
A destination is a **decision**, not a lookup: it is decided by the code entity and
|
|
1125
|
+
confirmed by the tree. The confidence is a `0..1` number built from five sources:
|
|
1126
|
+
|
|
1127
|
+
| source | question | weight |
|
|
1128
|
+
| --- | --- | --- |
|
|
1129
|
+
| `declared` | does the tree call this file that entity (its owner node's entities)? | 0.45 |
|
|
1130
|
+
| `inferred` | did the engine infer that entity from the code itself? | 0.30 |
|
|
1131
|
+
| `named` | does a home of that entity name this file? | 0.13 |
|
|
1132
|
+
| `hostable` | can a real node instance host that home today? | 0.07 |
|
|
1133
|
+
| `branch` | is that home in the file's own top branch? | 0.05 |
|
|
1134
|
+
|
|
1135
|
+
`permits` is **not** a weight — it is a **precondition**: the law is "everything not
|
|
1136
|
+
allowed is forbidden", so a place where the relation is still forbidden is not a
|
|
1137
|
+
destination at all, whatever the other signals say. A candidate also needs a known
|
|
1138
|
+
code entity (`declared` or `inferred`) and at least two sources with confidence ≥ 0.5.
|
|
1139
|
+
When nothing qualifies, no move is offered and the repair is the removal.
|
|
1140
|
+
|
|
1141
|
+
### The modules
|
|
1142
|
+
|
|
1143
|
+
| path | what it owns |
|
|
1144
|
+
| --- | --- |
|
|
1145
|
+
| [entities/ast/](entities/ast) | reading code: imports, exports, calls, writes, declarations, comments → **facts** |
|
|
1146
|
+
| [entities/kinds.ts](entities/kinds.ts) | a fact → an **edge** (`{ path, line, piece, entity, fact, what }`); the eight relations |
|
|
1147
|
+
| [entities/tree/](entities/tree) | **where** files may live: `build.ts` (nodes → path variants + entity homes), `match.ts` (a path → its node, and whether that node is real there), `entries.ts` (walking a path, reporting undeclared entries) |
|
|
1148
|
+
| [nodes/](nodes) | `children.ts`, `child-entities.ts`, `similar.ts`; the home lookup lives in [entities/location/homes.ts](entities/location/homes.ts) |
|
|
1149
|
+
| [nodes/finally/](nodes/finally) | the built-in structure rule: `required.ts` (is this folder an instance of its node?), `queries.ts` (does this file match a child's query?), `relations.ts` (does this file reach code it may not?), `entities.ts` (does its kind fit the node?), `emit.ts` (one finding per decision) |
|
|
1150
|
+
| [rules/](rules) | a rule's own keys: `normalize.ts`, `name.ts`, `vars.ts`, `list-vars.ts`, `index.ts` (the evaluation) |
|
|
1151
|
+
| [report/errorTypes/](report/errorTypes) | **the words**: message, repairs, destinations, the ids the picture uses |
|
|
1152
|
+
| [report/user-report/](report/user-report) | the interactive overview: data → JSON → React |
|
|
1153
|
+
|
|
1154
|
+
### The overview page
|
|
1155
|
+
|
|
1156
|
+
`--overview [path]` writes one self-contained HTML file (no server, no network, no
|
|
1157
|
+
sidecar assets) that renders the architecture as a browsable model:
|
|
1158
|
+
|
|
1159
|
+
| screen | what it answers |
|
|
1160
|
+
| --- | --- |
|
|
1161
|
+
| **Overview** (`SummaryScreen`) | counts, findings by category, orphan files, the most important violations |
|
|
1162
|
+
| **Architecture tree** (`TreeScreen`) | every declared node, the entities that may live in it, the arrows that touch it, and its findings |
|
|
1163
|
+
| **Graph & code entities** (`GraphScreen`) | the entities list and the selected entity's card (how it is inferred, a real example, what may be done with it); the canvas draws **one box per code entity** and the relations the scan actually saw between entities |
|
|
1164
|
+
| **Rules** (`RulesScreen`) | each rule rewritten as plain conditions (`lines > 200`, `rule ≠ action`), with `where` / `ignore` named by kind |
|
|
1165
|
+
| **Findings** (`FindingsScreen`) | every violation with its message, the boundary it crossed, why it matters, and the fix |
|
|
1166
|
+
|
|
1167
|
+
### The graph screen
|
|
1168
|
+
|
|
1169
|
+
The canvas is **entity → entity**: one box per code entity (`data record`, `handler`,
|
|
1170
|
+
`atom`, `theme`, `barrel`, …), with the paths it may be met at listed inside. The
|
|
1171
|
+
selected entity's box is **always drawn**, even when no relation touches it, and then
|
|
1172
|
+
the screen says so in words — “No relation touches `data record` in this scan: nothing
|
|
1173
|
+
it declares is read, called or imported by another entity, and the architecture
|
|
1174
|
+
declares no rule for it either.” There is never an unexplained empty canvas.
|
|
1175
|
+
|
|
1176
|
+
The arrows are the relations the scan **judged**, not only the rules the config
|
|
1177
|
+
declares: `import`, `export`, `declare`, `call`, `mutate`, `assign`, `read`,
|
|
1178
|
+
`typeImport`, aggregated **per entity pair** — one arrow per kind, from, to. An arrow
|
|
1179
|
+
points from the code that **does** the thing to the code it does it to —
|
|
1180
|
+
`molecule ──import──▶ atom` means *the molecule's code imports the atom's code* —
|
|
1181
|
+
and hovering it prints the sentence and the `file:line` the scan read it from.
|
|
1182
|
+
|
|
1183
|
+
How to read one arrow:
|
|
1184
|
+
|
|
1185
|
+
| on the arrow | what it means |
|
|
1186
|
+
| --- | --- |
|
|
1187
|
+
| the kind and **`×N`** | `N` places in the scan do exactly this — the number is the count, not a guess |
|
|
1188
|
+
| red, dashed, `✕` and `×N` red | the architecture **refuses** these `N` places — the same arrows the Findings screen reports |
|
|
1189
|
+
| faint dashed | the config **declares** the relation but this scan never saw it — a rule without code behind it |
|
|
1190
|
+
| hover | the exact sentence of the first place, with its `file:line` (`imports \`src/x.ts\`` — `src/reader.ts:2`) |
|
|
1191
|
+
| click a box | opens that entity (`#graph?entity=<slug>`) |
|
|
1192
|
+
|
|
1193
|
+
The arrows do not carry the labels — the **kinds** do. Every arrow of one kind at one
|
|
1194
|
+
box is ONE **ribbon**: its arrows share one port on the box and one lane in the strip
|
|
1195
|
+
between the columns, so they run together and fan out only where they land. One ribbon
|
|
1196
|
+
per (box, side, kind), one **pill** per (box, kind) — `typeImport ×109` (every place of
|
|
1197
|
+
that kind at the box, both ways), `✕ import ×2` (red: every one of them refused),
|
|
1198
|
+
`import ×6 · ✕2` (mixed) — and no arrow has a label of its own. The ribbons of a box
|
|
1199
|
+
stand in the order of the kind chips (`declare`, `export`, `import`, `call`, `read`,
|
|
1200
|
+
`typeImport`…), so a ribbon sits where its chip sits. Pointing at a pill lights every
|
|
1201
|
+
arrow of its kind at that box and names the boxes it reaches under the drawing
|
|
1202
|
+
(`atom · typeImport ×109 · ✕2: barrel ×11, class ×10, constant ×10, +8 more`); pointing
|
|
1203
|
+
at a kind **chip** does the same for the ribbons of that kind at the selected entity.
|
|
1204
|
+
|
|
1205
|
+
The default canvas is calm on purpose: one arrow per (source, target, kind) — an
|
|
1206
|
+
observed relation and a declared hint about the same pair are one solid wire, a dashed
|
|
1207
|
+
one means declared and never once observed — drawn as a hairline at a third opacity.
|
|
1208
|
+
Refused arrows stay off the canvas until their own kind is pointed at (the pill already
|
|
1209
|
+
counts them), and the kind under the pointer comes forward while the rest fades.
|
|
1210
|
+
|
|
1211
|
+
The badge over the canvas counts what is drawn (`N entities · M relations`), the kind
|
|
1212
|
+
chips filter the arrows without losing the entity you selected (an empty filter says
|
|
1213
|
+
which filter is empty and how many relations it hides), and **Show all entities** draws
|
|
1214
|
+
every box. When nothing at all is left to draw, the chip row hides itself.
|
|
1215
|
+
|
|
1216
|
+
The data behind it is `access.observed`: one entry per kind + from + to with `count`
|
|
1217
|
+
(places seen), `broken` (how many of them were refused) and `sample` (`{ file, line,
|
|
1218
|
+
sentence }` of the first place). The engine fills it while it judges the relations —
|
|
1219
|
+
`report/observed.ts` per file, republished idempotently — and the report merges it with
|
|
1220
|
+
the declared arrows (`declared: true`, no `count` when never seen) in
|
|
1221
|
+
`report/user-report/data/graph-entities.ts`, so the page can tell “declared but not
|
|
1222
|
+
observed” from “observed and broken” from “observed and allowed”.
|
|
1223
|
+
|
|
1224
|
+
Nothing in the report is hardcoded per project: titles come from the configured
|
|
1225
|
+
messages, conditions from the configured filters, examples from real paths. Findings
|
|
1226
|
+
carry the engine's structured `data.repair`, so the UI never parses message text.
|
|
1227
|
+
|
|
1228
|
+
### Prebuilt bundle
|
|
1229
|
+
|
|
1230
|
+
The page inlines a React app compiled at **package build time**, not on first use:
|
|
1231
|
+
`scripts/build-report-bundle.mjs` writes `dist/report/user-report/build/bundle.prebuilt.js`,
|
|
1232
|
+
which ships inside `dist/`. A published CLI therefore never needs `esbuild`, React or
|
|
1233
|
+
`styled-components` at runtime.
|
|
1234
|
+
|
|
1235
|
+
Contributors running from source without a build still get overviews: when the asset is
|
|
1236
|
+
missing, the bundle is compiled on the fly and cached in `os.tmpdir()`. `pnpm build` =
|
|
1237
|
+
`clean` → `tsc` → `prebuild:report`; run the workspace build so `@md-code/sections`
|
|
1238
|
+
(which owns the code-diff board) is compiled before the packages that bundle its view.
|
|
1239
|
+
|
|
1240
|
+
## The ESLint rule
|
|
1241
|
+
|
|
1242
|
+
Rule name: **`md-code/follow-architecture`**, severity `error` in the config above
|
|
1243
|
+
(`meta.type: "problem"`). It is the same engine as the CLI: same architecture file,
|
|
1244
|
+
same facts, same wording — a finding the CLI prints is a diagnostic the editor
|
|
1245
|
+
underlines, on the line the violation starts at.
|
|
1246
|
+
|
|
1247
|
+
| Option | Type | Default | Meaning |
|
|
1248
|
+
| --- | --- | --- | --- |
|
|
1249
|
+
| `config` | `string` | `architecture.yaml` | The architecture file's path |
|
|
1250
|
+
| `configs` | `object` | — | Tool config paths (`tailwind.config.js`, an SCSS entry): key → path, read once per run |
|
|
1251
|
+
| `include` | `string[]` | — | Only files matching these globs are checked |
|
|
1252
|
+
| `exts` | `string[]` | the built-in list | Source extensions, added to `.ts`, `.tsx`, `.js`, `.jsx`, `.mts`, `.cts`, `.vue`, `.svelte` |
|
|
1253
|
+
| `similarity` | `number` | `0.6` | Threshold for the "similar file" facts |
|
|
1254
|
+
| `barrelDepth` | `integer ≥ 1` | `8` | How many barrels a name may pass through before the name stays on the module |
|
|
1255
|
+
| `ignoreDirs` | `string[]` | the tool's list | Folder names not entered, added to `node_modules`, `.git`, `dist`, `reports`, `.turbo`, … |
|
|
1256
|
+
| `ignores` | `string[]` | — | Repo-relative file globs skipped, added to the tool's list |
|
|
1257
|
+
| `exportPath` | `string \| false` | `reports/architecture-overview.html` | Where the rule writes its HTML overview; `false` turns it off |
|
|
1258
|
+
| `indexPath` | `string \| false` | `.turbo/md-code/file-index.jsonl` | The shared file index; `false` turns the index gate off |
|
|
1259
|
+
| `usage` | `"checker" \| "index"` | `checker` | Who answers `references` |
|
|
1260
|
+
| `warmIndex` | `boolean` | `true` | `false` never starts a background `pnpm index:warm` |
|
|
1261
|
+
|
|
1262
|
+
The option may also be a bare string (`["error", "architecture.yaml"]`), which is the
|
|
1263
|
+
same as `{ config: "architecture.yaml" }`. There is no `root` option: the rule anchors
|
|
1264
|
+
the repo on the file being linted (`findRepoRoot(dirname(filePath))`, then the working
|
|
1265
|
+
directory), which is the only value that is right both in an editor that starts the
|
|
1266
|
+
ESLint server in a package directory and in a root-level CLI run. The schema rejects
|
|
1267
|
+
unknown option keys.
|
|
1268
|
+
|
|
1269
|
+
**What is linted.** The same two default lists the CLI uses — `IGNORE_DIRS` and
|
|
1270
|
+
`IGNORE_PATHS` from `ignore.ts` (published as `@md-code/follow-architecture/ignore.js`) —
|
|
1271
|
+
plus `ignoreDirs` / `ignores`, then `include` narrowing. Both lists are additive, and
|
|
1272
|
+
neither is private to this tool: `@md-code/config/eslint` spreads `IGNORE_PATHS` into
|
|
1273
|
+
its global `ignores`, which is why a lint run and a scan run skip the same files. They
|
|
1274
|
+
name what they skip (`apps/**`, `packages/api/**`, `scripts/**`, `**/*.js`, …) and say
|
|
1275
|
+
nothing about tests, so this package's own tests are in the lint area like any other
|
|
1276
|
+
file — a test that breaks a law the architecture describes is reported, and the
|
|
1277
|
+
user-report source and `tests/cli/` are named in `ignore.ts` as deliberately kept.
|
|
1278
|
+
|
|
1279
|
+
**What the editor shows.** One diagnostic per finding: the finding's message, then
|
|
1280
|
+
`How to fix:` and the named repairs when the decision maker has any. Findings from a
|
|
1281
|
+
file's own facts, from peer files and from the accumulated verdicts all arrive this
|
|
1282
|
+
way. On a cold workspace the first line of every file is one sentence (see [Index](#the-rule-reads-the-index-never-builds-it)) and
|
|
1283
|
+
nothing else is reported for that file.
|
|
1284
|
+
|
|
1285
|
+
**What the rule writes.** Exactly one file: the HTML overview at `exportPath`, the same
|
|
1286
|
+
self-contained page `--overview` produces, accumulated across every linted file and
|
|
1287
|
+
flushed when the run ends — debounced while the run continues, one last write on
|
|
1288
|
+
process exit. It never writes the index (that is the CLI and `pnpm index:warm`), never
|
|
1289
|
+
writes Markdown, and never edits a source file. `exportPath: false` runs the rule with
|
|
1290
|
+
no writes at all.
|
|
1291
|
+
|
|
1292
|
+
## Index
|
|
1293
|
+
|
|
1294
|
+
A run keeps what it read in one index file (`.turbo/md-code/file-index.jsonl`, or
|
|
1295
|
+
`--index <path>`): per file, plain-data facts and the verdicts, so the next run reads
|
|
1296
|
+
the files that changed and the answers it already had. `--index off` neither reads nor
|
|
1297
|
+
writes it.
|
|
1298
|
+
|
|
1299
|
+
Each record has four sections — `fa` (the slimmable facts), `fa-peers` (the
|
|
1300
|
+
candidates), `fa-out` (the verdicts) and `fa-usage` (the `references` answers) — and
|
|
1301
|
+
every section value carries the stat of the file it was computed from. The record's own
|
|
1302
|
+
mtime/size say whether the FILE changed, which is what the write path needs; the
|
|
1303
|
+
value's stamp says whether *that* section still describes the file, so a section
|
|
1304
|
+
written by another tool cannot make this one look fresh. A value without a stamp is
|
|
1305
|
+
read as stale once. Fingerprints are the tool identity (package version, the
|
|
1306
|
+
fact-changing option values, a content hash of `dist/`) plus the file's own mtime and
|
|
1307
|
+
size: bumping the package or changing an option makes every section stale once, exactly
|
|
1308
|
+
like editing a file does.
|
|
1309
|
+
|
|
1310
|
+
The one fact a file cannot answer about itself is `references` — who uses a published
|
|
1311
|
+
name is a statement about every other file. It has two sources:
|
|
1312
|
+
|
|
1313
|
+
| `--usage` / option `usage` | how it is answered | exactness |
|
|
1314
|
+
| --- | --- | --- |
|
|
1315
|
+
| `checker` (default) | the type checker, on one project over the whole repository, once per run (`fa-usage` in the index) | what TypeScript says: the declaration a use actually binds to |
|
|
1316
|
+
| `index` | identifiers counted in the repo's text (`ts.createScanner`): per name, per file, member positions (`a.foo`) counted apart from value positions | an approximation: it cannot tell two same-named declarations apart |
|
|
1317
|
+
|
|
1318
|
+
`usage: index` is much faster cold and answers differently: a name no module imports
|
|
1319
|
+
reads as used because some other module writes the same name, and `this.value` is
|
|
1320
|
+
missed because a member is counted from its occurrences after a dot. Use it when the
|
|
1321
|
+
`references` rules are advisory and a cold run must be quick; keep `checker` when a
|
|
1322
|
+
finding about an unused export has to be true. The same choice exists in the ESLint
|
|
1323
|
+
rule, so an editor session and a CLI run can be compared like for like.
|
|
1324
|
+
|
|
1325
|
+
Editing `architecture.yaml` is not watched by the editor: restart the ESLint server
|
|
1326
|
+
(`ESLint: Restart ESLint Server`) after changing it.
|
|
1327
|
+
|
|
1328
|
+
### The rule reads the index, never builds it
|
|
1329
|
+
|
|
1330
|
+
Before the rule reads or parses anything it asks the index whether this workspace can
|
|
1331
|
+
answer right now: the file's record (`fa`), the pieces of other files a code entity
|
|
1332
|
+
names (`fa-peers`) and the verdicts of files the run did not revisit (`fa-out`) must
|
|
1333
|
+
all be present, current, and recorded by this build of the tool. When they are not — a
|
|
1334
|
+
fresh clone, a fresh pull, an edited `architecture.yaml` — the rule reports one
|
|
1335
|
+
sentence on the first line,
|
|
1336
|
+
|
|
1337
|
+
> the architecture index is not built or is out of date for this workspace; run
|
|
1338
|
+
> `pnpm index:warm` — this file is not checked until then
|
|
1339
|
+
|
|
1340
|
+
and starts `pnpm index:warm` once in the background for the whole workspace, so the
|
|
1341
|
+
next pass is answered from the index. No file is walked, no project is opened, nothing
|
|
1342
|
+
is written. Option `warmIndex: false` keeps the message but never starts the run;
|
|
1343
|
+
`indexPath: false` turns the gate off with the index itself and checks the file in a
|
|
1344
|
+
project of its own closure, as the command line does without an index.
|
|
1345
|
+
|
|
1346
|
+
### Warming the index
|
|
1347
|
+
|
|
1348
|
+
`pnpm index:warm` (repo root) runs `scripts/index-warm.mjs`: it reads the rule options
|
|
1349
|
+
from `@md-code/config/eslint` — the same file the editor loads — so the warm run
|
|
1350
|
+
asks for the same sections, with the same fingerprints, that the editor later reads.
|
|
1351
|
+
It writes `.turbo/md-code/file-index.jsonl`,
|
|
1352
|
+
logs to `.turbo/md-code/index-warm.log`, and takes a lock
|
|
1353
|
+
(`.turbo/md-code/index-warm.<label>.<hash>.lock`, 30 min TTL) so concurrent editors and
|
|
1354
|
+
CI cannot run it twice. `node scripts/index-warm.mjs --root <dir> --verbose` does the
|
|
1355
|
+
same for one root.
|
|
1356
|
+
|
|
1357
|
+
There is no `cache` option — the index *is* the cache, and every section it holds is a
|
|
1358
|
+
pure function of the file's content and the architecture.
|
|
1359
|
+
|
|
1360
|
+
## Outputs
|
|
1361
|
+
|
|
1362
|
+
| Flag | File | Default |
|
|
1363
|
+
| --- | --- | --- |
|
|
1364
|
+
| `--out <path>` | Markdown text report | none — the report goes to stdout |
|
|
1365
|
+
| `--overview [path]` | self-contained HTML page | `architecture-overview.html`, resolved against the repo root |
|
|
1366
|
+
| — | HTML overview from the ESLint rule | `exportPath`, default `reports/architecture-overview.html`; `false` turns it off |
|
|
1367
|
+
|
|
1368
|
+
`--check` turns either CLI run into a CI gate: the same findings, exit code 1 when
|
|
1369
|
+
there is at least one.
|
|
1370
|
+
|
|
1371
|
+
The Markdown report is `renderReport`:
|
|
1372
|
+
|
|
1373
|
+
```
|
|
1374
|
+
# follow-architecture report
|
|
1375
|
+
Generated against `<repoRoot>`.
|
|
1376
|
+
## Orphan files (only when there are some)
|
|
1377
|
+
## Rules (each declared rule, rewritten as plain conditions)
|
|
1378
|
+
## Findings (grouped by heading)
|
|
1379
|
+
#### `<what>` — `<file>:<line>`
|
|
1380
|
+
<message>
|
|
1381
|
+
**Fix** — N option(s):
|
|
1382
|
+
- <repair>
|
|
1383
|
+
---
|
|
1384
|
+
## Not read (N) (only when files were skipped, with the reason)
|
|
1385
|
+
```
|
|
1386
|
+
|
|
1387
|
+
There is no catalog file: the package produces a report, not a record set, so
|
|
1388
|
+
`exportPath` is the only output path a rule can name. The shared index is written by
|
|
1389
|
+
the CLI and by `pnpm index:warm` only, and is a cache — never an input you are
|
|
1390
|
+
expected to edit.
|
|
1391
|
+
|
|
1392
|
+
## Limitations and known debt
|
|
1393
|
+
|
|
1394
|
+
- **No auto-fix, no warning severity.** Every finding is an ESLint `error` and every
|
|
1395
|
+
repair is prose; moves are described, never applied.
|
|
1396
|
+
- **The rule writes one file.** `exportPath` HTML only, rewritten when the set of
|
|
1397
|
+
findings changes (debounced during the run, once at exit). It never writes Markdown
|
|
1398
|
+
and never touches a source file.
|
|
1399
|
+
- **Only the CLI and `pnpm index:warm` build the index.** The rule reports the cold
|
|
1400
|
+
sentence and, once per workspace, starts `pnpm index:warm` in the background. Where
|
|
1401
|
+
the root script does not exist (a published install outside a monorepo) the request
|
|
1402
|
+
fails quietly and the file stays unchecked until the CLI runs.
|
|
1403
|
+
- **The index is per-file and content-keyed.** The architecture's own fingerprint is
|
|
1404
|
+
part of every section, so editing the YAML invalidates the facts wholesale — but a
|
|
1405
|
+
running editor is not watching the file; restart the ESLint server.
|
|
1406
|
+
- **`usage: index` is an approximation.** It counts identifiers in the text, so two
|
|
1407
|
+
same-named declarations are indistinguishable. `references` rules get less
|
|
1408
|
+
trustworthy, not slower to compute.
|
|
1409
|
+
- **A run without an index is a whole-repo parse**: minutes and gigabytes on a
|
|
1410
|
+
monorepo this size (`--index off`, and the editor without an index). With a warm
|
|
1411
|
+
index the same run is seconds. The index is not an optimisation to skip casually.
|
|
1412
|
+
- **`dist/main.js` has no entry guard.** `node dist/main.js` exits 0 silently; the
|
|
1413
|
+
executable entry is `dist/bin/follow-architecture.js`.
|
|
1414
|
+
- **The overview's dev fallback needs esbuild.** When the prebuilt bundle is missing the
|
|
1415
|
+
page is compiled on the fly and cached in `os.tmpdir()`; only that path resolves the
|
|
1416
|
+
bundler.
|
|
1417
|
+
- **No catalogs, no `--check` staleness gate for anything but the index.** Findings are
|
|
1418
|
+
compared, not a record set, so there is nothing else to regenerate.
|
|
1419
|
+
|
|
1420
|
+
## Scripts
|
|
1421
|
+
|
|
1422
|
+
Package scripts (`pnpm <script>`; each runs in the
|
|
1423
|
+
package folder):
|
|
1424
|
+
|
|
1425
|
+
| Script | Runs |
|
|
1426
|
+
| --- | --- |
|
|
1427
|
+
| `build` | `clean` → `tsc -p tsconfig.json` → `prebuild:report` |
|
|
1428
|
+
| `clean` | removes `dist/` |
|
|
1429
|
+
| `prebuild:report` | `node scripts/build-report-bundle.mjs` |
|
|
1430
|
+
| `typecheck` | `tsc -p tsconfig.json --noEmit` |
|
|
1431
|
+
| `test` | `vitest run` |
|
|
1432
|
+
| `lint` | `eslint .` |
|
|
1433
|
+
| `format` | Prettier `--write` over `**/*.{ts,tsx,js,jsx,css,json}` |
|
|
1434
|
+
| `format:check` | the same globs with `--check` |
|
|
1435
|
+
| `lint:products` | ESLint with `--config packages/follow-architecture/eslint.products.config.mjs` over `packages`, `NODE_OPTIONS=--max-old-space-size=13312`, `LINT_OVERVIEW=0` — the products as rules, findings in the console |
|
|
1436
|
+
| `lint:products:overview` | the same run with `LINT_OVERVIEW=1`: identical console output, and each product also writes its page under `reports/` |
|
|
1437
|
+
| `overview` | `node dist/bin/follow-architecture.js --overview architecture-overview.html` (needs an `architecture.yaml` in the current folder) |
|
|
1438
|
+
| `prepublishOnly` | `build` → `vitest run --no-file-parallelism` |
|
|
1439
|
+
|
|
1440
|
+
Repo-root commands:
|
|
1441
|
+
|
|
1442
|
+
| Command | Runs |
|
|
1443
|
+
| --- | --- |
|
|
1444
|
+
| `pnpm test:packages` | `turbo test --filter=./packages/*` |
|
|
1445
|
+
| `pnpm check:all` | `turbo run build typecheck lint test format:check` |
|
|
1446
|
+
| `pnpm lint` | `turbo run lint` (every package's own lint, with the product rules off), then `turbo run lint:products --filter=@md-code/follow-architecture` |
|
|
1447
|
+
| `pnpm lint:overview` | the same two phases with `lint:products:overview` — identical console output, plus one `reports/*-overview.html` per product |
|
|
1448
|
+
| `pnpm typecheck` | `turbo run typecheck` |
|
|
1449
|
+
| `pnpm format:check` | Prettier `--check` over `packages/**/*.{ts,tsx,js,jsx,css,json}` |
|
|
1450
|
+
| `pnpm index:warm` | `node scripts/index-warm.mjs` — writes the workspace index (log: `.turbo/md-code/index-warm.log`) |
|
|
1451
|
+
|
|
1452
|
+
To run the CLI against a real architecture file, point `--config` at it:
|
|
1453
|
+
|
|
1454
|
+
```sh
|
|
1455
|
+
node dist/bin/follow-architecture.js --config architecture.yaml --overview architecture-overview.html
|
|
1456
|
+
```
|
|
630
1457
|
|
|
631
1458
|
## Tests
|
|
632
1459
|
|
|
633
1460
|
```sh
|
|
634
|
-
|
|
1461
|
+
pnpm test # vitest run
|
|
1462
|
+
pnpm test:packages # every package's suite
|
|
635
1463
|
```
|
|
636
1464
|
|
|
1465
|
+
The suite is the engine's contract: the filter operators, the config errors, the tree,
|
|
1466
|
+
the facets and the report. `tests/readme.test.ts` holds this document against the built
|
|
1467
|
+
`dist/`: every `--flag` the CLI accepts, every rule option the schema accepts, every
|
|
1468
|
+
command example it can run, every `@md-code/*` subpath it names, and the Install table
|
|
1469
|
+
against `package.json`.
|
|
1470
|
+
|
|
1471
|
+
## Version
|
|
1472
|
+
|
|
1473
|
+
`0.3.2` — package `follow-architecture`, Apache-2.0, Node `>=18`, ESLint peer `>=8.40.0`. Source: https://github.com/DrBoria/follow-architecture.
|
|
1474
|
+
|
|
637
1475
|
## License
|
|
638
1476
|
|
|
639
1477
|
[Apache License 2.0](./LICENSE)
|