Metrics
metrics
Structural code metrics over a :class:PackageInfo — language-agnostic.
These are facts about code structure (how big a class is, how many modules a module depends on), not quality judgments. axm-ast is the source of truth for such facts; a consumer like axm-audit reads them and applies a threshold. They work for any language whose backend populates the shared symbol model and the package dependency graph (Python, TypeScript, …), so the same metric powers the Python and node coupling/god-class rules from one implementation.
CouplingMetrics
Bases: BaseModel
Aggregate coupling metrics over a package.
Source code in packages/axm-ast/src/axm_ast/core/metrics.py
over_fan_out(threshold)
Return modules whose fan-out exceeds threshold.
GodClass
Bases: BaseModel
A class exceeding the size/method thresholds (a structural fact).
Source code in packages/axm-ast/src/axm_ast/core/metrics.py
ModuleCoupling
Bases: BaseModel
Fan-in / fan-out of a single module in the dependency graph.
Source code in packages/axm-ast/src/axm_ast/core/metrics.py
compute_coupling(pkg)
Compute fan-in / fan-out per module from the package dependency graph.
The edges in pkg.dependency_edges are (src, target) import relations
(built by the Python import resolver or the ES6 resolver), so fan-out is the
out-degree and fan-in the in-degree of each module — a pure graph metric,
language-agnostic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
PackageInfo
|
Analyzed package (with |
required |
Returns:
| Type | Description |
|---|---|
CouplingMetrics
|
class: |
Source code in packages/axm-ast/src/axm_ast/core/metrics.py
find_god_classes(pkg, *, max_lines=DEFAULT_MAX_LINES, max_methods=DEFAULT_MAX_METHODS)
Return classes exceeding the line or method thresholds across pkg.
Uses the shared symbol model (ClassInfo.line_start/line_end and
methods), so it is identical for Python and TypeScript classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
PackageInfo
|
Analyzed package. |
required |
max_lines
|
int
|
Line-span ceiling above which a class is a god class. |
DEFAULT_MAX_LINES
|
max_methods
|
int
|
Method-count ceiling above which a class is a god class. |
DEFAULT_MAX_METHODS
|
Returns:
| Name | Type | Description |
|---|---|---|
One |
list[GodClass]
|
class: |