Convert CPD CSV output into Xcode-style diagnostics so duplicated lines become visible in Xcode editor.
What is CPD? CPD (Copy/Paste Detector) is a tool from the PMD suite that detects duplicated code (code clones) across a codebase by tokenizing source files. CPD can emit results in several formats, including CSV — this project consumes that CSV output and converts it to Xcode-style diagnostics.
Quick overview
- CLI:
cpd-xc-format— reads a CPD CSV file and prints Xcode-formatted warnings. - Library: programmatic conversion via the
format(_:)API.
Build & run
# build
swift build
# run CLI
.build/debug/cpd-xc-format <path/to/duplicates.csv>
# run tests
swift testCLI usage
USAGE: cpd-xc-format <file-path>
ARGUMENTS:
<file-path> The path to the file containing the cpd csv output
OPTIONS:
-h, --help Show help information.
Examples
Input (CPD CSV)
lines,tokens,occurrences
3,844,2,955,/path/file1.swift,217,/path/file2.swiftOutput (Xcode format)
### Duplication #1
### 3 lines with 844 tokens in 2 files
/path/file1.swift:955:0: warning: 📑 Line equal with file2.swift:217:0
/path/file1.swift:956:0: warning: 📑 Line equal with file2.swift:218:0
/path/file1.swift:957:0: warning: 📑 Line equal with file2.swift:219:0
/path/file2.swift:217:0: warning: 📑 Line equal with file1.swift:955:0
/path/file2.swift:218:0: warning: 📑 Line equal with file1.swift:956:0
/path/file2.swift:219:0: warning: 📑 Line equal with file1.swift:957:0
### Summary
### 1 duplications in 2 files
Notes
- The parser expects CPD CSV rows in the format produced by CPD (lines,tokens,occurrences, then pairs of line,file).
- The CLI prints the formatted output to stdout; integrate the library functions if you need programmatic access.
License
- MIT — see LICENSE