Skip to content

Commit 2604810

Browse files
committed
errcheck + unused
1 parent b03bcc9 commit 2604810

File tree

7 files changed

+25
-26
lines changed

7 files changed

+25
-26
lines changed

colors/colors.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const (
1616
red
1717
green
1818
yellow
19-
blue
20-
magenta
19+
blue // unused
20+
magenta // unused
2121
cyan
2222
white
2323
)

colors/writer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type outputMode int
1616
const (
1717
_ outputMode = iota
1818
discardNonColorEscSeq
19-
outputNonColorEscSeq
19+
outputNonColorEscSeq // unused
2020
)
2121

2222
// Colored creates and initializes a new ansiColorWriter

fmt_junit.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,13 @@ func (j *junitFormatter) Summary() {
148148
j.current().Time = timeNowFunc().Sub(j.featStarted).String()
149149
}
150150
j.suite.Time = timeNowFunc().Sub(j.started).String()
151-
io.WriteString(j.out, xml.Header)
152-
151+
_, err := io.WriteString(j.out, xml.Header)
152+
if err != nil {
153+
fmt.Fprintln(os.Stderr, "failed to write junit string:", err)
154+
}
153155
enc := xml.NewEncoder(j.out)
154156
enc.Indent("", s(2))
155-
if err := enc.Encode(j.suite); err != nil {
157+
if err = enc.Encode(j.suite); err != nil {
156158
fmt.Fprintln(os.Stderr, "failed to write junit xml:", err)
157159
}
158160
}

fmt_junit_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,18 @@ func TestJUnitFormatterOutput(t *testing.T) {
152152
},
153153
}},
154154
}
155-
156155
s.run()
157156
s.fmt.Summary()
158157

159158
var exp bytes.Buffer
160-
io.WriteString(&exp, xml.Header)
161-
159+
if _, err = io.WriteString(&exp, xml.Header); err != nil {
160+
t.Fatalf("unexpected error: %v", err)
161+
}
162162
enc := xml.NewEncoder(&exp)
163163
enc.Indent("", " ")
164-
if err := enc.Encode(expected); err != nil {
164+
if err = enc.Encode(expected); err != nil {
165165
t.Fatalf("unexpected error: %v", err)
166166
}
167-
168167
if buf.String() != exp.String() {
169168
t.Fatalf("expected output does not match: %s", buf.String())
170169
}

run_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ func TestFailsWithUnknownFormatterOptionError(t *testing.T) {
178178
}
179179

180180
out := strings.TrimSpace(string(b))
181-
if strings.Index(out, `unregistered formatter name: "unknown", use one of`) == -1 {
182-
t.Fatalf("unexpected error output: \"%s\"", out)
181+
if !strings.Contains(out, `unregistered formatter name: "unknown", use one of`) {
182+
t.Fatalf("unexpected error output: %q", out)
183183
}
184184
}
185185

suite.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ func matchesTags(filter string, tags []string) (ok bool) {
805805
okComma = hasTag(tags, tag) || okComma
806806
}
807807
}
808-
ok = (false != okComma && ok && okComma) || false
808+
ok = ok && okComma
809809
}
810810
return
811811
}

utils.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ import (
77
"github.com/DATA-DOG/godog/colors"
88
)
99

10-
// empty struct value takes no space allocation
11-
type void struct{}
12-
13-
var red = colors.Red
14-
var redb = colors.Bold(colors.Red)
15-
var green = colors.Green
16-
var black = colors.Black
17-
var blackb = colors.Bold(colors.Black)
18-
var yellow = colors.Yellow
19-
var cyan = colors.Cyan
20-
var cyanb = colors.Bold(colors.Cyan)
21-
var whiteb = colors.Bold(colors.White)
10+
var (
11+
red = colors.Red
12+
redb = colors.Bold(colors.Red)
13+
green = colors.Green
14+
black = colors.Black
15+
yellow = colors.Yellow
16+
cyan = colors.Cyan
17+
cyanb = colors.Bold(colors.Cyan)
18+
whiteb = colors.Bold(colors.White)
19+
)
2220

2321
// repeats a space n times
2422
func s(n int) string {

0 commit comments

Comments
 (0)