polkadot-js/client

View on GitHub

Showing 50 of 50 total issues

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

  private __retrieveKey (key: KeyParts, value: Uint8Array | null, withValue: boolean, keyIndex: number, hdr: Uint8Array, hdrAt: number, keyAt: number): KVInfo | null {
    const hdrIndex = key.nibbles[keyIndex];
    const keyData = this._readKey(key.fileAt, keyAt);
    const prevKey = serializeKey(keyData.subarray(0, KEY_DATA_SIZE));
    let matchIndex = keyIndex;
Severity: Minor
Found in packages/client-db/src/engines/FileStructDb/Impl.ts - 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 queueBlocks has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  public queueBlocks (peer: PeerInterface, { blocks, id }: BlockResponse): void {
    const request = this.blockRequests.get(peer.id);
    const bestNumber = this.chain.blocks.bestNumber.get();

    this.blockRequests.delete(peer.id);
Severity: Minor
Found in packages/client-sync/src/index.ts - 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 _dialPeers has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  private _dialPeers (peer?: PeerInterface): void {
    if (this.dialTimer !== null) {
      clearTimeout(this.dialTimer);

      this.dialTimer = null;
Severity: Minor
Found in packages/client-p2p/src/index.ts - About 1 hr to fix

    Function incommingDial has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          const incommingDial = (offer: SSOffer): void => {
            if (offer.answer || offer.err) {
              return;
            }
    
    
    Severity: Minor
    Found in packages/client-signal/src/client.ts - About 1 hr to fix

      Function add has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        public add (peerInfo: PeerInfo): PeerInterface {
          const id = peerInfo.id.toB58String();
          const info = this.map.get(id);
      
          if (info) {
      Severity: Minor
      Found in packages/client-p2p/src/peers/index.ts - About 1 hr to fix

        Function _get has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private _get (key: Uint8Array): Uint8Array | null {
            const info = this._findValue(serializeKey(key));
        
            // console.log('_get', this._isTrie, key, info);
        
        
        Severity: Minor
        Found in packages/client-db/src/engines/FileStructDb/index.ts - About 1 hr to fix

          Function addConnection has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            public addConnection (connection: LibP2pConnection, isWritable: boolean): number {
              const connId = this.nextConnId++;
              const pushable = isWritable
                ? PullPushable((error): void => {
                  l.debug((): any[] => [`${this.shortId} pushable error`, error]);
          Severity: Minor
          Found in packages/client-p2p/src/peer/index.ts - About 1 hr to fix

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

                    (error): boolean => {
                      l.debug((): any[] => [`${this.shortId} receive error`, error]);
            
                      this.clearConnection(connId);
            
            
            Severity: Minor
            Found in packages/client-p2p/src/peer/index.ts and 1 other location - About 55 mins to fix
            packages/client-p2p/src/peer/index.ts on lines 250..256

            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 54.

            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

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

                } catch (error) {
                  l.debug((): any[] => [`${this.shortId} receive error`, error]);
            
                  this.clearConnection(connId);
            
            
            Severity: Minor
            Found in packages/client-p2p/src/peer/index.ts and 1 other location - About 55 mins to fix
            packages/client-p2p/src/peer/index.ts on lines 242..248

            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 54.

            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

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

              public put (key: Uint8Array, value: Uint8Array): void {
                // l.debug(() => ['put', { key, value }]);
            
                this._cache.set(key.toString(), value);
            
            
            Severity: Minor
            Found in packages/client-db/src/engines/FileStructDb/index.ts - 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

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

            function handleBlockResponse ({ sync }: P2pInterface, peer: PeerInterface, message: BlockResponse): void {
              // self.l.debug(() => [peer.shortId, 'BlockResponse', JSON.stringify(message)]);
            
              sync.queueBlocks(peer, message);
            }
            Severity: Minor
            Found in packages/client-p2p/src/handler/blockResponse.ts and 1 other location - About 55 mins to fix
            packages/client-p2p/src/handler/blockRequest.ts on lines 10..14

            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 53.

            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

            function handleBlockRequest ({ sync }: P2pInterface, peer: PeerInterface, message: BlockRequest): void {
              // self.l.debug(() => [peer.shortId, 'BlockRequest', JSON.stringify(message)]);
            
              sync.provideBlocks(peer, message);
            }
            Severity: Minor
            Found in packages/client-p2p/src/handler/blockRequest.ts and 1 other location - About 55 mins to fix
            packages/client-p2p/src/handler/blockResponse.ts on lines 10..14

            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 53.

            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

                twox_128: (dataPtr: Pointer, dataLen: number, outPtr: Pointer): void =>
                  instrument('twox_128', (): void =>
                    twox(128, dataPtr, dataLen, outPtr)
                  ),
            Severity: Minor
            Found in packages/client-runtime/src/crypto/index.ts and 1 other location - About 50 mins to fix
            packages/client-runtime/src/crypto/index.ts on lines 115..118

            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 52.

            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

                twox_256: (dataPtr: Pointer, dataLen: number, outPtr: Pointer): void =>
                  instrument('twox_128', (): void =>
                    twox(256, dataPtr, dataLen, outPtr)
                  )
            Severity: Minor
            Found in packages/client-runtime/src/crypto/index.ts and 1 other location - About 50 mins to fix
            packages/client-runtime/src/crypto/index.ts on lines 110..113

            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 52.

            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

              public get (ptr: Pointer, len: number): Uint8Array {
                return this.memory.uint8.subarray(ptr, ptr + len);
              }
            Severity: Minor
            Found in packages/client-runtime/src/environment/heap/index.ts and 1 other location - About 45 mins to fix
            packages/client-runtime/src/environment/heap/index.ts on lines 59..61

            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 50.

            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

              public dup (ptr: Pointer, len: number): Uint8Array {
                return this.memory.uint8.slice(ptr, ptr + len);
              }
            Severity: Minor
            Found in packages/client-runtime/src/environment/heap/index.ts and 1 other location - About 45 mins to fix
            packages/client-runtime/src/environment/heap/index.ts on lines 90..92

            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 50.

            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

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

              public listen (ma: Multiaddr, _callback: (error: Error | null) => void = noop): void {
                const callback = once(_callback);
            
                if (!this.options.wrtc && !getBrowserRtc()) {
                  return callback(new Error('WebRTC is not supported by your environment'));
            Severity: Minor
            Found in packages/client-signal/src/client.ts - 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 open has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              public open (): void {
                for (let i = 0; i < DB_MAX_FILES; i++) {
                  this._fds[i] = (['idx', 'key', 'val'] as (keyof Fds)[]).reduce((fds: any, type): Fds => {
                    const count = `0${i.toString(16)}`.slice(-2);
                    const file = path.join(this._path, `${count}.${type as string}`);
            Severity: Minor
            Found in packages/client-db/src/engines/FileStructDb/Files.ts - 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 wasm has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            export default async function wasm ({ config: { wasm: { heapSize = defaults.HEAP_SIZE_KB } }, l }: Options, runtime: RuntimeInterface, chainCode: Uint8Array, chainProxy: Uint8Array, forceNew = false): Promise<WasmInstanceExports> {
            Severity: Minor
            Found in packages/client-wasm/src/create/index.ts - About 35 mins to fix

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

                public get to (): Option<Hash> {
                  return this.message.get('to') as Option<Hash>;
                }
              Severity: Major
              Found in packages/client-types/src/messages/BlockRequest.ts and 3 other locations - About 35 mins to fix
              packages/client-types/src/messages/BlockRequest.ts on lines 95..97
              packages/client-types/src/messages/BlockResponse.ts on lines 36..38
              packages/client-types/src/messages/Transactions.ts on lines 26..28

              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 47.

              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

              Severity
              Category
              Status
              Source
              Language