cleanup Go linter settings (#16736)

This commit is contained in:
ferhat elmas 2023-03-05 05:57:35 +01:00 committed by GitHub
parent 9d062b37d7
commit 3423028713
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 59 additions and 52 deletions

1
.gitignore vendored
View File

@ -38,3 +38,4 @@ docs/debugging/s3-check-md5/s3-check-md5
docs/debugging/hash-set/hash-set docs/debugging/hash-set/hash-set
docs/debugging/healing-bin/healing-bin docs/debugging/healing-bin/healing-bin
docs/debugging/inspect/inspect docs/debugging/inspect/inspect
.bin/

View File

@ -1,39 +1,41 @@
linters-settings: linters-settings:
gofumpt: gofumpt:
lang-version: "1.18" lang-version: '1.19'
misspell: misspell:
locale: US locale: US
staticcheck:
go: '1.19'
checks: ['all', '-ST1005', '-ST1000', '-SA4000', '-SA9004', '-SA1019', '-SA1008', '-U1000', '-ST1016']
linters: linters:
disable-all: true disable-all: true
enable: enable:
- typecheck - durationcheck
- goimports - gocritic
- misspell
- govet
- revive
- ineffassign
- gomodguard
- gofmt - gofmt
- gofumpt
- goimports
- gomodguard
- govet
- ineffassign
- misspell
- revive
- staticcheck
- tenv
- typecheck
- unconvert - unconvert
- unused - unused
- gocritic
- gofumpt
- tenv
- durationcheck
issues: issues:
exclude-use-default: false exclude-use-default: false
exclude: exclude:
- should have a package comment - should have a package comment
- error strings should not be capitalized or end with punctuation or a newline - error strings should not be capitalized or end with punctuation or a newline
# todo fix these when we get enough time. # todo fix these when we get enough time.
- "singleCaseSwitch: should rewrite switch statement to if statement" - 'singleCaseSwitch: should rewrite switch statement to if statement'
- "unlambda: replace" - 'unlambda: replace'
- "captLocal:" - 'captLocal:'
- "ifElseChain:" - 'ifElseChain:'
- "elseif:" - 'elseif:'
service:
golangci-lint-version: 1.43.0 # use the fixed version to not introduce new linters unexpectedly

View File

@ -8,6 +8,10 @@ GOOS := $(shell go env GOOS)
VERSION ?= $(shell git describe --tags) VERSION ?= $(shell git describe --tags)
TAG ?= "minio/minio:$(VERSION)" TAG ?= "minio/minio:$(VERSION)"
GOLANGCI_VERSION = v1.51.2
GOLANGCI_DIR = .bin/golangci/$(GOLANGCI_VERSION)
GOLANGCI = $(GOLANGCI_DIR)/golangci-lint
all: build all: build
checks: ## check dependencies checks: ## check dependencies
@ -19,10 +23,9 @@ help: ## print this help
getdeps: ## fetch necessary dependencies getdeps: ## fetch necessary dependencies
@mkdir -p ${GOPATH}/bin @mkdir -p ${GOPATH}/bin
@echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin @echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOLANGCI_DIR) $(GOLANGCI_VERSION)
@echo "Installing msgp" && go install -v github.com/tinylib/msgp@v1.1.7 @echo "Installing msgp" && go install -v github.com/tinylib/msgp@v1.1.7
@echo "Installing stringer" && go install -v golang.org/x/tools/cmd/stringer@latest @echo "Installing stringer" && go install -v golang.org/x/tools/cmd/stringer@latest
@echo "Installing staticcheck" && go install honnef.co/go/tools/cmd/staticcheck@latest
crosscompile: ## cross compile minio crosscompile: ## cross compile minio
@(env bash $(PWD)/buildscripts/cross-compile.sh) @(env bash $(PWD)/buildscripts/cross-compile.sh)
@ -35,8 +38,7 @@ check-gen: ## check for updated autogenerated files
lint: ## runs golangci-lint suite of linters lint: ## runs golangci-lint suite of linters
@echo "Running $@ check" @echo "Running $@ check"
@${GOPATH}/bin/golangci-lint run --build-tags kqueue --timeout=10m --config ./.golangci.yml @$(GOLANGCI) run --build-tags kqueue --timeout=10m --config ./.golangci.yml
@${GOPATH}/bin/staticcheck --tests=false ./...
check: test check: test
test: verifiers build ## builds minio, runs linters, tests test: verifiers build ## builds minio, runs linters, tests

View File

@ -27,12 +27,12 @@ import (
"context" "context"
"fmt" "fmt"
"runtime" "runtime"
"sync"
"testing" "testing"
"time" "time"
"github.com/minio/madmin-go/v2" "github.com/minio/madmin-go/v2"
minio "github.com/minio/minio-go/v7" minio "github.com/minio/minio-go/v7"
"github.com/minio/minio/internal/sync/errgroup"
) )
func runAllIAMConcurrencyTests(suite *TestSuiteIAM, c *check) { func runAllIAMConcurrencyTests(suite *TestSuiteIAM, c *check) {
@ -129,18 +129,21 @@ func (s *TestSuiteIAM) TestDeleteUserRace(c *check) {
secretKeys[i] = secretKey secretKeys[i] = secretKey
} }
wg := sync.WaitGroup{} g := errgroup.Group{}
for i := 0; i < userCount; i++ { for i := 0; i < userCount; i++ {
wg.Add(1) g.Go(func(i int) func() error {
go func(i int) { return func() error {
defer wg.Done() uClient := s.getUserClient(c, accessKeys[i], secretKeys[i], "")
uClient := s.getUserClient(c, accessKeys[i], secretKeys[i], "") err := s.adm.RemoveUser(ctx, accessKeys[i])
err := s.adm.RemoveUser(ctx, accessKeys[i]) if err != nil {
if err != nil { return err
c.Fatalf("unable to remove user: %v", err) }
c.mustNotListObjects(ctx, uClient, bucket)
return nil
} }
c.mustNotListObjects(ctx, uClient, bucket) }(i), i)
}(i) }
if errs := g.Wait(); len(errs) > 0 {
c.Fatalf("unable to remove users: %v", errs)
} }
wg.Wait()
} }

View File

@ -825,7 +825,7 @@ func (s *TestSuiteIAM) TestGroupAddRemove(c *check) {
if set.CreateStringSet(groups...).Contains(group) { if set.CreateStringSet(groups...).Contains(group) {
c.Fatalf("created group still present!") c.Fatalf("created group still present!")
} }
groupInfo, err = s.adm.GetGroupDescription(ctx, group) _, err = s.adm.GetGroupDescription(ctx, group)
if err == nil { if err == nil {
c.Fatalf("group appears to exist") c.Fatalf("group appears to exist")
} }

View File

@ -1621,10 +1621,10 @@ func TestHealLastDataShard(t *testing.T) {
} }
firstGr, err := obj.GetObjectNInfo(ctx, bucket, object, nil, nil, noLock, ObjectOptions{}) firstGr, err := obj.GetObjectNInfo(ctx, bucket, object, nil, nil, noLock, ObjectOptions{})
defer firstGr.Close()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer firstGr.Close()
firstHealedH := sha256.New() firstHealedH := sha256.New()
_, err = io.Copy(firstHealedH, firstGr) _, err = io.Copy(firstHealedH, firstGr)
@ -1651,10 +1651,10 @@ func TestHealLastDataShard(t *testing.T) {
} }
secondGr, err := obj.GetObjectNInfo(ctx, bucket, object, nil, nil, noLock, ObjectOptions{}) secondGr, err := obj.GetObjectNInfo(ctx, bucket, object, nil, nil, noLock, ObjectOptions{})
defer secondGr.Close()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer secondGr.Close()
secondHealedH := sha256.New() secondHealedH := sha256.New()
_, err = io.Copy(secondHealedH, secondGr) _, err = io.Copy(secondHealedH, secondGr)

View File

@ -419,7 +419,7 @@ func Test_localLocker_RUnlock(t *testing.T) {
} }
start = time.Now() start = time.Now()
for _, lock := range toUnLock { for _, lock := range toUnLock {
ok, err := l.RUnlock(nil, lock) ok, err := l.RUnlock(context.TODO(), lock)
if err != nil || !ok { if err != nil || !ok {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -243,7 +243,7 @@ func untar(ctx context.Context, r io.Reader, putObject func(reader io.Reader, in
rc.Close() rc.Close()
<-asyncWriters <-asyncWriters
wg.Done() wg.Done()
//lint:ignore SA6002 we are fine with the tiny alloc //nolint:staticcheck // SA6002 we are fine with the tiny alloc
poolBuf128k.Put(b) poolBuf128k.Put(b)
}() }()
if err := putObject(&rc, fi, name); err != nil { if err := putObject(&rc, fi, name); err != nil {

View File

@ -678,7 +678,7 @@ func metaDataPoolGet() []byte {
// metaDataPoolPut will put an unused small buffer back into the pool. // metaDataPoolPut will put an unused small buffer back into the pool.
func metaDataPoolPut(buf []byte) { func metaDataPoolPut(buf []byte) {
if cap(buf) >= metaDataReadDefault && cap(buf) < metaDataReadDefault*4 { if cap(buf) >= metaDataReadDefault && cap(buf) < metaDataReadDefault*4 {
//lint:ignore SA6002 we are fine with the tiny alloc //nolint:staticcheck // SA6002 we are fine with the tiny alloc
metaDataPool.Put(buf) metaDataPool.Put(buf)
} }
} }

View File

@ -63,7 +63,7 @@ func testSimpleWriteLock(t *testing.T, duration time.Duration) (locked bool) {
lrwm.Unlock() lrwm.Unlock()
} else { } else {
// fmt.Println("Write lock failed due to timeout") t.Log("Write lock failed due to timeout")
} }
return return
} }
@ -109,7 +109,7 @@ func testDualWriteLock(t *testing.T, duration time.Duration) (locked bool) {
lrwm.Unlock() lrwm.Unlock()
} else { } else {
// fmt.Println("2nd write lock failed due to timeout") t.Log("2nd write lock failed due to timeout")
} }
return return
} }

View File

@ -69,7 +69,7 @@ func (r *Reader) Read(dst sql.Record) (sql.Record, error) {
r.err = io.EOF r.err = io.EOF
return nil, r.err return nil, r.err
} }
//lint:ignore SA6002 Using pointer would allocate more since we would have to copy slice header before taking a pointer. //nolint:staticcheck // SA6002 Using pointer would allocate more since we would have to copy slice header before taking a pointer.
r.csvDstPool.Put(r.current) r.csvDstPool.Put(r.current)
r.current = <-item.dst r.current = <-item.dst
r.err = item.err r.err = item.err
@ -269,7 +269,7 @@ func (r *Reader) startReaders(newReader func(io.Reader) *csv.Reader) error {
in.err = err in.err = err
} }
// We don't need the input any more. // We don't need the input any more.
//lint:ignore SA6002 Using pointer would allocate more since we would have to copy slice header before taking a pointer. //nolint:staticcheck // SA6002 Using pointer would allocate more since we would have to copy slice header before taking a pointer.
r.bufferPool.Put(in.input) r.bufferPool.Put(in.input)
in.input = nil in.input = nil
in.dst <- all in.dst <- all

View File

@ -66,7 +66,7 @@ func (r *PReader) Read(dst sql.Record) (sql.Record, error) {
r.err = io.EOF r.err = io.EOF
return nil, r.err return nil, r.err
} }
//lint:ignore SA6002 Using pointer would allocate more since we would have to copy slice header before taking a pointer. //nolint:staticcheck // SA6002 Using pointer would allocate more since we would have to copy slice header before taking a pointer.
r.kvDstPool.Put(r.current) r.kvDstPool.Put(r.current)
r.current = <-item.dst r.current = <-item.dst
r.err = item.err r.err = item.err
@ -204,7 +204,7 @@ func (r *PReader) startReaders() {
all = append(all, kvs) all = append(all, kvs)
} }
// We don't need the input any more. // We don't need the input any more.
//lint:ignore SA6002 Using pointer would allocate more since we would have to copy slice header before taking a pointer. //nolint:staticcheck // SA6002 Using pointer would allocate more since we would have to copy slice header before taking a pointer.
r.bufferPool.Put(in.input) r.bufferPool.Put(in.input)
in.input = nil in.input = nil
in.err = d.Err() in.err = d.Err()

View File

@ -1 +0,0 @@
checks = ["all", "-ST1005", "-ST1000", "-SA4000", "-SA9004", "-SA1019", "-SA1008", "-U1000", "-ST1016"]