Contents

ericodx/swift-cpd

**Detect and eliminate duplicated logic in Swift and Objective-C/C codebases to improve maintainability and code quality.**

Why

Code duplication leads to:

  • inconsistent behavior across features
  • fragile refactors and hidden regressions
  • increased maintenance cost and cognitive load

swift-cpd helps you detect and address duplication early, supporting long-term code health and developer productivity.


Features

  • Structural duplication detection (AST-based)
  • Works with Swift, Objective-C, and C codebases
  • Enforces duplication rules in CI pipelines
  • Supports code quality and governance practices

Install

brew tap ericodx/homebrew-tools
brew install swift-cpd

Other installation methods — pre-built binary, build from source, pre-commit hook, Xcode plugin — are covered in the Installation Guide.

Quick start

# Generate a config file (auto-detects your source directories)
swift-cpd init

# Run
swift-cpd

Example output:

Clone detected — Type 2 | 15 lines | 120 tokens | 100.0% similarity
  Sources/App/Services/UserService.swift    :  3448
  Sources/App/Services/ProductService.swift :  7185

1 clone(s) found in 32 file(s) — 2.1% duplication — 0.8s

Configuration

Drop a .swift-cpd.yml in the project root to control paths, thresholds, excluded files, and output format:

paths:
  - Sources/
minimumTokenCount: 50
minimumLineCount: 5
enabledCloneTypes: [1, 2, 3, 4]
ignoreSameFile: true
exclude:
  - "**/*Tests*"
  - "**/*.generated.swift"

Full reference in the Usage & Configuration Guide.

Documentation

| Document | Description | |---|---| | Installation | Homebrew, binary, source, pre-commit, Xcode plugin | | Usage & Configuration | CLI options, YAML config, output formats, CI integration | | Xcode Plugin | Step-by-step Xcode and SPM plugin setup | | Architecture | System design, pipeline, detection algorithms | | CodeBase Reference | Every type, protocol, and algorithm documented |

Package Metadata

Repository: ericodx/swift-cpd

Default branch: main

README: README.md