garbage-code-hunter 0.2.2

A humorous Rust code quality detector that roasts your garbage code
Documentation
# Swift Accuracy Report

> Generated: 2026-05-15 | Projects tested: 3 | Analyzer: garbage-code-hunter

---

## Tested Projects

| Project | Files | Lines | Issues | Score | Density |
|---------|:-----:|:-----:|:------:|:-----:|:-------:|
| Alamofire (HTTP client) | 108 | 47,268 | 5,843 | 54.2 | 123/k |
| SnapKit (Auto Layout DSL) | 44 | 4,529 | 380 | 42.8 | 83/k |
| vapor (web framework) | 298 | 38,407 | 2,880 | 39.7 | 74/k |

---

## Critical Bug: Non-Swift Files Scanned

**The analyzer scanned JavaScript files inside `docs/` directories**, producing massive false positive counts:

| File | Issues | Should Be |
|------|:------:|:---------:|
| jquery.min.js (Alamofire) | 1,632 | Excluded |
| lunr.min.js (Alamofire) | 390 | Excluded |
| typeahead.jquery.js | ~200 | Excluded |
| jazzy.search.js | ~50 | Excluded |

These are Jazzy-generated documentation assets, not project source code. **This single bug inflates Alamofire's issue count by ~2,300 (40%).**

**Fix:** Filter files by target language extension (`.swift` only) and exclude `docs/`, `vendor/`, `.build/` directories.

---

## Per-Rule Accuracy

### commented-code

| Metric | Value |
|--------|-------|
| Total detections | ~100+ |
| Verified TP rate | **~0%** (in sampled files) |
| FP rate | **~90-100%** |

**Source-code verification:**
- `Alamofire/AuthenticationInterceptor.swift` — 5 flagged. **All FP.** Every `//` line is either MIT license header, `// MARK: -` section dividers, or `///` doc comments.
- `vapor/Bcrypt.swift` — 3 flagged. **All FP.** Comments are explanatory (`// user provided salt`, `// OpenBSD doesn't support 2y revision.`).

**Root cause:** The commented-code rule matches `//` lines containing Swift-like keywords (`return`, `true`, `if`, `let`). This triggers on:
- `/// Documentation mentioning return values`
- `// MARK: - Private` (contains no keyword, but similar patterns do)
- `// Replace with 2b.` (contains no keyword, but other explanatory comments do)

**Verdict: Broken rule for Swift.** The `///` doc-comment syntax is Swift's standard API documentation format. The rule must skip `///` lines entirely. Single-line `//` comments containing natural language should also be exempt unless they contain actual code patterns (e.g., `// return x + 1`).

### magic-number

| Metric | Value |
|--------|-------|
| Total detections | ~1500+ |
| FP rate | ~30-40% |

**Source-code verification:**
- `SnapKit/ConstraintAttributes.swift` — 29 flagged. **Technically TP but contextually FP.** These are bitmask positions (`UInt(1) << 0` through `<< 19`) in a standard Swift `OptionSet`. This is idiomatic Swift, not magic numbers.
- `Alamofire/CombineTests.swift` — 236 flagged. These are HTTP status codes, port numbers, and timeout values in test assertions.

**Verdict: Over-sensitive for bitmasks and test code.** Swift `OptionSet` bit-shift patterns should be exempted. Test files should have a higher threshold.

### code-duplication

| Metric | Value |
|--------|-------|
| Total detections | ~2000+ |
| FP rate | **~70%** |

**Verdict: Same issue as other languages.** Test files with similar test structures produce massive false duplication counts.

### god-function / long-function

| Metric | Value |
|--------|-------|
| Total detections | ~10 |
| FP rate | **~50%** |

**Source-code verification:**
- `Alamofire/Session.swift` — reported god-function + long-function. **FP.** The file is 1,441 lines but contains a well-organized facade class with many small overloads (10-25 lines each). The large line count comes from extensive `///` documentation and API surface overloads, not from complex logic.

**Verdict: Doc comments inflate function length.** The analyzer counts `///` doc-comment lines toward function length. A function with 15 lines of documentation and 10 lines of code should not be flagged as a 25-line "long function."

---

## Accuracy Summary

| Rule | TP Rate | FP Source | Severity |
|------|:-------:|-----------|:--------:|
| commented-code | **~0-10%** | Doc comments (///), MARK dividers | **Broken** |
| magic-number | **~60-70%** | OptionSet bitmasks, test values | Needs context |
| code-duplication | **~30%** | Test patterns, API overloads | **Critical FP** |
| god-function | **~50%** | Doc comments inflate count | Needs fix |
| long-function | **~50%** | Doc comments inflate count | Needs fix |
| single-letter-var | **~60%** | Loop vars | Acceptable |
| file-too-long | **~70%** || Acceptable |
| **Overall** | **~30-40%** | | |

---

## Critical Issues

1. **Non-Swift files scanned** — JS files in `docs/` produce thousands of FP. Must filter by `.swift` extension.
2. **Commented-code rule broken**`///` doc comments are Swift's standard documentation format. The rule matches them as "commented code" with near-100% FP rate.
3. **Doc comments inflate function length** — Functions are measured including their `///` documentation, causing legitimate well-documented functions to be flagged as "long."

---

## Concrete Improvement Suggestions

1. **File extension filtering** — Only scan `.swift` files for Swift projects. Skip `docs/`, `vendor/`, `.build/`, `Pods/` directories.
2. **Fix commented-code for Swift** — Skip `///` doc-comment lines entirely. For `//` comments, only flag lines that contain actual code patterns (assignment, function calls, control flow) not natural language.
3. **Exclude doc comments from function length** — When measuring function length, skip `///` and `/** */` doc-comment blocks.
4. **OptionSet bitmask exemption** — Detect `UInt(1) << N` patterns and skip them in magic-number detection.

---

## False Negative Observations

1. **Force unwrapping** — No rule detects excessive `!` force unwraps, which are a major Swift code smell (equivalent to Rust's `unwrap()`).
2. **Missing `guard let`** — No rule detects `if let` chains that should be `guard let` for early returns.
3. **Completion handler hell** — No rule detects deeply nested completion handlers (pre-async/await pattern).