https://github.com/ericodx/swift-cpd
Detect and eliminate duplicated logic in Swift and Objective-C/C codebases to improve maintainability and code quality.
https://github.com/ericodx/swift-cpd
cli copy-paste-detector swift swift-package-manager xcode-plugin
Last synced: about 2 months ago
JSON representation
Detect and eliminate duplicated logic in Swift and Objective-C/C codebases to improve maintainability and code quality.
- Host: GitHub
- URL: https://github.com/ericodx/swift-cpd
- Owner: ericodx
- License: mit
- Created: 2026-03-13T13:07:07.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-03-30T13:21:47.000Z (3 months ago)
- Last Synced: 2026-04-02T02:46:20.616Z (2 months ago)
- Topics: cli, copy-paste-detector, swift, swift-package-manager, xcode-plugin
- Language: Swift
- Homepage: https://github.com/ericodx/swift-cpd
- Size: 1.01 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: .github/SECURITY.md
- Governance: Docs/GOVERNANCE.md
Awesome Lists containing this project
README
# Swift Code Duplication Detector
[](https://swiftpackageindex.com/ericodx/swift-cpd)
[](https://swiftpackageindex.com/ericodx/swift-cpd)
[](https://github.com/ericodx/swift-cpd/actions)
[](https://sonarcloud.io/summary/new_code?id=ericodx-swift-cpd)
[](https://sonarcloud.io/summary/new_code?id=ericodx-swift-cpd)

**Detect and eliminate duplicated logic in Swift and Objective-C/C codebases to improve maintainability and code quality.**
`swift-cpd` performs structural analysis to detect duplication patterns across Swift, Objective-C, and C codebases, going beyond simple text-based detection.
---
## 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
```bash
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](Docs/INSTALLATION.md).
## Quick start
```bash
# 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 : 34 – 48
Sources/App/Services/ProductService.swift : 71 – 85
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:
```yaml
paths:
- Sources/
minimumTokenCount: 50
minimumLineCount: 5
enabledCloneTypes: [1, 2, 3, 4]
ignoreSameFile: true
exclude:
- "**/*Tests*"
- "**/*.generated.swift"
```
Full reference in the [Usage & Configuration Guide](Docs/USAGE.md).
## Documentation
| Document | Description |
|---|---|
| [Installation](Docs/INSTALLATION.md) | Homebrew, binary, source, pre-commit, Xcode plugin |
| [Usage & Configuration](Docs/USAGE.md) | CLI options, YAML config, output formats, CI integration |
| [Xcode Plugin](Docs/xcode-plugin.md) | Step-by-step Xcode and SPM plugin setup |
| [Architecture](Docs/Architecture/README.md) | System design, pipeline, detection algorithms |
| [CodeBase Reference](Docs/CodeBase/README.md) | Every type, protocol, and algorithm documented |