[#148] linter: Add gocognit linter

Code with high cognitive complexity is hard intuitively to understand

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-03-20 10:18:24 +03:00
parent 97c36ed3ec
commit 481a1ca6f3
11 changed files with 18 additions and 13 deletions

View file

@ -27,8 +27,10 @@ linters-settings:
staticcheck: staticcheck:
checks: ["all", "-SA1019"] # TODO Enable SA1019 after deprecated warning are fixed. checks: ["all", "-SA1019"] # TODO Enable SA1019 after deprecated warning are fixed.
funlen: funlen:
lines: 80 lines: 80 # default 60
statements: 60 statements: 60 # default 40
gocognit:
min-complexity: 40 # default 30
linters: linters:
enable: enable:
@ -58,5 +60,6 @@ linters:
- whitespace - whitespace
- containedctx - containedctx
- funlen - funlen
- gocognit
disable-all: true disable-all: true
fast: false fast: false

View file

@ -44,7 +44,7 @@ const (
notaryEnabled = true notaryEnabled = true
) )
// nolint: funlen // nolint: funlen, gocognit
func dumpBalances(cmd *cobra.Command, _ []string) error { func dumpBalances(cmd *cobra.Command, _ []string) error {
var ( var (
dumpStorage, _ = cmd.Flags().GetBool(dumpBalancesStorageFlag) dumpStorage, _ = cmd.Flags().GetBool(dumpBalancesStorageFlag)

View file

@ -322,7 +322,7 @@ func (s *Server) registerStarter(f func() error) {
// New creates instance of inner ring sever structure. // 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) { func New(ctx context.Context, log *logger.Logger, cfg *viper.Viper, errChan chan<- error) (*Server, error) {
var err error var err error
server := &Server{log: log} server := &Server{log: log}

View file

@ -58,7 +58,7 @@ var errMustHaveTwoShards = errors.New("must have at least 1 spare shard")
// Evacuate moves data from one shard to the others. // Evacuate moves data from one shard to the others.
// The shard being moved must be in read-only mode. // The shard being moved must be in read-only mode.
// //
// nolint: funlen // nolint: funlen, gocognit
func (e *StorageEngine) Evacuate(prm EvacuateShardPrm) (EvacuateShardRes, error) { func (e *StorageEngine) Evacuate(prm EvacuateShardPrm) (EvacuateShardRes, error) {
sidList := make([]string, len(prm.shardID)) sidList := make([]string, len(prm.shardID))
for i := range prm.shardID { for i := range prm.shardID {

View file

@ -119,7 +119,7 @@ var ErrLockObjectRemoval = logicerr.New("lock object removal")
// NOTE: Marks any object with GC mark (despite any prohibitions on operations // NOTE: Marks any object with GC mark (despite any prohibitions on operations
// with that object) if WithForceGCMark option has been provided. // with that object) if WithForceGCMark option has been provided.
// //
// nolint: funlen // nolint: funlen, gocognit
func (db *DB) Inhume(prm InhumePrm) (res InhumeRes, err error) { func (db *DB) Inhume(prm InhumePrm) (res InhumeRes, err error) {
db.modeMtx.RLock() db.modeMtx.RLock()
defer db.modeMtx.RUnlock() defer db.modeMtx.RUnlock()

View file

@ -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 // 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 // of multiple locks. Also, if we knew what objects are locked, it would be
// possible to speed up the execution. // possible to speed up the execution.
//
// nolint: gocognit
func freePotentialLocks(tx *bbolt.Tx, idCnr cid.ID, locker oid.ID) error { func freePotentialLocks(tx *bbolt.Tx, idCnr cid.ID, locker oid.ID) error {
bucketLocked := tx.Bucket(bucketNameLocked) bucketLocked := tx.Bucket(bucketNameLocked)
if bucketLocked != nil { if bucketLocked != nil {

View file

@ -191,7 +191,7 @@ func (l *listener) listen(ctx context.Context, intError chan<- error) error {
return nil return nil
} }
// nolint: funlen // nolint: funlen, gocognit
func (l *listener) listenLoop(ctx context.Context, chEvent <-chan *state.ContainedNotificationEvent, intErr chan<- error) { func (l *listener) listenLoop(ctx context.Context, chEvent <-chan *state.ContainedNotificationEvent, intErr chan<- error) {
var ( var (
blockChan <-chan *block.Block blockChan <-chan *block.Block

View file

@ -33,7 +33,7 @@ import (
var errWrongMessageSeq = errors.New("incorrect message sequence") 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) { func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStream) (*getsvc.Prm, error) {
body := req.GetBody() body := req.GetBody()
@ -200,7 +200,7 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre
return p, nil return p, nil
} }
// nolint: funlen // nolint: funlen, gocognit
func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.GetObjectRangeStream) (*getsvc.RangePrm, error) { func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.GetObjectRangeStream) (*getsvc.RangePrm, error) {
body := req.GetBody() body := req.GetBody()
@ -426,7 +426,7 @@ func (w *headResponseWriter) WriteHeader(_ context.Context, hdr *object.Object)
return nil return nil
} }
// nolint: funlen // nolint: funlen, gocognit
func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp *objectV2.HeadResponse) (*getsvc.HeadPrm, error) { func (s *Service) toHeadPrm(ctx context.Context, req *objectV2.HeadRequest, resp *objectV2.HeadResponse) (*getsvc.HeadPrm, error) {
body := req.GetBody() body := req.GetBody()

View file

@ -22,7 +22,7 @@ import (
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" 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) { func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStream) (*searchsvc.Prm, error) {
body := req.GetBody() body := req.GetBody()

View file

@ -72,7 +72,7 @@ func TraverseSplitChain(r HeadReceiver, addr oid.Address, h SplitMemberHandler)
return err return err
} }
// nolint: funlen // nolint: funlen, gocognit
func traverseSplitChain(r HeadReceiver, addr oid.Address, h SplitMemberHandler) (bool, error) { func traverseSplitChain(r HeadReceiver, addr oid.Address, h SplitMemberHandler) (bool, error) {
v, err := r.Head(addr) v, err := r.Head(addr)
if err != nil { if err != nil {

View file

@ -255,7 +255,7 @@ func (s *Service) SynchronizeAll() error {
} }
} }
// nolint: funlen // nolint: funlen, gocognit
func (s *Service) syncLoop(ctx context.Context) { func (s *Service) syncLoop(ctx context.Context) {
for { for {
select { select {