Documentation
¶
Overview ¶
Package analyzer is the language-agnostic dependency-graph + metrics API surface.
Index ¶
- func ResolveInwardDependencies(depGraph *PackageAnalysisTree)
- type Analyzer
- type BoundaryProvider
- type CouplingStat
- type CouplingStats
- type Import
- type ImportInfo
- type LanguageMetricsSummary
- type Metrics
- type MetricsSummary
- type Package
- type PackageAnalysis
- type PackageAnalysisTree
- type PackageBoundary
- type PackageCouplingStats
- type PackageImportInfo
- type PackageImports
- type Position
- type StringInterner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResolveInwardDependencies ¶
func ResolveInwardDependencies(depGraph *PackageAnalysisTree)
ResolveInwardDependencies populates each package's inward coupling from the outward edges recorded in depGraph.
Types ¶
type Analyzer ¶
type Analyzer interface {
Name() string
Analyze(ctx context.Context, dir fs.FS) ([]Metrics, error)
}
Analyzer is expected to walk dir and extract the PackageImports.
type BoundaryProvider ¶
type BoundaryProvider interface {
Boundaries(ctx context.Context, dir fs.FS) ([]PackageBoundary, error)
}
BoundaryProvider is optionally implemented by analyzers that can report package boundaries. Boundaries() lazily invokes Analyze() if boundaries have not been populated yet.
type CouplingStat ¶
type CouplingStat struct {
Count uint `json:"count"`
Positions []Position `json:"positions,omitempty"`
}
CouplingStat records the occurrence count and source positions for a single coupling.
type CouplingStats ¶
type CouplingStats map[string]CouplingStat
CouplingStats stores granular dependency statistics key is a qualified type or selector expression e.g. context.Context: Count: 10 e.g. io.ReadAll: Count: 10.
type Import ¶
type Import Package
Import is semantically identical to package except in how it is used re-typed here to explicitly communicate the relationship in PackageImports.
type ImportInfo ¶
type ImportInfo struct {
Package string
// contains filtered or unexported fields
}
ImportInfo accumulates per-symbol coupling statistics for one imported package.
func NewImportInfo ¶
func NewImportInfo(pkg string) *ImportInfo
NewImportInfo returns an empty ImportInfo for pkg.
func (*ImportInfo) Add ¶
func (ii *ImportInfo) Add(key, expr string, pos Position)
Add records a single coupling occurrence for key at pos.
func (*ImportInfo) AddWithCount ¶
func (ii *ImportInfo) AddWithCount(key, expr string, count uint, positions []Position)
AddWithCount records a coupling for key with an explicit occurrence count and positions.
func (*ImportInfo) CouplingStats ¶
func (ii *ImportInfo) CouplingStats() CouplingStats
CouplingStats returns the accumulated coupling statistics with positions sorted deterministically.
type LanguageMetricsSummary ¶
type LanguageMetricsSummary struct {
Language string `json:"language"`
Metrics []MetricsSummary `json:"metrics"`
}
LanguageMetricsSummary pairs a language with simplified metrics.
type Metrics ¶
type Metrics struct {
Package Package `json:"package"`
// The number of packages that depend on this package
Inward PackageCouplingStats `json:"inward"`
// The number of other packages this package depends on
Outward PackageCouplingStats `json:"outward"`
}
Metrics is the coupling snapshot for a single package — the inward dependents and the outward dependencies, each carrying per-package CouplingStats. Marshalled JSON layout:
{
"github.com/f/uda/internal/analyzer": {
"outward": {
"context": {"context.Context": 1},
"io/fs": {"fs.FS": 1}
},
"inward": {
"github.com/f/uda/internal/analyzer/golang": {
"analyzer.Package": 5,
"analyzer.Analyzer": 1,
"analyzer.PackageImports": 2
}
}
}
}
func (Metrics) Instability ¶
Instability returns the ratio of outward coupling to inward coupling It is an indicator of the packages resilience to change.
func (Metrics) InwardCoupling ¶
InwardCoupling returns the number of packages that depend on this package.
func (Metrics) OutwardCoupling ¶
OutwardCoupling returns the number of packages this package depends on.
type MetricsSummary ¶
type MetricsSummary struct {
Package string `json:"package"`
Inward int `json:"inward"`
Outward int `json:"outward"`
Instability float64 `json:"instability"`
}
MetricsSummary is the simplified output format matching the table view.
type PackageAnalysis ¶
type PackageAnalysis struct {
Package string
Out *PackageImportInfo
In *PackageImportInfo
Aliases map[string]string
}
PackageAnalysis holds the inward and outward import information for one package.
func (*PackageAnalysis) Key ¶
func (p *PackageAnalysis) Key() string
Key returns the package name identifying this analysis.
type PackageAnalysisTree ¶
type PackageAnalysisTree struct {
// contains filtered or unexported fields
}
PackageAnalysisTree indexes PackageAnalysis nodes by package name.
func NewPackageAnalysisTree ¶
func NewPackageAnalysisTree() *PackageAnalysisTree
NewPackageAnalysisTree returns an empty PackageAnalysisTree.
func (*PackageAnalysisTree) Add ¶
func (p *PackageAnalysisTree) Add(packageName string) *PackageAnalysis
Add creates and stores a new PackageAnalysis for packageName and returns it.
func (*PackageAnalysisTree) Get ¶
func (p *PackageAnalysisTree) Get(packageName string) (*PackageAnalysis, bool)
Get returns the PackageAnalysis for packageName and whether it exists.
func (*PackageAnalysisTree) GetRootNodes ¶
func (p *PackageAnalysisTree) GetRootNodes() []*PackageAnalysis
GetRootNodes returns every PackageAnalysis node in the tree.
type PackageBoundary ¶
type PackageBoundary struct {
Name string `json:"Name"` // Package identifier (matches Package string value)
Dirs []string `json:"Dirs"` // Directories constituting this package (relative to analysis root)
}
PackageBoundary describes the filesystem scope of a package.
type PackageCouplingStats ¶
type PackageCouplingStats map[Package]CouplingStats
PackageCouplingStats is expected to contain a list of outward or inward dependencies Inward example:
"github.com/flamingoosesoftwareinc/uda/internal/analyzer/golang": {
"analyzer.Package": 3
}
Outward example:
"github.com/flamingoosesoftwareinc/uda/internal/analyzer": {
"context.Context": 3
}
func GetCouplingStats ¶
func GetCouplingStats(ctx context.Context, pii *PackageImportInfo) PackageCouplingStats
GetCouplingStats converts a PackageImportInfo into PackageCouplingStats.
type PackageImportInfo ¶
type PackageImportInfo struct {
// contains filtered or unexported fields
}
PackageImportInfo maps imported package names to their ImportInfo.
func (*PackageImportInfo) Add ¶
func (pi *PackageImportInfo) Add(pkg string) *ImportInfo
Add returns the ImportInfo for pkg, creating it if absent.
func (*PackageImportInfo) Get ¶
func (pi *PackageImportInfo) Get(pkg string) (*ImportInfo, bool)
Get returns the ImportInfo for pkg and whether it exists.
func (*PackageImportInfo) GetChildren ¶
func (pi *PackageImportInfo) GetChildren() []*ImportInfo
GetChildren returns every ImportInfo tracked by this PackageImportInfo.
type PackageImports ¶
PackageImports is expected to contain a mapping of a package and its dependencies e.g. {"analyzer":["context","io/fs"]}.
type Position ¶
type Position struct {
File string `json:"file"`
Line uint `json:"line"`
ColStart uint `json:"col_start"`
ColEnd uint `json:"col_end"`
}
Position records where a coupling reference occurs in source code.
type StringInterner ¶
type StringInterner struct {
// contains filtered or unexported fields
}
StringInterner deduplicates strings so that identical strings share the same underlying memory. This reduces memory usage when the same file path appears in many Position structs.
func NewStringInterner ¶
func NewStringInterner() *StringInterner
NewStringInterner creates a new string interner.
func (*StringInterner) Intern ¶
func (i *StringInterner) Intern(s string) string
Intern returns a canonical version of the string. If the string has been seen before, the previously stored string is returned (sharing memory). Otherwise, the string is stored and returned.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package all aggregates every supported language analyzer for one-shot analysis.
|
Package all aggregates every supported language analyzer for one-shot analysis. |
|
Package golang implements the Go source analyzer (package + import + symbol tracking).
|
Package golang implements the Go source analyzer (package + import + symbol tracking). |
|
cmd/gen-stdlib
command
gen-stdlib runs `go list std` and generates a Go source file containing the set of user-importable standard-library import paths for the current toolchain.
|
gen-stdlib runs `go list std` and generates a Go source file containing the set of user-importable standard-library import paths for the current toolchain. |
|
Package python implements the Python source analyzer (manifest + module + import tracking).
|
Package python implements the Python source analyzer (manifest + module + import tracking). |
|
Package rust implements the Rust source analyzer (crate + use + module tracking).
|
Package rust implements the Rust source analyzer (crate + use + module tracking). |
|
Package swift implements the Swift source analyzer (Package.swift target + import tracking).
|
Package swift implements the Swift source analyzer (Package.swift target + import tracking). |
|
cmd/gen-frameworks
command
gen-frameworks fetches Apple's technologies.json and generates a Go source file containing the set of system frameworks that support Swift.
|
gen-frameworks fetches Apple's technologies.json and generates a Go source file containing the set of system frameworks that support Swift. |
|
manifest
Package manifest parses Swift Package Manager Package.swift descriptors.
|
Package manifest parses Swift Package Manager Package.swift descriptors. |
|
Package typescript implements the TypeScript source analyzer (import + member + identifier tracking).
|
Package typescript implements the TypeScript source analyzer (import + member + identifier tracking). |
|
internal/barrel
Package barrel implements the TypeScript barrel-file boundary strategy.
|
Package barrel implements the TypeScript barrel-file boundary strategy. |
|
internal/directory
Package directory implements the TypeScript per-directory boundary strategy.
|
Package directory implements the TypeScript per-directory boundary strategy. |
|
internal/packagejson
Package packagejson implements the TypeScript per-package.json boundary strategy.
|
Package packagejson implements the TypeScript per-package.json boundary strategy. |
|
internal/tscore
Package tscore is the shared TypeScript parse + capture engine used by the boundary-strategy implementations.
|
Package tscore is the shared TypeScript parse + capture engine used by the boundary-strategy implementations. |