bitcoin/bitcoin

View on GitHub

Showing 80 of 84 total issues

Function to_binary has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def to_binary(self, fill: bool = False) -> bytes:
        """
        Convert this ASMap object to binary.

        Argument:
Severity: Minor
Found in contrib/seeds/asmap.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 tree_sha512sum has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

def tree_sha512sum(commit='HEAD'):
    """Calculate the Tree-sha512 for the commit.

    This is copied from github-merge.py. See https://github.com/bitcoin-core/bitcoin-maintainer-tools."""

Severity: Minor
Found in contrib/verify-commits/verify-commits.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 is_valid has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def is_valid(v):
    '''Check vector v for validity'''
    if len(set(v) - set(b58chars)) > 0:
        return is_valid_bech32(v)
    try:
Severity: Minor
Found in contrib/testgen/gen_key_io_test_vectors.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 print_report has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def print_report(file_infos, verbose):
    print(SEPARATOR)
    examined = [i['filename'] for i in file_infos]
    print("%d files examined according to INCLUDE and EXCLUDE fnmatch rules" %
          len(examined))
Severity: Minor
Found in contrib/devtools/copyright_header.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 render has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

def render(screen, peers, cur_list_pos, scroll, ROWS_AVALIABLE_FOR_LIST, info_panel):
Severity: Minor
Found in contrib/tracing/p2p_monitor.py - About 45 mins to fix

    Function update has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def update(self, prefix: list[bool], asn: int) -> None:
            """Update this ASMap object to map prefix to the specified asn."""
            assert asn == 0 or _CODER_ASN.can_encode(asn)
    
            def recurse(node: list, offset: int) -> None:
    Severity: Minor
    Found in contrib/seeds/asmap.py - About 45 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 main has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def main():
        parser = argparse.ArgumentParser(
            description=__doc__,
            epilog="EXAMPLE \n\t{0} -o out.json <data-dir>/message_capture/**/*.dat".format(sys.argv[0]),
            formatter_class=argparse.RawTextHelpFormatter)
    Severity: Minor
    Found in contrib/message-capture/message-capture-parser.py - About 45 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 deeply nested control flow statements.
    Open

                    if line.startswith("SF:") and p in line:
                        in_remove = True
                if not in_remove:
    Severity: Major
    Found in contrib/filter-lcov.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if HEADER_BATCH_COUNT * prob < 1.0e-16 * rate * len(align_choices):
                              break
                      # Update state from a new incoming batch (which is all forged)
                      after_good_commit += HEADER_BATCH_COUNT
      Severity: Major
      Found in contrib/devtools/headerssync-params.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                for path, old_asn, new_asn in diff:
                                    # Verify asmap and patched actually differ there.
                                    self.assertTrue(old_asn != new_asn)
                                    self.assertEqual(asmap.lookup(path), old_asn)
                                    self.assertEqual(patched.lookup(path), new_asn)
        Severity: Major
        Found in contrib/seeds/asmap.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if limit is not None and rate >= limit:
                                  return rate, None
                              # If the maximal term being added is negligible compared to rate, stop
                              # iterating.
                              if HEADER_BATCH_COUNT * prob < 1.0e-16 * rate * len(align_choices):
          Severity: Major
          Found in contrib/devtools/headerssync-params.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                            for dep in deps[src]:
                                if dep not in closure:
                                    closure[dep] = closure[src] + [src]
                        if len(closure) == old_size:
            Severity: Major
            Found in contrib/devtools/circular-dependencies.py - About 45 mins to fix

              Function make_branch has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def make_branch(node0: "_BinNode", node1: "_BinNode") -> "_BinNode":
                      """
                      Construct a _BinNode corresponding to running either the node0 or node1 subprogram,
                      based on the next input bit. It exploits shortcuts that are possible in the encoding,
                      and uses either a JUMP, MATCH, or END instruction.
              Severity: Minor
              Found in contrib/seeds/asmap.py - About 45 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 deeply nested control flow statements.
              Open

                                      if val[0] < threshold:
                                          ch |= BIT_PER_PIXEL[y][x]
                          line.append(chr(ch))
              Severity: Major
              Found in contrib/signet/getcoins.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                if included_module is not None and included_module in deps and included_module != module:
                                    deps[module].add(included_module)
                
                # Loop to find the shortest (remaining) circular dependency
                have_cycle: bool = False
                Severity: Major
                Found in contrib/devtools/circular-dependencies.py - About 45 mins to fix

                  Function find_bufsize has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  def find_bufsize(period, attack_headers, when, max_mem=None, min_bufsize=1):
                  Severity: Minor
                  Found in contrib/devtools/headerssync-params.py - About 35 mins to fix

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

                    def process_nodes(g, f, structname):
                        g.write('static const uint8_t %s[] = {\n' % structname)
                        for line in f:
                            comment = line.find('#')
                            if comment != -1:
                    Severity: Minor
                    Found in contrib/seeds/generate-seeds.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 parse_spec has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                    def parse_spec(s):
                        '''Convert endpoint string to BIP155 (networkID, addr, port) tuple.'''
                        match = re.match(r'\[([0-9a-fA-F:]+)\](?::([0-9]+))?$', s)
                        if match: # ipv6
                            host = match.group(1)
                    Severity: Minor
                    Found in contrib/seeds/generate-seeds.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 from_random has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def from_random(num_leaves: int = 10, max_asn: int = 6,
                                        unassigned_prob: float = 0.5) -> "ASMap":
                            """
                            Construct a random ASMap object, with specified:
                             - Number of leaves in its trie (at least 1)
                    Severity: Minor
                    Found in contrib/seeds/asmap.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 encode has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def encode(self, val: int, ret: list[int]) -> None:
                            """Append encoding of val onto integer list ret."""
                    
                            assert self._minval <= val <= self._maxval
                            val -= self._minval
                    Severity: Minor
                    Found in contrib/seeds/asmap.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

                    Severity
                    Category
                    Status
                    Source
                    Language