diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aebd31b..a1dd889 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,13 +29,13 @@ jobs: - name: Run gofmt run: gofmt -d -e . 2>&1 | tee outfile && test -z "$(cat outfile)" && rm outfile - name: Run staticcheck - if: matrix.go-version == '1.17.x' - run: | - bin/staticcheck_linux_amd64_2021.1.2 github.com/cucumber/godog - bin/staticcheck_linux_amd64_2021.1.2 github.com/cucumber/godog/cmd/godog - # Disable for now because of failing checks - # TODO: Add back in when fixes are made - # bin/staticcheck_linux_amd64_2021.1.2 ./... + if: matrix.go-version == '1.20.x' + uses: dominikh/staticcheck-action@v1.3.0 + with: + version: "2023.1.3" + install-go: false + cache-key: ${{ matrix.go }} + - name: Run go vet run: | go vet ./... diff --git a/bin/staticcheck_linux_amd64_2021.1.2 b/bin/staticcheck_linux_amd64_2021.1.2 deleted file mode 100755 index 1c92681..0000000 Binary files a/bin/staticcheck_linux_amd64_2021.1.2 and /dev/null differ diff --git a/internal/formatters/fmt_base.go b/internal/formatters/fmt_base.go index 880ba06..2166509 100644 --- a/internal/formatters/fmt_base.go +++ b/internal/formatters/fmt_base.go @@ -164,13 +164,13 @@ func (f *Base) Summary() { if totalSc == 0 { fmt.Fprintln(f.out, "No scenarios") } else { - fmt.Fprintln(f.out, fmt.Sprintf("%d scenarios (%s)", totalSc, strings.Join(scenarios, ", "))) + fmt.Fprintf(f.out, "%d scenarios (%s)\n", totalSc, strings.Join(scenarios, ", ")) } if totalSt == 0 { fmt.Fprintln(f.out, "No steps") } else { - fmt.Fprintln(f.out, fmt.Sprintf("%d steps (%s)", totalSt, strings.Join(steps, ", "))) + fmt.Fprintf(f.out, "%d steps (%s)\n", totalSt, strings.Join(steps, ", ")) } elapsedString := elapsed.String() diff --git a/internal/formatters/fmt_color_tag_test.go b/internal/formatters/fmt_color_tag_test.go index 871e333..747ab1a 100644 --- a/internal/formatters/fmt_color_tag_test.go +++ b/internal/formatters/fmt_color_tag_test.go @@ -51,34 +51,6 @@ const ( ansiForegroundCyan = "36" ansiForegroundWhite = "37" ansiForegroundDefault = "39" - - ansiBackgroundBlack = "40" - ansiBackgroundRed = "41" - ansiBackgroundGreen = "42" - ansiBackgroundYellow = "43" - ansiBackgroundBlue = "44" - ansiBackgroundMagenta = "45" - ansiBackgroundCyan = "46" - ansiBackgroundWhite = "47" - ansiBackgroundDefault = "49" - - ansiLightForegroundGray = "90" - ansiLightForegroundRed = "91" - ansiLightForegroundGreen = "92" - ansiLightForegroundYellow = "93" - ansiLightForegroundBlue = "94" - ansiLightForegroundMagenta = "95" - ansiLightForegroundCyan = "96" - ansiLightForegroundWhite = "97" - - ansiLightBackgroundGray = "100" - ansiLightBackgroundRed = "101" - ansiLightBackgroundGreen = "102" - ansiLightBackgroundYellow = "103" - ansiLightBackgroundBlue = "104" - ansiLightBackgroundMagenta = "105" - ansiLightBackgroundCyan = "106" - ansiLightBackgroundWhite = "107" ) var colorMap = map[string]string{ @@ -93,10 +65,6 @@ var colorMap = map[string]string{ ansiForegroundDefault: "", } -func (cw *tagColorWriter) flushBuffer() (int, error) { - return cw.flushTo(cw.w) -} - func (cw *tagColorWriter) resetBuffer() (int, error) { return cw.flushTo(nil) } @@ -147,7 +115,6 @@ func (cw *tagColorWriter) Write(p []byte) (int, error) { switch ch { case firstCsiChar: cw.paramStartBuf.WriteByte(ch) - break case secondeCsiChar: cw.paramStartBuf.WriteByte(ch) cw.state = secondCsiCode diff --git a/internal/formatters/fmt_multi.go b/internal/formatters/fmt_multi.go index a56f10d..e23e6ad 100644 --- a/internal/formatters/fmt_multi.go +++ b/internal/formatters/fmt_multi.go @@ -15,9 +15,8 @@ type MultiFormatter struct { } type formatter struct { - fmt formatters.FormatterFunc - out io.Writer - close bool + fmt formatters.FormatterFunc + out io.Writer } type repeater []formatters.Formatter diff --git a/internal/formatters/undefined_snippets_gen.go b/internal/formatters/undefined_snippets_gen.go index 03141dc..ff6cd79 100644 --- a/internal/formatters/undefined_snippets_gen.go +++ b/internal/formatters/undefined_snippets_gen.go @@ -11,10 +11,10 @@ import ( ) // some snippet formatting regexps -var snippetExprCleanup = regexp.MustCompile("([\\/\\[\\]\\(\\)\\\\^\\$\\.\\|\\?\\*\\+\\'])") -var snippetExprQuoted = regexp.MustCompile("(\\W|^)\"(?:[^\"]*)\"(\\W|$)") -var snippetMethodName = regexp.MustCompile("[^a-zA-Z\\_\\ ]") -var snippetNumbers = regexp.MustCompile("(\\d+)") +var snippetExprCleanup = regexp.MustCompile(`([\/\[\]\(\)\\^\$\.\|\?\*\+\'])`) +var snippetExprQuoted = regexp.MustCompile(`(\W|^)"(?:[^"]*)"(\W|$)`) +var snippetMethodName = regexp.MustCompile(`[^a-zA-Z\_\ ]`) +var snippetNumbers = regexp.MustCompile(`(\d+)`) var snippetHelperFuncs = template.FuncMap{ "backticked": func(s string) string { diff --git a/internal/models/stepdef_test.go b/internal/models/stepdef_test.go index dc1b705..6617f48 100644 --- a/internal/models/stepdef_test.go +++ b/internal/models/stepdef_test.go @@ -16,13 +16,15 @@ import ( messages "github.com/cucumber/messages/go/v21" ) +type ctxKey string + func TestShouldSupportContext(t *testing.T) { - ctx := context.WithValue(context.Background(), "original", 123) + ctx := context.WithValue(context.Background(), ctxKey("original"), 123) fn := func(ctx context.Context, a int64, b int32, c int16, d int8) context.Context { - assert.Equal(t, 123, ctx.Value("original")) + assert.Equal(t, 123, ctx.Value(ctxKey("original"))) - return context.WithValue(ctx, "updated", 321) + return context.WithValue(ctx, ctxKey("updated"), 321) } def := &models.StepDefinition{ @@ -35,17 +37,18 @@ func TestShouldSupportContext(t *testing.T) { def.Args = []interface{}{"1", "1", "1", "1"} ctx, err := def.Run(ctx) assert.Nil(t, err) - assert.Equal(t, 123, ctx.Value("original")) - assert.Equal(t, 321, ctx.Value("updated")) + assert.Equal(t, 123, ctx.Value(ctxKey("original"))) + assert.Equal(t, 321, ctx.Value(ctxKey("updated"))) } func TestShouldSupportContextAndError(t *testing.T) { - ctx := context.WithValue(context.Background(), "original", 123) + + ctx := context.WithValue(context.Background(), ctxKey("original"), 123) fn := func(ctx context.Context, a int64, b int32, c int16, d int8) (context.Context, error) { - assert.Equal(t, 123, ctx.Value("original")) + assert.Equal(t, 123, ctx.Value(ctxKey("original"))) - return context.WithValue(ctx, "updated", 321), nil + return context.WithValue(ctx, ctxKey("updated"), 321), nil } def := &models.StepDefinition{ @@ -58,8 +61,8 @@ func TestShouldSupportContextAndError(t *testing.T) { def.Args = []interface{}{"1", "1", "1", "1"} ctx, err := def.Run(ctx) assert.Nil(t, err) - assert.Equal(t, 123, ctx.Value("original")) - assert.Equal(t, 321, ctx.Value("updated")) + assert.Equal(t, 123, ctx.Value(ctxKey("original"))) + assert.Equal(t, 321, ctx.Value(ctxKey("updated"))) } func TestShouldSupportEmptyHandlerReturn(t *testing.T) { @@ -374,7 +377,7 @@ func TestStepDefinition_Run_StringConversionToFunctionType(t *testing.T) { // } type testStruct struct { - a string + _ string } func TestShouldSupportDocStringToStringConversion(t *testing.T) { diff --git a/internal/storage/storage.go b/internal/storage/storage.go index bfe7d36..3fce8a8 100644 --- a/internal/storage/storage.go +++ b/internal/storage/storage.go @@ -303,7 +303,7 @@ func (s *Storage) mustFirst(table, index string, args ...interface{}) interface{ if err != nil { panic(err) } else if v == nil { - err = fmt.Errorf("Couldn't find index: %q in table: %q with args: %+v", index, table, args) + err = fmt.Errorf("couldn't find index: %q in table: %q with args: %+v", index, table, args) panic(err) }