Add Swift function CRAP scores, coverage, and test discovery.

Swift packages and iOS apps had no per-function complexity or coverage join, so crapper could not write a .metrics/crap.edn entry that uml-viewer and mutator can attach to a function. The Swift reader scores top-level functions, methods, initializers, subscripts, computed properties, and closures bound with let or var. Nested closures stay inside the enclosing function. Decision points match the other languages: if, guard, loops, catch, ternary, each switch case, &&, ||, ??, and optional chaining.

Coverage reads llvm-cov JSON from swift test and xccov JSON from xcodebuild, joined on the file suffix and the function's line span. A package runs swift test --enable-code-coverage; an Xcode project runs xcodebuild and xcrun xccov view --report --json.

Proved by tests/test_swift.py against checked-in llvm-cov and xccov fixtures, the existing suite (174 passed), crapper with every function under CRAP 10, dryer with no duplicate at 0.8 or above, and mutator killing every mutant in the Swift reader.

Co-authored-by: Robert C. Martin <[email protected]>
This commit is contained in:
Cursor Agent
2026-11-25 23:45:32 +00:00
co-authored by Robert C. Martin
parent c757ec79a6
commit 10c4e43f7b
20 changed files with 1780 additions and 150 deletions
+1
View File
@@ -9,6 +9,7 @@ _SOURCES = [
("typescript", "export function view() { return 1 }\n", "src/ui.ts", "view"),
("python", "def run():\n return 1\n", "src/app.py", "run"),
("rust", "pub fn open() {}\n", "src/lib.rs", "open"),
("swift", "func open() {}\n", "Sources/Demo/Box.swift", "open"),
]