From 8403ed16ae031a083c3eec7fa80af2df9a72057a Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Thu, 23 Sep 2021 19:57:05 +0800 Subject: [PATCH] ci: add Lint check on commits (#1086) * ci: add Lint check on commits * ci: fix Lint script error * test: fix go vet errors * test: fix go vet errors, remove gofumpt to check go vet * test: fix go vet errors, try gofumpt * test: fix go vet errors, try gofumpt, round 1 * test: fix go vet errors, try gofumpt, round 2 * ci: fix Lint errors --- .github/workflows/go.yml | 6 +++++ core/discov/internal/statewatcher_mock.go | 3 ++- core/discov/internal/updatelistener_mock.go | 3 ++- core/fs/files.go | 1 + core/proc/shutdown.go | 1 + core/search/tree_debug.go | 1 + core/stat/alert.go | 1 + core/stat/alert_test.go | 1 + core/stores/mongo/internal/collection_mock.go | 3 ++- core/stores/mongo/iter_mock.go | 3 ++- core/syncx/pool_test.go | 7 ++++- zrpc/internal/mock/deposit.pb.go | 27 +++++++++++-------- 12 files changed, 41 insertions(+), 16 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 6709e5a7..564fafb8 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -25,6 +25,12 @@ jobs: run: | go get -v -t -d ./... + - name: Lint + run: | + go vet -stdmethods=false $(go list ./...) + go install mvdan.cc/gofumpt@latest + test -z "$(gofumpt -s -l -extra .)" + - name: Test run: go test -race -coverprofile=coverage.txt -covermode=atomic ./... diff --git a/core/discov/internal/statewatcher_mock.go b/core/discov/internal/statewatcher_mock.go index 7c0ebe3d..6450c7aa 100644 --- a/core/discov/internal/statewatcher_mock.go +++ b/core/discov/internal/statewatcher_mock.go @@ -6,9 +6,10 @@ package internal import ( context "context" + reflect "reflect" + gomock "github.com/golang/mock/gomock" connectivity "google.golang.org/grpc/connectivity" - reflect "reflect" ) // MocketcdConn is a mock of etcdConn interface diff --git a/core/discov/internal/updatelistener_mock.go b/core/discov/internal/updatelistener_mock.go index 392faa78..ae983e3c 100644 --- a/core/discov/internal/updatelistener_mock.go +++ b/core/discov/internal/updatelistener_mock.go @@ -5,8 +5,9 @@ package internal import ( - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockUpdateListener is a mock of UpdateListener interface diff --git a/core/fs/files.go b/core/fs/files.go index f29f7142..49d28725 100644 --- a/core/fs/files.go +++ b/core/fs/files.go @@ -1,3 +1,4 @@ +//go:build linux || darwin // +build linux darwin package fs diff --git a/core/proc/shutdown.go b/core/proc/shutdown.go index cb9eee37..a73c6fa5 100644 --- a/core/proc/shutdown.go +++ b/core/proc/shutdown.go @@ -1,3 +1,4 @@ +//go:build linux || darwin // +build linux darwin package proc diff --git a/core/search/tree_debug.go b/core/search/tree_debug.go index 1ef7418c..14dc240b 100644 --- a/core/search/tree_debug.go +++ b/core/search/tree_debug.go @@ -1,3 +1,4 @@ +//go:build debug // +build debug package search diff --git a/core/stat/alert.go b/core/stat/alert.go index afa43d42..bb4bd7c6 100644 --- a/core/stat/alert.go +++ b/core/stat/alert.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package stat diff --git a/core/stat/alert_test.go b/core/stat/alert_test.go index 26c17787..c5419698 100644 --- a/core/stat/alert_test.go +++ b/core/stat/alert_test.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package stat diff --git a/core/stores/mongo/internal/collection_mock.go b/core/stores/mongo/internal/collection_mock.go index 5f6b7b40..65b2ca7d 100644 --- a/core/stores/mongo/internal/collection_mock.go +++ b/core/stores/mongo/internal/collection_mock.go @@ -5,9 +5,10 @@ package internal import ( + reflect "reflect" + mgo "github.com/globalsign/mgo" gomock "github.com/golang/mock/gomock" - reflect "reflect" ) // MockMgoCollection is a mock of MgoCollection interface diff --git a/core/stores/mongo/iter_mock.go b/core/stores/mongo/iter_mock.go index dbc851ce..c44423a7 100644 --- a/core/stores/mongo/iter_mock.go +++ b/core/stores/mongo/iter_mock.go @@ -5,9 +5,10 @@ package mongo import ( + reflect "reflect" + bson "github.com/globalsign/mgo/bson" gomock "github.com/golang/mock/gomock" - reflect "reflect" ) // MockIter is a mock of Iter interface diff --git a/core/syncx/pool_test.go b/core/syncx/pool_test.go index 34a5d9ac..d59c47fd 100644 --- a/core/syncx/pool_test.go +++ b/core/syncx/pool_test.go @@ -17,10 +17,11 @@ func TestPoolGet(t *testing.T) { ch := make(chan lang.PlaceholderType) for i := 0; i < limit; i++ { + var fail AtomicBool go func() { v := stack.Get() if v.(int) != 1 { - t.Fatal("unmatch value") + fail.Set(true) } ch <- lang.Placeholder }() @@ -30,6 +31,10 @@ func TestPoolGet(t *testing.T) { case <-time.After(time.Second): t.Fail() } + + if fail.True() { + t.Fatal("unmatch value") + } } } diff --git a/zrpc/internal/mock/deposit.pb.go b/zrpc/internal/mock/deposit.pb.go index 32df60dd..6ebe3aab 100644 --- a/zrpc/internal/mock/deposit.pb.go +++ b/zrpc/internal/mock/deposit.pb.go @@ -8,13 +8,14 @@ package mock import ( context "context" + reflect "reflect" + sync "sync" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" ) const ( @@ -147,11 +148,14 @@ func file_deposit_proto_rawDescGZIP() []byte { return file_deposit_proto_rawDescData } -var file_deposit_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_deposit_proto_goTypes = []interface{}{ - (*DepositRequest)(nil), // 0: mock.DepositRequest - (*DepositResponse)(nil), // 1: mock.DepositResponse -} +var ( + file_deposit_proto_msgTypes = make([]protoimpl.MessageInfo, 2) + file_deposit_proto_goTypes = []interface{}{ + (*DepositRequest)(nil), // 0: mock.DepositRequest + (*DepositResponse)(nil), // 1: mock.DepositResponse + } +) + var file_deposit_proto_depIdxs = []int32{ 0, // 0: mock.DepositService.Deposit:input_type -> mock.DepositRequest 1, // 1: mock.DepositService.Deposit:output_type -> mock.DepositResponse @@ -214,8 +218,10 @@ func file_deposit_proto_init() { } // Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConnInterface +var ( + _ context.Context + _ grpc.ClientConnInterface +) // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. @@ -251,8 +257,7 @@ type DepositServiceServer interface { } // UnimplementedDepositServiceServer can be embedded to have forward compatible implementations. -type UnimplementedDepositServiceServer struct { -} +type UnimplementedDepositServiceServer struct{} func (*UnimplementedDepositServiceServer) Deposit(context.Context, *DepositRequest) (*DepositResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Deposit not implemented")