bitcoin/bitcoin

View on GitHub

Showing 86 of 86 total issues

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

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

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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    if 'out_of_order_cache_sz' not in settings:
        settings['out_of_order_cache_sz'] = 100 * 1000 * 1000
Severity: Minor
Found in contrib/linearize/linearize-data.py and 1 other location - About 35 mins to fix
contrib/linearize/linearize-data.py on lines 283..284

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 33.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    if 'max_out_sz' not in settings:
        settings['max_out_sz'] = 1000 * 1000 * 1000
Severity: Minor
Found in contrib/linearize/linearize-data.py and 1 other location - About 35 mins to fix
contrib/linearize/linearize-data.py on lines 285..286

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 33.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Avoid too many return statements within this function.
Open

            return _BinNode(_Instruction.MATCH, 2, node0)
Severity: Major
Found in contrib/asmap/asmap.py - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

            return obj
    Severity: Major
    Found in contrib/message-capture/message-capture-parser.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                      return None
      Severity: Major
      Found in contrib/seeds/makeseeds.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return (BIP155Network.CJDNS, addr_bytes)
        Severity: Major
        Found in contrib/seeds/generate-seeds.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                          return None
          Severity: Major
          Found in contrib/seeds/makeseeds.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return None
            Severity: Major
            Found in contrib/devtools/circular-dependencies.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return _BinNode(_Instruction.JUMP, node0, node1)
              Severity: Major
              Found in contrib/asmap/asmap.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return (BIP155Network.IPV6, addr_bytes)
                Severity: Major
                Found in contrib/seeds/generate-seeds.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return {
                  Severity: Major
                  Found in contrib/seeds/makeseeds.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return recurse(actual, require[0]) and recurse(actual, require[1])
                    Severity: Major
                    Found in contrib/asmap/asmap.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return None
                      Severity: Major
                      Found in contrib/seeds/makeseeds.py - About 30 mins to fix

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

                        def filterbyasn(asmap: ASMap, ips: list[dict], max_per_asn: dict, max_per_net: int) -> list[dict]:
                            """ Prunes `ips` by
                            (a) trimming ips to have at most `max_per_net` ips from each net (e.g. ipv4, ipv6); and
                            (b) trimming ips to have at most `max_per_asn` ips from each asn in each net.
                            """
                        Severity: Minor
                        Found in contrib/seeds/makeseeds.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 decode has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def decode(self, stream, bitpos) -> tuple[int,int]:
                                """Decode a number starting at bitpos in stream, returning value and new bitpos."""
                                val = self._minval
                                bits = 0
                                for k, bits in enumerate(self._clsbits):
                        Severity: Minor
                        Found in contrib/asmap/asmap.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 __init__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def __init__(self, ins: _Instruction, arg1=None, arg2=None):
                                """
                                Construct a new asmap node. Possibilities are:
                                - _BinNode(_Instruction.RETURN, asn)
                                - _BinNode(_Instruction.JUMP, node_0, node_1)
                        Severity: Minor
                        Found in contrib/asmap/asmap.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