Showing 1,468 of 1,914 total issues
Function parseUintList
has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring. Open
Open
func parseUintList(val string, maximum int) (map[int]bool, error) {
if val == "" {
return map[int]bool{}, nil
}
- 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 cnmNetworkAllocator.AllocateService
has 64 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (na *cnmNetworkAllocator) AllocateService(s *api.Service) (err error) {
defer func() {
if err != nil {
na.DeallocateService(s)
}
Function dispatch
has 64 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func dispatch(ctx context.Context, d dispatchRequest, cmd instructions.Command) (err error) {
if c, ok := cmd.(instructions.PlatformSpecific); ok {
err := c.CheckPlatform(d.state.operatingSystem)
if err != nil {
return errdefs.InvalidParameter(err)
Method cacheAdaptor.Get
has 64 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (c cacheAdaptor) Get(id image.ID) (*image.Image, error) {
ctx := context.TODO()
ref := id.String()
outImg, err := c.is.GetImage(ctx, id.String(), backend.GetImageOpts{})
Method ImageService.resolveImage
has 64 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (i *ImageService) resolveImage(ctx context.Context, refOrID string) (containerdimages.Image, error) {
parsed, err := reference.ParseAnyReference(refOrID)
if err != nil {
return containerdimages.Image{}, errdefs.InvalidParameter(err)
}
Method splunkLogger.tryPostMessages
has 64 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (l *splunkLogger) tryPostMessages(ctx context.Context, messages []*splunkMessage) error {
if len(messages) == 0 {
return nil
}
var buffer bytes.Buffer
Method Plugin.Set
has 63 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (p *Plugin) Set(args []string) error {
p.mu.Lock()
defer p.mu.Unlock()
if p.PluginObj.Enabled {
Method RestartManager.ShouldRestart
has 63 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (rm *RestartManager) ShouldRestart(exitCode uint32, hasBeenManuallyStopped bool, executionDuration time.Duration) (bool, chan error, error) {
if rm.policy.IsNone() {
return false, nil, nil
}
rm.Lock()
Method Daemon.ContainerAttach
has 63 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (daemon *Daemon) ContainerAttach(prefixOrName string, req *backend.ContainerAttachConfig) error {
keys := []byte{}
var err error
if req.DetachKeys != "" {
keys, err = term.ToBytes(req.DetachKeys)
Method CompoundMessage.Unmarshal
has 16 return statements (exceeds 4 allowed). Open
Open
func (m *CompoundMessage) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
Method driver.CreateEndpoint
has 16 return statements (exceeds 4 allowed). Open
Open
func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error {
var err error
if err = validateID(nid, eid); err != nil {
return err
}
Method containerRouter.postContainersCreate
has 16 return statements (exceeds 4 allowed). Open
Open
func (c *containerRouter) postContainersCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := httputils.ParseForm(r); err != nil {
return err
}
if err := httputils.CheckForJSON(r); err != nil {
Method ImageService.ImageDelete
has 16 return statements (exceeds 4 allowed). Open
Open
func (i *ImageService) ImageDelete(ctx context.Context, imageRef string, force, prune bool) (response []imagetypes.DeleteResponse, retErr error) {
start := time.Now()
defer func() {
if retErr == nil {
dimages.ImageActions.WithValues("delete").UpdateSince(start)
Method Cluster.Init
has 16 return statements (exceeds 4 allowed). Open
Open
func (c *Cluster) Init(req types.InitRequest) (string, error) {
c.controlMutex.Lock()
defer c.controlMutex.Unlock()
if c.nr != nil {
if req.ForceNewCluster {
Method Daemon.connectToNetwork
has 16 return statements (exceeds 4 allowed). Open
Open
func (daemon *Daemon) connectToNetwork(ctx context.Context, cfg *config.Config, ctr *container.Container, idOrName string, endpointConfig *network.EndpointSettings, updateSettings bool) (retErr error) {
containerName := strings.TrimPrefix(ctr.Name, "/")
ctx, span := otel.Tracer("").Start(ctx, "daemon.connectToNetwork", trace.WithAttributes(
attribute.String("container.ID", ctr.ID),
attribute.String("container.name", containerName),
Function newRepository
has 62 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func newRepository(
ctx context.Context, repoInfo *registry.RepositoryInfo, endpoint registry.APIEndpoint,
metaHeaders http.Header, authConfig *registrytypes.AuthConfig, actions ...string,
) (distribution.Repository, error) {
repoName := repoInfo.Name.Name()
Method Network.Services
has 62 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (n *Network) Services() map[string]ServiceInfo {
agent, ok := n.clusterAgent()
if !ok {
return nil
}
Method Controller.rmServiceBinding
has 62 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (c *Controller) rmServiceBinding(svcName, svcID, nID, eID, containerName string, vip net.IP, ingressPorts []*PortConfig, serviceAliases []string, taskAliases []string, ip net.IP, method string, deleteSvcRecords bool, fullRemove bool) error {
var rmService bool
skey := serviceKey{
id: svcID,
Method driver.link
has 62 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (d *driver) link(network *bridgeNetwork, endpoint *bridgeEndpoint, enable bool) (retErr error) {
cc := endpoint.containerConfig
ec := endpoint.extConnConfig
if cc == nil || ec == nil || (len(cc.ParentEndpoints) == 0 && len(cc.ChildEndpoints) == 0) {
// nothing to do
Function monitor
has 62 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func monitor(d *Daemon, c *container.Container, stop chan struct{}, probe probe) {
probeInterval := timeoutWithDefault(c.Config.Healthcheck.Interval, defaultProbeInterval)
startInterval := timeoutWithDefault(c.Config.Healthcheck.StartInterval, defaultStartInterval)
startPeriod := timeoutWithDefault(c.Config.Healthcheck.StartPeriod, defaultStartPeriod)