Repository navigation
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdds Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant ProcessArgs
participant ProcessFile
participant UnifiedDiff
User->>CLI: run gocondense with flags & paths
CLI->>ProcessArgs: parse flags, expand paths
ProcessArgs->>ProcessFile: dispatch each file (listOnly, showDiff)
ProcessFile->>ProcessFile: read original, compute condensed output
alt output differs
ProcessFile->>UnifiedDiff: unifiedDiff(filename, old, cur)
UnifiedDiff->>UnifiedDiff: split lines -> myersDiff -> backtrack -> write hunks
UnifiedDiff-->>ProcessFile: unified diff text
ProcessFile-->>User: print filename (if -l) or print diff (if -d)
ProcessFile-->>ProcessArgs: return resultChanged
else output same
ProcessFile-->>ProcessArgs: return resultOK
end
ProcessArgs-->>CLI: aggregate results, determine exit code
CLI-->>User: exit with status
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
cmd/gocondense/main.go (1)
155-175:⚠️ Potential issue | 🟠 MajorSerialize
-l/-doutput instead of writing from worker goroutines.These workers call
processFile, andprocessFilewrites directly to the sharedstdoutin check-only modes. That makes filename/diff order nondeterministic, and multi-file diffs can interleave. Collect the per-file payload from each worker and emit it from one place in walk order.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cmd/gocondense/main.go` around lines 155 - 175, Workers spawned in filepath.WalkDir currently call processFile which writes directly to shared stdout/stderr (for listOnly / showDiff), causing nondeterministic interleaving; change the workers (the goroutine created where sem.Acquire/wg.Add are used) to capture processFile's return/result and any output into a small result struct (e.g., {path string, result int/enum, output bytes}) and send that struct on a channel instead of writing to stdout/stderr, keep using sem and wg for concurrency control, and in the main goroutine (outside the WalkDir worker body) start a collector that reads from that channel and serially writes the payloads to stdout/stderr in the same order WalkDir yielded files (use a sequence counter or append results to a slice keyed by traversal order and flush in order after wg.Wait, or close the channel after wg.Wait and drain it serially) while still setting hasErrors/hasChanged based on the reported result values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cmd/gocondense/diff.go`:
- Around line 193-200: splitLines currently strips a final empty element so
"foo" and "foo\n" become identical; update splitLines to preserve a
trailing-newline-only change by not collapsing the final empty string when the
input ends with '\n' (e.g. detect bytes.HasSuffix(data, []byte("\n")) or check
s[len(s)-1] == '\n' and keep the last empty element), so myersDiff/unifiedDiff
will see the added empty line as a real change; ensure the function splitLines
still returns nil for empty input and that callers (myersDiff/unifiedDiff) can
handle the preserved trailing empty line.
- Line 25: The diff header uses filepath.Join which emits OS-specific
separators; replace the two filepath.Join usages used in the fmt.Fprintf call
that writes the header (the call that currently formats "--- %s\n+++ %s\n" using
filepath.Join("a", filename) and filepath.Join("b", filename")) with
path.Join("a", filepath.ToSlash(filename)) and path.Join("b",
filepath.ToSlash(filename")) so the headers always use forward slashes across
platforms; update imports to include "path" if missing and keep "filepath" for
ToSlash.
In `@cmd/gocondense/main.go`:
- Around line 240-246: The listOnly and showDiff branches call
fmt.Fprintln/fmt.Fprint but ignore their returned errors, so write failures
never change the exit code; update those branches in main (around listOnly,
showDiff and unifiedDiff usage) to capture the error from
fmt.Fprintln/Fmt.Fprint, and if non-nil return the error exit code (2) instead
of returning resultChanged; otherwise continue returning resultChanged. Ensure
the same error-propagation pattern is applied for both the listOnly branch and
the showDiff branch where unifiedDiff is written to stdout.
---
Outside diff comments:
In `@cmd/gocondense/main.go`:
- Around line 155-175: Workers spawned in filepath.WalkDir currently call
processFile which writes directly to shared stdout/stderr (for listOnly /
showDiff), causing nondeterministic interleaving; change the workers (the
goroutine created where sem.Acquire/wg.Add are used) to capture processFile's
return/result and any output into a small result struct (e.g., {path string,
result int/enum, output bytes}) and send that struct on a channel instead of
writing to stdout/stderr, keep using sem and wg for concurrency control, and in
the main goroutine (outside the WalkDir worker body) start a collector that
reads from that channel and serially writes the payloads to stdout/stderr in the
same order WalkDir yielded files (use a sequence counter or append results to a
slice keyed by traversal order and flush in order after wg.Wait, or close the
channel after wg.Wait and drain it serially) while still setting
hasErrors/hasChanged based on the reported result values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 793c70c6-5802-438c-ae74-8c0edec1ac95
📒 Files selected for processing (3)
cmd/gocondense/diff.gocmd/gocondense/main.gocmd/gocondense/main_test.go
|
Thanks a lot for the PR @hefa! I'll review properly over the weekend. |
|
@abemedia Thank you for the helpful tool! |
|



Add
-land-dflags for check-only modeSummary
-lflag that lists files whose formatting would change (without modifying them)-dflag that prints a unified diff of what would change (without modifying them)gofmtconvention (0 = clean, 1 = diffs found, 2 = errors)Motivation
There's currently no way to use gocondense in CI or pre-commit hooks to check formatting without rewriting files. Tools like
gofmt -landgoimports -lsupport this and it's become the standard pattern for Go formatting checks:Without this, the workaround is piping each file through stdin and diffing manually or copying the files to a tmp dir, running gocondense, and checking for changes.
What changed
All changes are in
cmd/gocondense/(library is untouched):main.go: two new flags (-land-d);processFilereturns a 3-way result (resultOK/resultChanged/resultError) instead ofbool, soprocessArgscan distinguish "file differs" from "error" for the exit code.processArgshas a//nolint:funlenbecause it was already near the 60-line limit and the new result handling pushes it slightly over; extracting a helper would mean refactoring the existing function (decision for the original author).diff.go(new): unified diff output using Myers algorithm, pure Go with no new dependenciesTests
-llists only files that differ, leaves all files unmodified-lreturns exit 0 when nothing differs-lworks with recursive directory walking (./...)-lrespects generated-file skipping-lreturns exit 2 on parse errors-dprints correct unified diff, leaves files unmodified-dreturns exit 0 when nothing differs-dreturns exit 2 on parse errorsSummary by CodeRabbit
New Features
-l(list changed files) and-d(show diffs) CLI flags.Behavior Changes
-lor-dare used, diffs or filenames are written to stdout; otherwise files are updated.Tests
-land-dcovering multiple files, no-change cases, recursive patterns, and error handling.Documentation
-land-dflags.