crap4clj

Analyzes Clojure projects to compute CRAP (Change Risk Anti-Pattern) scores, cyclomatic complexity, and test coverage for functions, highlighting complex and under-tested code.

23 stars
Complexity: medium

About this skill

The `crap4clj` skill provides a robust way to assess code quality and identify high-risk areas within Clojure projects. It automatically calculates the CRAP score for every function (`defn` and `defn-`), a metric that intelligently combines cyclomatic complexity with test coverage. This fusion helps pinpoint functions that are not only complex but also insufficiently tested, making them prime candidates for introducing bugs or requiring significant effort during maintenance. Developers can leverage this skill to gain an objective, data-driven perspective on their codebase's health. It integrates seamlessly with standard Clojure `deps.edn` setups, allowing for easy setup and execution within any Clojure project environment. By presenting a clear, sorted report, `crap4clj` enables teams to quickly visualize their most problematic functions. The primary benefit of using `crap4clj` is its ability to prioritize technical debt repayment and refactoring efforts. Instead of guessing which parts of the code need attention, users get a definitive list of functions with the highest change risk. This facilitates targeted improvements, leading to more maintainable, reliable, and test-covered Clojure applications.

Best use case

This skill is primarily used for comprehensive code quality assessment and risk identification in Clojure projects. It's invaluable for Clojure developers, tech leads, and teams committed to maintaining high code quality, reducing technical debt, and ensuring robust test coverage, especially in evolving or complex applications where change risks need to be proactively managed.

Analyzes Clojure projects to compute CRAP (Change Risk Anti-Pattern) scores, cyclomatic complexity, and test coverage for functions, highlighting complex and under-tested code.

A sorted table displaying CRAP scores, cyclomatic complexity, and test coverage percentages for Clojure functions, with the highest-risk (worst) functions listed first.

Practical example

Example input

Generate a CRAP report and code quality analysis for the current Clojure project.

Example output

CRAP Report
===========
Function                       Namespace                            CC   Cov%     CRAP
-------------------------------------------------------------------------------------
complex-fn                     my.namespace                         12   45.0%    130.2
simple-fn                      my.namespace                          1  100.0%      1.0

When to use this skill

  • When you need a CRAP report or detailed code quality metrics for a Clojure project.
  • When investigating cyclomatic complexity or test coverage in your Clojure codebase.
  • When identifying high-risk functions that are both complex and poorly tested.
  • Before merging pull requests or releases to ensure code quality standards are met.

When not to use this skill

  • For projects written in languages other than Clojure.
  • When the project lacks a test suite, as coverage data is essential for CRAP calculation.
  • If you only require basic linting or static analysis without complexity or coverage insights.

How crap4clj Compares

Feature / Agentcrap4cljStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexitymediumN/A

Frequently Asked Questions

What does this skill do?

Analyzes Clojure projects to compute CRAP (Change Risk Anti-Pattern) scores, cyclomatic complexity, and test coverage for functions, highlighting complex and under-tested code.

How difficult is it to install?

The installation complexity is rated as medium. You can find the installation instructions above.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# crap4clj — CRAP Metric for Clojure

Computes the **CRAP** (Change Risk Anti-Pattern) score for every `defn` and `defn-` in a Clojure project. CRAP combines cyclomatic complexity with test coverage to identify functions that are both complex and under-tested.

## Setup

Add both a `:cov` alias (Cloverage) and a `:crap` alias to the project's `deps.edn`:

```clojure
:cov  {:extra-deps {cloverage/cloverage {:mvn/version "1.2.4"}}
       :main-opts ["-m" "speclj.cloverage" "--" "-p" "src" "-s" "spec"]}
:crap {:extra-deps {io.github.unclebob/crap4clj
                     {:git/url "https://github.com/unclebob/crap4clj"
                      :git/sha "<current-sha>"}}
       :main-opts ["-m" "crap4clj.core"]}
```

The example above uses `speclj.cloverage` as the runner. For `clojure.test` projects, use `cloverage.coverage` instead:

```clojure
:cov  {:extra-deps {cloverage/cloverage {:mvn/version "1.2.4"}}
       :main-opts ["-m" "cloverage.coverage" "-p" "src" "-s" "test"]}
```

Adjust the `-p` (source path) and `-s` (test path) flags in `:cov` to match your project layout.

## Usage

```bash
# Analyze all source files under src/
clj -M:crap

# Filter to specific modules
clj -M:crap combat movement
```

crap4clj automatically deletes stale coverage reports, runs `clj -M:cov`, and then analyzes the results.

### Output

A table sorted by CRAP score (worst first):

```
CRAP Report
===========
Function                       Namespace                            CC   Cov%     CRAP
-------------------------------------------------------------------------------------
complex-fn                     my.namespace                         12   45.0%    130.2
simple-fn                      my.namespace                          1  100.0%      1.0
```

## Interpreting Scores

| CRAP Score | Meaning |
|-----------|---------|
| 1-5       | Clean — low complexity, well tested |
| 5-30      | Moderate — consider refactoring or adding tests |
| 30+       | Crappy — high complexity with poor coverage |

## How It Works

1. Deletes old coverage reports and runs Cloverage (`clj -M:cov`)
2. Finds all `.clj` and `.cljc` files under `src/`
3. Extracts `defn`/`defn-` functions with line ranges
4. Computes cyclomatic complexity (if/when/cond/condp/case/cond->/cond->>/some->/some->>/and/or/loop/catch)
5. Reads Cloverage HTML for per-line form coverage
6. Applies CRAP formula: `CC² × (1 - cov)³ + CC`
7. Sorts by CRAP score descending and prints report

Related Skills

laravel-expert

31392
from sickn33/antigravity-awesome-skills

Senior Laravel Engineer role for production-grade, maintainable, and idiomatic Laravel solutions. Focuses on clean architecture, security, performance, and modern standards (Laravel 10/11+).

Coding & DevelopmentClaude

debug-nw

7754
from nativewind/nativewind

Debug a Nativewind v5 setup issue. Walks through common configuration problems with metro, babel, postcss, and dependencies.

Coding & Development

Go Production Engineering

3891
from openclaw/skills

You are a Go production engineering expert. Follow this system for every Go project — from architecture decisions through production deployment. Apply phases sequentially for new projects; use individual phases as needed for existing codebases.

Coding & Development

Database Engineering Mastery

3891
from openclaw/skills

> Complete database design, optimization, migration, and operations system. From schema design to production monitoring — covers PostgreSQL, MySQL, SQLite, and general SQL patterns.

Coding & Development

afrexai-code-reviewer

3891
from openclaw/skills

Enterprise-grade code review agent. Reviews PRs, diffs, or code files for security vulnerabilities, performance issues, error handling gaps, architecture smells, and test coverage. Works with any language, any repo, no dependencies required.

Coding & Development

API Documentation Generator

3891
from openclaw/skills

Generate production-ready API documentation from endpoint descriptions. Outputs OpenAPI 3.0, markdown reference docs, and SDK quickstart guides.

Coding & Development

bili-rs

3891
from openclaw/skills

Development skill for bili-rs, a Rust CLI tool for Bilibili (B站). Use when implementing features, fixing bugs, or extending the bilibili-cli-rust codebase. Provides architecture conventions, API endpoints, coding patterns, and project-specific constraints. Triggers on tasks involving adding CLI commands, calling Bilibili APIs, handling authentication, implementing output formatting, or working with the layered cli/commands/client/payloads architecture.

Coding & Development

Puppeteer

3891
from openclaw/skills

Automate Chrome and Chromium with Puppeteer for scraping, testing, screenshots, and browser workflows.

Coding & Development

pharaoh

3891
from openclaw/skills

Codebase knowledge graph with 23 development workflow skills. Query architecture, dependencies, blast radius, dead code, and test coverage via MCP. Requires GitHub App installation (read-only repo access) and OAuth authentication. Connects to external MCP server at mcp.pharaoh.so.

Coding & Development

git-commit-helper

3891
from openclaw/skills

Generate standardized git commit messages following Conventional Commits format. Use this skill when the user asks to commit code, write a commit message, or create a git commit. Enforces team conventions for type prefixes, scope naming, message length, and breaking change documentation.

Coding & Development

ask-claude

3891
from openclaw/skills

Delegate a task to Claude Code CLI and immediately report the result back in chat. Supports persistent sessions with full context memory. Safe execution: no data exfiltration, no external calls, file operations confined to workspace. Use when the user asks to run Claude, delegate a coding task, continue a previous Claude session, or any task benefiting from Claude Code's tools (file editing, code analysis, bash, etc.).

Coding & Development

bnbchain-mcp

3891
from openclaw/skills

Interact with the BNB Chain Model Context Protocol (MCP) server. Blocks, contracts, tokens, NFTs, wallet, Greenfield, and ERC-8004 agent tools. Use npx @bnb-chain/mcp@latest or read the official skill page.

Coding & Development