From a85146250b312fcdd6da9a71285527fed544234f Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 14 Mar 2024 10:31:18 +0300 Subject: [PATCH] [#68] Makefile: Use gofumpt for formatting Signed-off-by: Evgenii Stratonikov --- .pre-commit-config.yaml | 9 +++++++++ Makefile | 16 +++++++--------- object/attributes_test.go | 2 +- object/types.go | 3 +-- session/types.go | 3 ++- session/util.go | 12 ++++++++---- util/proto/marshal_test.go | 4 +--- util/protogen/main.go | 14 +++++++------- util/signature/walletconnect/sign_test.go | 1 - 9 files changed, 36 insertions(+), 28 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 35769c1..a64cbaa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,6 +18,15 @@ repos: - id: end-of-file-fixer exclude: ".key$" + - repo: local + hooks: + - id: gofumpt + name: gofumpt + entry: make fumpt + pass_filenames: false + types: [go] + language: system + - repo: local hooks: - id: go-unit-tests diff --git a/Makefile b/Makefile index 888fd20..239565b 100755 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SHELL = bash VERSION ?= $(shell git describe --tags --match "v*" --abbrev=8 --dirty --always) -.PHONY: dep fmts fmt imports protoc test lint version help +.PHONY: dep fmts fumpt imports protoc test lint version help # Pull go dependencies dep: @@ -18,14 +18,7 @@ dep: go test ./... && echo OK # Run all code formatters -fmts: fmt imports - -# Reformat code -fmt: - @echo "⇒ Processing gofmt check" - @for f in `find . -type f -name '*.go' -not -path './vendor/*' -not -name '*.pb.go' -prune`; do \ - gofmt -s -w $$f; \ - done +fmts: fumpt imports # Reformat imports imports: @@ -34,6 +27,11 @@ imports: goimports -w $$f; \ done +# Run gofumpt +fumpt: + @echo "⇒ Processing gofumpt check" + @gofumpt -l -w . + # Regenerate code for proto files protoc: @GOPRIVATE=github.com/TrueCloudLab go mod vendor diff --git a/object/attributes_test.go b/object/attributes_test.go index 5bf411a..85635da 100644 --- a/object/attributes_test.go +++ b/object/attributes_test.go @@ -10,7 +10,7 @@ import ( func TestSetNotification(t *testing.T) { o := new(Object) - var ni = NotificationInfo{ + ni := NotificationInfo{ epoch: 10, topic: "test", } diff --git a/object/types.go b/object/types.go index 895afb0..f9e2ed6 100644 --- a/object/types.go +++ b/object/types.go @@ -318,8 +318,7 @@ type PutSingleRequest struct { session.RequestHeaders } -type PutSingleResponseBody struct { -} +type PutSingleResponseBody struct{} type PutSingleResponse struct { body *PutSingleResponseBody diff --git a/session/types.go b/session/types.go index 19cfecc..5732b29 100644 --- a/session/types.go +++ b/session/types.go @@ -632,7 +632,8 @@ func (r *ResponseMetaHeader) SetStatus(v *status.Status) { func SetStatus(msg interface { GetMetaHeader() *ResponseMetaHeader SetMetaHeader(*ResponseMetaHeader) -}, st *status.Status) { +}, st *status.Status, +) { meta := msg.GetMetaHeader() if meta == nil { meta = new(ResponseMetaHeader) diff --git a/session/util.go b/session/util.go index 7edca29..ff19deb 100644 --- a/session/util.go +++ b/session/util.go @@ -43,7 +43,8 @@ func (c *RequestHeaders) SetVerificationHeader(v *RequestVerificationHeader) { func (c *RequestHeaders) ToMessage(m interface { SetMetaHeader(*session.RequestMetaHeader) SetVerifyHeader(*session.RequestVerificationHeader) -}) { +}, +) { m.SetMetaHeader(c.metaHeader.ToGRPCMessage().(*session.RequestMetaHeader)) m.SetVerifyHeader(c.verifyHeader.ToGRPCMessage().(*session.RequestVerificationHeader)) } @@ -51,7 +52,8 @@ func (c *RequestHeaders) ToMessage(m interface { func (c *RequestHeaders) FromMessage(m interface { GetMetaHeader() *session.RequestMetaHeader GetVerifyHeader() *session.RequestVerificationHeader -}) error { +}, +) error { metaHdr := m.GetMetaHeader() if metaHdr == nil { c.metaHeader = nil @@ -122,7 +124,8 @@ func (c *ResponseHeaders) SetVerificationHeader(v *ResponseVerificationHeader) { func (c *ResponseHeaders) ToMessage(m interface { SetMetaHeader(*session.ResponseMetaHeader) SetVerifyHeader(*session.ResponseVerificationHeader) -}) { +}, +) { m.SetMetaHeader(c.metaHeader.ToGRPCMessage().(*session.ResponseMetaHeader)) m.SetVerifyHeader(c.verifyHeader.ToGRPCMessage().(*session.ResponseVerificationHeader)) } @@ -130,7 +133,8 @@ func (c *ResponseHeaders) ToMessage(m interface { func (c *ResponseHeaders) FromMessage(m interface { GetMetaHeader() *session.ResponseMetaHeader GetVerifyHeader() *session.ResponseVerificationHeader -}) error { +}, +) error { metaHdr := m.GetMetaHeader() if metaHdr == nil { c.metaHeader = nil diff --git a/util/proto/marshal_test.go b/util/proto/marshal_test.go index 11a4d8f..7119c8f 100644 --- a/util/proto/marshal_test.go +++ b/util/proto/marshal_test.go @@ -50,9 +50,7 @@ func (s *stablePrimitives) stableMarshal(buf []byte, wrongField bool) ([]byte, e buf = make([]byte, s.stableSize()) } - var ( - i, offset, fieldNum int - ) + var i, offset, fieldNum int fieldNum = 1 if wrongField { diff --git a/util/protogen/main.go b/util/protogen/main.go index fe89fbf..a295a28 100644 --- a/util/protogen/main.go +++ b/util/protogen/main.go @@ -205,22 +205,22 @@ type marshalerDesc struct { var marshalers = map[protoreflect.Kind]marshalerDesc{ protoreflect.BoolKind: {Prefix: "Bool"}, protoreflect.EnumKind: {Prefix: "Enum"}, - //protoreflect.Int32Kind: "", - //protoreflect.Sint32Kind: "", + // protoreflect.Int32Kind: "", + // protoreflect.Sint32Kind: "", protoreflect.Uint32Kind: {Prefix: "UInt32", RepeatedDouble: true}, protoreflect.Int64Kind: {Prefix: "Int64", RepeatedDouble: true}, - //protoreflect.Sint64Kind: "", + // protoreflect.Sint64Kind: "", protoreflect.Uint64Kind: {Prefix: "UInt64", RepeatedDouble: true}, - //protoreflect.Sfixed32Kind: "", + // protoreflect.Sfixed32Kind: "", protoreflect.Fixed32Kind: {Prefix: "Fixed32", RepeatedDouble: true}, - //protoreflect.FloatKind: "", - //protoreflect.Sfixed64Kind: "", + // protoreflect.FloatKind: "", + // protoreflect.Sfixed64Kind: "", protoreflect.Fixed64Kind: {Prefix: "Fixed64", RepeatedDouble: true}, protoreflect.DoubleKind: {Prefix: "Float64"}, protoreflect.StringKind: {Prefix: "String"}, protoreflect.BytesKind: {Prefix: "Bytes"}, protoreflect.MessageKind: {Prefix: "NestedStructure"}, - //protoreflect.GroupKind: "", + // protoreflect.GroupKind: "", } func sortFields(fs []*protogen.Field) []*protogen.Field { diff --git a/util/signature/walletconnect/sign_test.go b/util/signature/walletconnect/sign_test.go index b83e79f..1b4fe18 100644 --- a/util/signature/walletconnect/sign_test.go +++ b/util/signature/walletconnect/sign_test.go @@ -109,5 +109,4 @@ func TestVerifyNeonWallet(t *testing.T) { } require.True(t, VerifyMessage(nil, sm)) } - }