Skip to content

Commit b3401ff

Browse files
committed
Refactor stripDiffFormat guard clause logic
Rearranged the guard clause in stripDiffFormat to return early if no hunk header is found, improving code clarity and reducing nesting.
1 parent c0a2648 commit b3401ff

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

  • pkg/cmd/agent-task/shared

pkg/cmd/agent-task/shared/log.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,15 @@ func stripDiffFormat(diff string) string {
342342
}
343343
}
344344

345-
// If we found the hunk header end, we strip everything before it.
346-
if hunkEndIndex != -1 {
347-
lines = lines[hunkEndIndex+1:]
348-
} else {
349-
// This isn't a diff, so we defensively just return the original string.
345+
// Guard clause: if we didn't find a hunk header, this isn't a diff, so
346+
// we defensively just return the original string.
347+
if hunkEndIndex == -1 {
350348
return diff
351349
}
352350

351+
// We found the hunk header end; strip everything before it.
352+
lines = lines[hunkEndIndex+1:]
353+
353354
// Now we strip the leading + and - from lines, if they exist.
354355
// Note: most of the time, but not all the time, we get a diff without
355356
// these prefixes.

0 commit comments

Comments
 (0)