@optave/codegraph 3.5.0 → 3.7.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/README.md +47 -21
- package/dist/ast-analysis/engine.d.ts.map +1 -1
- package/dist/ast-analysis/engine.js +119 -127
- package/dist/ast-analysis/engine.js.map +1 -1
- package/dist/ast-analysis/visitors/ast-store-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/ast-store-visitor.js +14 -1
- package/dist/ast-analysis/visitors/ast-store-visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/complexity-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/complexity-visitor.js +11 -13
- package/dist/ast-analysis/visitors/complexity-visitor.js.map +1 -1
- package/dist/db/connection.d.ts +12 -2
- package/dist/db/connection.d.ts.map +1 -1
- package/dist/db/connection.js +81 -53
- package/dist/db/connection.js.map +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +1 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/migrations.d.ts.map +1 -1
- package/dist/db/migrations.js +38 -32
- package/dist/db/migrations.js.map +1 -1
- package/dist/domain/analysis/context.d.ts.map +1 -1
- package/dist/domain/analysis/context.js +51 -66
- package/dist/domain/analysis/context.js.map +1 -1
- package/dist/domain/analysis/dependencies.d.ts.map +1 -1
- package/dist/domain/analysis/dependencies.js +62 -70
- package/dist/domain/analysis/dependencies.js.map +1 -1
- package/dist/domain/analysis/diff-impact.d.ts +9 -7
- package/dist/domain/analysis/diff-impact.d.ts.map +1 -1
- package/dist/domain/analysis/exports.d.ts.map +1 -1
- package/dist/domain/analysis/exports.js +29 -33
- package/dist/domain/analysis/exports.js.map +1 -1
- package/dist/domain/analysis/fn-impact.d.ts +15 -17
- package/dist/domain/analysis/fn-impact.d.ts.map +1 -1
- package/dist/domain/analysis/fn-impact.js +35 -65
- package/dist/domain/analysis/fn-impact.js.map +1 -1
- package/dist/domain/analysis/module-map.d.ts.map +1 -1
- package/dist/domain/analysis/module-map.js +91 -6
- package/dist/domain/analysis/module-map.js.map +1 -1
- package/dist/domain/analysis/query-helpers.d.ts +20 -0
- package/dist/domain/analysis/query-helpers.d.ts.map +1 -0
- package/dist/domain/analysis/query-helpers.js +27 -0
- package/dist/domain/analysis/query-helpers.js.map +1 -0
- package/dist/domain/graph/builder/helpers.d.ts.map +1 -1
- package/dist/domain/graph/builder/helpers.js +15 -9
- package/dist/domain/graph/builder/helpers.js.map +1 -1
- package/dist/domain/graph/builder/incremental.d.ts.map +1 -1
- package/dist/domain/graph/builder/incremental.js +3 -2
- package/dist/domain/graph/builder/incremental.js.map +1 -1
- package/dist/domain/graph/builder/pipeline.d.ts.map +1 -1
- package/dist/domain/graph/builder/pipeline.js +69 -3
- package/dist/domain/graph/builder/pipeline.js.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.js +7 -51
- package/dist/domain/graph/builder/stages/build-edges.js.map +1 -1
- package/dist/domain/graph/builder/stages/build-structure.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/build-structure.js +7 -5
- package/dist/domain/graph/builder/stages/build-structure.js.map +1 -1
- package/dist/domain/graph/builder/stages/collect-files.js +2 -2
- package/dist/domain/graph/builder/stages/collect-files.js.map +1 -1
- package/dist/domain/graph/builder/stages/detect-changes.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/detect-changes.js +2 -2
- package/dist/domain/graph/builder/stages/detect-changes.js.map +1 -1
- package/dist/domain/graph/builder/stages/finalize.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/finalize.js +124 -105
- package/dist/domain/graph/builder/stages/finalize.js.map +1 -1
- package/dist/domain/graph/builder/stages/insert-nodes.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/insert-nodes.js +28 -15
- package/dist/domain/graph/builder/stages/insert-nodes.js.map +1 -1
- package/dist/domain/graph/builder/stages/resolve-imports.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/resolve-imports.js +3 -2
- package/dist/domain/graph/builder/stages/resolve-imports.js.map +1 -1
- package/dist/domain/graph/resolve.d.ts +0 -4
- package/dist/domain/graph/resolve.d.ts.map +1 -1
- package/dist/domain/graph/resolve.js +32 -48
- package/dist/domain/graph/resolve.js.map +1 -1
- package/dist/domain/graph/watcher.d.ts.map +1 -1
- package/dist/domain/graph/watcher.js +12 -12
- package/dist/domain/graph/watcher.js.map +1 -1
- package/dist/domain/parser.d.ts +1 -1
- package/dist/domain/parser.d.ts.map +1 -1
- package/dist/domain/parser.js +206 -101
- package/dist/domain/parser.js.map +1 -1
- package/dist/domain/search/search/cli-formatter.d.ts.map +1 -1
- package/dist/domain/search/search/cli-formatter.js +88 -83
- package/dist/domain/search/search/cli-formatter.js.map +1 -1
- package/dist/extractors/bash.d.ts +6 -0
- package/dist/extractors/bash.d.ts.map +1 -0
- package/dist/extractors/bash.js +91 -0
- package/dist/extractors/bash.js.map +1 -0
- package/dist/extractors/c.d.ts +6 -0
- package/dist/extractors/c.d.ts.map +1 -0
- package/dist/extractors/c.js +204 -0
- package/dist/extractors/c.js.map +1 -0
- package/dist/extractors/cpp.d.ts +6 -0
- package/dist/extractors/cpp.d.ts.map +1 -0
- package/dist/extractors/cpp.js +283 -0
- package/dist/extractors/cpp.js.map +1 -0
- package/dist/extractors/csharp.d.ts.map +1 -1
- package/dist/extractors/csharp.js +42 -54
- package/dist/extractors/csharp.js.map +1 -1
- package/dist/extractors/dart.d.ts +6 -0
- package/dist/extractors/dart.d.ts.map +1 -0
- package/dist/extractors/dart.js +277 -0
- package/dist/extractors/dart.js.map +1 -0
- package/dist/extractors/elixir.d.ts +9 -0
- package/dist/extractors/elixir.d.ts.map +1 -0
- package/dist/extractors/elixir.js +223 -0
- package/dist/extractors/elixir.js.map +1 -0
- package/dist/extractors/go.d.ts.map +1 -1
- package/dist/extractors/go.js +126 -130
- package/dist/extractors/go.js.map +1 -1
- package/dist/extractors/haskell.d.ts +8 -0
- package/dist/extractors/haskell.d.ts.map +1 -0
- package/dist/extractors/haskell.js +217 -0
- package/dist/extractors/haskell.js.map +1 -0
- package/dist/extractors/hcl.js +6 -6
- package/dist/extractors/hcl.js.map +1 -1
- package/dist/extractors/helpers.d.ts +32 -1
- package/dist/extractors/helpers.d.ts.map +1 -1
- package/dist/extractors/helpers.js +74 -0
- package/dist/extractors/helpers.js.map +1 -1
- package/dist/extractors/index.d.ts +12 -0
- package/dist/extractors/index.d.ts.map +1 -1
- package/dist/extractors/index.js +12 -0
- package/dist/extractors/index.js.map +1 -1
- package/dist/extractors/java.d.ts.map +1 -1
- package/dist/extractors/java.js +32 -47
- package/dist/extractors/java.js.map +1 -1
- package/dist/extractors/javascript.d.ts.map +1 -1
- package/dist/extractors/javascript.js +306 -292
- package/dist/extractors/javascript.js.map +1 -1
- package/dist/extractors/kotlin.d.ts +6 -0
- package/dist/extractors/kotlin.d.ts.map +1 -0
- package/dist/extractors/kotlin.js +275 -0
- package/dist/extractors/kotlin.js.map +1 -0
- package/dist/extractors/lua.d.ts +6 -0
- package/dist/extractors/lua.d.ts.map +1 -0
- package/dist/extractors/lua.js +162 -0
- package/dist/extractors/lua.js.map +1 -0
- package/dist/extractors/ocaml.d.ts +6 -0
- package/dist/extractors/ocaml.d.ts.map +1 -0
- package/dist/extractors/ocaml.js +236 -0
- package/dist/extractors/ocaml.js.map +1 -0
- package/dist/extractors/php.d.ts.map +1 -1
- package/dist/extractors/php.js +39 -44
- package/dist/extractors/php.js.map +1 -1
- package/dist/extractors/python.d.ts.map +1 -1
- package/dist/extractors/python.js +75 -93
- package/dist/extractors/python.js.map +1 -1
- package/dist/extractors/ruby.js +6 -13
- package/dist/extractors/ruby.js.map +1 -1
- package/dist/extractors/rust.d.ts.map +1 -1
- package/dist/extractors/rust.js +58 -83
- package/dist/extractors/rust.js.map +1 -1
- package/dist/extractors/scala.d.ts +6 -0
- package/dist/extractors/scala.d.ts.map +1 -0
- package/dist/extractors/scala.js +269 -0
- package/dist/extractors/scala.js.map +1 -0
- package/dist/extractors/swift.d.ts +6 -0
- package/dist/extractors/swift.d.ts.map +1 -0
- package/dist/extractors/swift.js +275 -0
- package/dist/extractors/swift.js.map +1 -0
- package/dist/extractors/zig.d.ts +9 -0
- package/dist/extractors/zig.d.ts.map +1 -0
- package/dist/extractors/zig.js +276 -0
- package/dist/extractors/zig.js.map +1 -0
- package/dist/features/ast.d.ts +2 -0
- package/dist/features/ast.d.ts.map +1 -1
- package/dist/features/ast.js +9 -24
- package/dist/features/ast.js.map +1 -1
- package/dist/features/audit.d.ts.map +1 -1
- package/dist/features/audit.js +17 -21
- package/dist/features/audit.js.map +1 -1
- package/dist/features/branch-compare.d.ts.map +1 -1
- package/dist/features/branch-compare.js +47 -3
- package/dist/features/branch-compare.js.map +1 -1
- package/dist/features/cfg.d.ts +7 -1
- package/dist/features/cfg.d.ts.map +1 -1
- package/dist/features/cfg.js +72 -61
- package/dist/features/cfg.js.map +1 -1
- package/dist/features/check.d.ts.map +1 -1
- package/dist/features/check.js +79 -62
- package/dist/features/check.js.map +1 -1
- package/dist/features/complexity-query.d.ts.map +1 -1
- package/dist/features/complexity-query.js +142 -137
- package/dist/features/complexity-query.js.map +1 -1
- package/dist/features/complexity.d.ts +7 -1
- package/dist/features/complexity.d.ts.map +1 -1
- package/dist/features/complexity.js +62 -1
- package/dist/features/complexity.js.map +1 -1
- package/dist/features/dataflow.d.ts +7 -1
- package/dist/features/dataflow.d.ts.map +1 -1
- package/dist/features/dataflow.js +356 -188
- package/dist/features/dataflow.js.map +1 -1
- package/dist/features/graph-enrichment.d.ts.map +1 -1
- package/dist/features/graph-enrichment.js +117 -104
- package/dist/features/graph-enrichment.js.map +1 -1
- package/dist/features/sequence.d.ts.map +1 -1
- package/dist/features/sequence.js +25 -4
- package/dist/features/sequence.js.map +1 -1
- package/dist/features/structure-query.d.ts.map +1 -1
- package/dist/features/structure-query.js +29 -4
- package/dist/features/structure-query.js.map +1 -1
- package/dist/features/structure.d.ts.map +1 -1
- package/dist/features/structure.js +35 -15
- package/dist/features/structure.js.map +1 -1
- package/dist/graph/algorithms/leiden/adapter.d.ts.map +1 -1
- package/dist/graph/algorithms/leiden/adapter.js +88 -73
- package/dist/graph/algorithms/leiden/adapter.js.map +1 -1
- package/dist/graph/algorithms/leiden/index.js +43 -28
- package/dist/graph/algorithms/leiden/index.js.map +1 -1
- package/dist/graph/algorithms/leiden/optimiser.d.ts.map +1 -1
- package/dist/graph/algorithms/leiden/optimiser.js +90 -104
- package/dist/graph/algorithms/leiden/optimiser.js.map +1 -1
- package/dist/graph/algorithms/leiden/partition.d.ts.map +1 -1
- package/dist/graph/algorithms/leiden/partition.js +89 -106
- package/dist/graph/algorithms/leiden/partition.js.map +1 -1
- package/dist/graph/model.d.ts +2 -0
- package/dist/graph/model.d.ts.map +1 -1
- package/dist/graph/model.js +20 -8
- package/dist/graph/model.js.map +1 -1
- package/dist/infrastructure/config.d.ts +0 -8
- package/dist/infrastructure/config.d.ts.map +1 -1
- package/dist/infrastructure/config.js +73 -62
- package/dist/infrastructure/config.js.map +1 -1
- package/dist/infrastructure/registry.d.ts +0 -8
- package/dist/infrastructure/registry.d.ts.map +1 -1
- package/dist/infrastructure/registry.js +12 -14
- package/dist/infrastructure/registry.js.map +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +45 -36
- package/dist/mcp/server.js.map +1 -1
- package/dist/presentation/audit.d.ts.map +1 -1
- package/dist/presentation/audit.js +61 -57
- package/dist/presentation/audit.js.map +1 -1
- package/dist/presentation/branch-compare.d.ts.map +1 -1
- package/dist/presentation/branch-compare.js +56 -38
- package/dist/presentation/branch-compare.js.map +1 -1
- package/dist/presentation/check.d.ts.map +1 -1
- package/dist/presentation/check.js +30 -32
- package/dist/presentation/check.js.map +1 -1
- package/dist/presentation/colors.d.ts.map +1 -1
- package/dist/presentation/colors.js +2 -0
- package/dist/presentation/colors.js.map +1 -1
- package/dist/presentation/complexity.d.ts.map +1 -1
- package/dist/presentation/complexity.js +25 -19
- package/dist/presentation/complexity.js.map +1 -1
- package/dist/presentation/queries-cli/exports.d.ts.map +1 -1
- package/dist/presentation/queries-cli/exports.js +15 -15
- package/dist/presentation/queries-cli/exports.js.map +1 -1
- package/dist/presentation/queries-cli/impact.d.ts.map +1 -1
- package/dist/presentation/queries-cli/impact.js +29 -19
- package/dist/presentation/queries-cli/impact.js.map +1 -1
- package/dist/types.d.ts +182 -7
- package/dist/types.d.ts.map +1 -1
- package/grammars/tree-sitter-bash.wasm +0 -0
- package/grammars/tree-sitter-c.wasm +0 -0
- package/grammars/tree-sitter-cpp.wasm +0 -0
- package/grammars/tree-sitter-dart.wasm +0 -0
- package/grammars/tree-sitter-elixir.wasm +0 -0
- package/grammars/tree-sitter-haskell.wasm +0 -0
- package/grammars/tree-sitter-kotlin.wasm +0 -0
- package/grammars/tree-sitter-lua.wasm +0 -0
- package/grammars/tree-sitter-ocaml.wasm +0 -0
- package/grammars/tree-sitter-scala.wasm +0 -0
- package/grammars/tree-sitter-swift.wasm +0 -0
- package/grammars/tree-sitter-zig.wasm +0 -0
- package/package.json +19 -7
- package/src/ast-analysis/engine.ts +147 -138
- package/src/ast-analysis/visitors/ast-store-visitor.ts +15 -2
- package/src/ast-analysis/visitors/complexity-visitor.ts +11 -11
- package/src/db/connection.ts +90 -59
- package/src/db/index.ts +1 -0
- package/src/db/migrations.ts +36 -32
- package/src/domain/analysis/context.ts +73 -75
- package/src/domain/analysis/dependencies.ts +78 -68
- package/src/domain/analysis/exports.ts +45 -34
- package/src/domain/analysis/fn-impact.ts +67 -64
- package/src/domain/analysis/module-map.ts +103 -8
- package/src/domain/analysis/query-helpers.ts +35 -0
- package/src/domain/graph/builder/helpers.ts +12 -6
- package/src/domain/graph/builder/incremental.ts +3 -2
- package/src/domain/graph/builder/pipeline.ts +71 -3
- package/src/domain/graph/builder/stages/build-edges.ts +10 -75
- package/src/domain/graph/builder/stages/build-structure.ts +9 -7
- package/src/domain/graph/builder/stages/collect-files.ts +2 -2
- package/src/domain/graph/builder/stages/detect-changes.ts +7 -2
- package/src/domain/graph/builder/stages/finalize.ts +159 -125
- package/src/domain/graph/builder/stages/insert-nodes.ts +32 -21
- package/src/domain/graph/builder/stages/resolve-imports.ts +3 -2
- package/src/domain/graph/resolve.ts +34 -46
- package/src/domain/graph/watcher.ts +12 -14
- package/src/domain/parser.ts +222 -97
- package/src/domain/search/search/cli-formatter.ts +121 -94
- package/src/extractors/bash.ts +97 -0
- package/src/extractors/c.ts +212 -0
- package/src/extractors/cpp.ts +298 -0
- package/src/extractors/csharp.ts +53 -56
- package/src/extractors/dart.ts +304 -0
- package/src/extractors/elixir.ts +251 -0
- package/src/extractors/go.ts +152 -134
- package/src/extractors/haskell.ts +235 -0
- package/src/extractors/hcl.ts +6 -6
- package/src/extractors/helpers.ts +93 -1
- package/src/extractors/index.ts +12 -0
- package/src/extractors/java.ts +43 -48
- package/src/extractors/javascript.ts +328 -281
- package/src/extractors/kotlin.ts +293 -0
- package/src/extractors/lua.ts +169 -0
- package/src/extractors/ocaml.ts +259 -0
- package/src/extractors/php.ts +46 -40
- package/src/extractors/python.ts +81 -104
- package/src/extractors/ruby.ts +6 -13
- package/src/extractors/rust.ts +65 -85
- package/src/extractors/scala.ts +285 -0
- package/src/extractors/swift.ts +293 -0
- package/src/extractors/zig.ts +294 -0
- package/src/features/ast.ts +10 -25
- package/src/features/audit.ts +24 -20
- package/src/features/branch-compare.ts +51 -4
- package/src/features/cfg.ts +113 -65
- package/src/features/check.ts +90 -74
- package/src/features/complexity-query.ts +181 -163
- package/src/features/complexity.ts +64 -1
- package/src/features/dataflow.ts +462 -217
- package/src/features/graph-enrichment.ts +161 -117
- package/src/features/sequence.ts +27 -4
- package/src/features/structure-query.ts +43 -4
- package/src/features/structure.ts +50 -22
- package/src/graph/algorithms/leiden/adapter.ts +126 -71
- package/src/graph/algorithms/leiden/index.ts +67 -28
- package/src/graph/algorithms/leiden/optimiser.ts +114 -105
- package/src/graph/algorithms/leiden/partition.ts +131 -98
- package/src/graph/model.ts +19 -7
- package/src/infrastructure/config.ts +60 -58
- package/src/infrastructure/registry.ts +17 -14
- package/src/mcp/server.ts +46 -37
- package/src/presentation/audit.ts +72 -67
- package/src/presentation/branch-compare.ts +54 -50
- package/src/presentation/check.ts +34 -34
- package/src/presentation/colors.ts +2 -0
- package/src/presentation/complexity.ts +39 -33
- package/src/presentation/queries-cli/exports.ts +17 -17
- package/src/presentation/queries-cli/impact.ts +30 -22
- package/src/types.ts +195 -7
|
@@ -15,6 +15,77 @@ interface AuditOpts {
|
|
|
15
15
|
config?: unknown;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/** Render health metrics for a single audit function. */
|
|
19
|
+
function renderHealthMetrics(fn: any): void {
|
|
20
|
+
if (fn.health.cognitive == null) return;
|
|
21
|
+
console.log(`\n Health:`);
|
|
22
|
+
console.log(
|
|
23
|
+
` Cognitive: ${fn.health.cognitive} Cyclomatic: ${fn.health.cyclomatic} Nesting: ${fn.health.maxNesting}`,
|
|
24
|
+
);
|
|
25
|
+
console.log(` MI: ${fn.health.maintainabilityIndex}`);
|
|
26
|
+
if (fn.health.halstead.volume) {
|
|
27
|
+
console.log(
|
|
28
|
+
` Halstead: vol=${fn.health.halstead.volume} diff=${fn.health.halstead.difficulty} effort=${fn.health.halstead.effort} bugs=${fn.health.halstead.bugs}`,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
if (fn.health.loc) {
|
|
32
|
+
console.log(
|
|
33
|
+
` LOC: ${fn.health.loc} SLOC: ${fn.health.sloc} Comments: ${fn.health.commentLines}`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Render a single audited function with all its sections. */
|
|
39
|
+
function renderAuditFunction(fn: any): void {
|
|
40
|
+
const lineRange = fn.endLine ? `${fn.line}-${fn.endLine}` : `${fn.line}`;
|
|
41
|
+
const roleTag = fn.role ? ` [${fn.role}]` : '';
|
|
42
|
+
console.log(`## ${kindIcon(fn.kind)} ${fn.name} (${fn.kind})${roleTag}`);
|
|
43
|
+
console.log(` ${fn.file}:${lineRange}${fn.lineCount ? ` (${fn.lineCount} lines)` : ''}`);
|
|
44
|
+
if (fn.summary) console.log(` ${fn.summary}`);
|
|
45
|
+
if (fn.signature) {
|
|
46
|
+
if (fn.signature.params != null) console.log(` Parameters: (${fn.signature.params})`);
|
|
47
|
+
if (fn.signature.returnType) console.log(` Returns: ${fn.signature.returnType}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
renderHealthMetrics(fn);
|
|
51
|
+
|
|
52
|
+
if (fn.health.thresholdBreaches.length > 0) {
|
|
53
|
+
console.log(`\n Threshold Breaches:`);
|
|
54
|
+
for (const b of fn.health.thresholdBreaches) {
|
|
55
|
+
const icon = b.level === 'fail' ? 'FAIL' : 'WARN';
|
|
56
|
+
console.log(` [${icon}] ${b.metric}: ${b.value} >= ${b.threshold}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
console.log(`\n Impact: ${fn.impact.totalDependents} transitive dependent(s)`);
|
|
61
|
+
for (const [level, nodes] of Object.entries(fn.impact.levels)) {
|
|
62
|
+
console.log(
|
|
63
|
+
` Level ${level}: ${(nodes as Array<{ name: string }>).map((n) => n.name).join(', ')}`,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (fn.callees.length > 0) {
|
|
68
|
+
console.log(`\n Calls (${fn.callees.length}):`);
|
|
69
|
+
for (const c of fn.callees) {
|
|
70
|
+
console.log(` ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (fn.callers.length > 0) {
|
|
74
|
+
console.log(`\n Called by (${fn.callers.length}):`);
|
|
75
|
+
for (const c of fn.callers) {
|
|
76
|
+
console.log(` ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (fn.relatedTests.length > 0) {
|
|
80
|
+
console.log(`\n Tests (${fn.relatedTests.length}):`);
|
|
81
|
+
for (const t of fn.relatedTests) {
|
|
82
|
+
console.log(` ${t.file}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log();
|
|
87
|
+
}
|
|
88
|
+
|
|
18
89
|
export function audit(
|
|
19
90
|
target: string,
|
|
20
91
|
customDbPath: string | undefined,
|
|
@@ -33,72 +104,6 @@ export function audit(
|
|
|
33
104
|
console.log(` ${data.functions.length} function(s) analyzed\n`);
|
|
34
105
|
|
|
35
106
|
for (const fn of data.functions) {
|
|
36
|
-
|
|
37
|
-
const roleTag = fn.role ? ` [${fn.role}]` : '';
|
|
38
|
-
console.log(`## ${kindIcon(fn.kind)} ${fn.name} (${fn.kind})${roleTag}`);
|
|
39
|
-
console.log(` ${fn.file}:${lineRange}${fn.lineCount ? ` (${fn.lineCount} lines)` : ''}`);
|
|
40
|
-
if (fn.summary) console.log(` ${fn.summary}`);
|
|
41
|
-
if (fn.signature) {
|
|
42
|
-
if (fn.signature.params != null) console.log(` Parameters: (${fn.signature.params})`);
|
|
43
|
-
if (fn.signature.returnType) console.log(` Returns: ${fn.signature.returnType}`);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Health metrics
|
|
47
|
-
if (fn.health.cognitive != null) {
|
|
48
|
-
console.log(`\n Health:`);
|
|
49
|
-
console.log(
|
|
50
|
-
` Cognitive: ${fn.health.cognitive} Cyclomatic: ${fn.health.cyclomatic} Nesting: ${fn.health.maxNesting}`,
|
|
51
|
-
);
|
|
52
|
-
console.log(` MI: ${fn.health.maintainabilityIndex}`);
|
|
53
|
-
if (fn.health.halstead.volume) {
|
|
54
|
-
console.log(
|
|
55
|
-
` Halstead: vol=${fn.health.halstead.volume} diff=${fn.health.halstead.difficulty} effort=${fn.health.halstead.effort} bugs=${fn.health.halstead.bugs}`,
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
if (fn.health.loc) {
|
|
59
|
-
console.log(
|
|
60
|
-
` LOC: ${fn.health.loc} SLOC: ${fn.health.sloc} Comments: ${fn.health.commentLines}`,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Threshold breaches
|
|
66
|
-
if (fn.health.thresholdBreaches.length > 0) {
|
|
67
|
-
console.log(`\n Threshold Breaches:`);
|
|
68
|
-
for (const b of fn.health.thresholdBreaches) {
|
|
69
|
-
const icon = b.level === 'fail' ? 'FAIL' : 'WARN';
|
|
70
|
-
console.log(` [${icon}] ${b.metric}: ${b.value} >= ${b.threshold}`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Impact
|
|
75
|
-
console.log(`\n Impact: ${fn.impact.totalDependents} transitive dependent(s)`);
|
|
76
|
-
for (const [level, nodes] of Object.entries(fn.impact.levels)) {
|
|
77
|
-
console.log(
|
|
78
|
-
` Level ${level}: ${(nodes as Array<{ name: string }>).map((n) => n.name).join(', ')}`,
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Call edges
|
|
83
|
-
if (fn.callees.length > 0) {
|
|
84
|
-
console.log(`\n Calls (${fn.callees.length}):`);
|
|
85
|
-
for (const c of fn.callees) {
|
|
86
|
-
console.log(` ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (fn.callers.length > 0) {
|
|
90
|
-
console.log(`\n Called by (${fn.callers.length}):`);
|
|
91
|
-
for (const c of fn.callers) {
|
|
92
|
-
console.log(` ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (fn.relatedTests.length > 0) {
|
|
96
|
-
console.log(`\n Tests (${fn.relatedTests.length}):`);
|
|
97
|
-
for (const t of fn.relatedTests) {
|
|
98
|
-
console.log(` ${t.file}`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
console.log();
|
|
107
|
+
renderAuditFunction(fn);
|
|
103
108
|
}
|
|
104
109
|
}
|
|
@@ -36,6 +36,57 @@ interface BranchCompareFormatData {
|
|
|
36
36
|
summary: BranchCompareSummary;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/** Format impact annotation for a symbol. */
|
|
40
|
+
function formatImpactLine(impact: unknown[] | undefined): string | null {
|
|
41
|
+
if (!impact || impact.length === 0) return null;
|
|
42
|
+
return ` ^ ${impact.length} transitive caller${impact.length !== 1 ? 's' : ''} affected`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Format added symbols section. */
|
|
46
|
+
function formatAddedSection(added: BranchCompareSymbol[]): string[] {
|
|
47
|
+
if (added.length === 0) return [];
|
|
48
|
+
const lines = ['', ` + Added (${added.length} symbol${added.length !== 1 ? 's' : ''}):`];
|
|
49
|
+
for (const sym of added) {
|
|
50
|
+
lines.push(` [${kindIcon(sym.kind)}] ${sym.name} -- ${sym.file}:${sym.line}`);
|
|
51
|
+
}
|
|
52
|
+
return lines;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Format removed symbols section. */
|
|
56
|
+
function formatRemovedSection(removed: BranchCompareSymbol[]): string[] {
|
|
57
|
+
if (removed.length === 0) return [];
|
|
58
|
+
const lines = ['', ` - Removed (${removed.length} symbol${removed.length !== 1 ? 's' : ''}):`];
|
|
59
|
+
for (const sym of removed) {
|
|
60
|
+
lines.push(` [${kindIcon(sym.kind)}] ${sym.name} -- ${sym.file}:${sym.line}`);
|
|
61
|
+
const impact = formatImpactLine(sym.impact);
|
|
62
|
+
if (impact) lines.push(impact);
|
|
63
|
+
}
|
|
64
|
+
return lines;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Format changed symbols section with delta details. */
|
|
68
|
+
function formatChangedSection(changed: BranchCompareSymbol[]): string[] {
|
|
69
|
+
if (changed.length === 0) return [];
|
|
70
|
+
const lines = ['', ` ~ Changed (${changed.length} symbol${changed.length !== 1 ? 's' : ''}):`];
|
|
71
|
+
for (const sym of changed) {
|
|
72
|
+
const parts: string[] = [];
|
|
73
|
+
if (sym.changes?.lineCount !== 0) {
|
|
74
|
+
parts.push(`lines: ${sym.base?.lineCount} -> ${sym.target?.lineCount}`);
|
|
75
|
+
}
|
|
76
|
+
if (sym.changes?.fanIn !== 0) {
|
|
77
|
+
parts.push(`fan_in: ${sym.base?.fanIn} -> ${sym.target?.fanIn}`);
|
|
78
|
+
}
|
|
79
|
+
if (sym.changes?.fanOut !== 0) {
|
|
80
|
+
parts.push(`fan_out: ${sym.base?.fanOut} -> ${sym.target?.fanOut}`);
|
|
81
|
+
}
|
|
82
|
+
const detail = parts.length > 0 ? ` (${parts.join(', ')})` : '';
|
|
83
|
+
lines.push(` [${kindIcon(sym.kind)}] ${sym.name} -- ${sym.file}:${sym.base?.line}${detail}`);
|
|
84
|
+
const impact = formatImpactLine(sym.impact);
|
|
85
|
+
if (impact) lines.push(impact);
|
|
86
|
+
}
|
|
87
|
+
return lines;
|
|
88
|
+
}
|
|
89
|
+
|
|
39
90
|
function formatText(data: BranchCompareFormatData): string {
|
|
40
91
|
if (data.error) return `Error: ${data.error}`;
|
|
41
92
|
|
|
@@ -48,56 +99,9 @@ function formatText(data: BranchCompareFormatData): string {
|
|
|
48
99
|
lines.push(` Target: ${data.targetRef} (${shortTarget})`);
|
|
49
100
|
lines.push(` Files changed: ${data.changedFiles.length}`);
|
|
50
101
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
for (const sym of data.added) {
|
|
55
|
-
lines.push(` [${kindIcon(sym.kind)}] ${sym.name} -- ${sym.file}:${sym.line}`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (data.removed.length > 0) {
|
|
60
|
-
lines.push('');
|
|
61
|
-
lines.push(
|
|
62
|
-
` - Removed (${data.removed.length} symbol${data.removed.length !== 1 ? 's' : ''}):`,
|
|
63
|
-
);
|
|
64
|
-
for (const sym of data.removed) {
|
|
65
|
-
lines.push(` [${kindIcon(sym.kind)}] ${sym.name} -- ${sym.file}:${sym.line}`);
|
|
66
|
-
if (sym.impact && sym.impact.length > 0) {
|
|
67
|
-
lines.push(
|
|
68
|
-
` ^ ${sym.impact.length} transitive caller${sym.impact.length !== 1 ? 's' : ''} affected`,
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (data.changed.length > 0) {
|
|
75
|
-
lines.push('');
|
|
76
|
-
lines.push(
|
|
77
|
-
` ~ Changed (${data.changed.length} symbol${data.changed.length !== 1 ? 's' : ''}):`,
|
|
78
|
-
);
|
|
79
|
-
for (const sym of data.changed) {
|
|
80
|
-
const parts: string[] = [];
|
|
81
|
-
if (sym.changes?.lineCount !== 0) {
|
|
82
|
-
parts.push(`lines: ${sym.base?.lineCount} -> ${sym.target?.lineCount}`);
|
|
83
|
-
}
|
|
84
|
-
if (sym.changes?.fanIn !== 0) {
|
|
85
|
-
parts.push(`fan_in: ${sym.base?.fanIn} -> ${sym.target?.fanIn}`);
|
|
86
|
-
}
|
|
87
|
-
if (sym.changes?.fanOut !== 0) {
|
|
88
|
-
parts.push(`fan_out: ${sym.base?.fanOut} -> ${sym.target?.fanOut}`);
|
|
89
|
-
}
|
|
90
|
-
const detail = parts.length > 0 ? ` (${parts.join(', ')})` : '';
|
|
91
|
-
lines.push(
|
|
92
|
-
` [${kindIcon(sym.kind)}] ${sym.name} -- ${sym.file}:${sym.base?.line}${detail}`,
|
|
93
|
-
);
|
|
94
|
-
if (sym.impact && sym.impact.length > 0) {
|
|
95
|
-
lines.push(
|
|
96
|
-
` ^ ${sym.impact.length} transitive caller${sym.impact.length !== 1 ? 's' : ''} affected`,
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
102
|
+
lines.push(...formatAddedSection(data.added));
|
|
103
|
+
lines.push(...formatRemovedSection(data.removed));
|
|
104
|
+
lines.push(...formatChangedSection(data.changed));
|
|
101
105
|
|
|
102
106
|
const s = data.summary;
|
|
103
107
|
lines.push('');
|
|
@@ -52,6 +52,39 @@ interface CheckDataResult {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/** Print violation details for a failed predicate (max 10 items). */
|
|
56
|
+
function formatPredicateViolations(pred: CheckPredicate): void {
|
|
57
|
+
const MAX_SHOWN = 10;
|
|
58
|
+
|
|
59
|
+
if (pred.name === 'cycles' && pred.cycles) {
|
|
60
|
+
for (const cycle of pred.cycles.slice(0, MAX_SHOWN)) {
|
|
61
|
+
console.log(` ${cycle.join(' -> ')}`);
|
|
62
|
+
}
|
|
63
|
+
if (pred.cycles.length > MAX_SHOWN) {
|
|
64
|
+
console.log(` ... and ${pred.cycles.length - MAX_SHOWN} more`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!pred.violations) return;
|
|
69
|
+
|
|
70
|
+
const formatViolation = (v: CheckViolation): string => {
|
|
71
|
+
if (pred.name === 'blast-radius') {
|
|
72
|
+
return `${v.name} (${v.kind}) at ${v.file}:${v.line} — ${v.transitiveCallers} callers (max: ${pred.threshold})`;
|
|
73
|
+
}
|
|
74
|
+
if (pred.name === 'boundaries') {
|
|
75
|
+
return `${v.from} -> ${v.to} (${v.edgeKind})`;
|
|
76
|
+
}
|
|
77
|
+
return `${v.name} (${v.kind}) at ${v.file}:${v.line}`;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
for (const v of pred.violations.slice(0, MAX_SHOWN)) {
|
|
81
|
+
console.log(` ${formatViolation(v)}`);
|
|
82
|
+
}
|
|
83
|
+
if (pred.violations.length > MAX_SHOWN) {
|
|
84
|
+
console.log(` ... and ${pred.violations.length - MAX_SHOWN} more`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
55
88
|
export function check(customDbPath: string | undefined, opts: CheckCliOpts = {}): void {
|
|
56
89
|
const data = checkData(customDbPath, {
|
|
57
90
|
ref: opts.ref,
|
|
@@ -89,40 +122,7 @@ export function check(customDbPath: string | undefined, opts: CheckCliOpts = {})
|
|
|
89
122
|
console.log(` [${icon}] ${pred.name}`);
|
|
90
123
|
|
|
91
124
|
if (!pred.passed) {
|
|
92
|
-
|
|
93
|
-
for (const cycle of pred.cycles.slice(0, 10)) {
|
|
94
|
-
console.log(` ${cycle.join(' -> ')}`);
|
|
95
|
-
}
|
|
96
|
-
if (pred.cycles.length > 10) {
|
|
97
|
-
console.log(` ... and ${pred.cycles.length - 10} more`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (pred.name === 'blast-radius' && pred.violations) {
|
|
101
|
-
for (const v of pred.violations.slice(0, 10)) {
|
|
102
|
-
console.log(
|
|
103
|
-
` ${v.name} (${v.kind}) at ${v.file}:${v.line} — ${v.transitiveCallers} callers (max: ${pred.threshold})`,
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
if (pred.violations.length > 10) {
|
|
107
|
-
console.log(` ... and ${pred.violations.length - 10} more`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if (pred.name === 'signatures' && pred.violations) {
|
|
111
|
-
for (const v of pred.violations.slice(0, 10)) {
|
|
112
|
-
console.log(` ${v.name} (${v.kind}) at ${v.file}:${v.line}`);
|
|
113
|
-
}
|
|
114
|
-
if (pred.violations.length > 10) {
|
|
115
|
-
console.log(` ... and ${pred.violations.length - 10} more`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (pred.name === 'boundaries' && pred.violations) {
|
|
119
|
-
for (const v of pred.violations.slice(0, 10)) {
|
|
120
|
-
console.log(` ${v.from} -> ${v.to} (${v.edgeKind})`);
|
|
121
|
-
}
|
|
122
|
-
if (pred.violations.length > 10) {
|
|
123
|
-
console.log(` ... and ${pred.violations.length - 10} more`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
125
|
+
formatPredicateViolations(pred);
|
|
126
126
|
}
|
|
127
127
|
if (pred.note) {
|
|
128
128
|
console.log(` ${pred.note}`);
|
|
@@ -23,6 +23,8 @@ export const DEFAULT_NODE_COLORS: Record<AnyNodeKind, string> = {
|
|
|
23
23
|
parameter: '#B0BEC5',
|
|
24
24
|
property: '#B0BEC5',
|
|
25
25
|
constant: '#B0BEC5',
|
|
26
|
+
namespace: '#78909C',
|
|
27
|
+
variable: '#B0BEC5',
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
export const DEFAULT_ROLE_COLORS: Partial<Record<CoreRole, string>> = {
|
|
@@ -48,6 +48,43 @@ interface ComplexityResult {
|
|
|
48
48
|
hasGraph: boolean;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/** Render health-focused table with Halstead + MI columns. */
|
|
52
|
+
function renderHealthTable(functions: ComplexityFunction[]): void {
|
|
53
|
+
console.log(
|
|
54
|
+
` ${'Function'.padEnd(35)} ${'File'.padEnd(25)} ${'MI'.padStart(5)} ${'Vol'.padStart(7)} ${'Diff'.padStart(6)} ${'Effort'.padStart(9)} ${'Bugs'.padStart(6)} ${'LOC'.padStart(5)} ${'SLOC'.padStart(5)}`,
|
|
55
|
+
);
|
|
56
|
+
console.log(
|
|
57
|
+
` ${'─'.repeat(35)} ${'─'.repeat(25)} ${'─'.repeat(5)} ${'─'.repeat(7)} ${'─'.repeat(6)} ${'─'.repeat(9)} ${'─'.repeat(6)} ${'─'.repeat(5)} ${'─'.repeat(5)}`,
|
|
58
|
+
);
|
|
59
|
+
for (const fn of functions) {
|
|
60
|
+
const name = fn.name.length > 33 ? `${fn.name.slice(0, 32)}…` : fn.name;
|
|
61
|
+
const file = fn.file.length > 23 ? `…${fn.file.slice(-22)}` : fn.file;
|
|
62
|
+
const miWarn = fn.exceeds?.includes('maintainabilityIndex') ? '!' : ' ';
|
|
63
|
+
console.log(
|
|
64
|
+
` ${name.padEnd(35)} ${file.padEnd(25)} ${String(fn.maintainabilityIndex).padStart(5)}${miWarn}${String(fn.halstead.volume).padStart(7)} ${String(fn.halstead.difficulty).padStart(6)} ${String(fn.halstead.effort).padStart(9)} ${String(fn.halstead.bugs).padStart(6)} ${String(fn.loc).padStart(5)} ${String(fn.sloc).padStart(5)}`,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Render default complexity table with MI column. */
|
|
70
|
+
function renderDefaultTable(functions: ComplexityFunction[]): void {
|
|
71
|
+
console.log(
|
|
72
|
+
` ${'Function'.padEnd(40)} ${'File'.padEnd(30)} ${'Cog'.padStart(4)} ${'Cyc'.padStart(4)} ${'Nest'.padStart(5)} ${'MI'.padStart(5)}`,
|
|
73
|
+
);
|
|
74
|
+
console.log(
|
|
75
|
+
` ${'─'.repeat(40)} ${'─'.repeat(30)} ${'─'.repeat(4)} ${'─'.repeat(4)} ${'─'.repeat(5)} ${'─'.repeat(5)}`,
|
|
76
|
+
);
|
|
77
|
+
for (const fn of functions) {
|
|
78
|
+
const name = fn.name.length > 38 ? `${fn.name.slice(0, 37)}…` : fn.name;
|
|
79
|
+
const file = fn.file.length > 28 ? `…${fn.file.slice(-27)}` : fn.file;
|
|
80
|
+
const warn = fn.exceeds ? ' !' : '';
|
|
81
|
+
const mi = fn.maintainabilityIndex > 0 ? String(fn.maintainabilityIndex) : '-';
|
|
82
|
+
console.log(
|
|
83
|
+
` ${name.padEnd(40)} ${file.padEnd(30)} ${String(fn.cognitive).padStart(4)} ${String(fn.cyclomatic).padStart(4)} ${String(fn.maxNesting).padStart(5)} ${mi.padStart(5)}${warn}`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
51
88
|
export function complexity(customDbPath: string | undefined, opts: ComplexityCliOpts = {}): void {
|
|
52
89
|
const data = complexityData(customDbPath, opts as any) as unknown as ComplexityResult;
|
|
53
90
|
|
|
@@ -74,40 +111,9 @@ export function complexity(customDbPath: string | undefined, opts: ComplexityCli
|
|
|
74
111
|
console.log(`\n# ${header}\n`);
|
|
75
112
|
|
|
76
113
|
if (opts.health) {
|
|
77
|
-
|
|
78
|
-
console.log(
|
|
79
|
-
` ${'Function'.padEnd(35)} ${'File'.padEnd(25)} ${'MI'.padStart(5)} ${'Vol'.padStart(7)} ${'Diff'.padStart(6)} ${'Effort'.padStart(9)} ${'Bugs'.padStart(6)} ${'LOC'.padStart(5)} ${'SLOC'.padStart(5)}`,
|
|
80
|
-
);
|
|
81
|
-
console.log(
|
|
82
|
-
` ${'─'.repeat(35)} ${'─'.repeat(25)} ${'─'.repeat(5)} ${'─'.repeat(7)} ${'─'.repeat(6)} ${'─'.repeat(9)} ${'─'.repeat(6)} ${'─'.repeat(5)} ${'─'.repeat(5)}`,
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
for (const fn of data.functions) {
|
|
86
|
-
const name = fn.name.length > 33 ? `${fn.name.slice(0, 32)}…` : fn.name;
|
|
87
|
-
const file = fn.file.length > 23 ? `…${fn.file.slice(-22)}` : fn.file;
|
|
88
|
-
const miWarn = fn.exceeds?.includes('maintainabilityIndex') ? '!' : ' ';
|
|
89
|
-
console.log(
|
|
90
|
-
` ${name.padEnd(35)} ${file.padEnd(25)} ${String(fn.maintainabilityIndex).padStart(5)}${miWarn}${String(fn.halstead.volume).padStart(7)} ${String(fn.halstead.difficulty).padStart(6)} ${String(fn.halstead.effort).padStart(9)} ${String(fn.halstead.bugs).padStart(6)} ${String(fn.loc).padStart(5)} ${String(fn.sloc).padStart(5)}`,
|
|
91
|
-
);
|
|
92
|
-
}
|
|
114
|
+
renderHealthTable(data.functions);
|
|
93
115
|
} else {
|
|
94
|
-
|
|
95
|
-
console.log(
|
|
96
|
-
` ${'Function'.padEnd(40)} ${'File'.padEnd(30)} ${'Cog'.padStart(4)} ${'Cyc'.padStart(4)} ${'Nest'.padStart(5)} ${'MI'.padStart(5)}`,
|
|
97
|
-
);
|
|
98
|
-
console.log(
|
|
99
|
-
` ${'─'.repeat(40)} ${'─'.repeat(30)} ${'─'.repeat(4)} ${'─'.repeat(4)} ${'─'.repeat(5)} ${'─'.repeat(5)}`,
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
for (const fn of data.functions) {
|
|
103
|
-
const name = fn.name.length > 38 ? `${fn.name.slice(0, 37)}…` : fn.name;
|
|
104
|
-
const file = fn.file.length > 28 ? `…${fn.file.slice(-27)}` : fn.file;
|
|
105
|
-
const warn = fn.exceeds ? ' !' : '';
|
|
106
|
-
const mi = fn.maintainabilityIndex > 0 ? String(fn.maintainabilityIndex) : '-';
|
|
107
|
-
console.log(
|
|
108
|
-
` ${name.padEnd(40)} ${file.padEnd(30)} ${String(fn.cognitive).padStart(4)} ${String(fn.cyclomatic).padStart(4)} ${String(fn.maxNesting).padStart(5)} ${mi.padStart(5)}${warn}`,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
116
|
+
renderDefaultTable(data.functions);
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
if (data.summary) {
|
|
@@ -97,6 +97,22 @@ function printReexportedSymbols(reexportedSymbols: ReexportedSymbol[]): void {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
function printReexportedSection(data: ExportsDataResult, opts: ExportsOpts): void {
|
|
101
|
+
const totalReexported = opts.unused
|
|
102
|
+
? (data.totalReexportedUnused ?? data.reexportedSymbols.length)
|
|
103
|
+
: (data.totalReexported ?? data.reexportedSymbols.length);
|
|
104
|
+
const plural = totalReexported !== 1 ? 's' : '';
|
|
105
|
+
if (data.results.length === 0) {
|
|
106
|
+
const label = opts.unused ? 'unused re-exported' : 're-exported';
|
|
107
|
+
console.log(
|
|
108
|
+
`\n# ${data.file} — barrel file (${totalReexported} ${label} symbol${plural} from sub-modules)\n`,
|
|
109
|
+
);
|
|
110
|
+
} else {
|
|
111
|
+
console.log(`\n Re-exported symbols (${totalReexported} from sub-modules):`);
|
|
112
|
+
}
|
|
113
|
+
printReexportedSymbols(data.reexportedSymbols);
|
|
114
|
+
}
|
|
115
|
+
|
|
100
116
|
export function fileExports(file: string, customDbPath: string, opts: ExportsOpts = {}): void {
|
|
101
117
|
const data = exportsData(file, customDbPath, opts) as ExportsDataResult;
|
|
102
118
|
if (outputResult(data as unknown as Record<string, unknown>, 'results', opts)) return;
|
|
@@ -118,23 +134,7 @@ export function fileExports(file: string, customDbPath: string, opts: ExportsOpt
|
|
|
118
134
|
}
|
|
119
135
|
|
|
120
136
|
if (hasReexported) {
|
|
121
|
-
|
|
122
|
-
? (data.totalReexportedUnused ?? data.reexportedSymbols.length)
|
|
123
|
-
: (data.totalReexported ?? data.reexportedSymbols.length);
|
|
124
|
-
if (data.results.length === 0) {
|
|
125
|
-
if (opts.unused) {
|
|
126
|
-
console.log(
|
|
127
|
-
`\n# ${data.file} — barrel file (${totalReexported} unused re-exported symbol${totalReexported !== 1 ? 's' : ''} from sub-modules)\n`,
|
|
128
|
-
);
|
|
129
|
-
} else {
|
|
130
|
-
console.log(
|
|
131
|
-
`\n# ${data.file} — barrel file (${totalReexported} re-exported symbol${totalReexported !== 1 ? 's' : ''} from sub-modules)\n`,
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
console.log(`\n Re-exported symbols (${totalReexported} from sub-modules):`);
|
|
136
|
-
}
|
|
137
|
-
printReexportedSymbols(data.reexportedSymbols);
|
|
137
|
+
printReexportedSection(data, opts);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
if (data.reexports.length > 0) {
|
|
@@ -151,6 +151,33 @@ export function fileDeps(file: string, customDbPath: string, opts: OutputOpts =
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
function printFnDepsCallees(callees: SymbolRef[]): void {
|
|
155
|
+
if (callees.length === 0) return;
|
|
156
|
+
console.log(` -> Calls (${callees.length}):`);
|
|
157
|
+
for (const c of callees) console.log(` -> ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function printFnDepsCallers(callers: CallerRef[]): void {
|
|
161
|
+
if (callers.length === 0) return;
|
|
162
|
+
console.log(`\n <- Called by (${callers.length}):`);
|
|
163
|
+
for (const c of callers) {
|
|
164
|
+
const via = c.viaHierarchy ? ` (via ${c.viaHierarchy})` : '';
|
|
165
|
+
console.log(` <- ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}${via}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function printFnDepsTransitive(transitiveCallers: Record<string, SymbolRef[]>): void {
|
|
170
|
+
for (const [d, fns] of Object.entries(transitiveCallers)) {
|
|
171
|
+
const depth = parseInt(d, 10);
|
|
172
|
+
console.log(`\n ${'<-'.repeat(depth)} Transitive callers (depth ${d}, ${fns.length}):`);
|
|
173
|
+
for (const n of fns.slice(0, 20))
|
|
174
|
+
console.log(
|
|
175
|
+
` ${' '.repeat(depth - 1)}<- ${kindIcon(n.kind)} ${n.name} ${n.file}:${n.line}`,
|
|
176
|
+
);
|
|
177
|
+
if (fns.length > 20) console.log(` ... and ${fns.length - 20} more`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
154
181
|
export function fnDeps(name: string, customDbPath: string, opts: OutputOpts = {}): void {
|
|
155
182
|
const data = fnDepsData(name, customDbPath, opts) as unknown as FnDepsData;
|
|
156
183
|
if (outputResult(data as unknown as Record<string, unknown>, 'results', opts)) return;
|
|
@@ -162,28 +189,9 @@ export function fnDeps(name: string, customDbPath: string, opts: OutputOpts = {}
|
|
|
162
189
|
|
|
163
190
|
for (const r of data.results) {
|
|
164
191
|
console.log(`\n${kindIcon(r.kind)} ${r.name} (${r.kind}) -- ${r.file}:${r.line}\n`);
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
console.log(` -> ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}`);
|
|
169
|
-
}
|
|
170
|
-
if (r.callers.length > 0) {
|
|
171
|
-
console.log(`\n <- Called by (${r.callers.length}):`);
|
|
172
|
-
for (const c of r.callers) {
|
|
173
|
-
const via = c.viaHierarchy ? ` (via ${c.viaHierarchy})` : '';
|
|
174
|
-
console.log(` <- ${kindIcon(c.kind)} ${c.name} ${c.file}:${c.line}${via}`);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
for (const [d, fns] of Object.entries(r.transitiveCallers)) {
|
|
178
|
-
console.log(
|
|
179
|
-
`\n ${'<-'.repeat(parseInt(d, 10))} Transitive callers (depth ${d}, ${fns.length}):`,
|
|
180
|
-
);
|
|
181
|
-
for (const n of fns.slice(0, 20))
|
|
182
|
-
console.log(
|
|
183
|
-
` ${' '.repeat(parseInt(d, 10) - 1)}<- ${kindIcon(n.kind)} ${n.name} ${n.file}:${n.line}`,
|
|
184
|
-
);
|
|
185
|
-
if (fns.length > 20) console.log(` ... and ${fns.length - 20} more`);
|
|
186
|
-
}
|
|
192
|
+
printFnDepsCallees(r.callees);
|
|
193
|
+
printFnDepsCallers(r.callers);
|
|
194
|
+
printFnDepsTransitive(r.transitiveCallers);
|
|
187
195
|
if (r.callees.length === 0 && r.callers.length === 0) {
|
|
188
196
|
console.log(` (no call edges found -- may be invoked dynamically or via re-exports)`);
|
|
189
197
|
}
|