Showing 1,008 of 1,820 total issues
Avoid deeply nested control flow statements. Open
Open
if oldTask, exists := tasksMap[v.Task.ID]; exists {
// States ASSIGNED and below are set by the orchestrator/scheduler,
// not the agent, so tasks in these states need to be sent to the
// agent even if nothing else has changed.
if equality.TasksEqualStable(oldTask, v.Task) && v.Task.Status.State > api.TaskStateAssigned {
Function validateIPAMConfiguration
has 7 return statements (exceeds 4 allowed). Open
Open
func validateIPAMConfiguration(ipamConf *api.IPAMConfig) error {
if ipamConf == nil {
return status.Errorf(codes.InvalidArgument, "ipam configuration: cannot be empty")
}
Avoid deeply nested control flow statements. Open
Open
if assignments.addOrUpdateTask(readTx, v.Task) {
oneModification()
}
Avoid deeply nested control flow statements. Open
Open
if time.Since(debouncingStarted) > maxLatency {
commitDebounceTimer.Stop()
commitDebounceTimer = nil
commitDebounceTimeout = nil
schedule()
Method Server.Watch
has 7 return statements (exceeds 4 allowed). Open
Open
func (s *Server) Watch(request *api.WatchRequest, stream api.Watch_WatchServer) error {
ctx := stream.Context()
s.mu.Lock()
pctx := s.pctx
Avoid deeply nested control flow statements. Open
Open
if atomic.LoadUint32(&n.signalledLeadership) == 1 {
atomic.StoreUint32(&n.signalledLeadership, 0)
n.leadershipBroadcast.Publish(IsFollower)
}
Avoid deeply nested control flow statements. Open
Open
} else if !wasLeader && rd.SoftState.RaftState == raft.StateLeader {
// Node just became a leader.
wasLeader = true
}
Function AtomicWriteFile
has 7 return statements (exceeds 4 allowed). Open
Open
func AtomicWriteFile(filename string, data []byte, perm os.FileMode) error {
f, err := os.CreateTemp(filepath.Dir(filename), ".tmp-"+filepath.Base(filename))
if err != nil {
return err
}
Method ResourceAllocator.DetachNetwork
has 7 return statements (exceeds 4 allowed). Open
Open
func (ra *ResourceAllocator) DetachNetwork(ctx context.Context, request *api.DetachNetworkRequest) (*api.DetachNetworkResponse, error) {
if request.AttachmentID == "" {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
}
Method Transport.Send
has 7 return statements (exceeds 4 allowed). Open
Open
func (t *Transport) Send(m raftpb.Message) error {
t.mu.Lock()
defer t.mu.Unlock()
if t.stopped {
return errors.New("transport stopped")
Method Node.reportNewAddress
has 7 return statements (exceeds 4 allowed). Open
Open
func (n *Node) reportNewAddress(ctx context.Context, id uint64) error {
// too early
if !n.IsMember() {
return nil
}
Method peer.sendProcessMessage
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. Open
Open
func (p *peer) sendProcessMessage(ctx context.Context, m raftpb.Message) error {
// These lines used to be in the code, but they've been removed. I'm
// leaving them in in a comment just in case they cause some unforeseen
// breakage later, to show why they were removed.
//
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
Open
if err := a.commitAllocatedNetwork(ctx, batch, nc.ingressNetwork); err != nil {
log.G(ctx).WithError(err).Error("failed committing allocation of ingress network during init")
}
Avoid deeply nested control flow statements. Open
Open
select {
case <-commitGuard:
memDBTx.Commit()
default:
// Already Abort()ed.
Function CheckValuesOnNodes
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. Open
Open
func CheckValuesOnNodes(t *testing.T, clockSource *fakeclock.FakeClock, checkNodes map[uint64]*TestNode, ids []string, values []*api.Node) {
iteration := 0
for checkNodeID, node := range checkNodes {
assert.NoError(t, testutils.PollFunc(clockSource, func() error {
var err error
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method Node.registerNode
has 7 return statements (exceeds 4 allowed). Open
Open
func (n *Node) registerNode(node *api.RaftMember) error {
if n.cluster.IsIDRemoved(node.RaftID) {
return nil
}
Method Node.ProcessRaftMessage
has 7 return statements (exceeds 4 allowed). Open
Open
func (n *Node) ProcessRaftMessage(ctx context.Context, msg *api.ProcessRaftMessageRequest) (*api.ProcessRaftMessageResponse, error) {
if msg == nil || msg.Message == nil {
n.processRaftMessageLogger(ctx, msg).Debug("received empty message")
return &api.ProcessRaftMessageResponse{}, nil
}
Method session.sendTaskStatuses
has 6 return statements (exceeds 4 allowed). Open
Open
func (s *session) sendTaskStatuses(ctx context.Context, updates ...*api.UpdateTaskStatusRequest_TaskStatusUpdate) ([]*api.UpdateTaskStatusRequest_TaskStatusUpdate, error) {
if len(updates) < 1 {
return nil, nil
}
Method session.logSubscriptions
has 6 return statements (exceeds 4 allowed). Open
Open
func (s *session) logSubscriptions(ctx context.Context) error {
logger := log.G(ctx).WithFields(log.Fields{"method": "(*session).logSubscriptions"})
logger.Debugf("")
client := api.NewLogBrokerClient(s.conn.ClientConn)
Method session.watch
has 6 return statements (exceeds 4 allowed). Open
Open
func (s *session) watch(ctx context.Context) error {
logger := log.G(ctx).WithFields(log.Fields{"method": "(*session).watch"})
logger.Debugf("")
var (
resp *api.AssignmentsMessage