polkadot-js/client

View on GitHub

Showing 26 of 50 total issues

Function listen has 59 lines of code (exceeds 25 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: Major
Found in packages/client-signal/src/client.ts - About 2 hrs to fix

    Function dial has 55 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      public dial (ma: Multiaddr, options: any, _callback: any): void {
        if (typeof options === 'function') {
          _callback = options;
          options = {};
        }
    Severity: Major
    Found in packages/client-signal/src/client.ts - About 2 hrs to fix

      File index.ts has 253 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      // Copyright 2017-2019 @polkadot/client-sync authors & contributors
      // This software may be modified and distributed under the terms
      // of the Apache-2.0 license. See the LICENSE file for details.
      
      import { Config } from '@polkadot/client/types';
      Severity: Minor
      Found in packages/client-sync/src/index.ts - About 2 hrs to fix

        Function crypto has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function crypto ({ l, heap }: RuntimeEnv): RuntimeInterfaceCrypto {
          const twox = (bitLength: number, dataPtr: Pointer, dataLen: number, outPtr: Pointer): void => {
            const data = heap.get(dataPtr, dataLen);
            const hash = xxhashAsU8a(data, bitLength);
        
        
        Severity: Minor
        Found in packages/client-runtime/src/crypto/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 _receive has 44 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private _receive (connection: LibP2pConnection, connId: number): boolean {
            let data: Uint8Array | null = null;
            let received: number;
            let remaining = 0;
        
        
        Severity: Minor
        Found in packages/client-p2p/src/peer/index.ts - About 1 hr to fix

          Function data has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

          export default function data ({ l, heap, stateDb }: RuntimeEnv): RuntimeInterfaceStorageData {
            return {
              // eslint-disable-next-line @typescript-eslint/camelcase
              clear_prefix: (prefixPtr: Pointer, prefixLength: number): void =>
                instrument('clear_prefix', (): void => {
          Severity: Minor
          Found in packages/client-runtime/src/storage/data.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 ping has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            private async ping (): Promise<boolean> {
              if (!this.node || !this.isActive()) {
                this.startPing();
                return false;
              }
          Severity: Minor
          Found in packages/client-p2p/src/peer/index.ts - About 1 hr to fix

            Function __retrieveKey has 37 lines of code (exceeds 25 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

              Function put has 35 lines of code (exceeds 25 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 1 hr to fix

                Function queueBlocks has 30 lines of code (exceeds 25 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

                  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 __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 _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

                            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

                            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

                            Severity
                            Category
                            Status
                            Source
                            Language