Repository navigation
chore: move test-only BuildTokenizedFile and Detect into _test.go - #25
Conversation
dupehound scan --dead-code on its own source flagged BuildTokenizedFile and Detect as having no production callers — both are thin wrappers over the real production functions (BuildTokenizedFileWithIgnore, DetectWithOptions) and are only referenced from _test.go files. Move both into services/testhelpers_test.go so they are compiled only for tests. No test call sites change; production binary no longer ships them.
StructLint — All checks passed73 rules validated against
|
There was a problem hiding this comment.
Core Changes
This pull request refactors the services package by moving two test-only helper functions, BuildTokenizedFile and Detect, from services/detector.go to a new test-specific file, services/testhelpers_test.go. These functions were thin wrappers around the production functions (BuildTokenizedFileWithIgnore and DetectWithOptions) and were only ever called from test files.
This change improves code organization by making these utilities internal to the test suite, reducing the public API surface of the services package, and slightly optimizing the production binary by not compiling these unused exports.
Concerns
None. This is a beneficial refactoring that improves code clarity and reduces unnecessary exports without impacting functionality or introducing regressions.
Verdict
Approve: Changes look good and are safe to merge
Code review performed by GEMINI - gemini-2.5-flash.
…ls, fnv hashing Acts on the clones dupehound itself flagged: - services/reporter.go: extract partitionClones() and per-format writeClonesTextSection / writeClonesMdSection helpers. Test-prod and normal-clone sections in both formatters now share the partitioning and the capped-loop-plus-overflow-line logic. - services/deadcode.go: extract appendFuncDef() so every per-language scanner in extractFunctionDefs records definitions through one struct-literal site. - services/detector.go: fold hashWindow and hashWindowFull onto a shared hashTokens core; the only real difference was mixing in OrigText. Skipped the scan.go c.IsSet override boilerplate — idiomatic urfave/cli; extracting it would be noisier than the duplication. Self-scan result: 17 → 10 clones, 8.6% → 6.2% duplication. Remaining clones live in text-vs-markdown preamble / hotspot tables where the output shapes genuinely differ (plain lines vs markdown tables), so unifying them further would hurt readability.
dupehound scan results
Hotspots
Top clones (by impact)#1
|
dupehound scan results
Hotspots
Top clones (by impact)#1
|
There was a problem hiding this comment.
Core Changes
This PR focuses on significant code refactoring to reduce duplication and improve code organization, directly addressing findings from dupehound run against its own source. Key changes include:
- Encapsulation of Test Helpers: The
BuildTokenizedFileandDetectfunctions, previously inservices/detector.gobut only used by tests, have been moved to a newservices/testhelpers_test.gofile. This improves the clarity of theservicespackage's public API by removing test-specific exports. - Refactoring Clone Reporting Logic: In
services/reporter.go, duplicated logic for partitioning clones (test↔prod vs. normal), handling suppression, and formatting output with limits and overflow messages has been extracted into new helper functions:partitionClones,writeClonesTextSection, andwriteClonesMdSection. This significantly cleans upformatTextandformatMarkdown. - Consolidation of Hashing Logic: In
services/detector.go, thehashWindowandhashWindowFullfunctions have been consolidated into a singlehashTokensfunction, reducing redundant code by parameterizing the inclusion ofOrigText. - Centralized Function Definition Appending: In
services/deadcode.go, theappendFuncDefhelper was introduced to centralize theFunctionDefstruct literal creation, reducing duplication across per-language scanners inextractFunctionDefs.
These changes have resulted in a reduction of reported clones and overall duplication percentage within the dupehound codebase itself.
Concerns
None. The changes are purely refactoring and improve code quality without introducing new risks.
Verdict
Approve: Changes look good and are safe to merge
Code review performed by GEMINI - gemini-2.5-flash.
There was a problem hiding this comment.
Core Changes
This PR focuses on significant code refactoring to reduce duplication and improve code organization, directly addressing findings from dupehound run against its own source. Key changes include:
- Encapsulation of Test Helpers: The
BuildTokenizedFileandDetectfunctions, previously inservices/detector.gobut only used by tests, have been moved to a newservices/testhelpers_test.gofile. This improves the clarity of theservicespackage's public API by removing test-specific exports. - Refactoring Clone Reporting Logic: In
services/reporter.go, duplicated logic for partitioning clones (test↔prod vs. normal), handling suppression, and formatting output with limits and overflow messages has been extracted into new helper functions:partitionClones,writeClonesTextSection, andwriteClonesMdSection. This significantly cleans upformatTextandformatMarkdown. - Consolidation of Hashing Logic: In
services/detector.go, thehashWindowandhashWindowFullfunctions have been consolidated into a singlehashTokensfunction, reducing redundant code by parameterizing the inclusion ofOrigText. - Centralized Function Definition Appending: In
services/deadcode.go, theappendFuncDefhelper was introduced to centralize theFunctionDefstruct literal creation, reducing duplication across per-language scanners inextractFunctionDefs.
These changes have resulted in a reduction of reported clones and overall duplication percentage within the dupehound codebase itself.
Concerns
None. The changes are purely refactoring and improve code quality without introducing new risks.
Verdict
Approve: Changes look good and are safe to merge
Code review performed by GEMINI - gemini-2.5-flash.
Summary
Acts on the dead code and duplication that
dupehound scan --dead-codeflagged when run against its own source.Dead test-only exports
BuildTokenizedFileandDetectinservices/detector.gohad zero production callers — only referenced from_test.gofiles. Both are thin wrappers over the real production functions (BuildTokenizedFileWithIgnore,DetectWithOptions).services/testhelpers_test.goso they compile only for tests. No test call sites change.Duplication cleanup (acting on what the tool reported)
services/reporter.go: extractpartitionClonesand per-formatwriteClonesTextSection/writeClonesMdSectionhelpers. Test-prod and normal-clone sections in both formatters now share the partitioning and the capped-loop-plus-overflow-line logic.services/deadcode.go: extractappendFuncDefso every per-language scanner inextractFunctionDefsrecords definitions through one struct-literal site.services/detector.go: foldhashWindowandhashWindowFullonto a sharedhashTokenscore (the only real difference was mixing inOrigText).Skipped the
scan.go c.IsSetoverride boilerplate — idiomatic urfave/cli; extracting it would be noisier than the duplication.Self-scan impact: 17 → 10 clones, 8.6% → 6.2% duplication. Remaining clones live in text-vs-markdown preamble / hotspot tables where the output shapes genuinely differ (plain lines vs markdown tables).
Test plan
go build ./...passesgo test ./...— 274 tests pass across 6 packagesdupehound scan --dead-codeno longer reports the two functionsdupehound scanreports fewer clones and lower duplication %