ARM-software/golang-utils

View on GitHub

Showing 78 of 97 total issues

File iconv.go has 1670 lines of code (exceeds 1000 allowed). Consider refactoring.
Open

/*
 * Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
 * SPDX-License-Identifier: Apache-2.0
 */
package charsetaliases
Severity: Major
Found in utils/charset/charsetaliases/iconv.go - About 2 days to fix

    Function initialiseMapping has 380 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func initialiseMapping() {
        mappingOnce.Do(func() {
            // This mapping list was created based on the following indexes:
            // - https://www.iana.org/assignments/character-sets/character-sets.xhtml
            // - https://encoding.spec.whatwg.org/encodings.json
    Severity: Major
    Found in utils/charset/mapping.go - About 1 day to fix

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

      func (fs *VFS) unzip(ctx context.Context, source string, destination string, limits ILimits, currentDepth int64) (fileList []string, fileOnDiskCount uint64, sizeOnDisk uint64, err error) {
      
          err = parallelisation.DetermineContextError(ctx)
          if err != nil {
              return
      Severity: Minor
      Found in utils/filesystem/zip.go - About 1 day 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 InheritsFrom has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
      Open

      func InheritsFrom(object interface{}, parentType reflect.Type) bool {
          if parentType == nil {
              return object == nil
          }
          r := reflect.ValueOf(object)
      Severity: Minor
      Found in utils/reflection/reflection.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

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

      func (fs *VFS) ZipWithContextAndLimitsAndExclusionPatterns(ctx context.Context, source string, destination string, limits ILimits, exclusionPatterns ...string) (err error) {
          if limits == nil {
              err = fmt.Errorf("%w: missing file system limits", commonerrors.ErrUndefined)
              return
          }
      Severity: Minor
      Found in utils/filesystem/zip.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

      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

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

      func findRetryAfter(resp *http.Response) (wait time.Duration, found bool) {
          if resp != nil {
              if resp.StatusCode == http.StatusTooManyRequests || resp.StatusCode == http.StatusServiceUnavailable {
                  if s, ok := resp.Header[headers.RetryAfter]; ok {
                      retryAfter := s[0]
      Severity: Minor
      Found in utils/http/retry_policy.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

      Function GenerateTestFileTree has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

      func GenerateTestFileTree(t *testing.T, fs FS, testDir, basePath string, withLinks bool, fileModTime time.Time, fileAccessTime time.Time) []string {
          err := fs.MkDir(testDir)
          require.NoError(t, err)
      
          var sLinks []string
      Severity: Minor
      Found in utils/filesystem/testing.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 VFS.unzip has 95 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (fs *VFS) unzip(ctx context.Context, source string, destination string, limits ILimits, currentDepth int64) (fileList []string, fileOnDiskCount uint64, sizeOnDisk uint64, err error) {
      
          err = parallelisation.DetermineContextError(ctx)
          if err != nil {
              return
      Severity: Major
      Found in utils/filesystem/zip.go - About 2 hrs to fix

        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.ZipWithContextAndLimitsAndExclusionPatterns has 78 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (fs *VFS) ZipWithContextAndLimitsAndExclusionPatterns(ctx context.Context, source string, destination string, limits ILimits, exclusionPatterns ...string) (err error) {
              if limits == nil {
                  err = fmt.Errorf("%w: missing file system limits", commonerrors.ErrUndefined)
                  return
              }
          Severity: Major
          Found in utils/filesystem/zip.go - About 2 hrs to fix

            Function linkFlagKeysToStructureKeys has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
            Open

            func linkFlagKeysToStructureKeys(viperSession *viper.Viper, envVarPrefix string) {
                // The following is a workaround of the aliases implementation in viper which does not really work well with multi-level keys
                // Similarly BindEnv does not seem to work well with multi-level configuration structures
                keys := viperSession.AllKeys()
                for i := range keys {
            Severity: Minor
            Found in utils/config/service_configuration.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

            Function SetStructField has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
            Open

            func SetStructField(structure interface{}, fieldName string, value interface{}) error {
                ValueStructure := reflect.ValueOf(structure)
                Field := ValueStructure.Elem().FieldByName(fieldName)
                // Test field exists on structure
                if !Field.IsValid() {
            Severity: Minor
            Found in utils/reflection/reflection.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

            Function ReadAtMost has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
            Open

            func ReadAtMost(ctx context.Context, src io.Reader, max int64, bufferCapacity int64) (content []byte, err error) {
                if bufferCapacity < 0 {
                    if max < 0 {
                        bufferCapacity = bytes.MinRead
                    } else {
            Severity: Minor
            Found in utils/safeio/read.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 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 listCompleteFilesByModTime has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

            func listCompleteFilesByModTime(ctx context.Context, fs filesystem.FS, entryDir string) (sorted []string, err error) {
                err = parallelisation.DetermineContextError(ctx)
                if err != nil {
                    return
                }
            Severity: Minor
            Found in utils/sharedcache/sharedcache_immutable.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 deserialiseCommonError has 66 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func deserialiseCommonError(errStr string) (bool, error) {
                errStr = strings.TrimSpace(errStr)
                switch {
                case errStr == "":
                    return true, nil
            Severity: Minor
            Found in utils/commonerrors/errors.go - About 1 hr to fix

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

              func TransferFiles(ctx context.Context, fs filesystem.FS, dst, src string) (destFile string, err error) {
                  err = parallelisation.DetermineContextError(ctx)
                  if err != nil {
                      return
                  }
              Severity: Minor
              Found in utils/sharedcache/common.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

              Severity
              Category
              Status
              Source
              Language