bitcoin/bitcoin

View on GitHub

Showing 82 of 86 total issues

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

    def _set_trie(self, trie) -> None:
        """Set trie directly. Internal use only."""
        def recurse(node: list) -> None:
            if len(node) < 2:
                return
Severity: Minor
Found in contrib/asmap/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 test_asmap_roundtrips has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def test_asmap_roundtrips(self) -> None:
        """Test case that verifies random ASMap objects roundtrip to/from entries/binary."""
        # Iterate over the number of leaves the random test ASMap objects have.
        for leaves in range(1, 20):
            # Iterate over the number of bits in the AS numbers used.
Severity: Minor
Found in contrib/asmap/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 parse_config_into_btc_config has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

def parse_config_into_btc_config():
    def find_between( s, first, last ):
        try:
            start = s.index( first ) + len( first )
            end = s.index( last, start )
Severity: Minor
Found in build_msvc/msvc-autogen.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

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

    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/asmap/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 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

                        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 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/asmap/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

                                  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/asmap/asmap.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

                              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 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 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 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/asmap/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