Skip to content

v0.1.0 — crap4swift

Choose a tag to compare

@JordanCoin JordanCoin released this 29 Jul 01:50

crap4swift v0.1.0 — the first release of Change Risk Anti-Patterns for Swift.

Finds functions that are risky to change (complex and under-tested), and hands an AI reviewer a measured risk map instead of a blind diff.

CRAP(f) = CC(f)² · (1 − coverage(f))³ + CC(f)

What's in it

  • Complexity via SwiftSyntax (SwiftLint-compatible rules) — result builders, macros, SwiftUI DSL parse exactly.
  • Coverage from two worlds behind one interfaceswift test/llvm-cov (SPM, server-side) and Xcode xccov/.xcresult (iOS apps).
  • Two doors: --spm <dir> and --xcodeproj <p> --scheme <s> run the tests themselves; or feed pre-generated coverage.
  • PR-native: --changed <base> scopes to touched functions; --format review fuses CRAP + SwiftLint into agent-ready JSON.
  • Five formats: human, json, review, sarif (GitHub Code Scanning), html (dashboard).
  • Regression gate: --baseline + --fail-regression — fail only if a function got worse.
  • CI: a pull_request workflow (Linux) that posts a risk-map comment, uploads SARIF, and gates. Exit codes: 0 clean · 1 usage · 2 over threshold.

Install (macOS)

brew install JordanCoin/tap/crap4swift

Universal binary (arm64 + x86_64) attached below. Linux / from source: swift build -c release.

Credits

The CRAP metric is by Alberto Savoia & Bob Evans (crap4j, 2007). Inspired by unclebob/crap4java and minikin/cargo-crap.