Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use staticcheck GitHub Action #563

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down
Binary file removed bin/staticcheck_linux_amd64_2021.1.2
Binary file not shown.
4 changes: 2 additions & 2 deletions internal/formatters/fmt_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
33 changes: 0 additions & 33 deletions internal/formatters/fmt_color_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions internal/formatters/fmt_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/formatters/undefined_snippets_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 14 additions & 11 deletions internal/models/stepdef_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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) {
Expand Down Expand Up @@ -374,7 +377,7 @@ func TestStepDefinition_Run_StringConversionToFunctionType(t *testing.T) {
// }

type testStruct struct {
a string
_ string
}

func TestShouldSupportDocStringToStringConversion(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down