Skip to content

Commit e2aef63

Browse files
authored
Fix space only line (#81)
1 parent db8e340 commit e2aef63

6 files changed

+13
-0
lines changed

internal/marker/indent.go

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ func handleAbsoluteIndentation(lineData []byte, exportMarkerIndent, targetIndent
7777
}
7878

7979
func prependWhitespaces(x []byte, count int) []byte {
80+
// If provided line only has space chars, return the line data as is.
81+
if len(bytes.TrimSpace(x)) == 0 {
82+
return x
83+
}
8084
empty := bytes.Repeat([]byte(" "), count)
8185
// x = append(x, empty...)
8286
// copy(x[count:], x)

internal/marker/indent_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func TestPrependWhitespaces(t *testing.T) {
5555
whitespaceCount: 6,
5656
want: []byte(" abcdef"),
5757
},
58+
"line with only whitespace": {
59+
originalSlice: []byte(" "),
60+
whitespaceCount: 6,
61+
want: []byte(" "), // No change
62+
},
5863
}
5964
for name, tc := range cases {
6065
t.Run(name, func(t *testing.T) {

testdata/markdown/verbatim-yaml-updated.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
requests:
77
cpu: 10m
88
memory: 10Mi
9+
910
limits:
1011
cpu: 30m
1112
memory: 30Mi

testdata/markdown/verbatim-yaml-wrap-updated.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
requests:
77
cpu: 10m
88
memory: 10Mi
9+
910
limits:
1011
cpu: 30m
1112
memory: 30Mi

testdata/yaml/k8s-color-svc-updated.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ spec:
6363
requests:
6464
cpu: 10m
6565
memory: 10Mi
66+
6667
limits:
6768
cpu: 30m
6869
memory: 30Mi

testdata/yaml/snippet-k8s-resource.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ minimal:
44
requests:
55
cpu: 10m
66
memory: 10Mi
7+
78
limits:
89
cpu: 30m
910
memory: 30Mi

0 commit comments

Comments
 (0)