Skip to content

Commit b1df156

Browse files
committed
Make show deleted whitespaces in diff.
1 parent 3e059fc commit b1df156

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

hooks/jsonnet-fmt-hook/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log"
77
"os"
8+
"regexp"
89
"strings"
910

1011
"io/ioutil"
@@ -82,6 +83,7 @@ func summarizeDiff(diffs []diffmatchpatch.Diff) *FileDiff {
8283
const maxShowLine = 3
8384
const omissionText = "...\n"
8485
lastDiffIdx := len(diffs) - 1
86+
spaceRegexp := regexp.MustCompile(`\s`)
8587

8688
for i, diff := range diffs {
8789
text := diff.Text
@@ -92,7 +94,7 @@ func summarizeDiff(diffs []diffmatchpatch.Diff) *FileDiff {
9294
writeString(&builder, ansiGreen+text+ansiReset)
9395
fileDiff.numInsert += len(text)
9496
case diffmatchpatch.DiffDelete:
95-
writeString(&builder, ansiRed+text+ansiReset)
97+
writeString(&builder, ansiRed+regexp.QuoteMeta(spaceRegexp.ReplaceAllString(text, "␣"))+ansiReset)
9698
fileDiff.numDelete += len(text)
9799
case diffmatchpatch.DiffEqual:
98100
var showHead, showTail bool

0 commit comments

Comments
 (0)