cargo-crap: Finding Untested Complexity in AI-Generated Rust Code

14 points by mark


aleyan

I just tried cargo-crap on my rust project and it immediately surfaced 9 functions out 306 that exceeded the crap scope of 30. One had a crap score of 5256; it was a real "this method is bad and I should feel bad" moment for me. The rest were also bad, but I had already known they were bad.

The default formatting of errors into an ascii table complete with ╌╌╌╌ horizontal lines between each line was a tad annoying as it doubled how much I had to scroll to reach the top offenders.

A useful project and I will address its initial findings. I won't immediately make it part of my CI however, because I want to see my tools supported adequately over time first.

ocramz

what you really want is the gradient (dCRAP/dCov , dCRAP/cComp), and act on that

dpc_pw

On a TODO to try to integrate in CI and slop loops. Thought the code coverage is slow and heavy to compile and run, so might need to figure out some good ways to amortize?

pkhuong

If the score increased, ask the agent to either simplify the function or add meaningful branch coverage.

I wonder why you'd have uncovered lines at all if you're autogenerating tests. I would consider detecting garbage coverage (e.g., mutation testing) closer to a real issue in that context.