ARM-software/golang-utils

View on GitHub
utils/filesystem/files.go

Summary

Maintainability
F
3 days
Test Coverage

File files.go has 1695 lines of code (exceeds 1000 allowed). Consider refactoring.
Wontfix

/*
 * Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

Severity: Major
Found in utils/filesystem/files.go - About 2 days to fix

    Method VFS.walk has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    func (fs *VFS) walk(ctx context.Context, path string, info os.FileInfo, exclusions []*regexp.Regexp, fn filepath.WalkFunc) (err error) {
        err = fs.checkWhetherUnderlyingResourceIsClosed()
        if err != nil {
            return
        }
    Severity: Minor
    Found in utils/filesystem/files.go - About 4 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

    Function CopyBetweenFSWithExclusionRegexes has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    func CopyBetweenFSWithExclusionRegexes(ctx context.Context, srcFs FS, src string, destFs FS, dest string, exclusionSrcFsRegexes []*regexp.Regexp, exclusionDestFsRegexes []*regexp.Regexp) (err error) {
        if IsPathExcluded(src, exclusionSrcFsRegexes...) || IsPathExcluded(dest, exclusionDestFsRegexes...) {
            return
        }
        err = parallelisation.DetermineContextError(ctx)
    Severity: Minor
    Found in utils/filesystem/files.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

    VFS has 101 methods (exceeds 100 allowed). Consider refactoring.
    Open

    type VFS struct {
        resourceInUse resource.ICloseableResource
        vfs           afero.Fs
        fsType        FilesystemType
        pathConverter func(path string) string
    Severity: Major
    Found in utils/filesystem/files.go - About 2 hrs to fix

      Method VFS.moveFolder has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      func (fs *VFS) moveFolder(ctx context.Context, src string, dest string) (err error) {
          err = fs.checkWhetherUnderlyingResourceIsClosed()
          if err != nil {
              return
          }
      Severity: Minor
      Found in utils/filesystem/files.go - About 1 hr 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

      Function copyFolderBetweenFSWithExclusionRegexes has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      func copyFolderBetweenFSWithExclusionRegexes(ctx context.Context, srcFs FS, src string, destFs FS, dest string, exclusionSrcFsRegexes []*regexp.Regexp, exclusionDestFsRegexes []*regexp.Regexp) (err error) {
          if IsPathExcluded(src, exclusionSrcFsRegexes...) || IsPathExcluded(dest, exclusionDestFsRegexes...) {
              return
          }
          err = parallelisation.DetermineContextError(ctx)
      Severity: Minor
      Found in utils/filesystem/files.go - About 1 hr 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 VFS.RemoveWithContextAndExclusionPatterns has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      func (fs *VFS) RemoveWithContextAndExclusionPatterns(ctx context.Context, dir string, exclusionPatterns ...string) (err error) {
          err = fs.checkWhetherUnderlyingResourceIsClosed()
          if err != nil {
              return
          }
      Severity: Minor
      Found in utils/filesystem/files.go - About 1 hr 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 VFS.garbageCollectDir has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      func (fs *VFS) garbageCollectDir(ctx context.Context, durationSinceLastAccess time.Duration, path string, deletePath bool) (err error) {
          err = fs.checkWhetherUnderlyingResourceIsClosed()
          if err != nil {
              return
          }
      Severity: Minor
      Found in utils/filesystem/files.go - About 1 hr 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

      Function ListDirTreeWithContextAndExclusionPatterns has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      func ListDirTreeWithContextAndExclusionPatterns(ctx context.Context, fs FS, dirPath string, list *[]string, regexes []*regexp.Regexp) (err error) {
          err = parallelisation.DetermineContextError(ctx)
          if err != nil {
              return
          }
      Severity: Minor
      Found in utils/filesystem/files.go - About 1 hr 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 VFS.ReadFileContent has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      func (fs *VFS) ReadFileContent(ctx context.Context, file File, limits ILimits) (content []byte, err error) {
          err = fs.checkWhetherUnderlyingResourceIsClosed()
          if err != nil {
              return
          }
      Severity: Minor
      Found in utils/filesystem/files.go - About 1 hr 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

      Function CopyBetweenFSWithExclusionRegexes has 54 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func CopyBetweenFSWithExclusionRegexes(ctx context.Context, srcFs FS, src string, destFs FS, dest string, exclusionSrcFsRegexes []*regexp.Regexp, exclusionDestFsRegexes []*regexp.Regexp) (err error) {
          if IsPathExcluded(src, exclusionSrcFsRegexes...) || IsPathExcluded(dest, exclusionDestFsRegexes...) {
              return
          }
          err = parallelisation.DetermineContextError(ctx)
      Severity: Minor
      Found in utils/filesystem/files.go - About 1 hr to fix

        Method VFS.CopyToFileWithContext has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        func (fs *VFS) CopyToFileWithContext(ctx context.Context, src string, dest string) (err error) {
            err = fs.checkWhetherUnderlyingResourceIsClosed()
            if err != nil {
                return
            }
        Severity: Minor
        Found in utils/filesystem/files.go - About 1 hr 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 VFS.CleanDirWithContextAndExclusionPatterns has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        func (fs *VFS) CleanDirWithContextAndExclusionPatterns(ctx context.Context, dir string, exclusionPatterns ...string) (err error) {
            err = fs.checkWhetherUnderlyingResourceIsClosed()
            if err != nil {
                return
            }
        Severity: Minor
        Found in utils/filesystem/files.go - About 1 hr 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 VFS.SubDirectoriesWithContextAndExclusionPatterns has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        func (fs *VFS) SubDirectoriesWithContextAndExclusionPatterns(ctx context.Context, directory string, exclusionPatterns ...string) (directories []string, err error) {
            err = fs.checkWhetherUnderlyingResourceIsClosed()
            if err != nil {
                return
            }
        Severity: Minor
        Found in utils/filesystem/files.go - About 1 hr 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 VFS.walk has 51 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (fs *VFS) walk(ctx context.Context, path string, info os.FileInfo, exclusions []*regexp.Regexp, fn filepath.WalkFunc) (err error) {
            err = fs.checkWhetherUnderlyingResourceIsClosed()
            if err != nil {
                return
            }
        Severity: Minor
        Found in utils/filesystem/files.go - About 1 hr to fix

          Method VFS.MoveWithContext has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          func (fs *VFS) MoveWithContext(ctx context.Context, src string, dest string) (err error) {
              err = fs.checkWhetherUnderlyingResourceIsClosed()
              if err != nil {
                  return
              }
          Severity: Minor
          Found in utils/filesystem/files.go - About 55 mins 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

          Function copyFileBetweenFSWithExclusionPatternsWithExclusionRegexes has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          func copyFileBetweenFSWithExclusionPatternsWithExclusionRegexes(ctx context.Context, srcFs FS, src string, destFs FS, dest string, exclusionSrcFsRegexes []*regexp.Regexp, exclusionDestFsRegexes []*regexp.Regexp) (err error) {
              if IsPathExcluded(src, exclusionSrcFsRegexes...) || IsPathExcluded(dest, exclusionDestFsRegexes...) {
                  return
              }
              err = parallelisation.DetermineContextError(ctx)
          Severity: Minor
          Found in utils/filesystem/files.go - About 45 mins 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 VFS.WalkWithContextAndExclusionPatterns has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          func (fs *VFS) WalkWithContextAndExclusionPatterns(ctx context.Context, root string, fn filepath.WalkFunc, exclusionPatterns ...string) (err error) {
              err = fs.checkWhetherUnderlyingResourceIsClosed()
              if err != nil {
                  return
              }
          Severity: Minor
          Found in utils/filesystem/files.go - About 25 mins 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 VFS.RemoveWithPrivileges has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          func (fs *VFS) RemoveWithPrivileges(ctx context.Context, dir string) (err error) {
              err = fs.RemoveWithContext(ctx, dir)
              if commonerrors.Any(err, nil, commonerrors.ErrTimeout, commonerrors.ErrCancelled) {
                  return
              }
          Severity: Minor
          Found in utils/filesystem/files.go - About 25 mins 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 VFS.isDirEmpty has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          func (fs *VFS) isDirEmpty(name string) (empty bool, err error) {
              err = fs.checkWhetherUnderlyingResourceIsClosed()
              if err != nil {
                  return
              }
          Severity: Minor
          Found in utils/filesystem/files.go - About 25 mins 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

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

          func (fs *VFS) GenericOpen(name string) (File, error) {
              err := fs.checkWhetherUnderlyingResourceIsClosed()
              if err != nil {
                  return nil, err
              }
          Severity: Minor
          Found in utils/filesystem/files.go and 1 other location - About 50 mins to fix
          utils/filesystem/files.go on lines 279..285

          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 119.

          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

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

          func (fs *VFS) CreateFile(name string) (File, error) {
              err := fs.checkWhetherUnderlyingResourceIsClosed()
              if err != nil {
                  return nil, err
              }
          Severity: Minor
          Found in utils/filesystem/files.go and 1 other location - About 50 mins to fix
          utils/filesystem/files.go on lines 256..262

          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 119.

          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

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

          func (fs *VFS) IsFile(path string) (result bool, err error) {
              err = fs.checkWhetherUnderlyingResourceIsClosed()
              if err != nil {
                  return
              }
          Severity: Minor
          Found in utils/filesystem/files.go and 1 other location - About 45 mins to fix
          utils/filesystem/files.go on lines 727..741

          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 113.

          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

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

          func (fs *VFS) IsLink(path string) (result bool, err error) {
              err = fs.checkWhetherUnderlyingResourceIsClosed()
              if err != nil {
                  return
              }
          Severity: Minor
          Found in utils/filesystem/files.go and 1 other location - About 45 mins to fix
          utils/filesystem/files.go on lines 704..718

          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 113.

          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