willforde/python-htmlement

View on GitHub

Showing 11 of 11 total issues

Function _search has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

    def _search(self, tag, attrs):
        # Only search when the tag matches
        if tag == self.tag:
            # If we have required attrs to match then search all attrs for wanted attrs
            # And also check that we do not have any attrs that are unwanted
Severity: Minor
Found in htmlement.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 htmlement.py has 294 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# The MIT License (MIT)
#
Severity: Minor
Found in htmlement.py - About 3 hrs to fix

    Function handle_endtag has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def handle_endtag(self, tag):
            # Only process end tags when we have no filter or that the filter has been matched
            if self.enabled and tag not in self._voids:
                _elem = self._elem
                _root = self._root
    Severity: Minor
    Found in htmlement.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

    Avoid deeply nested control flow statements.
    Open

                            if key in unwanted_attrs:
                                return False
    
                            # Check for wanted attrs
                            elif key in wanted_attrs:
    Severity: Major
    Found in htmlement.py - About 45 mins to fix

      Function __init__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def __init__(self, tag="", attrs=None):
              # Initiate HTMLParser
              HTMLParser.__init__(self)
              self.convert_charrefs = True
              self._root = None  # root element
      Severity: Minor
      Found in htmlement.py - About 35 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 _flush has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def _flush(self):
              if self._data:
                  if self._last is not None:
                      text = "".join(self._data)
                      if self._tail:
      Severity: Minor
      Found in htmlement.py - About 35 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 _handle_starttag has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def _handle_starttag(self, tag, attrs, self_closing=False):
              enabled = self.enabled
              # Add tag element to tree if we have no filter or that the filter matches
              if enabled or self._search(tag, attrs):
                  # Convert attrs to dictionary
      Severity: Minor
      Found in htmlement.py - About 35 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 feed has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def feed(self, data):
              """
              Feeds data to the parser.
      
              If *data*, is of type :class:`bytes` and where no encoding was specified, then the encoding
      Severity: Minor
      Found in htmlement.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

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

          def handle_charref(self, name):
              if self.enabled:
                  try:
                      if name[0].lower() == "x":
                          name = chr(int(name[1:], 16))
      Severity: Minor
      Found in htmlement.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

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

      def parse(source, tag="", attrs=None, encoding=None):
          """
          Load an external "HTML document" into an element tree.
      
          :param source: A filename or file like object containing HTML data.
      Severity: Minor
      Found in htmlement.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

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

          def close(self):
              self._flush()
              if self.enabled == 0:
                  msg = "Unable to find requested section with tag of '{}' and attributes of {}"
                  raise RuntimeError(msg.format(self.tag, self.attrs))
      Severity: Minor
      Found in htmlement.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