diff --git a/.gitignore b/.gitignore index 051b764..c5bc10e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ vendor/ bin/ .cache -.test_coverage.txt +coverage.out diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..f3e2dbd --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,109 @@ +run: + # timeout for analysis, e.g. 30s, 5m, default is 1m + timeout: 1m + + # include test files or not, default is true + tests: true + + # list of build tags, all linters use it. Default is empty list. + build-tags: [] + +# settings of specific linters +linters-settings: + govet: + check-shadowing: false + golint: + min-confidence: 0 + maligned: + suggest-new: true + dupl: + threshold: 100 + goconst: + min-len: 2 + min-occurrences: 2 + misspell: + locale: US + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - style + disabled-checks: + - dupImport # https://github.com/go-critic/go-critic/issues/845 + - ifElseChain + - octalLiteral + - wrapperFunc + +linters: + disable-all: true + enable: + - bodyclose + - deadcode + - depguard + - dogsled + - dupl + - errcheck + - goconst + - gocritic + - gofmt + - goimports + - golint + - gosec + - gosimple + - govet + - ineffassign + - interfacer + - misspell + - nakedret + - scopelint + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - varcheck + - whitespace + + # don't enable: + # - funlen + # - gochecknoglobals + # - gocognit + # - gocyclo + # - godox + # - lll + # - maligned + # - prealloc + # - gochecknoinits + + +issues: + # Excluding configuration per-path, per-linter, per-text and per-source + exclude-rules: + # Exclude some linters from running on tests files. + - path: _test\.go + linters: + - gocyclo + - errcheck + - dupl + - gosec + - scopelint + - goconst + - funlen + - gocritic + + # Maximum issues count per one linter. Set to 0 to disable. Default is 50. + max-issues-per-linter: 0 + + # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. + max-same-issues: 0 + + # Show only new issues: if there are unstaged changes or untracked files, + # only those changes are analyzed, else only changes in HEAD~ are analyzed. + # It's a super-useful option for integration of golangci-lint into existing + # large codebase. It's not practical to fix all existing issues at the moment + # of integration: much better don't allow issues in new code. + # Default is false. + new: false diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..7a85506 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +language: go + +go: + - "1.13.x" + - "1.14.x" + +env: + - GO111MODULE=on + +install: + - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0 + +script: + - make test + - make lint + +after_success: + - go get github.com/mattn/goveralls + - goveralls -coverprofile=coverage.out -service=travis-ci diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4ac00c0 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +.PHONY: test help fmt report-coveralls benchmark lint + +help: ## Show the help text + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[93m %s\n", $$1, $$2}' + +test: ## Run unit tests + @go test -coverprofile=coverage.out -covermode=atomic -race ./... + +lint: # Run linters using golangci-lint + @golangci-lint run + +fmt: ## Format files + @goimports -w $$(find . -name "*.go" -not -path "./vendor/*") + +benchmark: ## Run benchmarks + @go test -run=NONE -benchmem -benchtime=5s -bench=. ./... diff --git a/runner_pool.go b/runner_pool.go index 6352ec2..179153a 100644 --- a/runner_pool.go +++ b/runner_pool.go @@ -97,7 +97,7 @@ func (w *worker) Release() { w.once.Do(func() { close(w.released) }) } -// Worker returns an error, if possible withing the provided context, otherwise it will return ctx.Err() +// Worker returns an error, if possible within the provided context, otherwise it will return ctx.Err() func (p *WorkerPool) Worker(ctx context.Context) (Worker, error) { select { case w := <-p.workers: diff --git a/runner_pool_test.go b/runner_pool_test.go index 869d1ce..ba73c82 100644 --- a/runner_pool_test.go +++ b/runner_pool_test.go @@ -243,11 +243,8 @@ func goRunner(f func()) { go f() } func recoverFromPanics(f func()) { go func() { - defer func() { - if err := recover(); err != nil { - // recover the panic - } - }() + // deferring recover() directly causes a warning in linters, IDEs, etc, so we defer an anonoymous function calling recover() + defer func() { recover() }() f() }() }