Skip to content

Commit

Permalink
port to golangci and make travisci improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Cox committed Oct 9, 2018
1 parent 9c8302b commit 261d64e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 49 deletions.
30 changes: 30 additions & 0 deletions .golangci.yml
@@ -0,0 +1,30 @@
run:
deadline: 5m

linters:
disable-all: true
enable:
- dupl
- goconst
- gocyclo
- gofmt
- golint
- govet
- ineffassign
- interfacer
- lll
- misspell
- nakedret
- structcheck
- unparam
- varcheck

linters-settings:
dupl:
threshold: 400
lll:
line-length: 170
gocyclo:
min-complexity: 15
golint:
min-confidence: 0.85
16 changes: 10 additions & 6 deletions .travis.yml
Expand Up @@ -5,15 +5,19 @@ go:

go_import_path: sigs.k8s.io/kustomize

sudo: false

# Only clone the most recent commit.
git:
depth: 1

env:
- GOLANGCI_RELEASE="v1.10.2"

before_install:
- source ./bin/consider-early-travis-exit.sh
- sudo apt-get install tree
- go get -u github.com/golang/lint/golint
- go get -u golang.org/x/tools/cmd/goimports
- go get -u github.com/onsi/ginkgo/ginkgo
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $GOPATH/bin ${GOLANGCI_RELEASE}
- go get -u github.com/monopole/mdrip
- go get -u github.com/fzipp/gocyclo
- go get -u gopkg.in/alecthomas/gometalinter.v2 && gometalinter.v2 --install

# Install must be set to prevent default `go get` to run.
# The dependencies have already been vendored by `dep` so
Expand Down
46 changes: 3 additions & 43 deletions bin/pre-commit.sh
Expand Up @@ -11,10 +11,6 @@ cd "$base_dir" || {

rc=0

function go_dirs {
go list -f '{{.Dir}}' ./... | tail -n +2 | tr '\n' '\0'
}

function runTest {
local name=$1
local result="SUCCESS"
Expand All @@ -28,40 +24,8 @@ function runTest {
printf "============== end %s : %s code=%d\n\n\n" "$name" "$result" $code
}

function testGoFmt {
diff <(echo -n) <(go_dirs | xargs -0 gofmt -s -d -l)
}


function testGoCyclo {
diff <(echo -n) <(go_dirs | xargs -0 gocyclo -over 15)
}

function testGoLint {
diff -u <(echo -n) <(go_dirs | xargs -0 golint --min_confidence 0.85 )
}

# Not using the 'goimports' check because it reports hyphens in imported
# package names as errors, and we vendor in packages that have
# hyphens in their names.
function testGoMetalinter {
diff -u <(echo -n) <(go_dirs | xargs -0 gometalinter.v2 --disable-all --deadline 5m \
--enable=misspell \
--enable=structcheck \
--enable=deadcode \
--enable=varcheck \
--enable=goconst \
--enable=unparam \
--enable=ineffassign \
--enable=nakedret \
--enable=interfacer \
--enable=misspell \
--line-length=170 --enable=lll \
--dupl-threshold=400 --enable=dupl)
}

function testGoVet {
go vet -all ./...
function testGoLangCILint {
golangci-lint run ./...
}

function testGoTest {
Expand All @@ -72,11 +36,7 @@ function testExamples {
mdrip --mode test --label test README.md ./examples
}

runTest testGoFmt
runTest testGoMetalinter
runTest testGoLint
runTest testGoVet
runTest testGoCyclo
runTest testGoLangCILint
runTest testGoTest
runTest testExamples

Expand Down

0 comments on commit 261d64e

Please sign in to comment.