go-sprout/sprout

View on GitHub

Showing 27 of 49 total issues

Function parseCodeBlock has a Cognitive Complexity of 51 (exceeds 20 allowed). Consider refactoring.
Open

func parseCodeBlock(codeBlock, funcName, filePath string) []Example {
    var examples []Example
    lines := strings.Split(codeBlock, "\n")

    i := 0
Severity: Minor
Found in tools/docvalidator/parsing.go - About 5 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 parseCodeBlock has 85 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func parseCodeBlock(codeBlock, funcName, filePath string) []Example {
    var examples []Example
    lines := strings.Split(codeBlock, "\n")

    i := 0
Severity: Major
Found in tools/docvalidator/parsing.go - About 2 hrs to fix

    Method StringsRegistry.transformString has a Cognitive Complexity of 32 (exceeds 20 allowed). Consider refactoring.
    Open

    func (sr *StringsRegistry) transformString(style caseStyle, value string) string {
        var result strings.Builder
        result.Grow(len(value) + 10) // Allocate a bit more for potential separators
    
        capitalizeNext := style.CapitalizeNext
    Severity: Minor
    Found in registry/strings/helpers.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

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

    func (nr *NumericRegistry) Min(subtrahend any, values ...any) (int64, error) {
        intA, err := cast.ToInt64E(subtrahend)
        if err != nil {
            return 0, sprout.NewErrConvertFailed("int64", subtrahend, err)
        }
    Severity: Major
    Found in registry/numeric/functions.go and 1 other location - About 1 hr to fix
    registry/numeric/functions.go on lines 350..367

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

    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 RandomRegistry.randomString has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
    Open

    func (rr *RandomRegistry) randomString(size int, opts *randomOpts) string {
        if size <= 0 {
            return ""
        }
    
    
    Severity: Minor
    Found in registry/random/helpers.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 (nr *NumericRegistry) Max(value any, values ...any) (int64, error) {
        intA, err := cast.ToInt64E(value)
        if err != nil {
            return 0, sprout.NewErrConvertFailed("int64", value, err)
        }
    Severity: Major
    Found in registry/numeric/functions.go and 1 other location - About 1 hr to fix
    registry/numeric/functions.go on lines 287..303

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

    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 (nr *NumericRegistry) Minf(subtrahend any, values ...any) (float64, error) {
        floatA, err := cast.ToFloat64E(subtrahend)
        if err != nil {
            return 0, sprout.NewErrConvertFailed("float64", subtrahend, err)
        }
    Severity: Major
    Found in registry/numeric/functions.go and 1 other location - About 1 hr to fix
    registry/numeric/functions.go on lines 384..397

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

    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 (nr *NumericRegistry) Maxf(value any, values ...any) (float64, error) {
        floatA, err := cast.ToFloat64E(value)
        if err != nil {
            return 0, sprout.NewErrConvertFailed("float64", value, err)
        }
    Severity: Major
    Found in registry/numeric/functions.go and 1 other location - About 1 hr to fix
    registry/numeric/functions.go on lines 320..333

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

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

    func (tr *TimeRegistry) DurationRound(duration any) string {
        var d time.Duration
    
        switch duration := duration.(type) {
        case string:
    Severity: Minor
    Found in registry/time/functions.go - About 1 hr to fix

      Method SlicesRegistry.Slice has 8 return statements (exceeds 4 allowed).
      Open

      func (sr *SlicesRegistry) Slice(args ...any) (any, error) {
          // ! BACKWARDS COMPATIBILITY: deprecated in v1.0 and removed in v1.1
          // ! Due to change in signature, this function still supports the old signature
          // ! to let users transition to the new signature.
          // * Old signature: Slice(list any, indices ...any)
      Severity: Major
      Found in registry/slices/functions.go - About 50 mins to fix

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

            switch date := date.(type) {
            default:
                t = time.Now()
            case time.Time:
                t = date
        Severity: Minor
        Found in registry/time/functions.go and 1 other location - About 45 mins to fix
        registry/time/functions.go on lines 47..60

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

        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

            switch date := date.(type) {
            default:
                t = time.Now()
            case time.Time:
                t = date
        Severity: Minor
        Found in registry/time/functions.go and 1 other location - About 45 mins to fix
        registry/time/functions.go on lines 118..131

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

        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 StringsRegistry.wordWrap has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
        Open

        func (sr *StringsRegistry) wordWrap(wrapLength int, newLineCharacter string, wrapLongWords bool, value string) string {
            if wrapLength < 1 {
                wrapLength = 1
            }
            if newLineCharacter == "" {
        Severity: Minor
        Found in registry/strings/helpers.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 run has 7 return statements (exceeds 4 allowed).
        Open

        func run(fs FileSystem) error {
            // Set the log level based on the flag
            if err := setLogLevel(logLevel); err != nil {
                return err
            }
        Severity: Major
        Found in tools/docvalidator/main.go - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if nextLine == "" || strings.HasPrefix(nextLine, "{{") || strings.Contains(nextLine, "// Output:") || strings.Contains(nextLine, "// Error") {
                                  i--
                                  break
                              }
          Severity: Major
          Found in tools/docvalidator/parsing.go - About 45 mins to fix

            Function processExample has 7 return statements (exceeds 4 allowed).
            Open

            func processExample(example Example) error {
                if example.Skipped {
                    return nil
                }
            
            
            Severity: Major
            Found in tools/docvalidator/processing.go - About 45 mins to fix

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

              func (rr *RegexpRegistry) RegexFindAll(regex string, value string, n int) ([]string, error) {
                  r, err := regexp.Compile(regex)
                  if err != nil {
                      return []string{}, err
                  }
              Severity: Minor
              Found in registry/regexp/functions.go and 1 other location - About 40 mins to fix
              registry/regexp/functions.go on lines 109..115

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

              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 (rr *RegexpRegistry) RegexSplit(regex string, value string, n int) ([]string, error) {
                  r, err := regexp.Compile(regex)
                  if err != nil {
                      return []string{}, err
                  }
              Severity: Minor
              Found in registry/regexp/functions.go and 1 other location - About 40 mins to fix
              registry/regexp/functions.go on lines 65..71

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

              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 (rr *RegexpRegistry) RegexReplaceAllLiteral(regex string, value string, replacedBy string) (string, error) {
                  r, err := regexp.Compile(regex)
                  if err != nil {
                      return "", err
                  }
              Severity: Minor
              Found in registry/regexp/functions.go and 1 other location - About 35 mins to fix
              registry/regexp/functions.go on lines 134..140

              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 (rr *RegexpRegistry) RegexReplaceAll(regex string, value string, replacedBy string) (string, error) {
                  r, err := regexp.Compile(regex)
                  if err != nil {
                      return "", err
                  }
              Severity: Minor
              Found in registry/regexp/functions.go and 1 other location - About 35 mins to fix
              registry/regexp/functions.go on lines 159..165

              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

              Severity
              Category
              Status
              Source
              Language