KarrLab/wc_utils

View on GitHub
wc_utils/util/string.py

Summary

Maintainability
D
2 days
Test Coverage
B
89%

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

def __indent_forest(forest, indentation, depth, keep_trailing_blank_lines):
    """ Private, recursive method to generate a list of lines indented by their depth in a forest

    Args:
        forest (:obj:`list` of :obj:`list`): a forest as an iterator of nested iterators
Severity: Minor
Found in wc_utils/util/string.py - 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 rpartition_nth has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

def rpartition_nth(s, sep, n):
    """ Partition a string on the nth-last occurrence of a substring

    Args:
        s (:obj:`str`): string to partition
Severity: Minor
Found in wc_utils/util/string.py - 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 partition_nth has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

def partition_nth(s, sep, n):
    """ Partition a string on the nth occurrence of a substring

    Args:
        s (:obj:`str`): string to partition
Severity: Minor
Found in wc_utils/util/string.py - 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 find_nth has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def find_nth(s, sub, n, start=0, end=float('inf')):
    """ Get the index of the nth occurrence of a substring within a string

    Args:
        s (:obj:`str`): string to search
Severity: Minor
Found in wc_utils/util/string.py - 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 rfind_nth has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def rfind_nth(s, sub, n, start=0, end=float('inf')):
    """ Get the index of the nth-last occurrence of a substring within a string

    Args:
        s (:obj:`str`): string to search
Severity: Minor
Found in wc_utils/util/string.py - 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

Avoid deeply nested control flow statements.
Open

                    for line in lines:
                        output.append(indent + line)
                else:
Severity: Major
Found in wc_utils/util/string.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                        if not keep_trailing_blank_lines:
                            delete_trailing_blanks(lines)
                        for line in lines:
    Severity: Major
    Found in wc_utils/util/string.py - About 45 mins to fix

      Function rfind_nth has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def rfind_nth(s, sub, n, start=0, end=float('inf')):
      Severity: Minor
      Found in wc_utils/util/string.py - About 35 mins to fix

        Function find_nth has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def find_nth(s, sub, n, start=0, end=float('inf')):
        Severity: Minor
        Found in wc_utils/util/string.py - About 35 mins to fix

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

              if i == -1:
                  return ('', '', s)
              else:
                  if i == 0:
                      before = ''
          Severity: Major
          Found in wc_utils/util/string.py and 1 other location - About 5 hrs to fix
          wc_utils/util/string.py on lines 201..214

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

          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

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

              if i == -1:
                  return (s, '', '')
              else:
                  if i == 0:
                      before = ''
          Severity: Major
          Found in wc_utils/util/string.py and 1 other location - About 5 hrs to fix
          wc_utils/util/string.py on lines 241..254

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

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status