Przejdź do treści
Biblioteka skilli
Programowanie · Analiza

crap-analyzer

/crap-analyzer

Tworzy oparty na ryzyku plan refaktoryzacji i testów dla ostatnio zmienionego kodu, licząc wskaźnik CRAP (złożoność razy brak testów) dla zmienionych metod w wielu językach z automatycznym wykryciem pokrycia.

Repozytorium
engineer ↗
Licencja
MIT
Ostatnia zmiana repozytorium
27.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
8
Skrypty
1
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 27.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co sprawdzić przed instalacją
  • 1 skrypt w paczce. Przejrzyj je przed instalacją, bo Claude może je uruchomić.

Skrypty: scripts/compute_crap.py

Co robi i kiedy

Tworzy oparty na ryzyku plan refaktoryzacji i testów dla ostatnio zmienionego kodu, licząc wskaźnik CRAP (złożoność razy brak testów) dla zmienionych metod w wielu językach z automatycznym wykryciem pokrycia.

Wyzwalacze z opisu

analyze CRAPcompute CRAPfind risky methodsfind complex untested methods
Oryginalny opis (EN)

Use to produce a risk-based refactor + test plan for recently-changed code on a diff/branch/PR by computing CRAP (complexity × untested) on changed methods. Multi-language — TypeScript, JavaScript, Python, Java, Kotlin, Go, Ruby, C#, Rust, PHP — auto-discovers how the repo generates coverage. Triggers — "/crap-analyzer", "analyze CRAP", "compute CRAP", "find risky methods", "find complex untested methods".

Jak działa

  1. Workflow
  2. Report format
  3. Config file
  4. When not to use this skill
Sekcje z nagłówków SKILL.md, w oryginale · 80 linii, 586 słów
Podgląd SKILL.md
---
name: crap-analyzer
description: Use to produce a risk-based refactor + test plan for recently-changed code on a diff/branch/PR by computing CRAP (complexity × untested) on changed methods. Multi-language — TypeScript, JavaScript, Python, Java, Kotlin, Go, Ruby, C#, Rust, PHP — auto-discovers how the repo generates coverage. Triggers — "/crap-analyzer", "analyze CRAP", "compute CRAP", "find risky methods", "find complex untested methods".
---

# CRAP Analyzer

CRAP (Change Risk Anti-Patterns) flags functions that are both **complex** and **poorly tested** — the worst-risk code to ship.

```
CRAP(m) = comp(m)² × (1 − cov(m))³ + comp(m)
```

This skill scopes analysis to a diff, ranks findings worst-first, and turns each finding into a concrete refactor + test-stub proposal.

## Workflow

1. **Determine the diff.** First that works:
   - `gh pr diff` / `gh pr diff <number>` if a GitHub PR is referenced.
   - `git diff --merge-base <main-branch>` — detect the main branch with `git remote show origin | grep 'HEAD branch'`.
   - `git diff --cached` for staged changes.
   - `git diff HEAD~N..HEAD` for a named commit range.
   - Explicit file list if the user names files.

   Pipe the diff to `scripts/compute_crap.py --diff -`.

2. **Locate or generate coverage.** Let the script auto-discover coverage files first (lcov, Cobertura, JaCoCo, Clover, Go `coverage.out`, coverage.py JSON). If nothing is found, follow [references/coverage-discovery.md](references/coverage-discovery.md) to detect the toolchain, then ask before running it. On decline, proceed with coverage=0% and flag it in the report header.

3. **Run the analyzer.**
   ```bash
   python3 <skill-dir>/scripts/compute_crap.py --diff - --repo-root <repo> --threshold <N> --format both
   ```
   Default threshold is 20. Read `.crap-analyzer.json` at repo root if present and pass its `threshold` through. Full flag list and output JSON shape: [references/script-reference.md](references/script-reference.md).

4. **Present the report.** Show the markdown table. For each finding, link `file:start_line`. If more than ~8 findings, surface the top 5 and mention the rest.

5. **Propose fixes per finding, worst-first.** For each function above threshold:
   - **Read the function.** Score alone is not enough — look at the code.
   - **Refactor proposal.** Extract-method diff or guard-clause rewrite. Patterns: [references/refactor-patterns.md](references/refactor-patterns.md).
   - **Test stubs.** Cover each uncovered branch in the repo's test framework. Templates: [references/test-stub-templates.md](references/test-stub-templates.md).
   - **Respect codebase conventions.** Read nearby code and match naming, error handling, DI, async patterns.

   When `len(findings) >= 3`, dispatch one subagent per finding in a **single message** — per-finding work is independent so parallelizing drops wall-clock from O(n) to O(1). Prompt template + aggregation rules: [references/subagent-prompt.md](references/subagent-prompt.md). After subagents return, sort by CRAP descending and sanity-check every "safe to auto-apply" claim against step 7.

6. **Present the wrap-up menu.** Dispatch refactor / test-stub work via `AskUserQuestion`. Menu structure and apply loop: [references/wrap-up-menu.md](references/wrap-up-menu.md). "Safe refactor" = pure extract-method with no behavior change (same inputs → same outputs, same side effects, same order). One Edit per action; confirm each before applying.

7. **Never auto-apply:**
   - Changes that reorder side effects or async operations (`await`, `.then`, `subscribe`, promise chains, RxJS / coroutine / goroutine ordering).
   - Changes to constructors, initializers, or lifecycle hooks.
   - Changes to reactive / stream operator ordering.
   - Template / markup / view changes — the script doesn't analyze those.

## Report format

```markdown
### 1. `file.py:42` — `do_thing` (CRAP 240)

**Why it's flagged:** complexity 15, coverage 0% (no tests touching body).

**Refactor proposal:**
<unified diff or code block>

**Test stubs to add:**
<framework-appropriate test block>
```

Keep each section tight — one paragraph of "why", diff, stubs. No preamble.

## Config file

Optional `.crap-analyzer.json` at repo root:

```json
{ "threshold": 20 }
```

Read if present, pass `--threshold` to the script. No other keys for now.

## When not to use this skill

- Analyzing a full codebase unprompted — scope is diff-only by design.
- Running as a blocking gate in CI — this is a Claude-driven review, not a deterministic check.
- Files the script doesn't recognize. Supported extensions listed in [references/script-reference.md](references/script-reference.md); binaries, generated code, and config files are skipped automatically.
Pliki w paczce (8)
  • SKILL.md 5 KB
  • references/coverage-discovery.md 9 KB
  • references/refactor-patterns.md 7 KB
  • references/script-reference.md 2 KB
  • references/subagent-prompt.md 3 KB
  • references/test-stub-templates.md 11 KB
  • references/wrap-up-menu.md 3 KB
  • scripts/compute_crap.py 43 KB

Wersje

W bazie nie ma innych skilli o nazwie crap-analyzer.

Migawka bazy z 13.11.2026 · wersja paczki a1467b5e32fa (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100crap-score
    Liczy wskaźnik CRAP (Change Risk Anti-Patterns) dla metod, klas lub plików .NET na podstawie pokrycia Cobertura i złożoności cyklomatycznej, aby ocenić jakość testów i ryzykowny nietestowany kod.
  • 100crap-score
    Liczy wskaźnik CRAP dla nazwanej metody, klasy lub pliku .NET na podstawie pokrycia i złożoności oraz wskazuje, które testy priorytetyzować.
  • 100crap-gate
    Czyta i naprawia ustalenia bramki CRAP (crap-check, raport hooka commita, Quality / CRAP): funkcja z raportu, dzielenie lub testowanie złożonej funkcji i decyzja o stopce Crap-Debt.
  • 84audit-coverage
    Odczytuje gotowe raporty pokrycia (lcov, Cobertura, coverage.py JSON, profil Go) i podaje pokrycie linii oraz wskaźnik CRAP dla plików i funkcji.
  • 100find-untested-sources
    Znajduje pliki źródłowe i moduły bez odpowiadających im testów oraz podpowiada lokalizacje nowych testów, używając Roslyn dla C# i tree-sitter dla innych języków.
  • 95review
    Mierzy zmiany, repozytorium lub dług skrótów w kodzie, wskazując ranking problemów z wynikami CRAP.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.