universal-ast-mapper 2.0.0 → 2.0.1
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 +9 -0
- package/README.md +261 -12
- package/dist/ai-refactor.js +185 -0
- package/dist/ai-testgen.js +105 -0
- package/dist/analysis.js +134 -0
- package/dist/arch-rules.js +82 -0
- package/dist/callgraph.js +467 -0
- package/dist/check.js +112 -0
- package/dist/cli.js +2284 -0
- package/dist/complexity.js +98 -0
- package/dist/config.js +53 -0
- package/dist/contextpack.js +79 -0
- package/dist/coupling.js +35 -0
- package/dist/covmerge.js +176 -0
- package/dist/crosslang.js +425 -0
- package/dist/dashboard.js +259 -0
- package/dist/diagram.js +264 -0
- package/dist/diskcache.js +97 -0
- package/dist/docgen.js +156 -0
- package/dist/embeddings.js +136 -0
- package/dist/explain.js +123 -0
- package/dist/explorer.js +123 -0
- package/dist/extractors/c.js +204 -0
- package/dist/extractors/common.js +56 -0
- package/dist/extractors/cpp.js +272 -0
- package/dist/extractors/csharp.js +209 -0
- package/dist/extractors/go.js +212 -0
- package/dist/extractors/java.js +152 -0
- package/dist/extractors/kotlin.js +159 -0
- package/dist/extractors/php.js +208 -0
- package/dist/extractors/python.js +153 -0
- package/dist/extractors/ruby.js +146 -0
- package/dist/extractors/rust.js +249 -0
- package/dist/extractors/swift.js +192 -0
- package/dist/extractors/typescript.js +577 -0
- package/dist/fix.js +92 -0
- package/dist/gitdiff.js +178 -0
- package/dist/graph-analysis.js +279 -0
- package/dist/graph.js +165 -0
- package/dist/history.js +36 -0
- package/dist/html.js +658 -0
- package/dist/incremental.js +122 -0
- package/dist/index.js +1945 -0
- package/dist/indexstore.js +105 -0
- package/dist/layers.js +36 -0
- package/dist/lsp.js +238 -0
- package/dist/modulecoupling.js +0 -0
- package/dist/parser.js +84 -0
- package/dist/patch.js +199 -0
- package/dist/plugins.js +88 -0
- package/dist/pool.js +114 -0
- package/dist/prompts.js +67 -0
- package/dist/registry.js +87 -0
- package/dist/report.js +441 -0
- package/dist/resolver.js +222 -0
- package/dist/roots.js +47 -0
- package/dist/search.js +68 -0
- package/dist/security.js +178 -0
- package/dist/semantic.js +365 -0
- package/dist/serve.js +185 -0
- package/dist/sfc.js +27 -0
- package/dist/similar.js +98 -0
- package/dist/skeleton.js +132 -0
- package/dist/smells.js +285 -0
- package/dist/sourcemap.js +60 -0
- package/dist/testgen.js +280 -0
- package/dist/testmap.js +167 -0
- package/dist/tsconfig.js +212 -0
- package/dist/typeflow.js +124 -0
- package/dist/types.js +5 -0
- package/dist/unused-params.js +127 -0
- package/dist/webapp.js +341 -0
- package/dist/worker.js +27 -0
- package/dist/workspace.js +330 -0
- package/package.json +2 -1
package/dist/check.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { buildReport } from "./report.js";
|
|
4
|
+
export const BASELINE_FILENAME = ".ast-map.baseline.json";
|
|
5
|
+
export function metricsFromReport(r) {
|
|
6
|
+
return {
|
|
7
|
+
fileCount: r.fileCount,
|
|
8
|
+
symbolCount: r.symbolCount,
|
|
9
|
+
cycles: r.cycles.count,
|
|
10
|
+
deadExports: r.dead.count,
|
|
11
|
+
sdpViolations: r.layerViolations.count,
|
|
12
|
+
veryHighComplexity: r.complexity.hotspots.filter((h) => h.complexity > 20).length,
|
|
13
|
+
maxComplexity: r.complexity.max,
|
|
14
|
+
score: r.score,
|
|
15
|
+
grade: r.grade,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function readBaseline(file) {
|
|
19
|
+
try {
|
|
20
|
+
const raw = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
21
|
+
return raw.metrics ?? null;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function checkThresholds(m, t, out) {
|
|
28
|
+
const rules = [
|
|
29
|
+
["maxCycles", "cycles", "max"],
|
|
30
|
+
["maxDeadExports", "deadExports", "max"],
|
|
31
|
+
["maxSdpViolations", "sdpViolations", "max"],
|
|
32
|
+
["maxVeryHighComplexity", "veryHighComplexity", "max"],
|
|
33
|
+
["maxComplexity", "maxComplexity", "max"],
|
|
34
|
+
["minScore", "score", "min"],
|
|
35
|
+
];
|
|
36
|
+
for (const [tKey, mKey, dir] of rules) {
|
|
37
|
+
const limit = t[tKey];
|
|
38
|
+
if (limit === undefined)
|
|
39
|
+
continue;
|
|
40
|
+
const actual = m[mKey];
|
|
41
|
+
const bad = dir === "max" ? actual > limit : actual < limit;
|
|
42
|
+
if (bad) {
|
|
43
|
+
out.push({
|
|
44
|
+
kind: "threshold",
|
|
45
|
+
metric: mKey,
|
|
46
|
+
limit,
|
|
47
|
+
actual,
|
|
48
|
+
message: `${mKey} is ${actual}, ${dir === "max" ? "exceeds max" : "below min"} ${limit}`,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** Metrics where an increase vs the baseline is a regression. */
|
|
54
|
+
const RATCHET_UP = [
|
|
55
|
+
"cycles",
|
|
56
|
+
"deadExports",
|
|
57
|
+
"sdpViolations",
|
|
58
|
+
"veryHighComplexity",
|
|
59
|
+
];
|
|
60
|
+
function checkBaseline(m, base, out) {
|
|
61
|
+
for (const key of RATCHET_UP) {
|
|
62
|
+
const was = base[key];
|
|
63
|
+
const now = m[key];
|
|
64
|
+
if (now > was) {
|
|
65
|
+
out.push({
|
|
66
|
+
kind: "regression",
|
|
67
|
+
metric: key,
|
|
68
|
+
limit: was,
|
|
69
|
+
actual: now,
|
|
70
|
+
message: `${key} regressed: ${was} → ${now} (baseline ratchet)`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (m.score < base.score) {
|
|
75
|
+
out.push({
|
|
76
|
+
kind: "regression",
|
|
77
|
+
metric: "score",
|
|
78
|
+
limit: base.score,
|
|
79
|
+
actual: m.score,
|
|
80
|
+
message: `health score regressed: ${base.score} → ${m.score}`,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export async function runQualityGate(absDir, root, opts = {}) {
|
|
85
|
+
const report = await buildReport(absDir, root);
|
|
86
|
+
const metrics = metricsFromReport(report);
|
|
87
|
+
const baselinePath = path.resolve(root, opts.baselinePath ?? BASELINE_FILENAME);
|
|
88
|
+
const baseline = readBaseline(baselinePath);
|
|
89
|
+
const failures = [];
|
|
90
|
+
if (opts.thresholds)
|
|
91
|
+
checkThresholds(metrics, opts.thresholds, failures);
|
|
92
|
+
if (baseline)
|
|
93
|
+
checkBaseline(metrics, baseline, failures);
|
|
94
|
+
let baselineUpdated = false;
|
|
95
|
+
if (opts.updateBaseline) {
|
|
96
|
+
const doc = {
|
|
97
|
+
tool: "universal-ast-mapper",
|
|
98
|
+
updatedAt: new Date().toISOString(),
|
|
99
|
+
metrics,
|
|
100
|
+
};
|
|
101
|
+
fs.writeFileSync(baselinePath, JSON.stringify(doc, null, 2) + "\n", "utf8");
|
|
102
|
+
baselineUpdated = true;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
passed: failures.length === 0,
|
|
106
|
+
metrics,
|
|
107
|
+
baseline,
|
|
108
|
+
baselinePath,
|
|
109
|
+
baselineUpdated,
|
|
110
|
+
failures,
|
|
111
|
+
};
|
|
112
|
+
}
|