edgewall/trac

View on GitHub
trac/versioncontrol/diff.py

Summary

Maintainability
F
1 wk
Test Coverage

Function filter_ignorable_lines has a Cognitive Complexity of 89 (exceeds 5 allowed). Consider refactoring.
Open

def filter_ignorable_lines(hunks, fromlines, tolines, context,
                           ignore_blank_lines, ignore_case,
                           ignore_space_changes):
    """Detect line changes that should be ignored and emits them as
    tagged as "equal", possibly joined with the preceding and/or
Severity: Minor
Found in trac/versioncontrol/diff.py - About 1 day 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 diff_blocks has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
Open

def diff_blocks(fromlines, tolines, context=None, tabwidth=8,
                ignore_blank_lines=0, ignore_case=0, ignore_space_changes=0):
    """Return an array that is adequate for adding to the data dictionary

    See `get_filtered_hunks` for the parameter descriptions.
Severity: Minor
Found in trac/versioncontrol/diff.py - About 7 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 unified_diff has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

def unified_diff(fromlines, tolines, context=None, ignore_blank_lines=0,
                 ignore_case=0, ignore_space_changes=0):
    """Generator producing lines corresponding to a textual diff.

    See `get_filtered_hunks` for the parameter descriptions.
Severity: Minor
Found in trac/versioncontrol/diff.py - About 4 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

File diff.py has 287 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
#
# Copyright (C) 2004-2023 Edgewall Software
# Copyright (C) 2004-2006 Christopher Lenz <cmlenz@gmx.de>
# All rights reserved.
Severity: Minor
Found in trac/versioncontrol/diff.py - About 2 hrs to fix

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

    def get_diff_options(req):
        """Retrieve user preferences for diffs.
    
        :return: ``(style, options, data)`` triple.
    
    
    Severity: Minor
    Found in trac/versioncontrol/diff.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 diff_blocks has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def diff_blocks(fromlines, tolines, context=None, tabwidth=8,
    Severity: Major
    Found in trac/versioncontrol/diff.py - About 50 mins to fix

      Function filter_ignorable_lines has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def filter_ignorable_lines(hunks, fromlines, tolines, context,
      Severity: Major
      Found in trac/versioncontrol/diff.py - About 50 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            for line in fromlines[i1:i2]:
                                line = expandtabs(line, tabwidth, '\0\1')
                                line = escape(line, quotes=False)
                                line = '<del>'.join(space_re.sub(htmlify, seg)
                                                    for seg in line.split('\0'))
        Severity: Major
        Found in trac/versioncontrol/diff.py - About 45 mins to fix

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

          def get_filtered_hunks(fromlines, tolines, context=None,
          Severity: Minor
          Found in trac/versioncontrol/diff.py - About 45 mins to fix

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

            def unified_diff(fromlines, tolines, context=None, ignore_blank_lines=0,
            Severity: Minor
            Found in trac/versioncontrol/diff.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                  if not all_equal():
                                      yield group
                                  group = []
              Severity: Major
              Found in trac/versioncontrol/diff.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                    for line in fromlines[i1:i2]:
                                        yield '-' + line
                                if tag in ('replace', 'insert'):
                Severity: Major
                Found in trac/versioncontrol/diff.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      if prev:
                                          prev = 'equal', prev[1], i2, prev[3], j2
                                      else:
                                          prev = 'equal', i1, i2, j1, j2
                                      continue
                  Severity: Major
                  Found in trac/versioncontrol/diff.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                        for line in tolines[j1:j2]:
                                            line = expandtabs(line, tabwidth, '\0\1')
                                            line = escape(line, quotes=False)
                                            line = '<ins>'.join(space_re.sub(htmlify, seg)
                                                                for seg in line.split('\0'))
                    Severity: Major
                    Found in trac/versioncontrol/diff.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                          for line in tolines[j1:j2]:
                                              yield '+' + line
                      
                      
                      Severity: Major
                      Found in trac/versioncontrol/diff.py - About 45 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return True
                        Severity: Major
                        Found in trac/versioncontrol/diff.py - About 30 mins to fix

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

                                          if tag in ('replace', 'insert'):
                                              for line in tolines[j1:j2]:
                                                  line = expandtabs(line, tabwidth, '\0\1')
                                                  line = escape(line, quotes=False)
                                                  line = '<ins>'.join(space_re.sub(htmlify, seg)
                          Severity: Major
                          Found in trac/versioncontrol/diff.py and 1 other location - About 1 day to fix
                          trac/versioncontrol/diff.py on lines 243..251

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

                          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

                                          if tag in ('replace', 'delete'):
                                              for line in fromlines[i1:i2]:
                                                  line = expandtabs(line, tabwidth, '\0\1')
                                                  line = escape(line, quotes=False)
                                                  line = '<del>'.join(space_re.sub(htmlify, seg)
                          Severity: Major
                          Found in trac/versioncontrol/diff.py and 1 other location - About 1 day to fix
                          trac/versioncontrol/diff.py on lines 252..260

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

                          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

                                          for line in tolines[j1:j2]:
                                              line = line.expandtabs(tabwidth)
                                              line = space_re.sub(htmlify, escape(line, quotes=False))
                                              blocks[-1]['changed']['lines'].append(Markup(str(line)))
                          Severity: Major
                          Found in trac/versioncontrol/diff.py and 1 other location - About 4 hrs to fix
                          trac/versioncontrol/diff.py on lines 234..237

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

                          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

                                          for line in fromlines[i1:i2]:
                                              line = line.expandtabs(tabwidth)
                                              line = space_re.sub(htmlify, escape(line, quotes=False))
                                              blocks[-1]['base']['lines'].append(Markup(str(line)))
                          Severity: Major
                          Found in trac/versioncontrol/diff.py and 1 other location - About 4 hrs to fix
                          trac/versioncontrol/diff.py on lines 238..241

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

                          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

                                                  fromlines[i1 + i] = (
                                                      fromline[:start] + '\0' + fromline[start:last] +
                                                      '\1' + fromline[last:])
                          Severity: Major
                          Found in trac/versioncontrol/diff.py and 1 other location - About 2 hrs to fix
                          trac/versioncontrol/diff.py on lines 217..219

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

                          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

                                                  tolines[j1 + i] = (
                                                      toline[:start] + '\0' + toline[start:last] +
                                                      '\1' + toline[last:])
                          Severity: Major
                          Found in trac/versioncontrol/diff.py and 1 other location - About 2 hrs to fix
                          trac/versioncontrol/diff.py on lines 213..215

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

                          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

                              def htmlify(match):
                                  div, mod = divmod(len(match.group(0)), 2)
                                  return Markup(div * '&nbsp; ' + mod * '&nbsp;')
                          Severity: Major
                          Found in trac/versioncontrol/diff.py and 1 other location - About 2 hrs to fix
                          trac/mimeview/patch.py on lines 91..93

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

                          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

                                          if tag in ('replace', 'insert'):
                                              for line in tolines[j1:j2]:
                                                  yield '+' + line
                          Severity: Major
                          Found in trac/versioncontrol/diff.py and 1 other location - About 1 hr to fix
                          trac/versioncontrol/diff.py on lines 283..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 38.

                          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

                                          if tag in ('replace', 'delete'):
                                              for line in fromlines[i1:i2]:
                                                  yield '-' + line
                          Severity: Major
                          Found in trac/versioncontrol/diff.py and 1 other location - About 1 hr to fix
                          trac/versioncontrol/diff.py on lines 286..288

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

                          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

                                              i1, j1 = max(i1, i2 - n), max(j1, j2 - n)
                          Severity: Minor
                          Found in trac/versioncontrol/diff.py and 1 other location - About 35 mins to fix
                          trac/versioncontrol/diff.py on lines 166..167

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

                          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 idx == 0 and tag == 'equal': # Fixup leading unchanged block
                                              i1, j1 = max(i1, i2 - n), max(j1, j2 - n)
                          Severity: Minor
                          Found in trac/versioncontrol/diff.py and 1 other location - About 35 mins to fix
                          trac/versioncontrol/diff.py on lines 174..174

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

                          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