Showing 1,820 of 1,820 total issues
Method Agent.Leave
has 5 return statements (exceeds 4 allowed). Open
func (a *Agent) Leave(ctx context.Context) error {
select {
case <-a.started:
default:
return errAgentNotStarted
Method nodePlugin.NodeStageVolume
has 5 return statements (exceeds 4 allowed). Open
func (np *nodePlugin) NodeStageVolume(ctx context.Context, req *api.VolumeAssignment) error {
np.mu.Lock()
defer np.mu.Unlock()
if !np.staging {
return nil
Method PayloadContext.secretGetter
has 5 return statements (exceeds 4 allowed). Open
func (ctx *PayloadContext) secretGetter(target string) (string, error) {
if ctx.restrictedSecrets == nil {
return "", errors.New("secrets unavailable")
}
Function loadData
has 5 return statements (exceeds 4 allowed). Open
func loadData(swarmdir, unlockKey string) (*storage.WALData, *raftpb.Snapshot, error) {
snapDir := filepath.Join(swarmdir, "raft", "snap-v3-encrypted")
walDir := filepath.Join(swarmdir, "raft", "wal-v3-encrypted")
var (
Function GetNetwork
has 5 return statements (exceeds 4 allowed). Open
func GetNetwork(ctx context.Context, c api.ControlClient, input string) (*api.Network, error) {
// GetService to match via full ID.
rg, err := c.GetNetwork(ctx, &api.GetNetworkRequest{NetworkID: input})
if err != nil {
// If any error (including NotFound), ListServices to match via full name.
Method Network.MarshalToSizedBuffer
has 5 return statements (exceeds 4 allowed). Open
func (m *Network) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
Method Node.MarshalToSizedBuffer
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
func (m *Node) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
- 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 Volume.MarshalToSizedBuffer
has 5 return statements (exceeds 4 allowed). Open
func (m *Volume) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
Method NetworkSpec.MarshalToSizedBuffer
has 5 return statements (exceeds 4 allowed). Open
func (m *NetworkSpec) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
Function GetAndValidateCertificateSubject
has 5 return statements (exceeds 4 allowed). Open
func GetAndValidateCertificateSubject(certs []tls.Certificate) (pkix.Name, error) {
for i := range certs {
cert := &certs[i]
x509Cert, err := x509.ParseCertificate(cert.Certificate[0])
if err != nil {
Method ConstraintEnforcer.rejectNoncompliantTasks
has 5 return statements (exceeds 4 allowed). Open
func (ce *ConstraintEnforcer) rejectNoncompliantTasks(node *api.Node) {
// If the availability is "drain", the orchestrator will
// shut down all tasks.
// If the availability is "pause", we shouldn't touch
// the tasks on this node.
Method tasksByCreationTimestamp.Less
has 5 return statements (exceeds 4 allowed). Open
func (t tasksByCreationTimestamp) Less(i, j int) bool {
if t[i].Meta.CreatedAt == nil {
return true
}
if t[j].Meta.CreatedAt == nil {
Method Orchestrator.Run
has 5 return statements (exceeds 4 allowed). Open
func (r *Orchestrator) Run(ctx context.Context) error {
defer close(r.doneChan)
// Watch changes to services and tasks
queue := r.store.WatchQueue()
Method Supervisor.waitRestart
has 5 return statements (exceeds 4 allowed). Open
func (r *Supervisor) waitRestart(ctx context.Context, oldDelay *delayedStart, cluster *api.Cluster, taskID string) {
// Wait for the last restart delay to elapse.
select {
case <-oldDelay.doneCh:
case <-ctx.Done():
Method Server.UpdateRootCA
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
func (s *Server) UpdateRootCA(ctx context.Context, cluster *api.Cluster, reconciler *rootRotationReconciler) error {
s.mu.Lock()
s.joinTokens = cluster.RootCA.JoinTokens.Copy()
s.mu.Unlock()
rCA := cluster.RootCA.Copy()
- 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 ConvertToECPrivateKeyPEM
has 5 return statements (exceeds 4 allowed). Open
func ConvertToECPrivateKeyPEM(inPEM []byte) ([]byte, error) {
block, _ := pem.Decode(inPEM)
if block == nil {
return nil, errors.New("invalid pem bytes")
}
Method Updater.useExistingTask
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
func (u *Updater) useExistingTask(ctx context.Context, slot orchestrator.Slot, existing *api.Task) error {
var removeTasks []*api.Task
for _, t := range slot {
if t != existing {
removeTasks = append(removeTasks, t)
- 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 ConvertECPrivateKeyPEM
has 5 return statements (exceeds 4 allowed). Open
func ConvertECPrivateKeyPEM(inPEM []byte) ([]byte, error) {
block, _ := pem.Decode(inPEM)
if block == nil {
return nil, errors.New("invalid pem bytes")
}
Method SecurityConfig.updateTLSCredentials
has 5 return statements (exceeds 4 allowed). Open
func (s *SecurityConfig) updateTLSCredentials(certificate *tls.Certificate, issuerInfo *IssuerInfo) error {
certs := []tls.Certificate{*certificate}
clientConfig, err := NewClientTLSConfig(certs, s.rootCA.Pool, ManagerRole)
if err != nil {
return errors.Wrap(err, "failed to create a new client config using the new root CA")
Function DownloadRootCA
has 5 return statements (exceeds 4 allowed). Open
func DownloadRootCA(ctx context.Context, paths CertPaths, token string, connBroker *connectionbroker.Broker) (RootCA, error) {
var rootCA RootCA
// Get a digest for the optional CA hash string that we've been provided
// If we were provided a non-empty string, and it is an invalid hash, return
// otherwise, allow the invalid digest through.