diff --git a/hack/tools/tools.go b/hack/tools/tools.go index a5a486f4..6601d8ca 100644 --- a/hack/tools/tools.go +++ b/hack/tools/tools.go @@ -6,11 +6,10 @@ https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for- */ package tools - import ( // linter(s) _ "github.com/golangci/golangci-lint/cmd/golangci-lint" // test runner _ "gotest.tools/gotestsum" -) \ No newline at end of file +) diff --git a/hack/update/gofmt.sh b/hack/update/gofmt.sh new file mode 100755 index 00000000..d02334b7 --- /dev/null +++ b/hack/update/gofmt.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Copyright 2018 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# script to run gofmt over our code (not vendor) +set -o errexit -o nounset -o pipefail + +# cd to the repo root +REPO_ROOT="$(git rev-parse --show-toplevel)" +cd "${REPO_ROOT}" + +hack/go_container.sh sh -c "find . -name '*.go' -type f -print0 | xargs -0 gofmt -s -w" diff --git a/hack/verify/lint.sh b/hack/verify/lint.sh index c38c65c6..8abc2ae9 100755 --- a/hack/verify/lint.sh +++ b/hack/verify/lint.sh @@ -24,6 +24,17 @@ cd "${REPO_ROOT}" SOURCE_DIR="${REPO_ROOT}/hack/tools" GOOS="linux" hack/go_container.sh \ go build -o /out/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint + +# run golangci-lint +LINTS=( + # default golangci-lint lints + deadcode errcheck gosimple govet ineffassign staticcheck \ + structcheck typecheck unused varcheck \ + # additional lints + golint gofmt misspell unparam scopelint gosec +) +LINTS_JOINED="$(IFS=','; echo "${LINTS[*]}")" + # first for the repo in general SOURCE_DIR="${REPO_ROOT}" hack/go_container.sh \ - /out/golangci-lint -v --enable-all --timeout=2m run . + /out/golangci-lint --disable-all --enable="${LINTS_JOINED}" --timeout=2m run ./...