netdata/netdata

View on GitHub
src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py

Summary

Maintainability
F
1 wk
Test Coverage

File scanner.py has 882 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# SPDX-License-Identifier: MIT

# Scanner produces tokens of the following types:
# STREAM-START
# STREAM-END
Severity: Major
Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 2 days to fix

    Scanner has 71 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Scanner:
    
        def __init__(self):
            """Initialize the scanner."""
            # It is assumed that Scanner and Reader will have a common descendant.
    Severity: Major
    Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 1 day to fix

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

          def scan_flow_scalar_non_spaces(self, double, start_mark):
              # See the specification for details.
              chunks = []
              while True:
                  length = 0
      Severity: Minor
      Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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 scan_plain_spaces has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          def scan_plain_spaces(self, indent, start_mark):
              # See the specification for details.
              # The specification is really confusing about tabs in plain scalars.
              # We just forbid them completely. Do not use tabs in YAML!
              chunks = []
      Severity: Minor
      Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 3 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 scan_block_scalar has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          def scan_block_scalar(self, style):
              # See the specification for details.
      
              if style == '>':
                  folded = True
      Severity: Minor
      Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 3 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 scan_plain has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          def scan_plain(self):
              # See the specification for details.
              # We add an additional restriction for the flow context:
              #   plain scalars in the flow context cannot contain ',', ':' and '?'.
              # We also keep track of the `allow_simple_key` flag here.
      Severity: Minor
      Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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 fetch_more_tokens has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          def fetch_more_tokens(self):
      
              # Eat whitespaces and comments until we reach the next token.
              self.scan_to_next_token()
      
      
      Severity: Minor
      Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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 scan_block_scalar_indicators has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          def scan_block_scalar_indicators(self, start_mark):
              # See the specification for details.
              chomping = None
              increment = None
              ch = self.peek()
      Severity: Minor
      Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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 fetch_value has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def fetch_value(self):
      
              # Do we determine a simple key?
              if self.flow_level in self.possible_simple_keys:
      
      
      Severity: Minor
      Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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 scan_to_next_token has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def scan_to_next_token(self):
              # We ignore spaces, line breaks and comments.
              # If we find a line break in the block context, we set the flag
              # `allow_simple_key` on.
              # The byte order mark is stripped if it's the first character in the
      Severity: Minor
      Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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 scan_tag has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def scan_tag(self):
              # See the specification for details.
              start_mark = self.get_mark()
              ch = self.peek(1)
              if ch == '<':
      Severity: Minor
      Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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 scan_flow_scalar_breaks has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def scan_flow_scalar_breaks(self, double, start_mark):
              # See the specification for details.
              chunks = []
              while True:
                  # Instead of checking indentation, we check for document
      Severity: Minor
      Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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

      Consider simplifying this complex logical expression.
      Open

                  if not double and ch == '\'' and self.peek(1) == '\'':
                      chunks.append('\'')
                      self.forward(2)
                  elif (double and ch == '\'') or (not double and ch in '\"\\'):
                      chunks.append(ch)
      Severity: Major
      Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 1 hr to fix

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

            def check_token(self, *choices):
                # Check if the next token is one of the given types.
                while self.need_more_tokens():
                    self.fetch_more_tokens()
                if self.tokens:
        Severity: Minor
        Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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 __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(self, token_number, required, index, line, column, mark):
        Severity: Minor
        Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if self.peek(k) not in '0123456789ABCDEFabcdef':
                                      raise ScannerError("while scanning a double-quoted scalar", start_mark,
                                              "expected escape sequence of %d hexdecimal numbers, but found %r" %
                                                  (length, self.peek(k)), self.get_mark())
                              code = int(self.prefix(length), 16)
          Severity: Major
          Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 45 mins to fix

            Consider simplifying this complex logical expression.
            Open

                            if ch in '\0 \t\r\n\x85\u2028\u2029'    \
                                    or (not self.flow_level and ch == ':' and
                                            self.peek(length+1) in '\0 \t\r\n\x85\u2028\u2029') \
                                    or (self.flow_level and ch in ',:?[]{}'):
                                break
            Severity: Major
            Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 40 mins to fix

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

                  def scan_block_scalar_indentation(self):
                      # See the specification for details.
                      chunks = []
                      max_indent = 0
                      end_mark = self.get_mark()
              Severity: Minor
              Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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 scan_tag_handle has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def scan_tag_handle(self, name, start_mark):
                      # See the specification for details.
                      # For some strange reasons, the specification does not allow '_' in
                      # tag handles. I have allowed it anyway.
                      ch = self.peek()
              Severity: Minor
              Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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 scan_flow_scalar_spaces has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def scan_flow_scalar_spaces(self, double, start_mark):
                      # See the specification for details.
                      chunks = []
                      length = 0
                      while self.peek(length) in ' \t':
              Severity: Minor
              Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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 scan_uri_escapes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def scan_uri_escapes(self, name, start_mark):
                      # See the specification for details.
                      codes = []
                      mark = self.get_mark()
                      while self.peek() == '%':
              Severity: Minor
              Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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

              Avoid too many return statements within this function.
              Open

                          return self.fetch_flow_entry()
              Severity: Major
              Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return self.fetch_alias()
                Severity: Major
                Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return self.fetch_literal()
                  Severity: Major
                  Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return self.fetch_flow_sequence_end()
                    Severity: Major
                    Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return self.fetch_key()
                      Severity: Major
                      Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return self.fetch_anchor()
                        Severity: Major
                        Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                      return self.fetch_tag()
                          Severity: Major
                          Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                        return self.fetch_folded()
                            Severity: Major
                            Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                          return self.fetch_single()
                              Severity: Major
                              Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                            return self.fetch_plain()
                                Severity: Major
                                Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                              return self.fetch_flow_sequence_start()
                                  Severity: Major
                                  Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                                return self.fetch_flow_mapping_start()
                                    Severity: Major
                                    Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                                  return self.fetch_flow_mapping_end()
                                      Severity: Major
                                      Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                    return self.fetch_value()
                                        Severity: Major
                                        Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                      return self.fetch_double()
                                          Severity: Major
                                          Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                        return self.fetch_block_entry()
                                            Severity: Major
                                            Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.py - About 30 mins to fix

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

                                                  def fetch_block_entry(self):
                                              
                                                      # Block context needs additional checks.
                                                      if not self.flow_level:
                                              
                                              
                                              Severity: Minor
                                              Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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 scan_tag_uri has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                                  def scan_tag_uri(self, name, start_mark):
                                                      # See the specification for details.
                                                      # Note: we do not check if URI is well-formed.
                                                      chunks = []
                                                      length = 0
                                              Severity: Minor
                                              Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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 stale_possible_simple_keys has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                                  def stale_possible_simple_keys(self):
                                                      # Remove entries that are no longer possible simple keys. According to
                                                      # the YAML specification, simple keys
                                                      # - should be limited to a single line,
                                                      # - should be no longer than 1024 characters.
                                              Severity: Minor
                                              Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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 scan_anchor has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                                  def scan_anchor(self, TokenClass):
                                                      # The specification does not restrict characters for anchors and
                                                      # aliases. This may lead to problems, for instance, the document:
                                                      #   [ *alias, value ]
                                                      # can be interpteted in two ways, as
                                              Severity: Minor
                                              Found in src/collectors/python.d.plugin/python_modules/pyyaml3/scanner.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

                                              There are no issues that match your filters.

                                              Category
                                              Status