minikin/cargo-crap

Change Risk Anti-Patterns (CRAP) metric for Rust projects

What it solves

It identifies "crappy" code in Rust projects by finding functions that are both highly complex and poorly tested. This helps developers find where bugs are most likely to hide, particularly in AI-generated code where complexity may be high but test coverage is lacking.

How it works

The tool computes the CRAP (Change Risk Anti-Patterns) metric, which combines cyclomatic complexity (CC) and test coverage into a single score.

  • A low score (e.g., 1.0) indicates a trivial, fully covered function.
  • A high score indicates a function that is complex and lacks coverage.
  • If a function has 100% coverage, the CRAP score equals its cyclomatic complexity.
  • Functions with very high complexity (CC > 30) are flagged regardless of their test coverage.

Who it’s for

Rust developers and teams who want to integrate automated code quality gating in their CI/CD pipelines to prevent complex, untested code from entering the production codebase.

Highlights

  • CI Integration: Supports --fail-above to exit with an error if any function exceeds a specific threshold.
  • Baseline Comparison: Can compare current results against a JSON baseline to detect regressions in code quality.
  • Multiple Output Formats: Supports human-readable tables, JSON, GitHub annotations, Markdown, SARIF, and Shields.io badges.
  • Workspace Support: Capable of analyzing entire Cargo workspaces (monorepos).