@md-code/follow-architecture 0.3.0 → 0.3.3
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 +38 -0
- package/README.md +1341 -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 +122 -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} +81 -54
- package/dist/code-entities/project.d.ts +21 -0
- package/dist/code-entities/project.js +249 -0
- package/dist/code-entities/walk.d.ts +31 -0
- package/dist/code-entities/walk.js +95 -0
- package/dist/config-options.d.ts +23 -0
- package/dist/config-options.js +18 -1
- package/dist/config-project.js +10 -2
- package/dist/config-report.d.ts +1 -1
- package/dist/config-report.js +20 -3
- package/dist/config-rule.d.ts +25 -0
- package/dist/config-rule.js +89 -6
- package/dist/config-state.d.ts +14 -3
- package/dist/config-state.js +180 -17
- package/dist/config.d.ts +25 -0
- package/dist/css/index.d.ts +11 -7
- package/dist/css/index.js +124 -23
- 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 +1 -1
- 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 +4 -2
- package/dist/css/syntax/scss/index.d.ts +2 -2
- package/dist/css/syntax/scss/index.js +1 -1
- 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 +17 -7
- 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 +15 -8
- 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 +4 -4
- 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 +131 -30
- 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 +8 -6
- package/dist/entities/location/where.js +79 -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 +72 -12
- 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 +95 -44
- package/dist/entities/tree/entries.d.ts +3 -3
- 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 +9 -5
- 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 +232 -0
- package/dist/fa-store.d.ts +22 -0
- package/dist/fa-store.js +222 -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 +287 -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 +8 -4
- 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 +48 -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 +209 -0
- package/dist/main.d.ts +5 -2
- package/dist/main.js +207 -34
- 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 +54 -11
- package/dist/nodes/finally/emit.d.ts +3 -3
- 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 +61 -49
- 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 +47 -55
- 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.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 +4 -4
- 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/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 +9 -0
- 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 +15 -12
- 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 +126 -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 +16 -16
- 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 +2 -2
- 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/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/{invariants → rules}/normalize.js +35 -32
- 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 +2 -2
- package/dist/usage-index.d.ts +4 -0
- package/dist/usage-index.js +272 -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 +254 -0
- package/dist/utils/aliases.d.ts +22 -0
- package/dist/utils/aliases.js +163 -0
- package/dist/utils/classify.d.ts +2 -2
- package/dist/utils/classify.js +4 -4
- package/dist/utils/distinct.js +4 -2
- package/dist/utils/files.js +24 -30
- 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 +66 -12
- 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 +197 -0
- package/dist/utils/path-label.js +3 -1
- package/dist/utils/pattern.d.ts +5 -4
- package/dist/utils/pattern.js +38 -8
- 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/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
|
@@ -23,39 +23,40 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
// Normalize
|
|
26
|
+
exports.normalizeRule = void 0;
|
|
27
|
+
// Normalize a rule from the YAML into the runtime shape the gates and
|
|
28
28
|
// checkers consume.
|
|
29
29
|
//
|
|
30
|
-
//
|
|
30
|
+
// A rule is: WHERE it applies (`where`), where it does NOT (`ignore`),
|
|
31
31
|
// and what it forbids (`infer`). Both `where` and `ignore` are the same
|
|
32
|
-
// mechanism the code
|
|
32
|
+
// mechanism the code entities use (utils/where.js).
|
|
33
33
|
//
|
|
34
|
-
// `infer` is the SAME key as in
|
|
35
|
-
// language: the difference is only what a match means. In
|
|
36
|
-
// "this code IS that
|
|
34
|
+
// `infer` is the SAME key as in an entity, because it is the SAME filter
|
|
35
|
+
// language: the difference is only what a match means. In an entity a match says
|
|
36
|
+
// "this code IS that entity"; in a rule it says "this file breaks the
|
|
37
37
|
// rule". There is one check: a finding when the filter matches. "This must be
|
|
38
38
|
// true" is the same filter under `not:` — the language already has it, so a
|
|
39
39
|
// second key would be a second way to say one thing.
|
|
40
|
-
const location_1 = require("
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
40
|
+
const location_1 = require("@md-code/follow-architecture/entities/location");
|
|
41
|
+
const aliases_1 = require("@md-code/follow-architecture/utils/aliases");
|
|
42
|
+
const schema_1 = require("@md-code/follow-architecture/entities/schema");
|
|
43
|
+
const field_1 = require("@md-code/follow-architecture/utils/field");
|
|
44
|
+
const configError = __importStar(require("@md-code/follow-architecture/report/configErrors"));
|
|
45
|
+
// Every key a rule may carry — anything else is a declaration the config
|
|
45
46
|
// believes it made, so it fails loudly instead of doing nothing.
|
|
46
|
-
const
|
|
47
|
+
const RULE_KEYS = new Set(schema_1.SCHEMA.rule);
|
|
47
48
|
const checkKeys = (raw) => {
|
|
48
49
|
for (const key of Object.keys(raw)) {
|
|
49
|
-
if (
|
|
50
|
+
if (RULE_KEYS.has(key))
|
|
50
51
|
continue;
|
|
51
|
-
throw configError.
|
|
52
|
+
throw configError.unknownRuleKey({ id: raw.id, key });
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
55
|
// `dedupeBy` is `where` vocabulary, not a fact name. A bare string that is not
|
|
55
|
-
// a declared
|
|
56
|
+
// a declared entity and not a path is a mistake worth failing on: `path.dir`
|
|
56
57
|
// used to be a fact name and would now silently match no path at all.
|
|
57
|
-
const parseDedupe = (raw,
|
|
58
|
-
const entries = (0, location_1.parseWhere)(raw,
|
|
58
|
+
const parseDedupe = (raw, entities, aliases) => {
|
|
59
|
+
const entries = (0, location_1.parseWhere)(raw, entities, aliases);
|
|
59
60
|
for (const entry of entries) {
|
|
60
61
|
if (entry.type !== "glob")
|
|
61
62
|
continue;
|
|
@@ -65,31 +66,33 @@ const parseDedupe = (raw, roles) => {
|
|
|
65
66
|
}
|
|
66
67
|
return entries;
|
|
67
68
|
};
|
|
68
|
-
// `
|
|
69
|
-
//
|
|
70
|
-
// code-
|
|
71
|
-
const
|
|
69
|
+
// `entities` (a Set of declared slugs) is only needed so a bare string naming a
|
|
70
|
+
// entity is read as an entity reference instead of a glob — the same rule the
|
|
71
|
+
// code-entity actions follow.
|
|
72
|
+
const normalizeRule = (raw, entities = null, aliases = null) => {
|
|
72
73
|
if (!(0, field_1.isObj)(raw))
|
|
73
|
-
throw configError.
|
|
74
|
+
throw configError.ruleNotAnObject();
|
|
74
75
|
if (!raw.id)
|
|
75
|
-
throw configError.
|
|
76
|
+
throw configError.ruleWithoutId();
|
|
76
77
|
checkKeys(raw);
|
|
77
78
|
return {
|
|
78
79
|
id: String(raw.id),
|
|
79
|
-
// The SAME `where` mechanism the code-
|
|
80
|
-
where: (0, location_1.parseWhere)(raw.where,
|
|
81
|
-
ignore: (0, location_1.parseWhere)(raw.ignore,
|
|
80
|
+
// The SAME `where` mechanism the code-entity actions use.
|
|
81
|
+
where: (0, location_1.parseWhere)(raw.where, entities, aliases),
|
|
82
|
+
ignore: (0, location_1.parseWhere)(raw.ignore, entities, aliases),
|
|
82
83
|
when: raw.when ?? null,
|
|
83
84
|
// A finding when a filter MATCHES. "Must be true" is the same filter
|
|
84
85
|
// under `not:` — one check, one direction, negation in the filter.
|
|
85
|
-
infer
|
|
86
|
+
// `infer` is the filter language too, so a `location` filter in it reads
|
|
87
|
+
// `@`-patterns as aliases — the same rewrite `where` gets.
|
|
88
|
+
infer: (0, location_1.toList)(raw.infer).map((entry) => (0, aliases_1.expandLocationFilters)(entry, aliases)),
|
|
86
89
|
report: typeof raw.report === "string" || (0, field_1.isObj)(raw.report) ? raw.report : null,
|
|
87
90
|
// WHERE the findings are counted: a `where` entry, the same vocabulary
|
|
88
|
-
// the
|
|
91
|
+
// the entities use. `{ node: feature }` = one finding per feature folder,
|
|
89
92
|
// a glob = one per matched folder, a filter = one per file's folder.
|
|
90
93
|
// The engine only counts — the entry says which place.
|
|
91
|
-
dedupeBy: parseDedupe(raw.dedupeBy,
|
|
92
|
-
children: (0, location_1.toList)(raw.children).map((c) =>
|
|
94
|
+
dedupeBy: parseDedupe(raw.dedupeBy, entities, aliases),
|
|
95
|
+
children: (0, location_1.toList)(raw.children).map((c) => normalizeRule(c, entities, aliases)),
|
|
93
96
|
};
|
|
94
97
|
};
|
|
95
|
-
exports.
|
|
98
|
+
exports.normalizeRule = normalizeRule;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type FieldValue } from "
|
|
2
|
-
import type { QueryScope } from "
|
|
3
|
-
import type { FileContext } from "
|
|
1
|
+
import { type FieldValue } from "@md-code/follow-architecture/utils/field";
|
|
2
|
+
import type { QueryScope } from "@md-code/follow-architecture/entities/architecture";
|
|
3
|
+
import type { FileContext } from "@md-code/follow-architecture/entities/context";
|
|
4
4
|
type ReportVars = Record<string, string | number>;
|
|
5
5
|
declare const filterOf: (entry: FieldValue) => FieldValue;
|
|
6
6
|
declare const enrichedVars: (ctx: FileContext) => ReportVars;
|
|
@@ -10,10 +10,12 @@ declare const QUANTIFIERS: Set<string>;
|
|
|
10
10
|
declare const branchOf: (sub: FieldValue) => FieldValue;
|
|
11
11
|
declare const describePiece: (c: {
|
|
12
12
|
lines?: number[];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
framework?: {
|
|
14
|
+
css?: {
|
|
15
|
+
templates?: {
|
|
16
|
+
tag?: string;
|
|
17
|
+
}[];
|
|
18
|
+
};
|
|
17
19
|
};
|
|
18
20
|
}) => string;
|
|
19
21
|
export { filterOf, enrichedVars, listHit, collectScalars, branchOf, describePiece, QUANTIFIERS };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QUANTIFIERS = exports.describePiece = exports.branchOf = exports.collectScalars = exports.listHit = exports.enrichedVars = exports.filterOf = void 0;
|
|
4
|
-
// Report VARIABLES for the
|
|
4
|
+
// Report VARIABLES for the rule runtime: the placeholders a finding's
|
|
5
5
|
// sentence may name. Every variable is read off the facts themselves — the
|
|
6
6
|
// path vars, the scalars a fact carries, the items a filter matched — so no
|
|
7
7
|
// list of known names can fall behind the fact model.
|
|
8
|
-
const queries_1 = require("
|
|
9
|
-
const field_1 = require("
|
|
10
|
-
const record_1 = require("
|
|
8
|
+
const queries_1 = require("@md-code/follow-architecture/entities/queries");
|
|
9
|
+
const field_1 = require("@md-code/follow-architecture/utils/field");
|
|
10
|
+
const record_1 = require("@md-code/follow-architecture/utils/record");
|
|
11
11
|
const name_1 = require("./name");
|
|
12
12
|
// A check's `report` is the message template for its findings, not a filter
|
|
13
13
|
// key — strip it before matching so it is not treated as a fact field. The
|
|
@@ -111,7 +111,7 @@ exports.branchOf = branchOf;
|
|
|
111
111
|
// so the sentence can still be followed to a line.
|
|
112
112
|
const describePiece = (c) => {
|
|
113
113
|
const line = c.lines?.[0] ?? 1;
|
|
114
|
-
const tag = c.css?.templates?.[0]?.tag ?? null;
|
|
114
|
+
const tag = c.framework?.css?.templates?.[0]?.tag ?? null;
|
|
115
115
|
return tag ? `the ${tag} block at line ${line}` : `the code at line ${line}`;
|
|
116
116
|
};
|
|
117
117
|
exports.describePiece = describePiece;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Project } from "ts-morph";
|
|
2
|
+
import type { Arch } from "./entities/architecture";
|
|
3
|
+
import type { ProjectEntityIndex } from "./code-entities/project";
|
|
4
|
+
declare const openRun: (next: {
|
|
5
|
+
repoRoot: string;
|
|
6
|
+
arch: Pick<Arch, "aliases">;
|
|
7
|
+
absFiles: readonly string[];
|
|
8
|
+
whole?: Project | null;
|
|
9
|
+
}) => void;
|
|
10
|
+
declare const endRun: () => void;
|
|
11
|
+
declare const runIsOpen: () => boolean;
|
|
12
|
+
declare const adoptEntityIndex: (index: ProjectEntityIndex | null) => void;
|
|
13
|
+
declare const useRegistrySource: (source: (() => ProjectEntityIndex | null) | null) => void;
|
|
14
|
+
declare const sourcedRegistry: () => ProjectEntityIndex | null;
|
|
15
|
+
declare const adoptedEntityIndex: () => ProjectEntityIndex | null;
|
|
16
|
+
declare const scannedFiles: () => readonly string[];
|
|
17
|
+
declare const wholeRepoProject: () => Project;
|
|
18
|
+
declare const projectsOpened: () => number;
|
|
19
|
+
declare const openWholeRepoProject: () => Project | null;
|
|
20
|
+
export { openRun, endRun, runIsOpen, scannedFiles, wholeRepoProject, projectsOpened, openWholeRepoProject, adoptEntityIndex, adoptedEntityIndex, useRegistrySource, sourcedRegistry, };
|
package/dist/scan-run.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sourcedRegistry = exports.useRegistrySource = exports.adoptedEntityIndex = exports.adoptEntityIndex = exports.openWholeRepoProject = exports.projectsOpened = exports.wholeRepoProject = exports.scannedFiles = exports.runIsOpen = exports.endRun = exports.openRun = void 0;
|
|
4
|
+
// WHICH PROJECT A RUN OPENS, AND HOW LONG IT LIVES.
|
|
5
|
+
//
|
|
6
|
+
// A scan asks two kinds of question, and they differ in what they need in
|
|
7
|
+
// memory:
|
|
8
|
+
//
|
|
9
|
+
// - about ONE file: which pieces it declares, which entity each piece carries,
|
|
10
|
+
// what its syntax does. One file's syntax would be enough.
|
|
11
|
+
// - about the WHOLE repo: who uses a name (`references`, `implementations`),
|
|
12
|
+
// which custom properties every stylesheet declares, where the lookalikes of
|
|
13
|
+
// a folder are. A project holding one file answers "nobody" for a helper the
|
|
14
|
+
// rest of the repo calls, so these questions force a project over EVERY
|
|
15
|
+
// scanned file.
|
|
16
|
+
//
|
|
17
|
+
// Sharding was tried and measured: a batch project for the per-file work does not
|
|
18
|
+
// help. The whole-repo project has to exist anyway (the questions above are
|
|
19
|
+
// always asked), so the second project only parses every file twice — same
|
|
20
|
+
// memory, more time. What is left here is therefore ONE project over every
|
|
21
|
+
// scanned file, created on the first question that needs it, so a run that asks
|
|
22
|
+
// nothing (an all-unchanged warm run) pays nothing for it.
|
|
23
|
+
//
|
|
24
|
+
// The ESLint rule already owns such a project, and linting interleaves repos in
|
|
25
|
+
// one process: a run is a NAMED entry (one per repo root), and the rule hands its
|
|
26
|
+
// project in instead of letting this module open a second copy.
|
|
27
|
+
const config_project_1 = require("./config-project");
|
|
28
|
+
const runs = new Map();
|
|
29
|
+
let current = null;
|
|
30
|
+
// The project-wide entity index, when the run got it from the file index instead
|
|
31
|
+
// of reading every file: the pass that builds it is the run's most expensive one,
|
|
32
|
+
// and a run whose records are all fresh would otherwise repeat it for nothing.
|
|
33
|
+
let adopted = null;
|
|
34
|
+
// Make `repoRoot`'s run current, creating it on first sight. `whole` is a project
|
|
35
|
+
// the caller already built over the same file list — reusing it is the point, as
|
|
36
|
+
// a second copy would double the largest structure in the run.
|
|
37
|
+
const openRun = (next) => {
|
|
38
|
+
openedProjects = 0;
|
|
39
|
+
const known = runs.get(next.repoRoot);
|
|
40
|
+
if (known && known.absFiles === next.absFiles) {
|
|
41
|
+
current = known;
|
|
42
|
+
if (next.whole)
|
|
43
|
+
known.whole = next.whole;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
adopted = null;
|
|
47
|
+
const created = {
|
|
48
|
+
repoRoot: next.repoRoot,
|
|
49
|
+
arch: next.arch,
|
|
50
|
+
absFiles: next.absFiles,
|
|
51
|
+
whole: next.whole ?? null,
|
|
52
|
+
};
|
|
53
|
+
runs.set(next.repoRoot, created);
|
|
54
|
+
current = created;
|
|
55
|
+
};
|
|
56
|
+
exports.openRun = openRun;
|
|
57
|
+
// A CLI run's end: the run's project goes away with it. (The ESLint rule never
|
|
58
|
+
// ends its run — its state lives as long as the lint session.)
|
|
59
|
+
const endRun = () => {
|
|
60
|
+
if (current)
|
|
61
|
+
runs.delete(current.repoRoot);
|
|
62
|
+
current = null;
|
|
63
|
+
};
|
|
64
|
+
exports.endRun = endRun;
|
|
65
|
+
const runIsOpen = () => current != null;
|
|
66
|
+
exports.runIsOpen = runIsOpen;
|
|
67
|
+
// Hand the run an index it did not have to build (`code-entities/project` reads it
|
|
68
|
+
// before its own pass), or clear it with null.
|
|
69
|
+
const adoptEntityIndex = (index) => {
|
|
70
|
+
adopted = index;
|
|
71
|
+
};
|
|
72
|
+
exports.adoptEntityIndex = adoptEntityIndex;
|
|
73
|
+
// Where a run that never enumerated the tree can get the project-wide index from:
|
|
74
|
+
// the index file's own summaries and pieces. The rule path asks about one file at
|
|
75
|
+
// a time and never walks the repo, so without this its first check would read every
|
|
76
|
+
// file's syntax to answer a question the index already answered. The source is
|
|
77
|
+
// consulted ONCE per run (the run caches what it returns by its file list).
|
|
78
|
+
let registrySource = null;
|
|
79
|
+
const useRegistrySource = (source) => {
|
|
80
|
+
registrySource = source;
|
|
81
|
+
};
|
|
82
|
+
exports.useRegistrySource = useRegistrySource;
|
|
83
|
+
const sourcedRegistry = () => (registrySource === null ? null : registrySource());
|
|
84
|
+
exports.sourcedRegistry = sourcedRegistry;
|
|
85
|
+
const adoptedEntityIndex = () => adopted;
|
|
86
|
+
exports.adoptedEntityIndex = adoptedEntityIndex;
|
|
87
|
+
// The files the run scans, in scan order. The array's identity is the run's
|
|
88
|
+
// identity: a cache keyed by it belongs to one run only.
|
|
89
|
+
const scannedFiles = () => current?.absFiles ?? [];
|
|
90
|
+
exports.scannedFiles = scannedFiles;
|
|
91
|
+
// The project over every scanned file — created on first use, which is where the
|
|
92
|
+
// run's largest structure comes from.
|
|
93
|
+
//
|
|
94
|
+
// Asked before any run was opened, nothing is scanned: an empty project sees no
|
|
95
|
+
// files, so a whole-repo question reads "no evidence" instead of taking a lint
|
|
96
|
+
// session down. That answer is WRONG for a real scan, so the state is made loud
|
|
97
|
+
// where it can be seen — a process warning on stderr (a technical note about the
|
|
98
|
+
// run, not a sentence about the config a reader has to act on) — while the run
|
|
99
|
+
// itself keeps going. Both entry points (the CLI and the rule) open a run before
|
|
100
|
+
// the first question, so this is a wiring bug, not a state a scan reaches.
|
|
101
|
+
const NO_FILES = [];
|
|
102
|
+
const EMPTY = { repoRoot: "", arch: { aliases: {} }, files: NO_FILES };
|
|
103
|
+
let warnedNoRun = false;
|
|
104
|
+
const warnNoRun = () => {
|
|
105
|
+
if (warnedNoRun)
|
|
106
|
+
return;
|
|
107
|
+
warnedNoRun = true;
|
|
108
|
+
process.emitWarning("follow-architecture: a whole-repo question was asked with no scan run open (empty project)");
|
|
109
|
+
};
|
|
110
|
+
// How many whole-repo projects this run has BUILT (not merely asked for): the
|
|
111
|
+
// number a run must keep at one — the extraction's answer pass builds it, the
|
|
112
|
+
// checks reuse it, and a second one would be a second parse of the repo.
|
|
113
|
+
let openedProjects = 0;
|
|
114
|
+
const wholeRepoProject = () => {
|
|
115
|
+
if (current == null) {
|
|
116
|
+
warnNoRun();
|
|
117
|
+
return (0, config_project_1.openProject)(EMPTY.repoRoot, EMPTY.files, EMPTY.arch);
|
|
118
|
+
}
|
|
119
|
+
if (current.whole == null) {
|
|
120
|
+
current.whole = (0, config_project_1.openProject)(current.repoRoot, current.absFiles, current.arch);
|
|
121
|
+
openedProjects += 1;
|
|
122
|
+
}
|
|
123
|
+
return current.whole;
|
|
124
|
+
};
|
|
125
|
+
exports.wholeRepoProject = wholeRepoProject;
|
|
126
|
+
const projectsOpened = () => openedProjects;
|
|
127
|
+
exports.projectsOpened = projectsOpened;
|
|
128
|
+
// That project when something already opened it.
|
|
129
|
+
const openWholeRepoProject = () => current?.whole ?? null;
|
|
130
|
+
exports.openWholeRepoProject = openWholeRepoProject;
|
|
@@ -103,9 +103,9 @@ for (const f of data.findings) {
|
|
|
103
103
|
// divergence this file exists to catch.
|
|
104
104
|
for (const o of f.fixOptions ?? []) {
|
|
105
105
|
// Repairs with no geometry: the rule's own words (`rules`), "give this code
|
|
106
|
-
//
|
|
106
|
+
// an entity" (`entity`), "create what is missing" (`add`). They name no place,
|
|
107
107
|
// and the card says so — that is not a divergence.
|
|
108
|
-
if (o.code === "rules" || o.code === "
|
|
108
|
+
if (o.code === "rules" || o.code === "entity" || o.code === "add")
|
|
109
109
|
continue;
|
|
110
110
|
// A deletion has no geometry either — and it is NOT the same as "nothing":
|
|
111
111
|
// the card must say "removed", which `plan.remove` carries.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ReferencesFact } from "@md-code/follow-architecture/entities/facts";
|
|
2
|
+
declare const primeUsageIndex: (repoRoot: string, repoFiles: readonly string[]) => void;
|
|
3
|
+
declare const usageFromIndex: (name: string | null, rel: string, exported: boolean, kindName: string | null | undefined) => ReferencesFact | null;
|
|
4
|
+
export { primeUsageIndex, usageFromIndex };
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.usageFromIndex = exports.primeUsageIndex = void 0;
|
|
27
|
+
// THE OPTIONAL, CHEAPER SOURCE OF `references` (option `usage: index`, CLI
|
|
28
|
+
// `--usage index`): an answer computed from an index of IDENTIFIER OCCURRENCES
|
|
29
|
+
// instead of from a program that holds the whole repository. The default stays
|
|
30
|
+
// the checker (`entities/ast/usage.ts`), whose answer is what this mode
|
|
31
|
+
// approximates: it is faster and costs less memory, and it is wrong wherever two
|
|
32
|
+
// modules use one name for different things.
|
|
33
|
+
//
|
|
34
|
+
// The index is one pass over the text of every scanned file with `ts.createScanner`
|
|
35
|
+
// — tokens, no AST, no project, no checker. Per name it keeps, per file: how many
|
|
36
|
+
// standalone occurrences, how many after a dot (`?.` included — a member, not the
|
|
37
|
+
// value), how many import specifiers (a binding, but the checker counts it as a
|
|
38
|
+
// reference too), how many `export … from` specifiers (a republish, which
|
|
39
|
+
// `usedIn` excludes), and whether the file declares the name at top level (then
|
|
40
|
+
// every occurrence in it belongs to that declaration, not to the name).
|
|
41
|
+
//
|
|
42
|
+
// The answer keeps the shape and the meaning of `ReferencesFact`
|
|
43
|
+
// (`entities/facts.ts:138`): `total`, `outside`, `files`, `usedIn`.
|
|
44
|
+
const fs = __importStar(require("node:fs"));
|
|
45
|
+
const path = __importStar(require("node:path"));
|
|
46
|
+
const ts_morph_1 = require("ts-morph");
|
|
47
|
+
const empty = () => ({ declares: false, plain: 0, member: 0, imported: 0, exported: 0, declared: 0 });
|
|
48
|
+
const emptySums = () => ({ total: 0, outside: 0, where: [], used: [] });
|
|
49
|
+
let index = null;
|
|
50
|
+
const isDeclKeyword = (kind) => kind === ts_morph_1.ts.SyntaxKind.FunctionKeyword ||
|
|
51
|
+
kind === ts_morph_1.ts.SyntaxKind.ClassKeyword ||
|
|
52
|
+
kind === ts_morph_1.ts.SyntaxKind.ConstKeyword ||
|
|
53
|
+
kind === ts_morph_1.ts.SyntaxKind.LetKeyword ||
|
|
54
|
+
kind === ts_morph_1.ts.SyntaxKind.VarKeyword ||
|
|
55
|
+
kind === ts_morph_1.ts.SyntaxKind.InterfaceKeyword ||
|
|
56
|
+
kind === ts_morph_1.ts.SyntaxKind.TypeKeyword ||
|
|
57
|
+
kind === ts_morph_1.ts.SyntaxKind.EnumKeyword ||
|
|
58
|
+
kind === ts_morph_1.ts.SyntaxKind.AbstractKeyword ||
|
|
59
|
+
kind === ts_morph_1.ts.SyntaxKind.AsyncKeyword;
|
|
60
|
+
// One file's text → its occurrences. The scanner is the parser's own lexer: it
|
|
61
|
+
// knows a comment from a string from a template from a regex, which is the reason
|
|
62
|
+
// the index can be built without an AST at all.
|
|
63
|
+
// eslint-disable-next-line complexity, max-lines-per-function -- a token scanner is a state machine: the roles (value / member / import / export / declaration) are decided from one running cursor and the previous token, and the branches are its states.
|
|
64
|
+
const scanInto = (into, rel, text) => {
|
|
65
|
+
const scanner = ts_morph_1.ts.createScanner(ts_morph_1.ts.ScriptTarget.Latest, true, ts_morph_1.ts.LanguageVariant.JSX, text);
|
|
66
|
+
const touch = (name) => {
|
|
67
|
+
let files = into.get(name);
|
|
68
|
+
if (!files) {
|
|
69
|
+
files = new Map();
|
|
70
|
+
into.set(name, files);
|
|
71
|
+
}
|
|
72
|
+
let found = files.get(rel);
|
|
73
|
+
if (!found) {
|
|
74
|
+
found = empty();
|
|
75
|
+
files.set(rel, found);
|
|
76
|
+
}
|
|
77
|
+
return found;
|
|
78
|
+
};
|
|
79
|
+
let previous = ts_morph_1.ts.SyntaxKind.Unknown;
|
|
80
|
+
let depth = 0;
|
|
81
|
+
// `export { … } from "x"`: the names between the braces, kept until `from`
|
|
82
|
+
// says they are a republish. Any other token ends the guess.
|
|
83
|
+
let pendingExport = null;
|
|
84
|
+
let pendingState = "idle";
|
|
85
|
+
// `import { … } from` / `import x from`: the same shape, marked as a binding.
|
|
86
|
+
let pendingImport = null;
|
|
87
|
+
let importing = false;
|
|
88
|
+
// The next identifier is a declaration of its own name (`function foo`).
|
|
89
|
+
let declareNext = false;
|
|
90
|
+
const flush = (names, field) => {
|
|
91
|
+
for (const name of names ?? [])
|
|
92
|
+
touch(name)[field] += 1;
|
|
93
|
+
};
|
|
94
|
+
for (;;) {
|
|
95
|
+
const kind = scanner.scan();
|
|
96
|
+
if (kind === ts_morph_1.ts.SyntaxKind.EndOfFileToken)
|
|
97
|
+
break;
|
|
98
|
+
if (kind === ts_morph_1.ts.SyntaxKind.OpenBraceToken) {
|
|
99
|
+
depth += 1;
|
|
100
|
+
if (pendingState === "after-export") {
|
|
101
|
+
pendingExport = [];
|
|
102
|
+
pendingState = "in-list";
|
|
103
|
+
}
|
|
104
|
+
else if (pendingState !== "in-list") {
|
|
105
|
+
flush(pendingExport, "exported");
|
|
106
|
+
pendingExport = null;
|
|
107
|
+
pendingState = "idle";
|
|
108
|
+
flush(pendingImport, "imported");
|
|
109
|
+
pendingImport = null;
|
|
110
|
+
importing = false;
|
|
111
|
+
}
|
|
112
|
+
previous = kind;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (kind === ts_morph_1.ts.SyntaxKind.CloseBraceToken) {
|
|
116
|
+
depth -= 1;
|
|
117
|
+
if (pendingState === "in-list")
|
|
118
|
+
pendingState = "after-close";
|
|
119
|
+
previous = kind;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (kind === ts_morph_1.ts.SyntaxKind.ExportKeyword) {
|
|
123
|
+
flush(pendingExport, "exported");
|
|
124
|
+
pendingExport = null;
|
|
125
|
+
pendingState = "after-export";
|
|
126
|
+
declareNext = false;
|
|
127
|
+
previous = kind;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (kind === ts_morph_1.ts.SyntaxKind.ImportKeyword) {
|
|
131
|
+
importing = true;
|
|
132
|
+
pendingImport = null;
|
|
133
|
+
previous = kind;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (kind === ts_morph_1.ts.SyntaxKind.FromKeyword) {
|
|
137
|
+
flush(pendingExport, "exported");
|
|
138
|
+
pendingExport = null;
|
|
139
|
+
pendingState = "idle";
|
|
140
|
+
flush(pendingImport, "imported");
|
|
141
|
+
pendingImport = null;
|
|
142
|
+
importing = false;
|
|
143
|
+
previous = kind;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (kind === ts_morph_1.ts.SyntaxKind.Identifier) {
|
|
147
|
+
const name = scanner.getTokenText();
|
|
148
|
+
const found = touch(name);
|
|
149
|
+
if (declareNext && depth === 0) {
|
|
150
|
+
found.declares = true;
|
|
151
|
+
found.declared += 1;
|
|
152
|
+
declareNext = false;
|
|
153
|
+
}
|
|
154
|
+
else if (pendingState === "in-list") {
|
|
155
|
+
if (pendingExport !== null)
|
|
156
|
+
pendingExport.push(name);
|
|
157
|
+
}
|
|
158
|
+
else if (pendingState === "after-export") {
|
|
159
|
+
// `export const x` / `export default x`: no list, the name is a value.
|
|
160
|
+
pendingState = "idle";
|
|
161
|
+
if (previous === ts_morph_1.ts.SyntaxKind.DotToken || previous === ts_morph_1.ts.SyntaxKind.QuestionDotToken)
|
|
162
|
+
found.member += 1;
|
|
163
|
+
else
|
|
164
|
+
found.plain += 1;
|
|
165
|
+
}
|
|
166
|
+
else if (importing) {
|
|
167
|
+
pendingImport?.push(name);
|
|
168
|
+
found.imported += 1;
|
|
169
|
+
if (pendingImport === null)
|
|
170
|
+
pendingImport = [name];
|
|
171
|
+
}
|
|
172
|
+
else if (previous === ts_morph_1.ts.SyntaxKind.DotToken || previous === ts_morph_1.ts.SyntaxKind.QuestionDotToken) {
|
|
173
|
+
found.member += 1;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
found.plain += 1;
|
|
177
|
+
}
|
|
178
|
+
previous = kind;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
// Anything else ends a list being guessed at (an `as` alias keeps it: the
|
|
182
|
+
// LOCAL name is a binding of the imported one, and the checker names the
|
|
183
|
+
// pair by the one on the left).
|
|
184
|
+
if (kind !== ts_morph_1.ts.SyntaxKind.CommaToken && kind !== ts_morph_1.ts.SyntaxKind.AsKeyword) {
|
|
185
|
+
if (pendingState !== "idle") {
|
|
186
|
+
flush(pendingExport, "exported");
|
|
187
|
+
pendingExport = null;
|
|
188
|
+
pendingState = "idle";
|
|
189
|
+
}
|
|
190
|
+
if (pendingImport !== null || importing) {
|
|
191
|
+
flush(pendingImport, "imported");
|
|
192
|
+
pendingImport = null;
|
|
193
|
+
importing = false;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (depth === 0 && isDeclKeyword(kind))
|
|
197
|
+
declareNext = true;
|
|
198
|
+
else if (kind !== ts_morph_1.ts.SyntaxKind.DefaultKeyword)
|
|
199
|
+
declareNext = false;
|
|
200
|
+
previous = kind;
|
|
201
|
+
}
|
|
202
|
+
flush(pendingExport, "exported");
|
|
203
|
+
flush(pendingImport, "imported");
|
|
204
|
+
};
|
|
205
|
+
// Build the index for the files this run can see. Called once, before any file is
|
|
206
|
+
// read: an answer about a name is a statement about every file, so a partial
|
|
207
|
+
// index would answer with a part of the truth.
|
|
208
|
+
const primeUsageIndex = (repoRoot, repoFiles) => {
|
|
209
|
+
const into = new Map();
|
|
210
|
+
for (const rel of repoFiles) {
|
|
211
|
+
let text;
|
|
212
|
+
try {
|
|
213
|
+
text = fs.readFileSync(path.join(repoRoot, rel), "utf8");
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
scanInto(into, rel, text);
|
|
219
|
+
}
|
|
220
|
+
index = into;
|
|
221
|
+
};
|
|
222
|
+
exports.primeUsageIndex = primeUsageIndex;
|
|
223
|
+
// A member of an object or a shape is named after the property; a value, a
|
|
224
|
+
// function, a class or a type is named after the binding. The two are counted from
|
|
225
|
+
// different occurrences, which is what keeps `a.foo` from reading as a use of `foo`.
|
|
226
|
+
const isMemberKind = (kindName) => kindName === "PropertyDeclaration" ||
|
|
227
|
+
kindName === "MethodDeclaration" ||
|
|
228
|
+
kindName === "PropertySignature" ||
|
|
229
|
+
kindName === "MethodSignature" ||
|
|
230
|
+
kindName === "EnumMember" ||
|
|
231
|
+
kindName === "GetAccessor" ||
|
|
232
|
+
kindName === "SetAccessor";
|
|
233
|
+
// How many uses of the name one file's part counts, given the role the
|
|
234
|
+
// declaration plays (a member is counted from its occurrences after a dot).
|
|
235
|
+
const tally = (member, found) => member ? found.member : found.plain + found.imported + found.exported;
|
|
236
|
+
// The name's parts in every file but the declaring one: `outside` counts the
|
|
237
|
+
// occurrences, `where` the files that mention it, `used` the files that would
|
|
238
|
+
// break without it. A file that owns the name is skipped — its occurrences are
|
|
239
|
+
// its own declaration, not a use.
|
|
240
|
+
const sumParts = (files, rel, member) => {
|
|
241
|
+
const sums = emptySums();
|
|
242
|
+
for (const [file, found] of files) {
|
|
243
|
+
if (file !== rel && found.declares)
|
|
244
|
+
continue;
|
|
245
|
+
const n = tally(member, found);
|
|
246
|
+
sums.total += n;
|
|
247
|
+
if (file === rel)
|
|
248
|
+
continue;
|
|
249
|
+
sums.outside += n;
|
|
250
|
+
if (n > 0)
|
|
251
|
+
sums.where.push(file);
|
|
252
|
+
if (isUse(member, found))
|
|
253
|
+
sums.used.push(file);
|
|
254
|
+
}
|
|
255
|
+
return sums;
|
|
256
|
+
};
|
|
257
|
+
// Whether a file's occurrences are USES rather than a republish or a member of
|
|
258
|
+
// another object: `usedIn` counts places that would break if the name went away.
|
|
259
|
+
const isUse = (member, found) => member ? found.member > found.exported : found.plain + found.imported > 0;
|
|
260
|
+
// The answer for one name, in the shape `usageFact` returns. `null` where the
|
|
261
|
+
// question does not apply — the same rule as the checker path: only a named,
|
|
262
|
+
// exported piece has a reach beyond itself.
|
|
263
|
+
const usageFromIndex = (name, rel, exported, kindName) => {
|
|
264
|
+
if (index === null || name === null || !exported)
|
|
265
|
+
return null;
|
|
266
|
+
const files = index.get(name);
|
|
267
|
+
if (files === undefined)
|
|
268
|
+
return { total: 0, outside: 0, files: [], usedIn: [] };
|
|
269
|
+
const sums = sumParts(files, rel, isMemberKind(kindName));
|
|
270
|
+
return { total: sums.total, outside: sums.outside, files: sums.where.sort(), usedIn: sums.used.sort() };
|
|
271
|
+
};
|
|
272
|
+
exports.usageFromIndex = usageFromIndex;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type UsageMode = "checker" | "index";
|
|
2
|
+
declare const DEFAULT_USAGE: UsageMode;
|
|
3
|
+
declare const usageModeOf: (raw: string | undefined) => UsageMode;
|
|
4
|
+
declare const setUsageMode: (next: UsageMode) => void;
|
|
5
|
+
declare const usageMode: () => UsageMode;
|
|
6
|
+
export { DEFAULT_USAGE, setUsageMode, usageMode, usageModeOf };
|
|
7
|
+
export type { UsageMode };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usageModeOf = exports.usageMode = exports.setUsageMode = exports.DEFAULT_USAGE = void 0;
|
|
4
|
+
const DEFAULT_USAGE = "checker";
|
|
5
|
+
exports.DEFAULT_USAGE = DEFAULT_USAGE;
|
|
6
|
+
let mode = DEFAULT_USAGE;
|
|
7
|
+
// Anything but the exact spelling of `index` keeps the checker: a typo must not
|
|
8
|
+
// silently change what a rule is told about the code.
|
|
9
|
+
const usageModeOf = (raw) => (raw === "index" ? "index" : DEFAULT_USAGE);
|
|
10
|
+
exports.usageModeOf = usageModeOf;
|
|
11
|
+
const setUsageMode = (next) => {
|
|
12
|
+
mode = next;
|
|
13
|
+
};
|
|
14
|
+
exports.setUsageMode = setUsageMode;
|
|
15
|
+
const usageMode = () => mode;
|
|
16
|
+
exports.usageMode = usageMode;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Index, type Usage } from "./fa-index";
|
|
2
|
+
import type { RunArgs } from "./index-run";
|
|
3
|
+
import type { Candidate } from "./entities/facts";
|
|
4
|
+
import type { SourceFile } from "ts-morph";
|
|
5
|
+
type UsageArgs = {
|
|
6
|
+
run: RunArgs;
|
|
7
|
+
index: Index;
|
|
8
|
+
zone: ReadonlySet<string>;
|
|
9
|
+
absOf: ReadonlyMap<string, string>;
|
|
10
|
+
};
|
|
11
|
+
type UsageStats = {
|
|
12
|
+
files: number;
|
|
13
|
+
asked: number;
|
|
14
|
+
answered: number;
|
|
15
|
+
};
|
|
16
|
+
declare const usageFor: (sf: SourceFile, candidates: readonly Candidate[], repoRoot: string) => Usage;
|
|
17
|
+
declare const runUsagePass: (args: UsageArgs) => UsageStats;
|
|
18
|
+
export { runUsagePass, usageFor };
|
|
19
|
+
export type { UsageStats };
|