Skip to content

Commit 04b8f5a

Browse files
committed
skip-blank-lines ignores lines that only consist of spaces
1 parent bcfdb4c commit 04b8f5a

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ func generateFile(config Config, containers Context) bool {
410410
scanner := bufio.NewScanner(bufio.NewReader(&buf))
411411
for scanner.Scan() {
412412
line := scanner.Text()
413-
if len(line) > 0 {
413+
if !isBlank(line) {
414414
fmt.Fprintln(dest, line)
415415
}
416416
}

utils.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"os"
55
"strings"
6+
"unicode"
67
)
78

89
func getEndpoint() (string, error) {
@@ -50,3 +51,12 @@ func pathExists(path string) (bool, error) {
5051
}
5152
return false, err
5253
}
54+
55+
func isBlank(str string) bool {
56+
for _, r := range str {
57+
if !unicode.IsSpace(r) {
58+
return false
59+
}
60+
}
61+
return true
62+
}

utils_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,29 @@ func TestSplitKeyValueSlice(t *testing.T) {
8787

8888
}
8989
}
90+
91+
func TestIsBlank(t *testing.T) {
92+
93+
tests := []struct {
94+
input string
95+
expected bool
96+
}{
97+
{"", true},
98+
{" ", true},
99+
{" ", true},
100+
{"\t", true},
101+
{"\t\n\v\f\r\u0085\u00A0", true},
102+
{"a", false},
103+
{" a ", false},
104+
{"a ", false},
105+
{" a", false},
106+
{"日本語", false},
107+
}
108+
109+
for _, i := range tests {
110+
v := isBlank(i.input)
111+
if v != i.expected {
112+
t.Fatalf("expected '%v'. got '%v'", i.expected, v)
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)