wikimedia/pywikibot

View on GitHub
pywikibot/textlib.py

Summary

Maintainability
F
3 days
Test Coverage

File textlib.py has 1662 lines of code (exceeds 900 allowed). Consider refactoring.
Open

"""Functions for manipulating wiki-text."""
#
# (C) Pywikibot team, 2008-2024
#
# Distributed under the terms of the MIT license.
Severity: Major
Found in pywikibot/textlib.py - About 2 days to fix

    Function replaceExcept has a Cognitive Complexity of 34 (exceeds 10 allowed). Consider refactoring.
    Open

    def replaceExcept(text: str,
                      old: str | Pattern[str],
                      new: str | Callable[[Match[str]], str],
                      exceptions: SequenceType[str | Pattern[str]],
                      caseInsensitive: bool = False,
    Severity: Minor
    Found in pywikibot/textlib.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

    Function get_regexes has a Cognitive Complexity of 21 (exceeds 10 allowed). Consider refactoring.
    Open

    def get_regexes(
        keys: str | Iterable[str],
        site: pywikibot.site.BaseSite | None = None
    ) -> list[Pattern[str]]:
        """Fetch compiled regexes.
    Severity: Minor
    Found in pywikibot/textlib.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 replaceExcept has 9 arguments (exceeds 7 allowed). Consider refactoring.
    Open

    def replaceExcept(text: str,
    Severity: Major
    Found in pywikibot/textlib.py - About 45 mins to fix

      TODO found
      Open

              # TODO: add option for template to be None to match any template
      Severity: Minor
      Found in pywikibot/textlib.py by fixme

      TODO found
      Open

                  # TODO: Work on the link within the label too
      Severity: Minor
      Found in pywikibot/textlib.py by fixme

      TODO found
      Open

          # TODO: There is no semantic difference between hyphens and
      Severity: Minor
      Found in pywikibot/textlib.py by fixme

      TODO found
      Open

          # TODO: currently, we do not have any, but BCP 47 allows digits, and
      Severity: Minor
      Found in pywikibot/textlib.py by fixme

      TODO found
      Open

              # TODO: handle nested tables.
      Severity: Minor
      Found in pywikibot/textlib.py by fixme

      hack found
      Open

                  # it is a little hack to make \n work. It would be better
      Severity: Minor
      Found in pywikibot/textlib.py by fixme

      TODO found
      Open

              # TODO: add ability to also match contents within the template
      Severity: Minor
      Found in pywikibot/textlib.py by fixme

      TODO found
      Open

              # TODO: merge regex with NESTED_TEMPLATE_REGEX
      Severity: Minor
      Found in pywikibot/textlib.py by fixme

      TODO found
      Open

                      # TODO: Unclosed link label, what happens there?
      Severity: Minor
      Found in pywikibot/textlib.py by fixme

      TODO found
      Open

                      # TODO: This must also compare everything that was used as a
      Severity: Minor
      Found in pywikibot/textlib.py by fixme

      There are no issues that match your filters.

      Category
      Status