@nielspeter/eess-ts 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +364 -0
- package/dist/builders/call-rule-builder.d.ts +199 -0
- package/dist/builders/call-rule-builder.d.ts.map +1 -0
- package/dist/builders/call-rule-builder.js +254 -0
- package/dist/builders/call-rule-builder.js.map +1 -0
- package/dist/builders/class-rule-builder.d.ts +136 -0
- package/dist/builders/class-rule-builder.d.ts.map +1 -0
- package/dist/builders/class-rule-builder.js +253 -0
- package/dist/builders/class-rule-builder.js.map +1 -0
- package/dist/builders/cross-layer-builder.d.ts +96 -0
- package/dist/builders/cross-layer-builder.d.ts.map +1 -0
- package/dist/builders/cross-layer-builder.js +172 -0
- package/dist/builders/cross-layer-builder.js.map +1 -0
- package/dist/builders/function-rule-builder.d.ts +198 -0
- package/dist/builders/function-rule-builder.d.ts.map +1 -0
- package/dist/builders/function-rule-builder.js +287 -0
- package/dist/builders/function-rule-builder.js.map +1 -0
- package/dist/builders/jsx-rule-builder.d.ts +113 -0
- package/dist/builders/jsx-rule-builder.d.ts.map +1 -0
- package/dist/builders/jsx-rule-builder.js +150 -0
- package/dist/builders/jsx-rule-builder.js.map +1 -0
- package/dist/builders/module-rule-builder.d.ts +159 -0
- package/dist/builders/module-rule-builder.d.ts.map +1 -0
- package/dist/builders/module-rule-builder.js +237 -0
- package/dist/builders/module-rule-builder.js.map +1 -0
- package/dist/builders/scoped-function-rule-builder.d.ts +21 -0
- package/dist/builders/scoped-function-rule-builder.d.ts.map +1 -0
- package/dist/builders/scoped-function-rule-builder.js +26 -0
- package/dist/builders/scoped-function-rule-builder.js.map +1 -0
- package/dist/builders/slice-rule-builder.d.ts +85 -0
- package/dist/builders/slice-rule-builder.d.ts.map +1 -0
- package/dist/builders/slice-rule-builder.js +134 -0
- package/dist/builders/slice-rule-builder.js.map +1 -0
- package/dist/builders/type-rule-builder.d.ts +103 -0
- package/dist/builders/type-rule-builder.d.ts.map +1 -0
- package/dist/builders/type-rule-builder.js +170 -0
- package/dist/builders/type-rule-builder.js.map +1 -0
- package/dist/cli/bin.d.ts +3 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +4 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/commands/baseline.d.ts +11 -0
- package/dist/cli/commands/baseline.d.ts.map +1 -0
- package/dist/cli/commands/baseline.js +16 -0
- package/dist/cli/commands/baseline.js.map +1 -0
- package/dist/cli/commands/check.d.ts +21 -0
- package/dist/cli/commands/check.d.ts.map +1 -0
- package/dist/cli/commands/check.js +94 -0
- package/dist/cli/commands/check.js.map +1 -0
- package/dist/cli/commands/explain.d.ts +9 -0
- package/dist/cli/commands/explain.d.ts.map +1 -0
- package/dist/cli/commands/explain.js +49 -0
- package/dist/cli/commands/explain.js.map +1 -0
- package/dist/cli/config.d.ts +31 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +20 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/index.d.ts +21 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +168 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/load-rules.d.ts +20 -0
- package/dist/cli/load-rules.d.ts.map +1 -0
- package/dist/cli/load-rules.js +97 -0
- package/dist/cli/load-rules.js.map +1 -0
- package/dist/cli/resolve-config.d.ts +11 -0
- package/dist/cli/resolve-config.d.ts.map +1 -0
- package/dist/cli/resolve-config.js +61 -0
- package/dist/cli/resolve-config.js.map +1 -0
- package/dist/cli/watch.d.ts +49 -0
- package/dist/cli/watch.d.ts.map +1 -0
- package/dist/cli/watch.js +138 -0
- package/dist/cli/watch.js.map +1 -0
- package/dist/conditions/body-analysis-function.d.ts +23 -0
- package/dist/conditions/body-analysis-function.d.ts.map +1 -0
- package/dist/conditions/body-analysis-function.js +103 -0
- package/dist/conditions/body-analysis-function.js.map +1 -0
- package/dist/conditions/body-analysis-module.d.ts +27 -0
- package/dist/conditions/body-analysis-module.d.ts.map +1 -0
- package/dist/conditions/body-analysis-module.js +99 -0
- package/dist/conditions/body-analysis-module.js.map +1 -0
- package/dist/conditions/body-analysis.d.ts +34 -0
- package/dist/conditions/body-analysis.d.ts.map +1 -0
- package/dist/conditions/body-analysis.js +95 -0
- package/dist/conditions/body-analysis.js.map +1 -0
- package/dist/conditions/call.d.ts +62 -0
- package/dist/conditions/call.d.ts.map +1 -0
- package/dist/conditions/call.js +267 -0
- package/dist/conditions/call.js.map +1 -0
- package/dist/conditions/catch-analysis.d.ts +31 -0
- package/dist/conditions/catch-analysis.d.ts.map +1 -0
- package/dist/conditions/catch-analysis.js +78 -0
- package/dist/conditions/catch-analysis.js.map +1 -0
- package/dist/conditions/class.d.ts +33 -0
- package/dist/conditions/class.d.ts.map +1 -0
- package/dist/conditions/class.js +110 -0
- package/dist/conditions/class.js.map +1 -0
- package/dist/conditions/cross-layer.d.ts +28 -0
- package/dist/conditions/cross-layer.d.ts.map +1 -0
- package/dist/conditions/cross-layer.js +105 -0
- package/dist/conditions/cross-layer.js.map +1 -0
- package/dist/conditions/dependency.d.ts +73 -0
- package/dist/conditions/dependency.d.ts.map +1 -0
- package/dist/conditions/dependency.js +177 -0
- package/dist/conditions/dependency.js.map +1 -0
- package/dist/conditions/exports.d.ts +33 -0
- package/dist/conditions/exports.d.ts.map +1 -0
- package/dist/conditions/exports.js +101 -0
- package/dist/conditions/exports.js.map +1 -0
- package/dist/conditions/function.d.ts +79 -0
- package/dist/conditions/function.d.ts.map +1 -0
- package/dist/conditions/function.js +167 -0
- package/dist/conditions/function.js.map +1 -0
- package/dist/conditions/helpers.d.ts +14 -0
- package/dist/conditions/helpers.d.ts.map +1 -0
- package/dist/conditions/helpers.js +26 -0
- package/dist/conditions/helpers.js.map +1 -0
- package/dist/conditions/jsx.d.ts +40 -0
- package/dist/conditions/jsx.d.ts.map +1 -0
- package/dist/conditions/jsx.js +133 -0
- package/dist/conditions/jsx.js.map +1 -0
- package/dist/conditions/members.d.ts +74 -0
- package/dist/conditions/members.d.ts.map +1 -0
- package/dist/conditions/members.js +224 -0
- package/dist/conditions/members.js.map +1 -0
- package/dist/conditions/pattern.d.ts +20 -0
- package/dist/conditions/pattern.d.ts.map +1 -0
- package/dist/conditions/pattern.js +108 -0
- package/dist/conditions/pattern.js.map +1 -0
- package/dist/conditions/reverse-dependency.d.ts +28 -0
- package/dist/conditions/reverse-dependency.d.ts.map +1 -0
- package/dist/conditions/reverse-dependency.js +275 -0
- package/dist/conditions/reverse-dependency.js.map +1 -0
- package/dist/conditions/slice.d.ts +49 -0
- package/dist/conditions/slice.d.ts.map +1 -0
- package/dist/conditions/slice.js +153 -0
- package/dist/conditions/slice.js.map +1 -0
- package/dist/conditions/structural.d.ts +58 -0
- package/dist/conditions/structural.d.ts.map +1 -0
- package/dist/conditions/structural.js +102 -0
- package/dist/conditions/structural.js.map +1 -0
- package/dist/conditions/type-level.d.ts +29 -0
- package/dist/conditions/type-level.d.ts.map +1 -0
- package/dist/conditions/type-level.js +48 -0
- package/dist/conditions/type-level.js.map +1 -0
- package/dist/core/import-options.d.ts +32 -0
- package/dist/core/import-options.d.ts.map +1 -0
- package/dist/core/import-options.js +29 -0
- package/dist/core/import-options.js.map +1 -0
- package/dist/core/module-dependencies.d.ts +28 -0
- package/dist/core/module-dependencies.d.ts.map +1 -0
- package/dist/core/module-dependencies.js +35 -0
- package/dist/core/module-dependencies.js.map +1 -0
- package/dist/core/pair-condition.d.ts +10 -0
- package/dist/core/pair-condition.d.ts.map +1 -0
- package/dist/core/pair-condition.js +2 -0
- package/dist/core/pair-condition.js.map +1 -0
- package/dist/core/project.d.ts +68 -0
- package/dist/core/project.d.ts.map +1 -0
- package/dist/core/project.js +127 -0
- package/dist/core/project.js.map +1 -0
- package/dist/core/type-matcher.d.ts +10 -0
- package/dist/core/type-matcher.d.ts.map +1 -0
- package/dist/core/type-matcher.js +2 -0
- package/dist/core/type-matcher.js.map +1 -0
- package/dist/core/violation.d.ts +38 -0
- package/dist/core/violation.d.ts.map +1 -0
- package/dist/core/violation.js +130 -0
- package/dist/core/violation.js.map +1 -0
- package/dist/graphql/index.d.ts +76 -0
- package/dist/graphql/index.d.ts.map +1 -0
- package/dist/graphql/index.js +108 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/graphql/resolver-rule-builder.d.ts +75 -0
- package/dist/graphql/resolver-rule-builder.d.ts.map +1 -0
- package/dist/graphql/resolver-rule-builder.js +146 -0
- package/dist/graphql/resolver-rule-builder.js.map +1 -0
- package/dist/graphql/schema-conditions.d.ts +31 -0
- package/dist/graphql/schema-conditions.d.ts.map +1 -0
- package/dist/graphql/schema-conditions.js +119 -0
- package/dist/graphql/schema-conditions.js.map +1 -0
- package/dist/graphql/schema-loader.d.ts +75 -0
- package/dist/graphql/schema-loader.d.ts.map +1 -0
- package/dist/graphql/schema-loader.js +113 -0
- package/dist/graphql/schema-loader.js.map +1 -0
- package/dist/graphql/schema-predicates.d.ts +42 -0
- package/dist/graphql/schema-predicates.d.ts.map +1 -0
- package/dist/graphql/schema-predicates.js +74 -0
- package/dist/graphql/schema-predicates.js.map +1 -0
- package/dist/graphql/schema-rule-builder.d.ts +74 -0
- package/dist/graphql/schema-rule-builder.d.ts.map +1 -0
- package/dist/graphql/schema-rule-builder.js +188 -0
- package/dist/graphql/schema-rule-builder.js.map +1 -0
- package/dist/helpers/body-traversal.d.ts +58 -0
- package/dist/helpers/body-traversal.d.ts.map +1 -0
- package/dist/helpers/body-traversal.js +180 -0
- package/dist/helpers/body-traversal.js.map +1 -0
- package/dist/helpers/callback-extractor.d.ts +28 -0
- package/dist/helpers/callback-extractor.d.ts.map +1 -0
- package/dist/helpers/callback-extractor.js +159 -0
- package/dist/helpers/callback-extractor.js.map +1 -0
- package/dist/helpers/complexity.d.ts +26 -0
- package/dist/helpers/complexity.d.ts.map +1 -0
- package/dist/helpers/complexity.js +64 -0
- package/dist/helpers/complexity.js.map +1 -0
- package/dist/helpers/matchers.d.ts +206 -0
- package/dist/helpers/matchers.d.ts.map +1 -0
- package/dist/helpers/matchers.js +470 -0
- package/dist/helpers/matchers.js.map +1 -0
- package/dist/helpers/pattern.d.ts +37 -0
- package/dist/helpers/pattern.d.ts.map +1 -0
- package/dist/helpers/pattern.js +22 -0
- package/dist/helpers/pattern.js.map +1 -0
- package/dist/helpers/slice-graph.d.ts +32 -0
- package/dist/helpers/slice-graph.d.ts.map +1 -0
- package/dist/helpers/slice-graph.js +89 -0
- package/dist/helpers/slice-graph.js.map +1 -0
- package/dist/helpers/tarjan.d.ts +21 -0
- package/dist/helpers/tarjan.d.ts.map +1 -0
- package/dist/helpers/tarjan.js +71 -0
- package/dist/helpers/tarjan.js.map +1 -0
- package/dist/helpers/type-matchers.d.ts +67 -0
- package/dist/helpers/type-matchers.d.ts.map +1 -0
- package/dist/helpers/type-matchers.js +108 -0
- package/dist/helpers/type-matchers.js.map +1 -0
- package/dist/helpers/within.d.ts +41 -0
- package/dist/helpers/within.d.ts.map +1 -0
- package/dist/helpers/within.js +32 -0
- package/dist/helpers/within.js.map +1 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +116 -0
- package/dist/index.js.map +1 -0
- package/dist/models/arch-call.d.ts +83 -0
- package/dist/models/arch-call.d.ts.map +1 -0
- package/dist/models/arch-call.js +90 -0
- package/dist/models/arch-call.js.map +1 -0
- package/dist/models/arch-function.d.ts +76 -0
- package/dist/models/arch-function.d.ts.map +1 -0
- package/dist/models/arch-function.js +122 -0
- package/dist/models/arch-function.js.map +1 -0
- package/dist/models/arch-jsx-element.d.ts +75 -0
- package/dist/models/arch-jsx-element.d.ts.map +1 -0
- package/dist/models/arch-jsx-element.js +231 -0
- package/dist/models/arch-jsx-element.js.map +1 -0
- package/dist/models/cross-layer.d.ts +15 -0
- package/dist/models/cross-layer.d.ts.map +1 -0
- package/dist/models/cross-layer.js +2 -0
- package/dist/models/cross-layer.js.map +1 -0
- package/dist/models/slice.d.ts +60 -0
- package/dist/models/slice.d.ts.map +1 -0
- package/dist/models/slice.js +89 -0
- package/dist/models/slice.js.map +1 -0
- package/dist/predicates/call.d.ts +49 -0
- package/dist/predicates/call.d.ts.map +1 -0
- package/dist/predicates/call.js +115 -0
- package/dist/predicates/call.js.map +1 -0
- package/dist/predicates/class.d.ts +42 -0
- package/dist/predicates/class.d.ts.map +1 -0
- package/dist/predicates/class.js +83 -0
- package/dist/predicates/class.js.map +1 -0
- package/dist/predicates/function.d.ts +81 -0
- package/dist/predicates/function.d.ts.map +1 -0
- package/dist/predicates/function.js +157 -0
- package/dist/predicates/function.js.map +1 -0
- package/dist/predicates/identity.d.ts +55 -0
- package/dist/predicates/identity.d.ts.map +1 -0
- package/dist/predicates/identity.js +96 -0
- package/dist/predicates/identity.js.map +1 -0
- package/dist/predicates/index.d.ts +4 -0
- package/dist/predicates/index.d.ts.map +1 -0
- package/dist/predicates/index.js +3 -0
- package/dist/predicates/index.js.map +1 -0
- package/dist/predicates/jsx.d.ts +41 -0
- package/dist/predicates/jsx.d.ts.map +1 -0
- package/dist/predicates/jsx.js +84 -0
- package/dist/predicates/jsx.js.map +1 -0
- package/dist/predicates/metrics.d.ts +30 -0
- package/dist/predicates/metrics.d.ts.map +1 -0
- package/dist/predicates/metrics.js +65 -0
- package/dist/predicates/metrics.js.map +1 -0
- package/dist/predicates/module.d.ts +44 -0
- package/dist/predicates/module.d.ts.map +1 -0
- package/dist/predicates/module.js +70 -0
- package/dist/predicates/module.js.map +1 -0
- package/dist/predicates/type.d.ts +48 -0
- package/dist/predicates/type.d.ts.map +1 -0
- package/dist/predicates/type.js +107 -0
- package/dist/predicates/type.js.map +1 -0
- package/dist/presets/boundaries.d.ts +19 -0
- package/dist/presets/boundaries.d.ts.map +1 -0
- package/dist/presets/boundaries.js +93 -0
- package/dist/presets/boundaries.js.map +1 -0
- package/dist/presets/data-layer.d.ts +20 -0
- package/dist/presets/data-layer.d.ts.map +1 -0
- package/dist/presets/data-layer.js +30 -0
- package/dist/presets/data-layer.js.map +1 -0
- package/dist/presets/index.d.ts +9 -0
- package/dist/presets/index.d.ts.map +1 -0
- package/dist/presets/index.js +5 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/presets/layered.d.ts +21 -0
- package/dist/presets/layered.d.ts.map +1 -0
- package/dist/presets/layered.js +103 -0
- package/dist/presets/layered.js.map +1 -0
- package/dist/presets/shared.d.ts +3 -0
- package/dist/presets/shared.d.ts.map +1 -0
- package/dist/presets/shared.js +5 -0
- package/dist/presets/shared.js.map +1 -0
- package/dist/rules/architecture.d.ts +10 -0
- package/dist/rules/architecture.d.ts.map +1 -0
- package/dist/rules/architecture.js +14 -0
- package/dist/rules/architecture.js.map +1 -0
- package/dist/rules/code-quality.d.ts +55 -0
- package/dist/rules/code-quality.d.ts.map +1 -0
- package/dist/rules/code-quality.js +116 -0
- package/dist/rules/code-quality.js.map +1 -0
- package/dist/rules/dependencies.d.ts +32 -0
- package/dist/rules/dependencies.d.ts.map +1 -0
- package/dist/rules/dependencies.js +37 -0
- package/dist/rules/dependencies.js.map +1 -0
- package/dist/rules/errors.d.ts +31 -0
- package/dist/rules/errors.d.ts.map +1 -0
- package/dist/rules/errors.js +97 -0
- package/dist/rules/errors.js.map +1 -0
- package/dist/rules/hygiene.d.ts +54 -0
- package/dist/rules/hygiene.d.ts.map +1 -0
- package/dist/rules/hygiene.js +62 -0
- package/dist/rules/hygiene.js.map +1 -0
- package/dist/rules/metrics-function.d.ts +45 -0
- package/dist/rules/metrics-function.d.ts.map +1 -0
- package/dist/rules/metrics-function.js +87 -0
- package/dist/rules/metrics-function.js.map +1 -0
- package/dist/rules/metrics.d.ts +64 -0
- package/dist/rules/metrics.d.ts.map +1 -0
- package/dist/rules/metrics.js +157 -0
- package/dist/rules/metrics.js.map +1 -0
- package/dist/rules/naming.d.ts +24 -0
- package/dist/rules/naming.d.ts.map +1 -0
- package/dist/rules/naming.js +51 -0
- package/dist/rules/naming.js.map +1 -0
- package/dist/rules/security.d.ts +59 -0
- package/dist/rules/security.d.ts.map +1 -0
- package/dist/rules/security.js +92 -0
- package/dist/rules/security.js.map +1 -0
- package/dist/rules/typescript.d.ts +73 -0
- package/dist/rules/typescript.d.ts.map +1 -0
- package/dist/rules/typescript.js +105 -0
- package/dist/rules/typescript.js.map +1 -0
- package/dist/smells/duplicate-bodies.d.ts +24 -0
- package/dist/smells/duplicate-bodies.d.ts.map +1 -0
- package/dist/smells/duplicate-bodies.js +131 -0
- package/dist/smells/duplicate-bodies.js.map +1 -0
- package/dist/smells/fingerprint.d.ts +27 -0
- package/dist/smells/fingerprint.d.ts.map +1 -0
- package/dist/smells/fingerprint.js +50 -0
- package/dist/smells/fingerprint.js.map +1 -0
- package/dist/smells/inconsistent-siblings.d.ts +21 -0
- package/dist/smells/inconsistent-siblings.d.ts.map +1 -0
- package/dist/smells/inconsistent-siblings.js +135 -0
- package/dist/smells/inconsistent-siblings.js.map +1 -0
- package/dist/smells/index.d.ts +12 -0
- package/dist/smells/index.d.ts.map +1 -0
- package/dist/smells/index.js +15 -0
- package/dist/smells/index.js.map +1 -0
- package/dist/smells/smell-builder.d.ts +37 -0
- package/dist/smells/smell-builder.d.ts.map +1 -0
- package/dist/smells/smell-builder.js +51 -0
- package/dist/smells/smell-builder.js.map +1 -0
- package/package.json +121 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type CallExpression, type SourceFile, type Node } from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link ArchCall.getName}.
|
|
4
|
+
*
|
|
5
|
+
* Both fields are opt-in. With no options, `getName()` returns the bare
|
|
6
|
+
* `${object}.${method}` form (e.g. `app.post`) — the predicate-visible
|
|
7
|
+
* identity.
|
|
8
|
+
*/
|
|
9
|
+
export interface GetNameOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Index of an argument whose source text should be folded into the
|
|
12
|
+
* returned name. When the indexed argument is a `StringLiteral` or
|
|
13
|
+
* `NoSubstitutionTemplateLiteral`, the returned name becomes
|
|
14
|
+
* `` `${callee}(${arg.getText()})` ``. Otherwise the bare name is
|
|
15
|
+
* returned unchanged (graceful degrade — see plan 0057 edge cases).
|
|
16
|
+
*/
|
|
17
|
+
readonly withArgument?: number;
|
|
18
|
+
/**
|
|
19
|
+
* When `true` and `withArgument` produced an enriched name, elide
|
|
20
|
+
* the middle of a literal whose `getText()` exceeds 80 characters
|
|
21
|
+
* with `…`. Uses `slice(0, 38) + '…' + slice(-38)` so the resulting
|
|
22
|
+
* literal portion is exactly 77 characters.
|
|
23
|
+
*
|
|
24
|
+
* Used at violation-message sites to keep CI output scannable.
|
|
25
|
+
* The element field passes `elide: false` (the default) so exclusion
|
|
26
|
+
* patterns key on stable, verbatim identities.
|
|
27
|
+
*/
|
|
28
|
+
readonly elide?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Unified representation of a call expression in the project.
|
|
32
|
+
*
|
|
33
|
+
* Wraps a ts-morph CallExpression with precomputed fields for
|
|
34
|
+
* efficient predicate evaluation.
|
|
35
|
+
*
|
|
36
|
+
* Satisfies Named and Located interfaces from identity predicates.
|
|
37
|
+
* Does NOT satisfy Exportable --- call expressions cannot be exported.
|
|
38
|
+
*/
|
|
39
|
+
export interface ArchCall {
|
|
40
|
+
/**
|
|
41
|
+
* Full expression text, e.g. "app.get", "router.post", "db.query".
|
|
42
|
+
*
|
|
43
|
+
* With `options.withArgument` set, folds the indexed argument's raw
|
|
44
|
+
* source text into the name when it's a `StringLiteral` or
|
|
45
|
+
* `NoSubstitutionTemplateLiteral`. See {@link GetNameOptions}.
|
|
46
|
+
*
|
|
47
|
+
* Identity predicates (`haveNameMatching`, etc.) call this with no
|
|
48
|
+
* arguments and see the bare name — argument enrichment is an
|
|
49
|
+
* identity/exclusion concern, not a filtering concern. To filter by
|
|
50
|
+
* argument value, use `withStringArg(i, glob)` or
|
|
51
|
+
* `withArgMatching(i, pattern)`.
|
|
52
|
+
*/
|
|
53
|
+
getName(options?: GetNameOptions): string | undefined;
|
|
54
|
+
/** Source file containing this call expression. */
|
|
55
|
+
getSourceFile(): SourceFile;
|
|
56
|
+
/** The object the method is called on, or undefined for bare calls. */
|
|
57
|
+
getObjectName(): string | undefined;
|
|
58
|
+
/** The method name, or the function name for bare calls. */
|
|
59
|
+
getMethodName(): string | undefined;
|
|
60
|
+
/** The arguments to the call expression. */
|
|
61
|
+
getArguments(): Node[];
|
|
62
|
+
/** Underlying ts-morph CallExpression node. */
|
|
63
|
+
getNode(): CallExpression;
|
|
64
|
+
/** Start line number in the source file. */
|
|
65
|
+
getStartLineNumber(): number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Create an ArchCall from a CallExpression.
|
|
69
|
+
*
|
|
70
|
+
* Precomputes object name and method name from the call expression.
|
|
71
|
+
* For `app.get(...)`, objectName is "app" and methodName is "get".
|
|
72
|
+
* For `handleError(...)`, objectName is undefined and methodName is "handleError".
|
|
73
|
+
*/
|
|
74
|
+
export declare function fromCallExpression(expr: CallExpression): ArchCall;
|
|
75
|
+
/**
|
|
76
|
+
* Scan a source file for all call expressions.
|
|
77
|
+
*
|
|
78
|
+
* Walks all descendants of kind CallExpression. This includes
|
|
79
|
+
* nested calls (e.g., calls inside callbacks), which is intentional ---
|
|
80
|
+
* users filter with predicates to select the calls they care about.
|
|
81
|
+
*/
|
|
82
|
+
export declare function collectCalls(sourceFile: SourceFile): ArchCall[];
|
|
83
|
+
//# sourceMappingURL=arch-call.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arch-call.d.ts","sourceRoot":"","sources":["../../src/models/arch-call.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,IAAI,EAGV,MAAM,UAAU,CAAA;AAEjB;;;;;;GAMG;AAEH,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;IAE9B;;;;;;;;;OASG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CACzB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS,CAAA;IAErD,mDAAmD;IACnD,aAAa,IAAI,UAAU,CAAA;IAE3B,uEAAuE;IACvE,aAAa,IAAI,MAAM,GAAG,SAAS,CAAA;IAEnC,4DAA4D;IAC5D,aAAa,IAAI,MAAM,GAAG,SAAS,CAAA;IAEnC,4CAA4C;IAC5C,YAAY,IAAI,IAAI,EAAE,CAAA;IAEtB,+CAA+C;IAC/C,OAAO,IAAI,cAAc,CAAA;IAEzB,4CAA4C;IAC5C,kBAAkB,IAAI,MAAM,CAAA;CAC7B;AAqCD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,cAAc,GAAG,QAAQ,CAmCjE;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,QAAQ,EAAE,CAM/D"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Node as NodeUtils, SyntaxKind, } from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* Build the argument-enriched suffix for `ArchCall.getName`.
|
|
4
|
+
*
|
|
5
|
+
* Returns the raw source text of `expr.getArguments()[index]` iff that
|
|
6
|
+
* argument is a `StringLiteral` or `NoSubstitutionTemplateLiteral`.
|
|
7
|
+
* Otherwise returns undefined → caller falls back to the bare name.
|
|
8
|
+
*
|
|
9
|
+
* Degrade cases (all return undefined):
|
|
10
|
+
* - Out-of-bounds index
|
|
11
|
+
* - `AsExpression` (e.g. `'/foo' as const`)
|
|
12
|
+
* - `ParenthesizedExpression` (e.g. `('/foo')`)
|
|
13
|
+
* - `TemplateExpression` with substitutions (e.g. `` `/foo/${x}` ``)
|
|
14
|
+
* - Tagged templates (e.g. `` sql`SELECT ...` ``)
|
|
15
|
+
* - Identifiers and member expressions
|
|
16
|
+
* - Spread elements
|
|
17
|
+
* - Non-string literals (numeric, boolean, etc.)
|
|
18
|
+
*/
|
|
19
|
+
function buildEnrichedSuffix(expr, index, elide) {
|
|
20
|
+
const args = expr.getArguments();
|
|
21
|
+
const arg = args[index];
|
|
22
|
+
if (!arg)
|
|
23
|
+
return undefined;
|
|
24
|
+
if (!NodeUtils.isStringLiteral(arg) && !NodeUtils.isNoSubstitutionTemplateLiteral(arg)) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const raw = arg.getText();
|
|
28
|
+
if (elide && raw.length > 80) {
|
|
29
|
+
return `${raw.slice(0, 38)}…${raw.slice(-38)}`;
|
|
30
|
+
}
|
|
31
|
+
return raw;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create an ArchCall from a CallExpression.
|
|
35
|
+
*
|
|
36
|
+
* Precomputes object name and method name from the call expression.
|
|
37
|
+
* For `app.get(...)`, objectName is "app" and methodName is "get".
|
|
38
|
+
* For `handleError(...)`, objectName is undefined and methodName is "handleError".
|
|
39
|
+
*/
|
|
40
|
+
export function fromCallExpression(expr) {
|
|
41
|
+
const callExpr = expr.getExpression();
|
|
42
|
+
let objectName;
|
|
43
|
+
let methodName;
|
|
44
|
+
if (NodeUtils.isPropertyAccessExpression(callExpr)) {
|
|
45
|
+
// app.get(...) => object="app", method="get"
|
|
46
|
+
// router.route.get(...) => object="router.route", method="get"
|
|
47
|
+
methodName = callExpr.getName();
|
|
48
|
+
objectName = callExpr.getExpression().getText();
|
|
49
|
+
}
|
|
50
|
+
else if (NodeUtils.isIdentifier(callExpr)) {
|
|
51
|
+
// handleError(...) => object=undefined, method="handleError"
|
|
52
|
+
methodName = callExpr.getText();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// Computed or other expression, e.g. getHandler()()
|
|
56
|
+
methodName = callExpr.getText();
|
|
57
|
+
}
|
|
58
|
+
const fullName = objectName !== undefined ? `${objectName}.${methodName}` : methodName;
|
|
59
|
+
return {
|
|
60
|
+
getName: (options) => {
|
|
61
|
+
if (options?.withArgument === undefined)
|
|
62
|
+
return fullName;
|
|
63
|
+
const suffix = buildEnrichedSuffix(expr, options.withArgument, options.elide ?? false);
|
|
64
|
+
if (suffix === undefined)
|
|
65
|
+
return fullName;
|
|
66
|
+
return `${fullName}(${suffix})`;
|
|
67
|
+
},
|
|
68
|
+
getSourceFile: () => expr.getSourceFile(),
|
|
69
|
+
getObjectName: () => objectName,
|
|
70
|
+
getMethodName: () => methodName,
|
|
71
|
+
getArguments: () => expr.getArguments(),
|
|
72
|
+
getNode: () => expr,
|
|
73
|
+
getStartLineNumber: () => expr.getStartLineNumber(),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Scan a source file for all call expressions.
|
|
78
|
+
*
|
|
79
|
+
* Walks all descendants of kind CallExpression. This includes
|
|
80
|
+
* nested calls (e.g., calls inside callbacks), which is intentional ---
|
|
81
|
+
* users filter with predicates to select the calls they care about.
|
|
82
|
+
*/
|
|
83
|
+
export function collectCalls(sourceFile) {
|
|
84
|
+
const calls = [];
|
|
85
|
+
for (const callExpr of sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)) {
|
|
86
|
+
calls.push(fromCallExpression(callExpr));
|
|
87
|
+
}
|
|
88
|
+
return calls;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=arch-call.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arch-call.js","sourceRoot":"","sources":["../../src/models/arch-call.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,IAAI,IAAI,SAAS,EACjB,UAAU,GACX,MAAM,UAAU,CAAA;AA6EjB;;;;;;;;;;;;;;;;GAgBG;AACH,SAAS,mBAAmB,CAC1B,IAAoB,EACpB,KAAa,EACb,KAAc;IAEd,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,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C,GAAG,UAAU,IAAI,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,CAAA;IAEtF,OAAO;QACL,OAAO,EAAE,CAAC,OAAwB,EAAsB,EAAE;YACxD,IAAI,OAAO,EAAE,YAAY,KAAK,SAAS;gBAAE,OAAO,QAAQ,CAAA;YACxD,MAAM,MAAM,GAAG,mBAAmB,CAAC,IAAI,EAAE,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,CAAA;YACtF,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,QAAQ,CAAA;YACzC,OAAO,GAAG,QAAQ,IAAI,MAAM,GAAG,CAAA;QACjC,CAAC;QACD,aAAa,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE;QACzC,aAAa,EAAE,GAAG,EAAE,CAAC,UAAU;QAC/B,aAAa,EAAE,GAAG,EAAE,CAAC,UAAU;QAC/B,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,YAAY,EAAE;QACvC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI;QACnB,kBAAkB,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,kBAAkB,EAAE;KACpD,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,UAAsB;IACjD,MAAM,KAAK,GAAe,EAAE,CAAA;IAC5B,KAAK,MAAM,QAAQ,IAAI,UAAU,CAAC,oBAAoB,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;QAClF,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAA;IAC1C,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type FunctionDeclaration, type VariableDeclaration, type MethodDeclaration, type SourceFile, type ParameterDeclaration, type Type, type Node } from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* Unified representation of a TypeScript function.
|
|
4
|
+
*
|
|
5
|
+
* Wraps both FunctionDeclaration (`function foo() {}`) and
|
|
6
|
+
* VariableDeclaration with ArrowFunction initializer (`const foo = () => {}`).
|
|
7
|
+
*
|
|
8
|
+
* Satisfies Named, Located, and Exportable interfaces from identity predicates.
|
|
9
|
+
*/
|
|
10
|
+
export interface ArchFunction {
|
|
11
|
+
/** Function name, or undefined for anonymous functions. */
|
|
12
|
+
getName(): string | undefined;
|
|
13
|
+
/** Source file containing this function. */
|
|
14
|
+
getSourceFile(): SourceFile;
|
|
15
|
+
/** Whether this function is exported from its module. */
|
|
16
|
+
isExported(): boolean;
|
|
17
|
+
/** Whether this function is declared async. */
|
|
18
|
+
isAsync(): boolean;
|
|
19
|
+
/** Parameter declarations of this function. */
|
|
20
|
+
getParameters(): ParameterDeclaration[];
|
|
21
|
+
/** Return type of this function (resolved by the type checker). */
|
|
22
|
+
getReturnType(): Type;
|
|
23
|
+
/** Function body node, for body analysis (plan 0011). */
|
|
24
|
+
getBody(): Node | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Underlying ts-morph node for violation reporting.
|
|
27
|
+
* FunctionDeclaration or VariableDeclaration.
|
|
28
|
+
*/
|
|
29
|
+
getNode(): Node;
|
|
30
|
+
/**
|
|
31
|
+
* Start line number in the source file.
|
|
32
|
+
* Used for violation reporting.
|
|
33
|
+
*/
|
|
34
|
+
getStartLineNumber(): number;
|
|
35
|
+
/**
|
|
36
|
+
* Visibility scope of this function.
|
|
37
|
+
*
|
|
38
|
+
* - Standalone functions and arrow functions are always `'public'` (module-level).
|
|
39
|
+
* - Class methods return their actual modifier (`public`, `protected`, or `private`).
|
|
40
|
+
* Methods with no explicit modifier default to `'public'`.
|
|
41
|
+
*/
|
|
42
|
+
getScope(): 'public' | 'protected' | 'private';
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Create an ArchFunction from a FunctionDeclaration.
|
|
46
|
+
*/
|
|
47
|
+
export declare function fromFunctionDeclaration(decl: FunctionDeclaration): ArchFunction;
|
|
48
|
+
/**
|
|
49
|
+
* Create an ArchFunction from a VariableDeclaration whose initializer
|
|
50
|
+
* is an ArrowFunction.
|
|
51
|
+
*
|
|
52
|
+
* Precondition: caller must verify the initializer is an ArrowFunction.
|
|
53
|
+
*/
|
|
54
|
+
export declare function fromArrowVariableDeclaration(decl: VariableDeclaration): ArchFunction;
|
|
55
|
+
/**
|
|
56
|
+
* Create an ArchFunction from a class MethodDeclaration.
|
|
57
|
+
*
|
|
58
|
+
* Method name is prefixed with the class name for clarity in violation messages:
|
|
59
|
+
* "Space.getWebhooks" instead of just "getWebhooks".
|
|
60
|
+
*/
|
|
61
|
+
export declare function fromMethodDeclaration(method: MethodDeclaration): ArchFunction;
|
|
62
|
+
/**
|
|
63
|
+
* Scan a source file for all functions.
|
|
64
|
+
*
|
|
65
|
+
* Returns ArchFunction wrappers for:
|
|
66
|
+
* 1. FunctionDeclarations — `function foo() {}`
|
|
67
|
+
* 2. VariableDeclarations with ArrowFunction initializer — `const foo = () => {}`
|
|
68
|
+
* 3. Class MethodDeclarations — `class Foo { bar() {} }` (when includeMethods is true)
|
|
69
|
+
*
|
|
70
|
+
* @param sourceFile - The source file to scan
|
|
71
|
+
* @param options - Set `includeMethods: true` to include class methods (default: true)
|
|
72
|
+
*/
|
|
73
|
+
export declare function collectFunctions(sourceFile: SourceFile, options?: {
|
|
74
|
+
includeMethods?: boolean;
|
|
75
|
+
}): ArchFunction[];
|
|
76
|
+
//# sourceMappingURL=arch-function.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arch-function.d.ts","sourceRoot":"","sources":["../../src/models/arch-function.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,oBAAoB,EACzB,KAAK,IAAI,EACT,KAAK,IAAI,EAIV,MAAM,UAAU,CAAA;AAEjB;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,OAAO,IAAI,MAAM,GAAG,SAAS,CAAA;IAE7B,4CAA4C;IAC5C,aAAa,IAAI,UAAU,CAAA;IAE3B,yDAAyD;IACzD,UAAU,IAAI,OAAO,CAAA;IAErB,+CAA+C;IAC/C,OAAO,IAAI,OAAO,CAAA;IAElB,+CAA+C;IAC/C,aAAa,IAAI,oBAAoB,EAAE,CAAA;IAEvC,mEAAmE;IACnE,aAAa,IAAI,IAAI,CAAA;IAErB,yDAAyD;IACzD,OAAO,IAAI,IAAI,GAAG,SAAS,CAAA;IAE3B;;;OAGG;IACH,OAAO,IAAI,IAAI,CAAA;IAEf;;;OAGG;IACH,kBAAkB,IAAI,MAAM,CAAA;IAE5B;;;;;;OAMG;IACH,QAAQ,IAAI,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAA;CAC/C;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,mBAAmB,GAAG,YAAY,CAa/E;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,mBAAmB,GAAG,YAAY,CAoBpF;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,iBAAiB,GAAG,YAAY,CAgC7E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,UAAU,EACtB,OAAO,CAAC,EAAE;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,GACrC,YAAY,EAAE,CA0BhB"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Node as NodeClass, Scope, SyntaxKind, } from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* Create an ArchFunction from a FunctionDeclaration.
|
|
4
|
+
*/
|
|
5
|
+
export function fromFunctionDeclaration(decl) {
|
|
6
|
+
return {
|
|
7
|
+
getName: () => decl.getName(),
|
|
8
|
+
getSourceFile: () => decl.getSourceFile(),
|
|
9
|
+
isExported: () => decl.isExported(),
|
|
10
|
+
isAsync: () => decl.isAsync(),
|
|
11
|
+
getParameters: () => decl.getParameters(),
|
|
12
|
+
getReturnType: () => decl.getReturnType(),
|
|
13
|
+
getBody: () => decl.getBody(),
|
|
14
|
+
getNode: () => decl,
|
|
15
|
+
getStartLineNumber: () => decl.getStartLineNumber(),
|
|
16
|
+
getScope: () => 'public',
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create an ArchFunction from a VariableDeclaration whose initializer
|
|
21
|
+
* is an ArrowFunction.
|
|
22
|
+
*
|
|
23
|
+
* Precondition: caller must verify the initializer is an ArrowFunction.
|
|
24
|
+
*/
|
|
25
|
+
export function fromArrowVariableDeclaration(decl) {
|
|
26
|
+
const arrow = decl.getInitializerIfKind(SyntaxKind.ArrowFunction);
|
|
27
|
+
if (!arrow)
|
|
28
|
+
throw new Error('Expected arrow function initializer');
|
|
29
|
+
return {
|
|
30
|
+
getName: () => decl.getName(),
|
|
31
|
+
getSourceFile: () => decl.getSourceFile(),
|
|
32
|
+
isExported: () => {
|
|
33
|
+
// VariableDeclaration itself doesn't have isExported —
|
|
34
|
+
// check the parent VariableStatement.
|
|
35
|
+
const varStatement = decl.getVariableStatement();
|
|
36
|
+
return varStatement?.isExported() ?? false;
|
|
37
|
+
},
|
|
38
|
+
isAsync: () => arrow.isAsync(),
|
|
39
|
+
getParameters: () => arrow.getParameters(),
|
|
40
|
+
getReturnType: () => arrow.getReturnType(),
|
|
41
|
+
getBody: () => arrow.getBody(),
|
|
42
|
+
getNode: () => decl,
|
|
43
|
+
getStartLineNumber: () => decl.getStartLineNumber(),
|
|
44
|
+
getScope: () => 'public',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create an ArchFunction from a class MethodDeclaration.
|
|
49
|
+
*
|
|
50
|
+
* Method name is prefixed with the class name for clarity in violation messages:
|
|
51
|
+
* "Space.getWebhooks" instead of just "getWebhooks".
|
|
52
|
+
*/
|
|
53
|
+
export function fromMethodDeclaration(method) {
|
|
54
|
+
const parent = method.getParent();
|
|
55
|
+
const className = NodeClass.isClassDeclaration(parent)
|
|
56
|
+
? (parent.getName() ?? '<anonymous>')
|
|
57
|
+
: '<anonymous>';
|
|
58
|
+
return {
|
|
59
|
+
getName: () => {
|
|
60
|
+
const methodName = method.getName();
|
|
61
|
+
return `${className}.${methodName}`;
|
|
62
|
+
},
|
|
63
|
+
getSourceFile: () => method.getSourceFile(),
|
|
64
|
+
isExported: () => {
|
|
65
|
+
// A method is "exported" if its class is exported (ADR-005: use type guard)
|
|
66
|
+
const cls = method.getParent();
|
|
67
|
+
if (NodeClass.isClassDeclaration(cls)) {
|
|
68
|
+
return cls.isExported();
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
},
|
|
72
|
+
isAsync: () => method.isAsync(),
|
|
73
|
+
getParameters: () => method.getParameters(),
|
|
74
|
+
getReturnType: () => method.getReturnType(),
|
|
75
|
+
getBody: () => method.getBody(),
|
|
76
|
+
getNode: () => method,
|
|
77
|
+
getStartLineNumber: () => method.getStartLineNumber(),
|
|
78
|
+
getScope: () => {
|
|
79
|
+
const scope = method.getScope();
|
|
80
|
+
if (scope === Scope.Protected)
|
|
81
|
+
return 'protected';
|
|
82
|
+
if (scope === Scope.Private)
|
|
83
|
+
return 'private';
|
|
84
|
+
return 'public';
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Scan a source file for all functions.
|
|
90
|
+
*
|
|
91
|
+
* Returns ArchFunction wrappers for:
|
|
92
|
+
* 1. FunctionDeclarations — `function foo() {}`
|
|
93
|
+
* 2. VariableDeclarations with ArrowFunction initializer — `const foo = () => {}`
|
|
94
|
+
* 3. Class MethodDeclarations — `class Foo { bar() {} }` (when includeMethods is true)
|
|
95
|
+
*
|
|
96
|
+
* @param sourceFile - The source file to scan
|
|
97
|
+
* @param options - Set `includeMethods: true` to include class methods (default: true)
|
|
98
|
+
*/
|
|
99
|
+
export function collectFunctions(sourceFile, options) {
|
|
100
|
+
const includeMethods = options?.includeMethods ?? true;
|
|
101
|
+
const functions = [];
|
|
102
|
+
// Pattern 1: FunctionDeclarations
|
|
103
|
+
for (const fn of sourceFile.getFunctions()) {
|
|
104
|
+
functions.push(fromFunctionDeclaration(fn));
|
|
105
|
+
}
|
|
106
|
+
// Pattern 2: const arrow functions
|
|
107
|
+
for (const varDecl of sourceFile.getVariableDeclarations()) {
|
|
108
|
+
if (varDecl.getInitializerIfKind(SyntaxKind.ArrowFunction)) {
|
|
109
|
+
functions.push(fromArrowVariableDeclaration(varDecl));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Pattern 3: class methods
|
|
113
|
+
if (includeMethods) {
|
|
114
|
+
for (const cls of sourceFile.getClasses()) {
|
|
115
|
+
for (const method of cls.getMethods()) {
|
|
116
|
+
functions.push(fromMethodDeclaration(method));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return functions;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=arch-function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arch-function.js","sourceRoot":"","sources":["../../src/models/arch-function.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,IAAI,IAAI,SAAS,EACjB,KAAK,EACL,UAAU,GACX,MAAM,UAAU,CAAA;AAsDjB;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAyB;IAC/D,OAAO;QACL,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE;QAC7B,aAAa,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE;QACzC,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE;QACnC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE;QAC7B,aAAa,EAAE,GAAG,EAAE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K,KAAK,CAAC,SAAS;gBAAE,OAAO,WAAW,CAAA;YACjD,IAAI,KAAK,KAAK,KAAK,CAAC,OAAO;gBAAE,OAAO,SAAS,CAAA;YAC7C,OAAO,QAAQ,CAAA;QACjB,CAAC;KACF,CAAA;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAC9B,UAAsB,EACtB,OAAsC;IAEtC,MAAM,cAAc,GAAG,OAAO,EAAE,cAAc,IAAI,IAAI,CAAA;IACtD,MAAM,SAAS,GAAmB,EAAE,CAAA;IAEpC,kCAAkC;IAClC,KAAK,MAAM,EAAE,IAAI,UAAU,CAAC,YAAY,EAAE,EAAE,CAAC;QAC3C,SAAS,CAAC,IAAI,CAAC,uBAAuB,CAAC,EAAE,CAAC,CAAC,CAAA;IAC7C,CAAC;IAED,mCAAmC;IACnC,KAAK,MAAM,OAAO,IAAI,UAAU,CAAC,uBAAuB,EAAE,EAAE,CAAC;QAC3D,IAAI,OAAO,CAAC,oBAAoB,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;YAC3D,SAAS,CAAC,IAAI,CAAC,4BAA4B,CAAC,OAAO,CAAC,CAAC,CAAA;QACvD,CAAC;IACH,CAAC;IAED,2BAA2B;IAC3B,IAAI,cAAc,EAAE,CAAC;QACnB,KAAK,MAAM,GAAG,IAAI,UAAU,CAAC,UAAU,EAAE,EAAE,CAAC;YAC1C,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,UAAU,EAAE,EAAE,CAAC;gBACtC,SAAS,CAAC,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAA;YAC/C,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type JsxElement, type JsxSelfClosingElement, type SourceFile } from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* Standard HTML tag names per the WHATWG HTML Living Standard.
|
|
4
|
+
* Use with `areHtmlElements(...STANDARD_HTML_TAGS)`
|
|
5
|
+
* for unambiguous "all standard HTML elements" matching (excludes custom
|
|
6
|
+
* elements like `<my-widget>`).
|
|
7
|
+
*/
|
|
8
|
+
export declare const STANDARD_HTML_TAGS: readonly string[];
|
|
9
|
+
/**
|
|
10
|
+
* Unified representation of a JSX element in the project.
|
|
11
|
+
*
|
|
12
|
+
* Wraps both JsxElement (has children) and JsxSelfClosingElement (no children)
|
|
13
|
+
* with a uniform interface for predicate/condition evaluation.
|
|
14
|
+
*
|
|
15
|
+
* Satisfies Named (getName) and Located (getSourceFile) interfaces from
|
|
16
|
+
* identity predicates.
|
|
17
|
+
*/
|
|
18
|
+
export interface ArchJsxElement {
|
|
19
|
+
/** Tag name: 'div', 'Button', 'Icons.Check', etc. */
|
|
20
|
+
getName(): string;
|
|
21
|
+
/** Source file containing this element. */
|
|
22
|
+
getSourceFile(): SourceFile;
|
|
23
|
+
/**
|
|
24
|
+
* Whether this is an HTML intrinsic element (lowercase first char, no dot).
|
|
25
|
+
* Dot-notation tags (e.g. `motion.div`) are always classified as components.
|
|
26
|
+
*/
|
|
27
|
+
isHtmlElement(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Whether this is a component element (uppercase first char or dot-notation).
|
|
30
|
+
*/
|
|
31
|
+
isComponent(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Get attribute value by name. Returns undefined if absent or valueless.
|
|
34
|
+
* For valueless attributes (`<input disabled />`), returns undefined —
|
|
35
|
+
* use `hasAttribute('disabled')` for presence checks.
|
|
36
|
+
* For expression attributes (`onClick={() => {}}`), returns the raw
|
|
37
|
+
* initializer text including braces (e.g. `{() => {}}`).
|
|
38
|
+
*
|
|
39
|
+
* Only checks named JsxAttribute nodes — spread attributes are not inspected.
|
|
40
|
+
*/
|
|
41
|
+
getAttribute(name: string): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Check whether a named attribute exists (including valueless like `disabled`).
|
|
44
|
+
* Spread attributes (`{...props}`) are not inspected.
|
|
45
|
+
*/
|
|
46
|
+
hasAttribute(name: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Get all named attribute names. Spread attributes are excluded.
|
|
49
|
+
*/
|
|
50
|
+
getAttributeNames(): string[];
|
|
51
|
+
/** Whether this element has children (JsxElement vs JsxSelfClosingElement). */
|
|
52
|
+
hasChildren(): boolean;
|
|
53
|
+
/** Underlying ts-morph node. */
|
|
54
|
+
getNode(): JsxElement | JsxSelfClosingElement;
|
|
55
|
+
/** Start line number in the source file. */
|
|
56
|
+
getStartLineNumber(): number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create an ArchJsxElement from a JsxElement (has opening + closing tags).
|
|
60
|
+
*/
|
|
61
|
+
export declare function fromJsxElement(el: JsxElement): ArchJsxElement;
|
|
62
|
+
/**
|
|
63
|
+
* Create an ArchJsxElement from a JsxSelfClosingElement (no children).
|
|
64
|
+
*/
|
|
65
|
+
export declare function fromJsxSelfClosingElement(el: JsxSelfClosingElement): ArchJsxElement;
|
|
66
|
+
/**
|
|
67
|
+
* Scan a source file for all JSX elements.
|
|
68
|
+
*
|
|
69
|
+
* Short-circuits on non-.tsx/.jsx files. Uses single-pass traversal.
|
|
70
|
+
* Collects both JsxElement (has children) and JsxSelfClosingElement (no children).
|
|
71
|
+
* JsxFragment nodes are intentionally excluded — they have no tag name or attributes.
|
|
72
|
+
* Nested JSX elements ARE collected (consistent with collectCalls).
|
|
73
|
+
*/
|
|
74
|
+
export declare function collectJsxElements(sourceFile: SourceFile): ArchJsxElement[];
|
|
75
|
+
//# sourceMappingURL=arch-jsx-element.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arch-jsx-element.d.ts","sourceRoot":"","sources":["../../src/models/arch-jsx-element.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,qBAAqB,EAE1B,KAAK,UAAU,EAGhB,MAAM,UAAU,CAAA;AAEjB;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAiHtC,CAAA;AAEV;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC7B,qDAAqD;IACrD,OAAO,IAAI,MAAM,CAAA;IAEjB,2CAA2C;IAC3C,aAAa,IAAI,UAAU,CAAA;IAE3B;;;OAGG;IACH,aAAa,IAAI,OAAO,CAAA;IAExB;;OAEG;IACH,WAAW,IAAI,OAAO,CAAA;IAEtB;;;;;;;;OAQG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAE9C;;;OAGG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IAEnC;;OAEG;IACH,iBAAiB,IAAI,MAAM,EAAE,CAAA;IAE7B,+EAA+E;IAC/E,WAAW,IAAI,OAAO,CAAA;IAEtB,gCAAgC;IAChC,OAAO,IAAI,UAAU,GAAG,qBAAqB,CAAA;IAE7C,4CAA4C;IAC5C,kBAAkB,IAAI,MAAM,CAAA;CAC7B;AAiDD;;GAEG;AAEH,wBAAgB,cAAc,CAAC,EAAE,EAAE,UAAU,GAAG,cAAc,CAgB7D;AAED;;GAEG;AAEH,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,qBAAqB,GAAG,cAAc,CAenF;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,cAAc,EAAE,CAa3E"}
|