diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0f06e9fc..68f91e83 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -30,14 +30,18 @@ jobs: if: matrix.os == 'windows-latest' env: GO111MODULE: on - run: go test -v -race ./... + run: | + go build --ldflags="-s -w" -o %GOPATH%\bin\mc.exe + go test -v -race --timeout 30m ./... - name: Build on ${{ matrix.os }} if: matrix.os == 'ubuntu-latest' env: GO111MODULE: on run: | + make diff -au <(gofmt -d *.go) <(printf "") - diff -au <(gofmt -d cmd) <(printf "") - diff -au <(gofmt -d pkg) <(printf "") - go test -v -race ./... - make test + diff -au <(gofmt -s -d cmd) <(printf "") + diff -au <(gofmt -s -d pkg) <(printf "") + make test-race + make verify + make crosscompile diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..99e06b20 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,28 @@ +linters-settings: + golint: + min-confidence: 0 + + misspell: + locale: US + +linters: + disable-all: true + enable: + - typecheck + - goimports + - misspell + - govet + - golint + - ineffassign + - gosimple + - deadcode + - structcheck + +issues: + exclude-use-default: false + exclude: + - instead of using struct literal + - should have a package comment + - error strings should not be capitalized or end with punctuation or a newline +service: + golangci-lint-version: 1.20.0 # use the fixed version to not introduce new linters unexpectedly diff --git a/Makefile b/Makefile index dc90ba92..e1921280 100644 --- a/Makefile +++ b/Makefile @@ -18,18 +18,12 @@ checks: getdeps: @mkdir -p ${GOPATH}/bin - @which golint 1>/dev/null || (echo "Installing golint" && GO111MODULE=off go get -u golang.org/x/lint/golint) -ifeq ($(GOARCH),s390x) - @which staticcheck 1>/dev/null || (echo "Installing staticcheck" && GO111MODULE=off go get honnef.co/go/tools/cmd/staticcheck) -else - @which staticcheck 1>/dev/null || (echo "Installing staticcheck" && wget --quiet https://github.com/dominikh/go-tools/releases/download/2019.2.3/staticcheck_${GOOS}_${GOARCH}.tar.gz && tar xf staticcheck_${GOOS}_${GOARCH}.tar.gz && mv staticcheck/staticcheck ${GOPATH}/bin/staticcheck && chmod +x ${GOPATH}/bin/staticcheck && rm -f staticcheck_${GOOS}_${GOARCH}.tar.gz && rm -rf staticcheck) -endif - @which misspell 1>/dev/null || (echo "Installing misspell" && GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell) + @which golangci-lint 1>/dev/null || (echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.27.0) crosscompile: @(env bash $(PWD)/buildscripts/cross-compile.sh) -verifiers: getdeps vet fmt lint staticcheck spelling +verifiers: getdeps vet fmt lint docker: build @docker build -t $(TAG) . -f Dockerfile.dev @@ -44,19 +38,9 @@ fmt: @GO111MODULE=on gofmt -d pkg/ lint: - @echo "Running $@" - @GO111MODULE=on ${GOPATH}/bin/golint -set_exit_status github.com/minio/mc/cmd/... - @GO111MODULE=on ${GOPATH}/bin/golint -set_exit_status github.com/minio/mc/pkg/... - -staticcheck: - @echo "Running $@" - @GO111MODULE=on ${GOPATH}/bin/staticcheck github.com/minio/mc/cmd/... - @GO111MODULE=on ${GOPATH}/bin/staticcheck github.com/minio/mc/pkg/... - -spelling: - @GO111MODULE=on ${GOPATH}/bin/misspell -locale US -error `find cmd/` - @GO111MODULE=on ${GOPATH}/bin/misspell -locale US -error `find pkg/` - @GO111MODULE=on ${GOPATH}/bin/misspell -locale US -error `find docs/` + @echo "Running $@ check" + @GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean + @GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=5m --config ./.golangci.yml # Builds mc, runs the verifiers then runs the tests. check: test @@ -66,9 +50,16 @@ test: verifiers build @echo "Running functional tests" @(env bash $(PWD)/functional-tests.sh) -coverage: build - @echo "Running all coverage for MinIO" - @(env bash $(PWD)/buildscripts/go-coverage.sh) +test-race: verifiers build + @echo "Running unit tests under -race" + @GO111MODULE=on go test -race -v --timeout 20m ./... 1>/dev/null + +# Verify mc binary +verify: + @echo "Verifying build with race" + @GO111MODULE=on CGO_ENABLED=1 go build -race -tags kqueue -trimpath --ldflags "$(LDFLAGS)" -o $(PWD)/mc 1>/dev/null + @echo "Running functional tests" + @(env bash $(PWD)/functional-tests.sh) # Builds mc locally. build: checks diff --git a/buildscripts/go-coverage.sh b/buildscripts/go-coverage.sh deleted file mode 100755 index 5efcfbb0..00000000 --- a/buildscripts/go-coverage.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -e - -GO111MODULE=on CGO_ENABLED=0 go test -v -coverprofile=coverage.txt -covermode=atomic ./... diff --git a/cmd/admin-console.go b/cmd/admin-console.go index 38f425da..cdabe97f 100644 --- a/cmd/admin-console.go +++ b/cmd/admin-console.go @@ -185,8 +185,7 @@ func mainAdminConsole(ctx *cli.Context) error { fatalIf(errInvalidArgument().Trace(ctx.Args()...), "please set a proper limit, for example: '--limit 5' to display last 5 logs, omit this flag to display all available logs") } } - var logType string - logType = strings.ToLower(ctx.String("type")) + logType := strings.ToLower(ctx.String("type")) if logType != "minio" && logType != "application" && logType != "all" { fatalIf(errInvalidArgument().Trace(ctx.Args()...), "Invalid value for --type flag. Valid options are [minio, application, all]") } diff --git a/cmd/client-fs_test.go b/cmd/client-fs_test.go index 325ce656..2470c1f6 100644 --- a/cmd/client-fs_test.go +++ b/cmd/client-fs_test.go @@ -352,8 +352,7 @@ func (s *TestSuite) TestCopy(c *C) { c.Assert(err, IsNil) data := "hello world" - var reader io.Reader - reader = bytes.NewReader([]byte(data)) + reader := bytes.NewReader([]byte(data)) n, err := fsClientSource.Put(context.Background(), reader, int64(len(data)), map[string]string{ "Content-Type": "application/octet-stream", }, nil, nil, false, false) diff --git a/cmd/ilm/tabular_info.go b/cmd/ilm/tabular_info.go index aebd9438..42bf8709 100644 --- a/cmd/ilm/tabular_info.go +++ b/cmd/ilm/tabular_info.go @@ -52,16 +52,12 @@ const ( idLabel string = "ID" prefixLabel string = "Prefix" statusLabel string = "Enabled " - statusDisabledLabel string = "Disabled" expiryLabel string = "Expiry" expiryDatesLabel string = "Date/Days " - singleTagLabel string = "Tag" tagLabel string = "Tags" transitionLabel string = "Transition" transitionDateLabel string = "Date/Days " storageClassLabel string = "Storage-Class " - forceLabel string = "force" - allLabel string = "all" ) // Keys to be used in map structure which stores the columns to be displayed. @@ -70,7 +66,6 @@ const ( storageClassLabelKey string = "Storage-Class" expiryDatesLabelKey string = "Expiry-Dates" transitionDatesLabelKey string = "Transition-Date" - transitionDaysLabelKey string = "Transition-Days" ) // Some cell values diff --git a/pkg/probe/probe.go b/pkg/probe/probe.go index 27270023..ad3358f5 100644 --- a/pkg/probe/probe.go +++ b/pkg/probe/probe.go @@ -1,5 +1,5 @@ /* - * MinIO Cloud Storage, (C) 2015 MinIO, Inc. + * MinIO Cloud Storage, (C) 2015-2020 MinIO, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -143,7 +143,7 @@ func (e *Error) trace(fields ...string) *Error { function := runtime.FuncForPC(pc).Name() _, function = filepath.Split(function) file = strings.TrimPrefix(file, rootPath+string(os.PathSeparator)) // trims project's root path. - tp := TracePoint{} + var tp TracePoint if len(fields) > 0 { tp = TracePoint{Line: line, Filename: file, Function: function, Env: map[string][]string{"Tags": fields}} } else { diff --git a/staticcheck.conf b/staticcheck.conf index 24d24f28..e5bf6051 100644 --- a/staticcheck.conf +++ b/staticcheck.conf @@ -1 +1 @@ -checks = ["all", "-S1021", "-ST1005", "-S1016"] +checks = ["all", "-S1016"]