wikimedia/pywikibot

View on GitHub
pywikibot/diff.py

Summary

Maintainability
D
2 days
Test Coverage

Function review_hunks has a Cognitive Complexity of 90 (exceeds 10 allowed). Consider refactoring.
Open

    def review_hunks(self) -> None:
        """Review hunks."""
        def find_pending(start: int, end: int) -> int | None:
            step = -1 if start > end else +1
            for pending in range(start, end, step):
Severity: Minor
Found in pywikibot/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 format_diff has a Cognitive Complexity of 23 (exceeds 10 allowed). Consider refactoring.
Open

    def format_diff(self) -> Iterable[str]:
        """Color diff lines."""
        diff = iter(self.diff)

        fmt: str | None = ''
Severity: Minor
Found in pywikibot/diff.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 create_diff has a Cognitive Complexity of 20 (exceeds 10 allowed). Consider refactoring.
Open

    def create_diff(self) -> Iterable[str]:
        """Generator of diff text for this hunk, without formatting.

        Check each line ends with line feed to prevent behaviour like
        :issue:`46395`
Severity: Minor
Found in pywikibot/diff.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 color_line has a Cognitive Complexity of 19 (exceeds 10 allowed). Consider refactoring.
Open

    def color_line(self, line: str, line_ref: str | None = None) -> str:
        """Color line characters.

        If line_ref is None, the whole line is colored.
        If line_ref[i] is not blank, line[i] is colored.
Severity: Minor
Found in pywikibot/diff.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

Avoid deeply nested control flow statements.
Open

                        if hunk.reviewed == Hunk.PENDING:
                            hunk.reviewed = Hunk.NOT_APPR
            elif choice in ['a', 'd']:
Severity: Major
Found in pywikibot/diff.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                            if hunk.reviewed == Hunk.PENDING:
                                hunk.reviewed = \
                                    Hunk.APPR if choice == 'a' else Hunk.NOT_APPR
                    position = find_pending(0, position)
    Severity: Major
    Found in pywikibot/diff.py - About 45 mins to fix

      Function _generate_super_hunks has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
      Open

          def _generate_super_hunks(self, hunks: Iterable[Hunk] | None = None
                                    ) -> list[_SuperHunk]:
              if hunks is None:
                  hunks = self.hunks
      
      
      Severity: Minor
      Found in pywikibot/diff.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

      TODO found
      Open

              # TODO
      Severity: Minor
      Found in pywikibot/diff.py by fixme

      There are no issues that match your filters.

      Category
      Status