tk0miya/diff-highlight

View on GitHub

Showing 17 of 37 total issues

Function highlight_hunk has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

def highlight_hunk(new, new_lo, new_hi, old, old_lo, old_hi):
    # derived from difflib.py (Python stdlib) Differ#_fancy_replace()
    best_ratio, cutoff = 0.59, 0.60

    cruncher = SequenceMatcher(None)
Severity: Minor
Found in src/highlights/pprint.py - 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 arrange_indented_hunks has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

def arrange_indented_hunks(lines):
    result = []

    def typeof(line):
        return line[0][0][0:1]  # +, - or other
Severity: Minor
Found in src/highlights/pprint.py - 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 is_mergeable has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

def is_mergeable(new, old, i):
    chars = '[a-zA-Z0-9_.]'
    startswith_word = lambda s: re.match('^%s' % chars, s[0])
    endswith_word = lambda s: re.search('%s$' % chars, s[0])
    is_word = lambda s: re.match('^(%s+|\s+)$' % chars, s[0])
Severity: Minor
Found in src/highlights/pprint.py - 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 highlight_main has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

def highlight_main():
    try:
        new, old = [], []
        in_header = True
        for rawline in sys.stdin:
Severity: Minor
Found in src/highlights/command.py - 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 flush_hunk has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    def flush_hunk(self):
        if self.hunk is None:  # not initialized yet
            return

        hunk = [(ret[0].decode('utf-8'), ret[1]) for ret in self.hunk]
Severity: Minor
Found in src/diff_highlight.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 highlight_pair has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

def highlight_pair(cruncher, newline, oldline):
    new = [[newline[0], INSERTED, False]]
    old = [[oldline[0], DELETED, False]]

    cruncher.set_seqs(newline[1:], oldline[1:])
Severity: Minor
Found in src/highlights/pprint.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 show_hunk has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

def show_hunk(new, old):
    for string, style, highlighted, in pprint_hunk(new, 0, len(new),
                                                   old, 0, len(old)):

        if style == INSERTED:
Severity: Minor
Found in src/highlights/command.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 highlight_hunk_helper has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

def highlight_hunk_helper(new, new_lo, new_hi, old, old_lo, old_hi):
    # derived from difflib.py (Python stdlib) Differ#_fancy_helper()
    if new_lo < new_hi:
        if old_lo < old_hi:
            for hunk in highlight_hunk(new, new_lo, new_hi, old, old_lo, old_hi):
Severity: Minor
Found in src/highlights/pprint.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 uisetup has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def uisetup(ui):
    if ui.plain():
        return

    try:
Severity: Minor
Found in src/diff_highlight.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 write has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def write(self, *args, **opts):
        label = opts.get('label')
        if label in (INSERT_NORM, DELETE_NORM):
            if self.tab is not None:
                change = self.hunk.pop()
Severity: Minor
Found in src/diff_highlight.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 highlight_hunk_helper has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

def highlight_hunk_helper(new, new_lo, new_hi, old, old_lo, old_hi):
Severity: Minor
Found in src/highlights/pprint.py - About 45 mins to fix

    Function pprint_hunk has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def pprint_hunk(new, new_lo, new_hi, old, old_lo, old_hi):
    Severity: Minor
    Found in src/highlights/pprint.py - About 45 mins to fix

      Function highlight_hunk has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def highlight_hunk(new, new_lo, new_hi, old, old_lo, old_hi):
      Severity: Minor
      Found in src/highlights/pprint.py - About 45 mins to fix

        Consider simplifying this complex logical expression.
        Open

                if (inserted[0][0] == "+" and re.match('^\s*$', inserted[1][0]) and len(inserted) == 4 and
                   deleted[0][0] == "-" and re.match('^\s*$', deleted[1][0]) and len(deleted) == 4):
                    return True
                else:
                    return False
        Severity: Major
        Found in src/highlights/pprint.py - About 40 mins to fix

          Avoid too many return statements within this function.
          Open

                  return True
          Severity: Major
          Found in src/highlights/pprint.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return False
            Severity: Major
            Found in src/highlights/pprint.py - About 30 mins to fix

              Function write has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              def write(string, color=None, highlight=False):
                  if color:
                      sys.stdout.write("\x1b[%dm" % colortable[color])
              
                  if highlight:
              Severity: Minor
              Found in src/highlights/command.py - About 25 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