fix(grep): format files_with_matches output as clean file paths

This commit is contained in:
YeonGyu-Kim
2026-02-22 15:19:26 +09:00
parent b175c11b35
commit c806a35e49
2 changed files with 132 additions and 2 deletions
+9 -2
View File
@@ -10,6 +10,7 @@ export function formatGrepResult(result: GrepResult): string {
}
const lines: string[] = []
const isFilesOnlyMode = result.matches.every((match) => match.line === 0 && match.text.trim() === "")
lines.push(`Found ${result.totalMatches} match(es) in ${result.filesSearched} file(s)`)
if (result.truncated) {
@@ -26,8 +27,14 @@ export function formatGrepResult(result: GrepResult): string {
for (const [file, matches] of byFile) {
lines.push(file)
for (const match of matches) {
lines.push(` ${match.line}: ${match.text.trim()}`)
if (!isFilesOnlyMode) {
for (const match of matches) {
const trimmedText = match.text.trim()
if (match.line === 0 && trimmedText === "") {
continue
}
lines.push(` ${match.line}: ${trimmedText}`)
}
}
lines.push("")
}