Skip to content

Commit

Permalink
squibble: normalize whitespace when diffing SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
creachadair committed Mar 19, 2024
1 parent 2035736 commit 859b5cb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion textcrime.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func diffSchema(ar, br []schemaRow) string {
if !ok {
fmt.Fprintf(&sb, "\n>> Remove %s %q\n", r.Type, r.Name)
} else if len(r.Columns) == 0 && len(o.Columns) == 0 {
sd := mdiff.New(mdiff.Lines(r.SQL), mdiff.Lines(o.SQL)).AddContext(2).Unify()
sd := mdiff.New(cleanLines(r.SQL), cleanLines(o.SQL)).AddContext(2).Unify()
if len(sd.Edits) != 0 {
fmt.Fprintf(&sb, "\n>> Modify %s %q\n", r.Type, r.Name)
mdiff.FormatUnified(&sb, sd, mdiff.NoHeader)
Expand Down Expand Up @@ -78,3 +78,11 @@ func diffColumns(w io.Writer, dc []slice.Edit[schemaCol], lhs, rhs []schemaCol)
}
}
}

func cleanLines(s string) []string {
lines := mdiff.Lines(s)
for i, s := range lines {
lines[i] = strings.TrimSpace(s)
}
return lines
}

0 comments on commit 859b5cb

Please sign in to comment.