diff --git a/.appveyor.yml b/.appveyor.yml index ab73bcd0f..6e2494ccb 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -24,11 +24,7 @@ before_build: #- choco install codecov build_script: - - bash.exe -elc "export PATH=/c/tools/mingw64/bin:$PATH ; mingw32-make.exe setup" - - bash.exe -elc "export PATH=/c/tools/mingw64/bin:$PATH ; mingw32-make.exe fmt" - - bash.exe -elc "export PATH=/c/tools/mingw64/bin:/c/gopath/bin:$PATH ; mingw32-make.exe lint" - - bash.exe -elc "export PATH=/c/tools/mingw64/bin:$PATH ; mingw32-make.exe vet" - - bash.exe -elc "export PATH=/c/tools/mingw64/bin:/c/gopath/bin:$PATH ; mingw32-make.exe ineffassign" + - bash.exe -elc "export PATH=/c/tools/mingw64/bin:/c/gopath/bin:$PATH ; mingw32-make.exe setup check" - bash.exe -elc "export PATH=/c/tools/mingw64/bin:$PATH ; mingw32-make.exe build" - bash.exe -elc "export PATH=/c/tools/mingw64/bin:$PATH ; mingw32-make.exe binaries" diff --git a/.gometalinter.json b/.gometalinter.json new file mode 100644 index 000000000..ef5d6f0d5 --- /dev/null +++ b/.gometalinter.json @@ -0,0 +1,19 @@ +{ + "Vendor": true, + "Deadline": "2m", + "Sort": ["linter", "severity", "path", "line"], + "Exclude": [ + ".*\\.pb\\.go", + "fetch\\.go:.*::error: unrecognized printf verb 'r'" + ], + "EnableGC": true, + "WarnUnmatchedDirective": true, + + "Enable": [ + "gofmt", + "goimports", + "golint", + "ineffassign", + "vet" + ] +} diff --git a/.travis.yml b/.travis.yml index d7989fb2c..38611b677 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,12 +48,9 @@ script: - export GOOS=$TRAVIS_GOOS - export CGO_ENABLED=$TRAVIS_CGO_ENABLED - GIT_CHECK_EXCLUDE="./vendor" TRAVIS_COMMIT_RANGE="${TRAVIS_COMMIT_RANGE/.../..}" make dco - - make fmt + - GOOS=linux make setup - go build -i . - - make setup - - make lint - - make vet - - make ineffassign + - make check - if [ "$GOOS" = "linux" ]; then make check-protos check-api-descriptors; fi - make build - make binaries diff --git a/Makefile b/Makefile index 672c67d2b..bb1c7fa2f 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,6 @@ endif WHALE = "🇩" ONI = "👹" -FIX_PATH = $1 RELEASE=containerd-$(VERSION:v%=%).${GOOS}-${GOARCH} @@ -61,7 +60,9 @@ TESTFLAGS_PARALLEL ?= 8 all: binaries -check: fmt vet lint ineffassign ## run fmt, vet, lint, ineffassign +check: proto-fmt ## run all linters + @echo "$(WHALE) $@" + gometalinter --config .gometalinter.json ./... ci: check binaries checkprotos coverage coverage-integration ## to be used by the CI @@ -71,9 +72,8 @@ AUTHORS: .mailmap .git/HEAD setup: ## install dependencies @echo "$(WHALE) $@" # TODO(stevvooe): Install these from the vendor directory - @go get -u github.com/golang/lint/golint - #@go get -u github.com/kisielk/errcheck - @go get -u github.com/gordonklaus/ineffassign + @go get -u github.com/alecthomas/gometalinter + @gometalinter --install @go get -u github.com/stevvooe/protobuild generate: protos @@ -96,25 +96,13 @@ check-api-descriptors: protos ## check that protobuf changes aren't present. ((git diff $$(find . -name '*.pb.txt') | cat) && \ (echo "$(ONI) please run 'make protos' when making changes to proto files and check-in the generated descriptor file changes" && false)) -# Depends on binaries because vet will silently fail if it can't load compiled -# imports -vet: ## run go vet +proto-fmt: ## check format of proto files @echo "$(WHALE) $@" - @test -z "$$(go vet ${PACKAGES} 2>&1 | grep -v 'constant [0-9]* not a string in call to Errorf' | grep -v 'unrecognized printf verb 'r'' | egrep -v '(timestamp_test.go|duration_test.go|fetch.go|exit status 1)' | tee /dev/stderr)" - -fmt: ## run go fmt - @echo "$(WHALE) $@" - @test -z "$$(gofmt -s -l . | grep -Fv $(call FIX_PATH,'vendor/') | grep -v ".pb.go$$" | tee /dev/stderr)" || \ - (echo "$(ONI) please format Go code with 'gofmt -s -w'" && false) @test -z "$$(find . -path ./vendor -prune -o -path ./protobuf/google/rpc -prune -o -name '*.proto' -type f -exec grep -Hn -e "^ " {} \; | tee /dev/stderr)" || \ (echo "$(ONI) please indent proto files with tabs only" && false) @test -z "$$(find . -path ./vendor -prune -o -name '*.proto' -type f -exec grep -Hn "Meta meta = " {} \; | grep -v '(gogoproto.nullable) = false' | tee /dev/stderr)" || \ (echo "$(ONI) meta fields in proto files must have option (gogoproto.nullable) = false" && false) -lint: ## run go lint - @echo "$(WHALE) $@" - @test -z "$$(golint ./... | grep -Fv $(call FIX_PATH,'vendor/') | grep -v ".pb.go:" | tee /dev/stderr)" - dco: ## dco check @which git-validation > /dev/null 2>/dev/null || (echo "ERROR: git-validation not found" && false) ifdef TRAVIS_COMMIT_RANGE @@ -123,14 +111,6 @@ else git-validation -v -run DCO,short-subject,dangling-whitespace -range $(EPOCH_TEST_COMMIT)..HEAD endif -ineffassign: ## run ineffassign - @echo "$(WHALE) $@" - @test -z "$$(ineffassign . | grep -Fv $(call FIX_PATH,'vendor/') | grep -v ".pb.go:" | tee /dev/stderr)" - -#errcheck: ## run go errcheck -# @echo "$(WHALE) $@" -# @test -z "$$(errcheck ./... | grep -Fv $(call FIX_PATH,'vendor/') | grep -v ".pb.go:" | tee /dev/stderr)" - build: ## build the go packages @echo "$(WHALE) $@" @go build -v ${EXTRA_FLAGS} ${GO_LDFLAGS} ${GO_GCFLAGS} ${PACKAGES} diff --git a/Makefile.windows b/Makefile.windows index f22ffeaaa..3ddb51bd7 100644 --- a/Makefile.windows +++ b/Makefile.windows @@ -1,7 +1,6 @@ #Windows specific settings. WHALE = "+" ONI = "-" -FIX_PATH = $(subst /,\,$1) BINARY_SUFFIX=".exe" diff --git a/mount/mount_unix.go b/mount/mount_unix.go index 23467a8cc..edb0e8dd1 100644 --- a/mount/mount_unix.go +++ b/mount/mount_unix.go @@ -5,17 +5,21 @@ package mount import "github.com/pkg/errors" var ( + // ErrNotImplementOnUnix is returned for methods that are not implemented ErrNotImplementOnUnix = errors.New("not implemented under unix") ) +// Mount is not implemented on this platform func (m *Mount) Mount(target string) error { return ErrNotImplementOnUnix } +// Unmount is not implemented on this platform func Unmount(mount string, flags int) error { return ErrNotImplementOnUnix } +// UnmountAll is not implemented on this platform func UnmountAll(mount string, flags int) error { return ErrNotImplementOnUnix } diff --git a/sys/stat_bsd.go b/sys/stat_bsd.go index 13db2b32e..e043ae52b 100644 --- a/sys/stat_bsd.go +++ b/sys/stat_bsd.go @@ -6,14 +6,17 @@ import ( "syscall" ) +// StatAtime returns the access time from a stat struct func StatAtime(st *syscall.Stat_t) syscall.Timespec { return st.Atimespec } +// StatCtime returns the created time from a stat struct func StatCtime(st *syscall.Stat_t) syscall.Timespec { return st.Ctimespec } +// StatMtime returns the modified time from a stat struct func StatMtime(st *syscall.Stat_t) syscall.Timespec { return st.Mtimespec }