diff --git a/.circleci/config.yml b/.circleci/config.yml index e55c1bc..cfca424 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,15 +3,9 @@ version: 2.1 executors: go: docker: - - image: circleci/golang:1.11 + - image: circleci/golang:1.12 jobs: - codequality: - executor: go - steps: - - checkout - - run: make verify - test: executor: go steps: @@ -26,5 +20,4 @@ workflows: version: 2 main: jobs: - - codequality - test \ No newline at end of file diff --git a/.gitignore b/.gitignore index 723ef36..9ec3459 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea \ No newline at end of file +.idea +/bin \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..014aa2f --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,55 @@ +run: + # timeout for analysis, e.g. 30s, 5m, default is 1m + deadline: 30s + + # exit code when at least one issue was found, default is 1 + issues-exit-code: 1 + + # include test files or not, default is true + tests: true + +# all available settings of specific linters +linters-settings: + gocyclo: + min-complexity: 20 + maligned: + suggest-new: true + dupl: + threshold: 100 + goconst: + min-len: 3 + min-occurrences: 2 + depguard: + lll: + line-length: 160 + nakedret: + max-func-lines: 10 + +linters: + enable: + - megacheck + - govet + - golint + - gosec + - unconvert + - goconst + - gocyclo + - gofmt + - maligned + - lll + - unparam + - nakedret + - misspell + enable-all: false + disable-all: false + presets: + - bugs + - unused + fast: false + +issues: + exclude-rules: + - path: probedata\.go + text: "ALL_CAPS" + linters: + - golint diff --git a/Makefile b/Makefile index 259a269..6c68961 100644 --- a/Makefile +++ b/Makefile @@ -1,48 +1,21 @@ -SHELL:=$(PREFIX)/bin/bash +GOLANGCILINT := $(shell command -v ./bin/golangci-lint 2> /dev/null) -all: verify test - -verify: fmt vet lint nakedreturns duplicatecode constants +all: lint test clean: # Cleaning test cache go clean -testcache -fmt: - # Checking project code formatting... - ! gofmt -d . | read || ( gofmt -d . && exit 1 ) - -vet: - # Checking for suspicious constructs - go vet ./... - lint: - @command -v golint >/dev/null 2>&1 || go get github.com/golang/lint/golint - # Checking project code style... - ! ( golint ./... | grep -v "ALL_CAPS" ) - -imports: - @command -v goimports >/dev/null 2>&1 || go get golang.org/x/tools/cmd/goimports - # Fixing imports - goimports -w . - -nakedreturns: - @command -v nakedret >/dev/null 2>&1 || go get github.com/alexkohler/nakedret - # Checking for naked returns - ! nakedret ./... 2>&1 | read || ( nakedret ./... && exit 1 ) - -duplicatecode: - @command -v dupl >/dev/null 2>&1 || go get github.com/mibk/dupl - # Checking for duplicate code - ! find . -name '*.go' | grep -v '_test.go' | dupl -t 75 -plumbing -files | read || ( find . -name '*.go' | grep -v '_test.go' | dupl -t 75 -files && exit 1 ) - -constants: - @command -v goconst >/dev/null 2>&1 || go get github.com/jgautheron/goconst/cmd/goconst - # Checking for possible constants - ! goconst ./... | read || ( goconst ./... && exit 1 ) +ifndef GOLANGCILINT + # golangci-lint not installed, downloading... + go get github.com/golangci/golangci-lint + curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.15.0 +endif + ./bin/golangci-lint run test: # Running tests go test -v -timeout 10s -race ./... -.PHONY: all verify clean fmt vet lint imports nakedreturns duplicatecode constants test \ No newline at end of file +.PHONY: all clean lint test \ No newline at end of file diff --git a/example/example.go b/example/example.go index f32b1d0..b186a5f 100644 --- a/example/example.go +++ b/example/example.go @@ -22,9 +22,15 @@ func main() { } buf, err := json.MarshalIndent(data, "", " ") + if err != nil { + log.Panicf("Error unmarshalling: %v", err) + } log.Print(string(buf)) buf, err = json.MarshalIndent(data.GetFirstVideoStream(), "", " ") + if err != nil { + log.Panicf("Error unmarshalling: %v", err) + } log.Print(string(buf)) log.Printf("%v", data.GetStreams(ffprobe.StreamVideo)) diff --git a/go.mod b/go.mod index bd2e2ba..c3abfc8 100644 --- a/go.mod +++ b/go.mod @@ -1 +1,3 @@ module github.com/vansante/go-ffprobe + +go 1.12