Skip to content

Commit

Permalink
Merge 59759d9 into 4f177b7
Browse files Browse the repository at this point in the history
  • Loading branch information
colega committed Jul 15, 2020
2 parents 4f177b7 + 59759d9 commit be31cac
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vendor/
bin/
.cache
.test_coverage.txt
coverage.out
109 changes: 109 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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=. ./...
2 changes: 1 addition & 1 deletion runner_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 2 additions & 5 deletions runner_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}()
}

0 comments on commit be31cac

Please sign in to comment.