fix: relativize Score.File paths in JSON output#87
Merged
jflowers merged 1 commit intounbound-force:mainfrom Apr 13, 2026
Merged
Conversation
The Analyze function populates Score.File from gocyclo's Stat.Pos.Filename, which contains absolute paths derived from filepath.WalkDir with an absolute module root. This causes the recommended_actions section (and potentially scores, worst_crap, worst_gaze_crap) to embed machine-specific absolute paths in JSON output, making baselines non-portable and leaking filesystem structure. Add a relativization pass after computeScores() returns — converting all Score.File values from absolute to relative using filepath.Rel against moduleDir. This is placed after coverage lookups (which need exact paths) but before buildSummary (which propagates paths to all summary sections), fixing all downstream consumers in one place. Assisted-by: OpenCode (claude-opus-4-6) Signed-off-by: Marcus Burghardt <maburgha@redhat.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Score.Filepaths against the module root directory aftercomputeScores()returns, converting absolute paths to relativerecommended_actionssection (and all other sections) emitting machine-specific absolute paths like/Users/hbraswel/github/complytime/complyctl/cmd/...in JSON outputTestAnalyze_RelativizesFilePathsto verify bothScore.FileandRecommendedAction.Fileare relativeContext
Discovered during review of complytime/complyctl#471. The regenerated
.gaze/baseline.jsoncontained 20 absolute paths in the newrecommended_actionssection, whilescores,worst_crap, andworst_gaze_craphappened to appear relative depending on how the tool was invoked.Root cause
computeScores()setsScore.File = stat.Pos.Filename, where the filename comes fromgocyclo.Analyze()which walks the filesystem using an absolutemoduleDirfromos.Getwd(). No relativization was applied before the scores were passed tobuildSummary(), which propagates file paths intoworst_crap,worst_gaze_crap, andrecommended_actions.Fix
A
filepath.Rel(moduleDir, ...)pass is added betweencomputeScores()(which needs absolute paths forlookupCoverage()map matching) andbuildSummary()(which propagates paths to all summary sections). This single fix point ensures all downstream consumers get relative paths.Verification
go build ./...— cleangolangci-lint run ./internal/crap/...— 0 issuesTestAnalyze_*tests pass (including the new one)TestResolvePackagePaths_InvalidPattern— unrelatedgo listbehavior)