Repository: zeromicro/go-zero
Pull request #1086 (2021-09-23 08:38:08)

ci: add Lint check on commits


Patch:
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/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/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")


Test patch:
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/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")
+		}
 	}
 }