Skip to main content

Module grouped_complexity

Module grouped_complexity 

Expand description

Shared helper for routing complexity-metric reads through complexity_metrics_grouped when opts.group_file is set.

apply_grouping rewrites changes.path to group names (hunks are never path-rewritten — hunks of grouped-away paths are dropped, identity-mapped paths keep theirs), but complexity_metrics is populated at HEAD-time keyed on raw file paths. Without an analogous rewrite, the MAX(cognitive) GROUP BY path reads in hotspots, code_health, god_classes, and stale_code silently produced 0 cognitive for grouped entities because changes.path (group name) never matched complexity_metrics.path (raw path). apply_grouping therefore also materialises complexity_metrics_grouped: one row per group carrying the per-group MAX of every complexity column the {cm_src} consumers read (cognitive, cyclomatic, loc, sloc, nargs, max_nesting, bool_ops) plus MAX kind='unit' MI — analyses opt in by reading from the table named here.

Centralised so the four affected analyses share one dispatch. This solves the same class of problem as analyses::lineage (swap an analysis’s source table based on an Options flag) but with a deliberately different mechanism: lineage regex-rewrites FROM changes in place, whereas this exposes a table name that callers substitute into an explicit {cm_src} placeholder. A placeholder is simpler and safer than a general SQL rewrite for the small, fixed set of complexity-reading analyses — they are NOT mirror images.

Functions§

source_table
Returns the complexity-metric source table for opts.