From d0a28b5a94d0c5c574e717180285d5bdb2db2225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20L=C3=B6nnblad?= Date: Sun, 3 May 2020 11:01:14 +0200 Subject: [PATCH] Updated linting checks in circleci config and fixed linting issues --- .circleci/config.yml | 52 ++++++++++++++++++------------- README.md | 4 --- _examples/assert-godogs/godogs.go | 1 - _examples/godogs/godogs.go | 1 - colors/colors.go | 9 ++++++ colors/no_colors.go | 2 ++ 6 files changed, 42 insertions(+), 27 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c78c0e41..4d5c0e8d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,57 +15,67 @@ executors: - image: circleci/golang:1.14.0 commands: + fmt: + description: "Run gofmt" + steps: + - run: gofmt -d -e . 2>&1 | tee outfile && test -z "$(cat outfile)" && rm outfile + lint: + description: "Run golint" + steps: + - run: go get -u golang.org/x/lint/golint + - run: golint -set_exit_status ./... + - run: cd _examples && golint -set_exit_status ./... && cd .. install: - description: "Install dependencies" + description: "Install dependencies for go1.12" steps: - - run: GO111MODULE=on go mod vendor -v + - run: GO111MODULE=on go mod vendor vet: description: "Run go vet" steps: - run: go vet github.com/cucumber/godog - run: go vet github.com/cucumber/godog/colors - fmt: - description: "Run go fmt" - steps: - - run: test -z "$(go fmt ./...)" - lint: - description: "Run golint" + go_test: + description: "Run go test" steps: - - run: go get -u golang.org/x/lint/golint - - run: golint ./godog - - run: golint ./cmd/godog/main.go + - run: go test -v -race -coverprofile=coverage.txt -covermode=atomic godog: description: "Run godog" steps: - run: go install ./cmd/godog - run: godog -f progress --strict - go_test: - description: "Run go test" - steps: - - run: go test -v -race -coverprofile=coverage.txt -covermode=atomic coverage: description: "Report on code coverage" steps: - codecov/upload: file: "coverage.txt" - all: - description: "Run all commands against godog code" + part1: + description: "Part1 include all commands that doesn't need dependencies installed" steps: - checkout - - install - - vet - fmt - lint - - godog + part2: + description: "Part2 is the all other commands" + steps: + - vet - go_test + - godog - coverage + all: + description: "Run all commands against godog code" + steps: + - part1 + - part2 + jobs: go1_12: working_directory: /go/src/github.com/cucumber/godog executor: exec_go_1_12 steps: - - all + - part1 + - install + - part2 go1_13: working_directory: /go/src/github.com/cucumber/godog executor: exec_go_1_13 diff --git a/README.md b/README.md index 6d3bfbc4..17daa59f 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,6 @@ Since we need a working implementation, we may start by implementing only what i We only need a number of **godogs** for now. Lets keep it simple. ``` go -/* file: $GOPATH/src/godogs/godogs.go */ package main // Godogs available to eat @@ -155,7 +154,6 @@ Now lets implement our step definitions, which we can copy from generated console output snippets in order to test our feature requirements: ``` go -/* file: $GOPATH/src/godogs/godogs_test.go */ package main import ( @@ -348,8 +346,6 @@ is one of the following: A more extensive example can be [found here](/_examples/assert-godogs). ``` go -/* file: $GOPATH/src/assert-godogs/godogs_test.go */ - func thereShouldBeRemaining(remaining int) error { return assertExpectedAndActual( assert.Equal, Godogs, remaining, diff --git a/_examples/assert-godogs/godogs.go b/_examples/assert-godogs/godogs.go index b735a872..e71f308c 100644 --- a/_examples/assert-godogs/godogs.go +++ b/_examples/assert-godogs/godogs.go @@ -1,4 +1,3 @@ -/* file: $GOPATH/src/godogs/godogs.go */ package main // Godogs available to eat diff --git a/_examples/godogs/godogs.go b/_examples/godogs/godogs.go index b735a872..e71f308c 100644 --- a/_examples/godogs/godogs.go +++ b/_examples/godogs/godogs.go @@ -1,4 +1,3 @@ -/* file: $GOPATH/src/godogs/godogs.go */ package main // Godogs available to eat diff --git a/colors/colors.go b/colors/colors.go index 02323176..539747bf 100644 --- a/colors/colors.go +++ b/colors/colors.go @@ -26,34 +26,43 @@ func colorize(s interface{}, c color) string { return fmt.Sprintf("%s[%dm%v%s[0m", ansiEscape, c, s, ansiEscape) } +// ColorFunc is a helper type to create colorized strings. type ColorFunc func(interface{}) string +// Bold will accept a ColorFunc and return a new ColorFunc +// that will make the string bold. func Bold(fn ColorFunc) ColorFunc { return ColorFunc(func(input interface{}) string { return strings.Replace(fn(input), ansiEscape+"[", ansiEscape+"[1;", 1) }) } +// Green will accept an interface and return a colorized green string. func Green(s interface{}) string { return colorize(s, green) } +// Red will accept an interface and return a colorized green string. func Red(s interface{}) string { return colorize(s, red) } +// Cyan will accept an interface and return a colorized green string. func Cyan(s interface{}) string { return colorize(s, cyan) } +// Black will accept an interface and return a colorized green string. func Black(s interface{}) string { return colorize(s, black) } +// Yellow will accept an interface and return a colorized green string. func Yellow(s interface{}) string { return colorize(s, yellow) } +// White will accept an interface and return a colorized green string. func White(s interface{}) string { return colorize(s, white) } diff --git a/colors/no_colors.go b/colors/no_colors.go index 3381d117..2eeb8024 100644 --- a/colors/no_colors.go +++ b/colors/no_colors.go @@ -11,6 +11,8 @@ type noColors struct { lastbuf bytes.Buffer } +// Uncolored will accept and io.Writer and return a +// new io.Writer that won't include colors. func Uncolored(w io.Writer) io.Writer { return &noColors{out: w} }