Skip to content

Commit

Permalink
Switch from golint to staticcheck (#457)
Browse files Browse the repository at this point in the history
* Switch from golint to staticcheck

* Remove unused function

run_test.go:618:6: func passingStepDefWithoutReturn is unused (U1000)

* Remove unused function

suite.go:421:6: func isEmptyFeature is unused (U1000)

* Fix unnecessary use of fmt.Sprintf

test_context_test.go:45:66: unnecessary use of fmt.Sprintf (S1039)
test_context_test.go:46:61: unnecessary use of fmt.Sprintf (S1039)

* Fix CI error

https://github.com/cucumber/godog/runs/5146601108?check_suite_focus=true#step:7:28

* Change CI to run staticcheck instead of golint

* Use staticcheck that definitely pass

* Fix CI staticcheck error

https://github.com/cucumber/godog/runs/5147133955?check_suite_focus=true#step:6:17

* Only run staticcheck for Go 1.17

Co-authored-by: Viacheslav Poturaev <nanopeni@gmail.com>

* Add staticcheck linux binary

* Update Go module dependencies in _examples

* Use static check binary in bin for CI

* Reduce number of dependencies

Also add a note to CONTRIBUTING.md about the _examples module

* Pin the version of staticcheck

Co-authored-by: Viacheslav Poturaev <nanopeni@gmail.com>

Co-authored-by: Matt Wynne <matt@cucumber.io>
Co-authored-by: Viacheslav Poturaev <nanopeni@gmail.com>
  • Loading branch information
3 people committed Feb 15, 2022
1 parent 1c91e6f commit c95871f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 20 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ jobs:
${{ runner.os }}-go-cache
- name: Run gofmt
run: gofmt -d -e . 2>&1 | tee outfile && test -z "$(cat outfile)" && rm outfile
- name: Run golint
- name: Run staticcheck
if: matrix.go-version == '1.17.x'
run: |
go install golang.org/x/lint/golint@latest
golint -set_exit_status ./...
cd _examples && golint -set_exit_status ./... && cd ..
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 ./...
- name: Run go vet
run: |
go vet ./...
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ If everything passes, you're ready to hack!
[install go]: https://golang.org/doc/install
[community Slack]: https://cucumber.io/community#slack
[raise an issue]: https://github.com/cucumber/godog/issues/new/choose

## Changing dependencies

If dependencies have changed, you will also need to update the _examples module. `go mod tidy` should be sufficient.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ test: check-go-version
@echo "running all tests"
@go install ./...
@go fmt ./...
@go run golang.org/x/lint/golint@latest github.com/cucumber/godog
@go run golang.org/x/lint/golint@latest github.com/cucumber/godog/cmd/godog
@go run honnef.co/go/tools/cmd/staticcheck@v0.2.2 github.com/cucumber/godog
@go run honnef.co/go/tools/cmd/staticcheck@v0.2.2 github.com/cucumber/godog/cmd/godog
go vet ./...
go test -race ./...
godog -f progress -c 4
Expand Down
Binary file added bin/staticcheck_linux_amd64_2021.1.2
Binary file not shown.
3 changes: 1 addition & 2 deletions run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,7 @@ type progressOutput struct {
bottomRows []string
}

func passingStepDef() error { return nil }
func passingStepDefWithoutReturn() {}
func passingStepDef() error { return nil }

func oddEvenStepDef(odd, even int) error { return oddOrEven(odd, even) }

Expand Down
10 changes: 0 additions & 10 deletions suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,16 +418,6 @@ func (s *suite) shouldFail(err error) bool {
return true
}

func isEmptyFeature(pickles []*messages.Pickle) bool {
for _, pickle := range pickles {
if len(pickle.Steps) > 0 {
return false
}
}

return true
}

func (s *suite) runPickle(pickle *messages.Pickle) (err error) {
ctx := s.defaultContext
if ctx == nil {
Expand Down
4 changes: 2 additions & 2 deletions test_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func TestScenarioContext_Step(t *testing.T) {
})

Convey("has more than 2 return values", func() {
So(func() { ctx.Step(".*", nokLimitCase) }, ShouldPanicWith, fmt.Sprintf("expected handler to return either zero, one or two values, but it has: 3"))
So(func() { ctx.Step(".*", nokMore) }, ShouldPanicWith, fmt.Sprintf("expected handler to return either zero, one or two values, but it has: 5"))
So(func() { ctx.Step(".*", nokLimitCase) }, ShouldPanicWith, "expected handler to return either zero, one or two values, but it has: 3")
So(func() { ctx.Step(".*", nokMore) }, ShouldPanicWith, "expected handler to return either zero, one or two values, but it has: 5")
})

Convey("return type is not an error or string slice or void", func() {
Expand Down

0 comments on commit c95871f

Please sign in to comment.