Architecture
architecture
Node architecture rules — circular imports (madge) and duplication (jscpd).
Ports the intent of the Python ARCH_CIRCULAR and ARCH_DUPLICATION rules
to the Node ecosystem. Both register under the architecture category (where
the Python CircularImportRule and DuplicationRule live).
False-green guard (from the research): madge/dependency-cruiser must resolve TS
path aliases ($lib, @/) or they silently analyse nothing. The scaffolded
template emits a .madgerc pointing at tsconfig.json so aliases resolve.
NodeCircularImportRule
Bases: NodeToolRule
Score circular-import cycles found by madge --circular --json.
Mirrors the Python CircularImportRule: 100 - cycles * 20.
madge --circular --json returns a JSON array of cycles (each a list of
files); an empty array means no cycles.
Source code in packages/axm-audit/src/axm_audit/core/rules/node/architecture.py
args
property
Report circular dependencies as JSON over the source tree.
rule_id
property
Unique identifier (shared with the Python circular-import rule).
score_output(parsed, project_path)
Score by the number of import cycles.
Source code in packages/axm-audit/src/axm_audit/core/rules/node/architecture.py
NodeDuplicationRule
Bases: NodeToolRule
Score code duplication found by jscpd --reporters json.
Mirrors the Python DuplicationRule intent. jscpd reports a duplicated
percentage; we map it to a score (0% → 100, ≥10% → 0) and pass below a 3%
duplication threshold (the research's recommended ceiling).
Source code in packages/axm-audit/src/axm_audit/core/rules/node/architecture.py
| Python | |
|---|---|
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
args
property
Placeholder — :meth:check builds the argv with a real output dir.
rule_id
property
Unique identifier (shared with the Python duplication rule).
check(project_path)
Run jscpd, reading the percentage from its JSON report file.
jscpd's json reporter writes jscpd-report.json to an output
directory; nothing structured lands on stdout (only a one-line human
summary). The base :class:NodeToolRule.parse JSON-decodes stdout, which
for jscpd always yields [] → pct 0 → a permanent false-green. So this
rule reads the report file instead of stdout.
Source code in packages/axm-audit/src/axm_audit/core/rules/node/architecture.py
score_output(parsed, project_path)
Score inversely to the duplicated-token percentage.