Skip to content

Commit

Permalink
Merge pull request #6 from vansante/golint-ci
Browse files Browse the repository at this point in the history
Use golangci-lint for all linting purposes (adds more static code analysis)
  • Loading branch information
vansante authored Mar 6, 2019
2 parents 70708c0 + f32f074 commit b4944c5
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 45 deletions.
9 changes: 1 addition & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -26,5 +20,4 @@ workflows:
version: 2
main:
jobs:
- codequality
- test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.idea
/bin
55 changes: 55 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
45 changes: 9 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
.PHONY: all clean lint test
6 changes: 6 additions & 0 deletions example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module github.com/vansante/go-ffprobe

go 1.12

0 comments on commit b4944c5

Please sign in to comment.