Showing 1,008 of 1,820 total issues
Method Scheduler.updateTask
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. Open
func (s *Scheduler) updateTask(ctx context.Context, t *api.Task) bool {
// Ignore all tasks that have not reached PENDING
// state.
if t.Status.State < api.TaskStatePending {
return false
- 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
Function watchNode
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
func watchNode(t *testing.T, watch chan events.Event, expectTimeout bool,
fn func(t assert.TestingT, originalNode, updatedNode *api.Node, networks []string) bool,
originalNode *api.Node,
networks []string) {
Function validateIPAMConfiguration
has 7 return statements (exceeds 4 allowed). Open
func validateIPAMConfiguration(ipamConf *api.IPAMConfig) error {
if ipamConf == nil {
return status.Errorf(codes.InvalidArgument, "ipam configuration: cannot be empty")
}
Function validateServiceSpec
has 7 return statements (exceeds 4 allowed). Open
func validateServiceSpec(spec *api.ServiceSpec) error {
if spec == nil {
return status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
}
if err := validateAnnotations(spec.Annotations); err != nil {
Avoid deeply nested control flow statements. Open
if status.NodeID == nodeID {
if assignments.addOrUpdateVolume(readTx, vol) {
oneModification()
}
}
Avoid deeply nested control flow statements. Open
if atomic.LoadUint32(&n.signalledLeadership) == 1 {
atomic.StoreUint32(&n.signalledLeadership, 0)
n.leadershipBroadcast.Publish(IsFollower)
}
Method Node.reportNewAddress
has 7 return statements (exceeds 4 allowed). Open
func (n *Node) reportNewAddress(ctx context.Context, id uint64) error {
// too early
if !n.IsMember() {
return nil
}
Avoid deeply nested control flow statements. Open
select {
case <-commitGuard:
memDBTx.Commit()
default:
// Already Abort()ed.
Function AtomicWriteFile
has 7 return statements (exceeds 4 allowed). 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 Node.registerNode
has 7 return statements (exceeds 4 allowed). Open
func (n *Node) registerNode(node *api.RaftMember) error {
if n.cluster.IsIDRemoved(node.RaftID) {
return nil
}
Method ResourceAllocator.DetachNetwork
has 7 return statements (exceeds 4 allowed). 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())
}
Function CheckValuesOnNodes
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. 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
Avoid deeply nested control flow statements. 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")
}
Method Node.ProcessRaftMessage
has 7 return statements (exceeds 4 allowed). 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
}
Avoid deeply nested control flow statements. Open
} else if !wasLeader && rd.SoftState.RaftState == raft.StateLeader {
// Node just became a leader.
wasLeader = true
}
Method Transport.Send
has 7 return statements (exceeds 4 allowed). 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 peer.sendProcessMessage
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. 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
Method session.logSubscriptions
has 6 return statements (exceeds 4 allowed). 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)
Function parsePortConfig
has 6 return statements (exceeds 4 allowed). Open
func parsePortConfig(portConfig string) (string, api.PortConfig_Protocol, uint32, uint32, error) {
protocol := api.ProtocolTCP
parts := strings.Split(portConfig, ":")
if len(parts) < 2 {
return "", protocol, 0, 0, errors.New("insufficient parameters in port configuration")
Function ParseAddSecret
has 6 return statements (exceeds 4 allowed). Open
func ParseAddSecret(cmd *cobra.Command, spec *api.ServiceSpec, flagName string) error {
flags := cmd.Flags()
if flags.Changed(flagName) {
secrets, err := flags.GetStringSlice(flagName)