From 481a1ca6f35625f890612b6b5fc6e2eed7c982f3 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Mon, 20 Mar 2023 10:18:24 +0300 Subject: [PATCH] [#148] linter: Add gocognit linter Code with high cognitive complexity is hard intuitively to understand Signed-off-by: Dmitrii Stepanov --- .golangci.yml | 7 +++++-- cmd/frostfs-adm/internal/modules/morph/balance.go | 2 +- pkg/innerring/innerring.go | 2 +- pkg/local_object_storage/engine/evacuate.go | 2 +- pkg/local_object_storage/metabase/inhume.go | 2 +- pkg/local_object_storage/metabase/lock.go | 2 ++ pkg/morph/event/listener.go | 2 +- pkg/services/object/get/v2/util.go | 6 +++--- pkg/services/object/search/v2/util.go | 2 +- pkg/services/object/util/chain.go | 2 +- pkg/services/tree/sync.go | 2 +- 11 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 683d976a..4612d96a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -27,8 +27,10 @@ linters-settings: staticcheck: checks: ["all", "-SA1019"] # TODO Enable SA1019 after deprecated warning are fixed. funlen: - lines: 80 - statements: 60 + lines: 80 # default 60 + statements: 60 # default 40 + gocognit: + min-complexity: 40 # default 30 linters: enable: @@ -58,5 +60,6 @@ linters: - whitespace - containedctx - funlen + - gocognit disable-all: true fast: false diff --git a/cmd/frostfs-adm/internal/modules/morph/balance.go b/cmd/frostfs-adm/internal/modules/morph/balance.go index c8549268..ca9d939f 100644 --- a/cmd/frostfs-adm/internal/modules/morph/balance.go +++ b/cmd/frostfs-adm/internal/modules/morph/balance.go @@ -44,7 +44,7 @@ const ( notaryEnabled = true ) -// nolint: funlen +// nolint: funlen, gocognit func dumpBalances(cmd *cobra.Command, _ []string) error { var ( dumpStorage, _ = cmd.Flags().GetBool(dumpBalancesStorageFlag) diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index ae3217fc..200a2017 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -322,7 +322,7 @@ func (s *Server) registerStarter(f func() error) { // New creates instance of inner ring sever structure. // -// nolint: funlen +// nolint: funlen, gocognit func New(ctx context.Context, log *logger.Logger, cfg *viper.Viper, errChan chan<- error) (*Server, error) { var err error server := &Server{log: log} diff --git a/pkg/local_object_storage/engine/evacuate.go b/pkg/local_object_storage/engine/evacuate.go index ee04212c..4bc7eac1 100644 --- a/pkg/local_object_storage/engine/evacuate.go +++ b/pkg/local_object_storage/engine/evacuate.go @@ -58,7 +58,7 @@ var errMustHaveTwoShards = errors.New("must have at least 1 spare shard") // Evacuate moves data from one shard to the others. // The shard being moved must be in read-only mode. // -// nolint: funlen +// nolint: funlen, gocognit func (e *StorageEngine) Evacuate(prm EvacuateShardPrm) (EvacuateShardRes, error) { sidList := make([]string, len(prm.shardID)) for i := range prm.shardID { diff --git a/pkg/local_object_storage/metabase/inhume.go b/pkg/local_object_storage/metabase/inhume.go index a067a187..3f33f990 100644 --- a/pkg/local_object_storage/metabase/inhume.go +++ b/pkg/local_object_storage/metabase/inhume.go @@ -119,7 +119,7 @@ var ErrLockObjectRemoval = logicerr.New("lock object removal") // NOTE: Marks any object with GC mark (despite any prohibitions on operations // with that object) if WithForceGCMark option has been provided. // -// nolint: funlen +// nolint: funlen, gocognit func (db *DB) Inhume(prm InhumePrm) (res InhumeRes, err error) { db.modeMtx.RLock() defer db.modeMtx.RUnlock() diff --git a/pkg/local_object_storage/metabase/lock.go b/pkg/local_object_storage/metabase/lock.go index 0ecd8cfe..65f9e669 100644 --- a/pkg/local_object_storage/metabase/lock.go +++ b/pkg/local_object_storage/metabase/lock.go @@ -138,6 +138,8 @@ func objectLocked(tx *bbolt.Tx, idCnr cid.ID, idObj oid.ID) bool { // Operation is very resource-intensive, which is caused by the admissibility // of multiple locks. Also, if we knew what objects are locked, it would be // possible to speed up the execution. +// +// nolint: gocognit func freePotentialLocks(tx *bbolt.Tx, idCnr cid.ID, locker oid.ID) error { bucketLocked := tx.Bucket(bucketNameLocked) if bucketLocked != nil { diff --git a/pkg/morph/event/listener.go b/pkg/morph/event/listener.go index 17be3ea1..ed2b9502 100644 --- a/pkg/morph/event/listener.go +++ b/pkg/morph/event/listener.go @@ -191,7 +191,7 @@ func (l *listener) listen(ctx context.Context, intError chan<- error) error { return nil } -// nolint: funlen +// nolint: funlen, gocognit func (l *listener) listenLoop(ctx context.Context, chEvent <-chan *state.ContainedNotificationEvent, intErr chan<- error) { var ( blockChan <-chan *block.Block diff --git a/pkg/services/object/get/v2/util.go b/pkg/services/object/get/v2/util.go index fb8e9970..e35cece3 100644 --- a/pkg/services/object/get/v2/util.go +++ b/pkg/services/object/get/v2/util.go @@ -33,7 +33,7 @@ import ( var errWrongMessageSeq = errors.New("incorrect message sequence") -// nolint: funlen +// nolint: funlen, gocognit func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStream) (*getsvc.Prm, error) { body := req.GetBody() @@ -200,7 +200,7 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre return p, nil } -// nolint: funlen +// nolint: funlen, gocognit func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.GetObjectRangeStream) (*getsvc.RangePrm, error) { body := req.GetBody() @@ -426,7 +426,7 @@ func (w *headResponseWriter) WriteHeader(_ context.Context, hdr *object.Object) return nil } -// nolint: funlen +// nolint: funlen, gocognit func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp *objectV2.HeadResponse) (*getsvc.HeadPrm, error) { body := req.GetBody() diff --git a/pkg/services/object/search/v2/util.go b/pkg/services/object/search/v2/util.go index c15217a1..2bde6b2f 100644 --- a/pkg/services/object/search/v2/util.go +++ b/pkg/services/object/search/v2/util.go @@ -22,7 +22,7 @@ import ( oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" ) -// nolint: funlen +// nolint: funlen, gocognit func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStream) (*searchsvc.Prm, error) { body := req.GetBody() diff --git a/pkg/services/object/util/chain.go b/pkg/services/object/util/chain.go index ded63731..e6ec9363 100644 --- a/pkg/services/object/util/chain.go +++ b/pkg/services/object/util/chain.go @@ -72,7 +72,7 @@ func TraverseSplitChain(r HeadReceiver, addr oid.Address, h SplitMemberHandler) return err } -// nolint: funlen +// nolint: funlen, gocognit func traverseSplitChain(r HeadReceiver, addr oid.Address, h SplitMemberHandler) (bool, error) { v, err := r.Head(addr) if err != nil { diff --git a/pkg/services/tree/sync.go b/pkg/services/tree/sync.go index fa7cc69f..abd683b7 100644 --- a/pkg/services/tree/sync.go +++ b/pkg/services/tree/sync.go @@ -255,7 +255,7 @@ func (s *Service) SynchronizeAll() error { } } -// nolint: funlen +// nolint: funlen, gocognit func (s *Service) syncLoop(ctx context.Context) { for { select {