Skip to content

Commit

Permalink
Fix space only line (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
rytswd authored Dec 13, 2021
1 parent db8e340 commit e2aef63
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/marker/indent.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func handleAbsoluteIndentation(lineData []byte, exportMarkerIndent, targetIndent
}

func prependWhitespaces(x []byte, count int) []byte {
// If provided line only has space chars, return the line data as is.
if len(bytes.TrimSpace(x)) == 0 {
return x
}
empty := bytes.Repeat([]byte(" "), count)
// x = append(x, empty...)
// copy(x[count:], x)
Expand Down
5 changes: 5 additions & 0 deletions internal/marker/indent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func TestPrependWhitespaces(t *testing.T) {
whitespaceCount: 6,
want: []byte(" abcdef"),
},
"line with only whitespace": {
originalSlice: []byte(" "),
whitespaceCount: 6,
want: []byte(" "), // No change
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions testdata/markdown/verbatim-yaml-updated.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
requests:
cpu: 10m
memory: 10Mi

limits:
cpu: 30m
memory: 30Mi
Expand Down
1 change: 1 addition & 0 deletions testdata/markdown/verbatim-yaml-wrap-updated.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
requests:
cpu: 10m
memory: 10Mi

limits:
cpu: 30m
memory: 30Mi
Expand Down
1 change: 1 addition & 0 deletions testdata/yaml/k8s-color-svc-updated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ spec:
requests:
cpu: 10m
memory: 10Mi

limits:
cpu: 30m
memory: 30Mi
Expand Down
1 change: 1 addition & 0 deletions testdata/yaml/snippet-k8s-resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ minimal:
requests:
cpu: 10m
memory: 10Mi

limits:
cpu: 30m
memory: 30Mi
Expand Down

0 comments on commit e2aef63

Please sign in to comment.