polkadot-js/client

View on GitHub

Showing 50 of 50 total issues

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

    ed25519_verify: (msgPtr: Pointer, msgLen: number, sigPtr: Pointer, pubkeyPtr: Pointer): number =>
      instrument('ed25519_verify', (): number => {
        const m = heap.get(msgPtr, msgLen);
        const s = heap.get(sigPtr, 64);
        const p = heap.get(pubkeyPtr, 32);
Severity: Major
Found in packages/client-runtime/src/crypto/index.ts and 1 other location - About 7 hrs to fix
packages/client-runtime/src/crypto/index.ts on lines 95..108

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

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

    sr25519_verify: (msgPtr: Pointer, msgLen: number, sigPtr: Pointer, pubkeyPtr: Pointer): number =>
      instrument('sr25519_verify', (): number => {
        const m = heap.get(msgPtr, msgLen);
        const s = heap.get(sigPtr, 64);
        const p = heap.get(pubkeyPtr, 32);
Severity: Major
Found in packages/client-runtime/src/crypto/index.ts and 1 other location - About 7 hrs to fix
packages/client-runtime/src/crypto/index.ts on lines 52..65

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

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

const VERBS = [
  'wipe',
  'direct',
  'debate',
  'smile',
Severity: Major
Found in packages/client-www/src/randName.ts and 1 other location - About 3 hrs to fix
packages/client-www/src/randName.ts on lines 13..114

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

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

const NOUNS = [
  'variation',
  'supermarket',
  'people',
  'perspective',
Severity: Major
Found in packages/client-www/src/randName.ts and 1 other location - About 3 hrs to fix
packages/client-www/src/randName.ts on lines 116..217

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

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

    print_utf8: (ptr: Pointer, len: number): void =>
      instrument('print_utf8', (): void => {
        l.debug((): any[] => ['print_utf8', [ptr, len]]);

        printUtf8(l, heap.get(ptr, len));
Severity: Major
Found in packages/client-runtime/src/io/index.ts and 1 other location - About 2 hrs to fix
packages/client-runtime/src/io/index.ts on lines 15..20

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

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

    print_hex: (ptr: Pointer, len: number): void =>
      instrument('print_hex', (): void => {
        l.debug((): any[] => ['print_hex', [ptr, len]]);

        printHex(l, heap.get(ptr, len));
Severity: Major
Found in packages/client-runtime/src/io/index.ts and 1 other location - About 2 hrs to fix
packages/client-runtime/src/io/index.ts on lines 29..34

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

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

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

                    if (config.rpc && config.rpc.active && config.rpc.port) {
                      this.rpc = new Rpc(config as Config, this.chain);
                    }
                Severity: Major
                Found in packages/client/src/index.ts and 1 other location - About 1 hr to fix
                packages/client/src/index.ts on lines 66..68

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

                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

                    memmove: (dst: Pointer, src: Pointer, num: number): Pointer =>
                      instrument('memmove', (): Pointer => {
                        // l.debug(() => ['memmove', [dst, src, num]]);
                
                        return memmove(heap, dst, src, num);
                Severity: Major
                Found in packages/client-runtime/src/memory/index.ts and 1 other location - About 1 hr to fix
                packages/client-runtime/src/memory/index.ts on lines 29..34

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

                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

                    memcpy: (dst: Pointer, src: Pointer, num: number): Pointer =>
                      instrument('memcpy', (): Pointer => {
                        // l.debug(() => ['memcpy', [dst, src, num]]);
                
                        return memcpy(heap, dst, src, num);
                Severity: Major
                Found in packages/client-runtime/src/memory/index.ts and 1 other location - About 1 hr to fix
                packages/client-runtime/src/memory/index.ts on lines 41..46

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

                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 (config.p2p && config.p2p.active && config.p2p.port) {
                      this.p2p = new P2p(config as Config, this.chain);
                    }
                Severity: Major
                Found in packages/client/src/index.ts and 1 other location - About 1 hr to fix
                packages/client/src/index.ts on lines 70..72

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

                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 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
                  Severity
                  Category
                  Status
                  Source
                  Language