Skip to content

feat: add FixStrategy field to CRAP scores for actionable remediation guidance - #49

Merged
jflowers merged 2 commits into
unbound-force:mainfrom
jflowers:report-actionability
Mar 15, 2026
Merged

jflowers merged 2 commits into
unbound-force:mainfrom
jflowers:report-actionability

Conversation

@jflowers

Copy link
Copy Markdown
Collaborator

Summary

  • Add FixStrategy field to crap.Score and FixStrategyCounts to crap.Summary
  • Each CRAPload function now carries a deterministic remediation label
  • Text report shows "Remediation Breakdown" section and [strategy] labels on worst offenders
  • JSON output includes new fields automatically via struct serialization

Motivation

The gaze report tells users what is wrong (high CRAP scores, Q4 quadrant) but not how to fix it. Users waste time on the wrong remediation strategy:

  • Functions with complexity >= 15 need decomposition, not more tests (CRAP at 100% coverage = complexity)
  • Functions with 94% line coverage but 0% contract coverage need assertions, not new tests
  • Functions with 0% coverage just need tests

The fix strategy is deterministic from the CRAP formula and existing metrics -- no new analysis needed.

Fix Strategies

Strategy Condition What to do
decompose complexity >= threshold, has coverage Split into smaller functions
add_tests complexity < threshold, zero coverage Write tests
add_assertions Q3 quadrant (line coverage but no contract assertions) Add assertions to existing tests
decompose_and_test complexity >= threshold AND zero coverage Both needed

New Fields

Score.FixStrategy (fix_strategy, omitempty) -- nil for healthy functions, populated for CRAPload functions.

Summary.FixStrategyCounts (fix_strategy_counts, omitempty) -- map of strategy to count, e.g. {"decompose": 3, "add_tests": 5}.

Tests

8 new tests: 5 for assignFixStrategy (all 4 strategies + below-threshold nil), 1 for computeScores integration, 1 for buildSummary accumulation, 1 for text report display.

Addresses

… guidance

Add deterministic remediation labels to each CRAPload function:
- decompose: complexity >= threshold, coverage alone can't help
- add_tests: zero coverage, complexity below threshold
- add_assertions: Q3 quadrant (has line coverage, lacks contract assertions)
- decompose_and_test: high complexity AND zero coverage

FixStrategy computed in assignFixStrategy, accumulated as
FixStrategyCounts in Summary. Text report shows 'Remediation
Breakdown' section and [strategy] labels on worst offenders.
JSON output includes new fields automatically via struct tags.

Addresses unbound-force#42, unbound-force#44, unbound-force#48
… additions

The coverage profile test fixtures referenced crap.go line numbers
(89, 92, 97, 105) that shifted when the FixStrategy type and
constants were added to crap.go. Updated to current positions
(124, 128, 134, 148).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant