ARM-software/golang-utils

View on GitHub

Showing 96 of 97 total issues

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

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

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

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

func (m *MockPage) GetNext(ctx context.Context) (page IPage, err error) {
    err = parallelisation.DetermineContextError(ctx)
    if err != nil {
        return
    }
Severity: Minor
Found in utils/collection/pagination/testing.go and 1 other location - About 40 mins to fix
utils/collection/pagination/testing.go on lines 141..151

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

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 (m *MockPage) GetFuture(ctx context.Context) (future IStream, err error) {
    err = parallelisation.DetermineContextError(ctx)
    if err != nil {
        return
    }
Severity: Minor
Found in utils/collection/pagination/testing.go and 1 other location - About 40 mins to fix
utils/collection/pagination/testing.go on lines 79..89

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

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 (c *MultipleLogger) Close() error {
    c.mu.Lock()
    defer c.mu.Unlock()
    g := new(errgroup.Group)
    for i := range c.loggers {
Severity: Minor
Found in utils/logs/multiple_logger.go and 1 other location - About 40 mins to fix
utils/logs/multiple_logger.go on lines 28..36

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

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 (c *MultipleLogger) Check() error {
    c.mu.Lock()
    defer c.mu.Unlock()
    g := new(errgroup.Group)
    for i := range c.loggers {
Severity: Minor
Found in utils/logs/multiple_logger.go and 1 other location - About 40 mins to fix
utils/logs/multiple_logger.go on lines 18..26

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

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 HasGroup(groupName string) (found bool, err error) {
    group, err := user.LookupGroup(groupName)
    if err != nil {
        err = ConvertUserGroupError(err)
        if commonerrors.Any(err, commonerrors.ErrNotFound) {
Severity: Minor
Found in utils/platform/users.go and 1 other location - About 35 mins to fix
utils/platform/users.go on lines 64..76

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

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 HasUser(username string) (found bool, err error) {
    user, err := user.Lookup(username)
    if err != nil {
        err = ConvertUserGroupError(err)
        if commonerrors.Any(err, commonerrors.ErrNotFound) {
Severity: Minor
Found in utils/platform/users.go and 1 other location - About 35 mins to fix
utils/platform/users.go on lines 168..180

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

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

func executeCommandAs(ctx context.Context, as *command.CommandAsDifferentUser, args ...string) error {
    if as == nil {
        return fmt.Errorf("%w: missing command wrapper", commonerrors.ErrUndefined)
    }
    if len(args) == 0 {
Severity: Minor
Found in utils/platform/deletion.go - About 35 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 (l *JSONLoggers) Log(output ...interface{}) {
    if len(output) == 1 && output[0] == "\n" {
        return
    }
    l.zerologger.Info().Str("source", l.GetLoggerSource()).Msg(fmt.Sprint(output...))
Severity: Minor
Found in utils/logs/json_logger.go and 1 other location - About 35 mins to fix
utils/logs/json_logger.go on lines 80..85

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

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 (l *JSONLoggers) LogError(err ...interface{}) {
    if len(err) == 1 && err[0] == "\n" {
        return
    }
    l.zerologger.Error().Str("source", l.GetLoggerSource()).Msg(fmt.Sprint(err...))
Severity: Minor
Found in utils/logs/json_logger.go and 1 other location - About 35 mins to fix
utils/logs/json_logger.go on lines 72..77

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

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

func processErrorStrLine(err string) (mErr *marshallingError) {
    err = strings.TrimSpace(err)
    if err == "" {
        return nil
    }
Severity: Minor
Found in utils/commonerrors/serialisation.go - About 35 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 CleanKillOfCommand has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

func CleanKillOfCommand(ctx context.Context, cmd *exec.Cmd) (err error) {
    if cmd == nil {
        return
    }
    defer func() {
Severity: Minor
Found in utils/subprocess/command_wrapper.go - About 35 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.IsZipWithContext has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

func (fs *VFS) IsZipWithContext(ctx context.Context, path string) (ok bool, err error) {
    if path == "" {
        err = fmt.Errorf("%w: missing path", commonerrors.ErrUndefined)
        return
    }
Severity: Minor
Found in utils/filesystem/zip.go - About 35 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 processErrorStr has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

func processErrorStr(s string) iMarshallingError {
    if strings.Contains(s, string(MultipleErrorSeparator)) {
        elems := strings.Split(s, string(MultipleErrorSeparator))
        m := &multiplemarshallingError{}
        for i := range elems {
Severity: Minor
Found in utils/commonerrors/serialisation.go - About 35 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 DecryptWithKeyPair has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

func DecryptWithKeyPair(keys IKeyPair, base64EncodedEncryptedMessage string) (decryptedMessage string, err error) {
    if keys == nil {
        err = fmt.Errorf("%w: missing keys", commonerrors.ErrUndefined)
        return
    }
Severity: Minor
Found in utils/encryption/encryption.go - About 35 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 RemoteLockFile.MakeStale has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

func (l *RemoteLockFile) MakeStale(ctx context.Context) error {
    l.cancelStore.Cancel()
    parallelisation.SleepWithContext(ctx, l.lockHeartBeatPeriod+time.Millisecond)
    lockPath := l.lockPath()
    filePath := l.heartBeatFile(lockPath)
Severity: Minor
Found in utils/filesystem/lockfile.go - About 35 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 flattenDefaultsMap has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

func flattenDefaultsMap(m map[string]interface{}) map[string]interface{} {
    output := make(map[string]interface{})
    for key, value := range m {
        switch child := value.(type) {
        case map[string]interface{}:
Severity: Minor
Found in utils/config/service_configuration.go - About 35 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