Skip to content

Commit ea50e4b

Browse files
authored
Use staticcheck GitHub Action (#563)
1 parent 7f75c5d commit ea50e4b

File tree

8 files changed

+30
-61
lines changed

8 files changed

+30
-61
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ jobs:
2929
- name: Run gofmt
3030
run: gofmt -d -e . 2>&1 | tee outfile && test -z "$(cat outfile)" && rm outfile
3131
- name: Run staticcheck
32-
if: matrix.go-version == '1.17.x'
33-
run: |
34-
bin/staticcheck_linux_amd64_2021.1.2 github.com/cucumber/godog
35-
bin/staticcheck_linux_amd64_2021.1.2 github.com/cucumber/godog/cmd/godog
36-
# Disable for now because of failing checks
37-
# TODO: Add back in when fixes are made
38-
# bin/staticcheck_linux_amd64_2021.1.2 ./...
32+
if: matrix.go-version == '1.20.x'
33+
uses: dominikh/[email protected]
34+
with:
35+
version: "2023.1.3"
36+
install-go: false
37+
cache-key: ${{ matrix.go }}
38+
3939
- name: Run go vet
4040
run: |
4141
go vet ./...

bin/staticcheck_linux_amd64_2021.1.2

-11.3 MB
Binary file not shown.

internal/formatters/fmt_base.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ func (f *Base) Summary() {
164164
if totalSc == 0 {
165165
fmt.Fprintln(f.out, "No scenarios")
166166
} else {
167-
fmt.Fprintln(f.out, fmt.Sprintf("%d scenarios (%s)", totalSc, strings.Join(scenarios, ", ")))
167+
fmt.Fprintf(f.out, "%d scenarios (%s)\n", totalSc, strings.Join(scenarios, ", "))
168168
}
169169

170170
if totalSt == 0 {
171171
fmt.Fprintln(f.out, "No steps")
172172
} else {
173-
fmt.Fprintln(f.out, fmt.Sprintf("%d steps (%s)", totalSt, strings.Join(steps, ", ")))
173+
fmt.Fprintf(f.out, "%d steps (%s)\n", totalSt, strings.Join(steps, ", "))
174174
}
175175

176176
elapsedString := elapsed.String()

internal/formatters/fmt_color_tag_test.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,6 @@ const (
5151
ansiForegroundCyan = "36"
5252
ansiForegroundWhite = "37"
5353
ansiForegroundDefault = "39"
54-
55-
ansiBackgroundBlack = "40"
56-
ansiBackgroundRed = "41"
57-
ansiBackgroundGreen = "42"
58-
ansiBackgroundYellow = "43"
59-
ansiBackgroundBlue = "44"
60-
ansiBackgroundMagenta = "45"
61-
ansiBackgroundCyan = "46"
62-
ansiBackgroundWhite = "47"
63-
ansiBackgroundDefault = "49"
64-
65-
ansiLightForegroundGray = "90"
66-
ansiLightForegroundRed = "91"
67-
ansiLightForegroundGreen = "92"
68-
ansiLightForegroundYellow = "93"
69-
ansiLightForegroundBlue = "94"
70-
ansiLightForegroundMagenta = "95"
71-
ansiLightForegroundCyan = "96"
72-
ansiLightForegroundWhite = "97"
73-
74-
ansiLightBackgroundGray = "100"
75-
ansiLightBackgroundRed = "101"
76-
ansiLightBackgroundGreen = "102"
77-
ansiLightBackgroundYellow = "103"
78-
ansiLightBackgroundBlue = "104"
79-
ansiLightBackgroundMagenta = "105"
80-
ansiLightBackgroundCyan = "106"
81-
ansiLightBackgroundWhite = "107"
8254
)
8355

8456
var colorMap = map[string]string{
@@ -93,10 +65,6 @@ var colorMap = map[string]string{
9365
ansiForegroundDefault: "",
9466
}
9567

96-
func (cw *tagColorWriter) flushBuffer() (int, error) {
97-
return cw.flushTo(cw.w)
98-
}
99-
10068
func (cw *tagColorWriter) resetBuffer() (int, error) {
10169
return cw.flushTo(nil)
10270
}
@@ -147,7 +115,6 @@ func (cw *tagColorWriter) Write(p []byte) (int, error) {
147115
switch ch {
148116
case firstCsiChar:
149117
cw.paramStartBuf.WriteByte(ch)
150-
break
151118
case secondeCsiChar:
152119
cw.paramStartBuf.WriteByte(ch)
153120
cw.state = secondCsiCode

internal/formatters/fmt_multi.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ type MultiFormatter struct {
1515
}
1616

1717
type formatter struct {
18-
fmt formatters.FormatterFunc
19-
out io.Writer
20-
close bool
18+
fmt formatters.FormatterFunc
19+
out io.Writer
2120
}
2221

2322
type repeater []formatters.Formatter

internal/formatters/undefined_snippets_gen.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
)
1212

1313
// some snippet formatting regexps
14-
var snippetExprCleanup = regexp.MustCompile("([\\/\\[\\]\\(\\)\\\\^\\$\\.\\|\\?\\*\\+\\'])")
15-
var snippetExprQuoted = regexp.MustCompile("(\\W|^)\"(?:[^\"]*)\"(\\W|$)")
16-
var snippetMethodName = regexp.MustCompile("[^a-zA-Z\\_\\ ]")
17-
var snippetNumbers = regexp.MustCompile("(\\d+)")
14+
var snippetExprCleanup = regexp.MustCompile(`([\/\[\]\(\)\\^\$\.\|\?\*\+\'])`)
15+
var snippetExprQuoted = regexp.MustCompile(`(\W|^)"(?:[^"]*)"(\W|$)`)
16+
var snippetMethodName = regexp.MustCompile(`[^a-zA-Z\_\ ]`)
17+
var snippetNumbers = regexp.MustCompile(`(\d+)`)
1818

1919
var snippetHelperFuncs = template.FuncMap{
2020
"backticked": func(s string) string {

internal/models/stepdef_test.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ import (
1616
messages "github.com/cucumber/messages/go/v21"
1717
)
1818

19+
type ctxKey string
20+
1921
func TestShouldSupportContext(t *testing.T) {
20-
ctx := context.WithValue(context.Background(), "original", 123)
22+
ctx := context.WithValue(context.Background(), ctxKey("original"), 123)
2123

2224
fn := func(ctx context.Context, a int64, b int32, c int16, d int8) context.Context {
23-
assert.Equal(t, 123, ctx.Value("original"))
25+
assert.Equal(t, 123, ctx.Value(ctxKey("original")))
2426

25-
return context.WithValue(ctx, "updated", 321)
27+
return context.WithValue(ctx, ctxKey("updated"), 321)
2628
}
2729

2830
def := &models.StepDefinition{
@@ -35,17 +37,18 @@ func TestShouldSupportContext(t *testing.T) {
3537
def.Args = []interface{}{"1", "1", "1", "1"}
3638
ctx, err := def.Run(ctx)
3739
assert.Nil(t, err)
38-
assert.Equal(t, 123, ctx.Value("original"))
39-
assert.Equal(t, 321, ctx.Value("updated"))
40+
assert.Equal(t, 123, ctx.Value(ctxKey("original")))
41+
assert.Equal(t, 321, ctx.Value(ctxKey("updated")))
4042
}
4143

4244
func TestShouldSupportContextAndError(t *testing.T) {
43-
ctx := context.WithValue(context.Background(), "original", 123)
45+
46+
ctx := context.WithValue(context.Background(), ctxKey("original"), 123)
4447

4548
fn := func(ctx context.Context, a int64, b int32, c int16, d int8) (context.Context, error) {
46-
assert.Equal(t, 123, ctx.Value("original"))
49+
assert.Equal(t, 123, ctx.Value(ctxKey("original")))
4750

48-
return context.WithValue(ctx, "updated", 321), nil
51+
return context.WithValue(ctx, ctxKey("updated"), 321), nil
4952
}
5053

5154
def := &models.StepDefinition{
@@ -58,8 +61,8 @@ func TestShouldSupportContextAndError(t *testing.T) {
5861
def.Args = []interface{}{"1", "1", "1", "1"}
5962
ctx, err := def.Run(ctx)
6063
assert.Nil(t, err)
61-
assert.Equal(t, 123, ctx.Value("original"))
62-
assert.Equal(t, 321, ctx.Value("updated"))
64+
assert.Equal(t, 123, ctx.Value(ctxKey("original")))
65+
assert.Equal(t, 321, ctx.Value(ctxKey("updated")))
6366
}
6467

6568
func TestShouldSupportEmptyHandlerReturn(t *testing.T) {
@@ -374,7 +377,7 @@ func TestStepDefinition_Run_StringConversionToFunctionType(t *testing.T) {
374377
// }
375378

376379
type testStruct struct {
377-
a string
380+
_ string
378381
}
379382

380383
func TestShouldSupportDocStringToStringConversion(t *testing.T) {

internal/storage/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func (s *Storage) mustFirst(table, index string, args ...interface{}) interface{
303303
if err != nil {
304304
panic(err)
305305
} else if v == nil {
306-
err = fmt.Errorf("Couldn't find index: %q in table: %q with args: %+v", index, table, args)
306+
err = fmt.Errorf("couldn't find index: %q in table: %q with args: %+v", index, table, args)
307307
panic(err)
308308
}
309309

0 commit comments

Comments
 (0)