ARM-software/golang-utils

View on GitHub

Showing 96 of 97 total issues

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 RemoteLockFile.Lock has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

func (l *RemoteLockFile) Lock(ctx context.Context) error {
    for {
        if err := parallelisation.DetermineContextError(ctx); err != nil {
            return err
        }
Severity: Minor
Found in utils/filesystem/lockfile.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.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 SharedImmutableCacheRepository.CleanEntry has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

func (s *SharedImmutableCacheRepository) CleanEntry(ctx context.Context, key 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

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

func removeUser(ctx context.Context, username string) (err error) {
    err = parallelisation.DetermineContextError(ctx)
    if err != nil {
        return
    }
Severity: Major
Found in utils/platform/users_windows_amd64.go and 1 other location - About 1 hr to fix
utils/platform/users_windows_amd64.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 135.

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

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

    Function ValidateEmbedded has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    func ValidateEmbedded(cfg Validator) error {
        r := reflect.ValueOf(cfg).Elem()
        for i := 0; i < r.NumField(); i++ {
            f := r.Field(i)
            if f.Kind() == reflect.Struct {
    Severity: Minor
    Found in utils/config/validation.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

    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 newZipReader has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    func newZipReader(fs FS, source string, limits ILimits, currentDepth int64) (zipReader *zip.Reader, file File, err error) {
        if fs == nil {
            err = fmt.Errorf("%w: missing file system", commonerrors.ErrUndefined)
            return
        }
    Severity: Minor
    Found in utils/filesystem/zip.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 getHash has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

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

    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) 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

    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

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

    func Parallelise(argList interface{}, action func(arg interface{}) (interface{}, error), resultType reflect.Type) (results interface{}, err error) {
        keepReturn := resultType != nil
        argListValue := reflect.ValueOf(argList)
        length := argListValue.Len()
        channel := make(chan result, length)
    Severity: Minor
    Found in utils/parallelisation/parallelisation.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

    Avoid deeply nested control flow statements.
    Open

                        if len(sLinks) > 1 {
                            sLinks = sLinks[1:]
                        } else {
                            sLinks = nil
                        }
    Severity: Major
    Found in utils/filesystem/testing.go - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if afterTime.After(time.Now()) {
                              wait = time.Until(afterTime)
                          } else {
                              wait = time.Duration(0)
                          }
      Severity: Major
      Found in utils/http/retry_policy.go - About 45 mins to fix

        Method RemoteLockFile.TryLock has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        func (l *RemoteLockFile) TryLock(ctx context.Context) (err error) {
            if err := parallelisation.DetermineContextError(ctx); err != nil {
                return err
            }
        
        
        Severity: Minor
        Found in utils/filesystem/lockfile.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

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

        func killProcessAndChildren(ctx context.Context, p *process.Process) (err error) {
            // See https://varunksaini.com/posts/kiling-processes-in-go/
            err = parallelisation.DetermineContextError(ctx)
            if err != nil {
                return
        Severity: Minor
        Found in utils/proc/process.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

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

        func SafeSchedule(ctx context.Context, period time.Duration, offset time.Duration, f func(context.Context, time.Time)) {
            err := DetermineContextError(ctx)
            if err != nil {
                return
            }
        Severity: Minor
        Found in utils/parallelisation/parallelisation.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 SharedImmutableCacheRepository.Store has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        func (s *SharedImmutableCacheRepository) Store(ctx context.Context, key, src string) (err error) {
            err = parallelisation.DetermineContextError(ctx)
            if err != nil {
                return
            }
        Severity: Minor
        Found in utils/sharedcache/sharedcache_immutable.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

        Severity
        Category
        Status
        Source
        Language