[#148] linter: Add gocognit linter

Code with high cognitive complexity is hard intuitively to understand

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
pull/148/head
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:
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

View File

@ -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)

View File

@ -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}

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.
// 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 {

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
// 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()

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
// 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 {

View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -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 {

View File

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