code-quality-crap

Evaluates method-level CRAP scores from cyclomatic complexity and test coverage to enforce quality gates.

138|5|Updated Sep 19, 2024
One-click install
npx skills add https://github.com/macalbert/envilder --skill code-quality-crap-macalbert
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: code-quality-crap
Source: https://github.com/macalbert/envilder/tree/main/.github/skills/code-quality-crap
Command: npx skills add https://github.com/macalbert/envilder --skill code-quality-crap-macalbert

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Complex methods with weak test coverage are the highest-risk code in a codebase, but teams lack an objective rule for when a method must be split or better covered. This Skill applies the CRAP (Change Risk Anti-Patterns) formula to give a single numeric risk score and a hard quality gate. ## Core Features & Use Cases - CRAP Score Calculation: Computes risk from cyclomatic complexity and coverage ratio using the standard formula comp(m)^2 x (1 - cov(m))^3 + comp(m). - Quality Gate Enforcement: Flags every method with a CRAP score of 6 or higher, with concrete coverage thresholds per complexity level. - Refactoring Guidance: Prescribes actions per scenario, such as extracting branches into smaller methods when complexity reaches 6 or more. - Use Case: During a code review or PURE_REFACTOR pass, evaluate each changed method's complexity and coverage to decide whether it must be split before merging. ## Quick Start Review the changed methods in this pull request and report each method's CRAP score with any required refactoring actions.

Frequently Asked Questions about code-quality-crap

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I calculate a CRAP score for a method?

Compute CRAP as comp(m)^2 x (1 - cov(m))^3 + comp(m), where comp(m) is the method's cyclomatic complexity and cov(m) is its test coverage ratio from 0 to 1. A score of 6 or higher fails the quality gate.

What is a good CRAP score threshold for code quality?

Every method should have a CRAP score below 6. At complexity 6 or higher, no amount of coverage can bring the score under the threshold, so the method must be split into smaller methods.

How much test coverage do I need for a complex method?

Coverage requirements scale with complexity: complexity 3 needs about 40% coverage, complexity 4 needs 60% or more, and complexity 5 needs 80% or more to keep CRAP below 6. Complexity 1-2 needs little or none.

Can more tests fix a high CRAP score?

No, not when complexity is 6 or higher, because the CRAP floor equals the complexity value itself. The only fix is refactoring to reduce cyclomatic complexity, typically by extracting branches into smaller methods.

When should I split a method instead of adding tests?

Split the method when its cyclomatic complexity reaches 6 or more, since testing cannot lower the score below the gate. For complexity 4-5 with low coverage, first reduce complexity, then address genuine behavior gaps with targeted verification.