docker/docker

View on GitHub
daemon/containerd/image_delete.go

Summary

Maintainability
F
3 days
Test Coverage

Method ImageService.ImageDelete has a Cognitive Complexity of 66 (exceeds 20 allowed). Consider refactoring.
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)
Severity: Minor
Found in daemon/containerd/image_delete.go - About 7 hrs to fix

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 ImageService.getSameReferences has a Cognitive Complexity of 42 (exceeds 20 allowed). Consider refactoring.
Open

func (i *ImageService) getSameReferences(ctx context.Context, named reference.Named, imgs []images.Image) ([]images.Image, error) {
    var (
        tag        string
        sameRef    []images.Image
        digestRefs = []images.Image{}
Severity: Minor
Found in daemon/containerd/image_delete.go - About 3 hrs to fix

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 ImageService.ImageDelete has 109 lines of code (exceeds 50 allowed). Consider refactoring.
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)
Severity: Major
Found in daemon/containerd/image_delete.go - About 3 hrs to fix

    Method ImageService.deleteAll has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring.
    Open

    func (i *ImageService) deleteAll(ctx context.Context, imgID image.ID, all []images.Image, c conflictType, prune bool) (records []imagetypes.DeleteResponse, err error) {
        // Workaround for: https://github.com/moby/buildkit/issues/3797
        possiblyDeletedConfigs := map[digest.Digest]struct{}{}
        if len(all) > 0 && i.content != nil {
            handled := map[digest.Digest]struct{}{}
    Severity: Minor
    Found in daemon/containerd/image_delete.go - About 2 hrs to fix

    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 ImageService.ImageDelete has 16 return statements (exceeds 4 allowed).
    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)
    Severity: Major
    Found in daemon/containerd/image_delete.go - About 1 hr to fix

      Method ImageService.deleteAll has 55 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (i *ImageService) deleteAll(ctx context.Context, imgID image.ID, all []images.Image, c conflictType, prune bool) (records []imagetypes.DeleteResponse, err error) {
          // Workaround for: https://github.com/moby/buildkit/issues/3797
          possiblyDeletedConfigs := map[digest.Digest]struct{}{}
          if len(all) > 0 && i.content != nil {
              handled := map[digest.Digest]struct{}{}
      Severity: Minor
      Found in daemon/containerd/image_delete.go - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                        } else if !allTags {
                            if tagged, ok := repoRef.(reference.Tagged); ok {
                                if tag == "" {
                                    tag = tagged.Tag()
                                } else if tag != tagged.Tag() {
        Severity: Major
        Found in daemon/containerd/image_delete.go - About 45 mins to fix

          Method ImageService.imageDeleteHelper has 6 return statements (exceeds 4 allowed).
          Open

          func (i *ImageService) imageDeleteHelper(ctx context.Context, img images.Image, all []images.Image, records *[]imagetypes.DeleteResponse, extra conflictType) error {
              // First, determine if this image has any conflicts. Ignore soft conflicts
              // if force is true.
              c := conflictHard | extra
          
          
          Severity: Major
          Found in daemon/containerd/image_delete.go - About 40 mins to fix

            Method ImageService.checkImageDeleteConflict has 6 return statements (exceeds 4 allowed).
            Open

            func (i *ImageService) checkImageDeleteConflict(ctx context.Context, imgID image.ID, all []images.Image, mask conflictType) error {
                if mask&conflictRunningContainer != 0 {
                    running := func(c *container.Container) bool {
                        return c.ImageID == imgID && c.IsRunning()
                    }
            Severity: Major
            Found in daemon/containerd/image_delete.go - About 40 mins to fix

              Method ImageService.imageDeleteHelper has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              func (i *ImageService) imageDeleteHelper(ctx context.Context, img images.Image, all []images.Image, records *[]imagetypes.DeleteResponse, extra conflictType) error {
              Severity: Minor
              Found in daemon/containerd/image_delete.go - About 35 mins to fix

                Method ImageService.deleteAll has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                func (i *ImageService) deleteAll(ctx context.Context, imgID image.ID, all []images.Image, c conflictType, prune bool) (records []imagetypes.DeleteResponse, err error) {
                Severity: Minor
                Found in daemon/containerd/image_delete.go - About 35 mins to fix

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                          if len(sameRef) != len(all) {
                              var records []imagetypes.DeleteResponse
                              for _, ref := range sameRef {
                                  // TODO: Add with target
                                  err := i.images.Delete(ctx, ref.Name)
                  Severity: Major
                  Found in daemon/containerd/image_delete.go and 1 other location - About 1 hr to fix
                  daemon/containerd/image_delete.go on lines 101..116

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 149.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                          if named != nil && len(sameRef) > 0 && len(sameRef) != len(all) {
                              var records []imagetypes.DeleteResponse
                              for _, ref := range sameRef {
                                  // TODO: Add with target
                                  err := i.images.Delete(ctx, ref.Name)
                  Severity: Major
                  Found in daemon/containerd/image_delete.go and 1 other location - About 1 hr to fix
                  daemon/containerd/image_delete.go on lines 132..152

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 149.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  There are no issues that match your filters.

                  Category
                  Status