Repository navigation
Closed
Description
Summary
A project-level duplication percentage and per-file breakdown transforms dupehound from a "here are the clones" tool into a genuine code quality gate. Teams can track improvement over time, set thresholds, and quickly identify the most duplicated files — exactly the information needed to prioritise refactoring.
New report fields
Global (domain.Report)
{
"scanned_files": 42,
"total_clones": 7,
"duplicate_lines": 183,
"total_lines": 2410,
"duplication_pct": 7.6
}Per-file breakdown (domain.FileStats)
"file_stats": [
{ "file": "services/handler.go", "total_lines": 312, "duplicate_lines": 88, "duplication_pct": 28.2 },
{ "file": "services/processor.go", "total_lines": 204, "duplicate_lines": 41, "duplication_pct": 20.1 }
]File stats sorted descending by duplication_pct, only files with > 0 duplicates included.
New flag
--min-duplication float fail (exit 1) if global duplication_pct exceeds this value (default: 0 = disabled)
Combined with issue #1 exit codes:
- Clones found → exit 1 (unless
--exit-zero) --min-duplication 5.0and project is at 7.6% → exit 1
Text output changes
Scanned 42 files · 2410 lines · 7 clones · 183 duplicate lines (7.6%)
Top duplicated files:
28.2% services/handler.go (88/312 lines)
20.1% services/processor.go (41/204 lines)
Clone #1 type-2 similarity: 1.00 ...
Implementation checklist
Domain
-
domain/types.go: addTotalLines int,DuplicationPct float64toReport -
domain/types.go: addFileStats []FileStatstoReport -
domain/types.go: defineFileStats struct { File string; TotalLines int; DuplicateLines int; DuplicationPct float64 }
Scanner
-
services/scanner.go: countTotalLinesper file (len ofRawLines) and sum globally -
services/scanner.go: computeDuplicationPct = DuplicateLines / TotalLines * 100 -
services/scanner.go: buildFileStatsslice after clone detection: for each file, count lines touched by any clone instance -
services/scanner.go: sortFileStatsbyDuplicationPctdescending, filter to pct > 0
Flags & action
-
flags.go: add--min-duplicationflag (float64, default0) -
services/scanner.go: addMinDuplication float64toScanOptions -
actions/scan.go: after scan, ifMinDuplication > 0 && report.DuplicationPct > MinDuplication→ returnErrClonesFound(or a newErrThresholdExceeded)
Reporter
-
services/reporter.go: text header line updated to includeduplicate lines (X.X%) -
services/reporter.go: text output shows "Top duplicated files" section (only whenlen(FileStats) > 0) -
services/reporter.go: JSON marshalling picks up new fields automatically (verify field names use snake_case json tags) -
services/reporter.go: SARIF run-levelpropertiesincludesduplicationPctandduplicateLines
Tests
-
services/scanner_test.go:report.TotalLines > 0after scanning real files -
services/scanner_test.go:report.DuplicationPctis in range (0, 100] when clones exist -
services/scanner_test.go:report.FileStatsis non-empty and sorted descending by pct -
services/scanner_test.go:--min-duplicationthreshold below actual pct → error returned -
services/scanner_test.go:--min-duplicationthreshold above actual pct → no error -
integration/cli_test.go: JSON output includestotal_linesandduplication_pct -
integration/cli_test.go: text output contains the duplication percentage -
integration/cli_test.go:--min-duplication 1on a codebase with duplicates → exit 1 -
integration/cli_test.go:--min-duplication 100on a codebase with duplicates → exit 0
Build & quality
-
make testpasses -
lefthookpre-commit passes - No regressions
Metadata
Metadata
Assignees
Labels
No labels
Activity
feat(#6): per-file duplication stats, global percentage, and threshol…
test(#6): integration tests for --min-duplication threshold and new r…
feat(#6): per-file duplication stats and global duplication percentage (