polkadot-js/common

View on GitHub

Showing 304 of 304 total issues

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

  it('does not extract from invalid paths (2)', (): void => {
    expect(
      (): ExtractResult => keyExtractPath('hello')
    ).toThrow(/does not match input/);
  });
Severity: Minor
Found in packages/util-crypto/src/key/extractPath.spec.ts and 2 other locations - About 30 mins to fix
packages/util-crypto/src/address/decode.spec.ts on lines 118..122
packages/util-crypto/src/key/extractPath.spec.ts on lines 40..44

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

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

  it('returns false on hex values (non % 2)', (): void => {
    expect(
      isHex(`0x${test}0`)
    ).toEqual(false);
  });
Severity: Minor
Found in packages/util/src/is/hex.spec.ts and 1 other location - About 30 mins to fix
packages/util/src/is/hex.spec.ts on lines 19..23

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

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 false;
Severity: Major
Found in packages/util/src/is/utf8.ts - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

              return false;
    Severity: Major
    Found in packages/util/src/is/utf8.ts - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                return false;
      Severity: Major
      Found in packages/util/src/is/utf8.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return false;
        Severity: Major
        Found in packages/util/src/is/utf8.ts - About 30 mins to fix

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

            it('fails when length is invalid', (): void => {
              expect(
                (): Uint8Array => decodeAddress('y9EMHt34JJo4rWLSaxoLGdYXvjgSXEd4zHUnQgfNzwES8b')
              ).toThrow(/address length/);
            });
          Severity: Minor
          Found in packages/util-crypto/src/address/decode.spec.ts and 2 other locations - About 30 mins to fix
          packages/util-crypto/src/key/extractPath.spec.ts on lines 40..44
          packages/util-crypto/src/key/extractPath.spec.ts on lines 46..50

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

          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

                    return [5, new BN(u8a[1] + (u8a[2] << 8) + (u8a[3] << 16) + (u8a[4] * 0x1_00_00_00))];
          Severity: Minor
          Found in packages/util/src/compact/fromU8a.ts and 1 other location - About 30 mins to fix
          packages/util/src/u8a/toBn.ts on lines 90..90

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

          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 bnSqrt has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          export function bnSqrt <ExtToBn extends ToBn> (value: ExtToBn | BN | bigint | string | number | null): BN {
            const n = bnToBn(value);
          
            if (n.isNeg()) {
              throw new Error('square root of negative numbers is not supported');
          Severity: Minor
          Found in packages/util/src/bn/sqrt.ts - 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 ed25519Verify has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          export function ed25519Verify (message: string | Uint8Array, signature: string | Uint8Array, publicKey: string | Uint8Array, onlyJs?: boolean): boolean {
            const messageU8a = u8aToU8a(message);
            const publicKeyU8a = u8aToU8a(publicKey);
            const signatureU8a = u8aToU8a(signature);
          
          
          Severity: Minor
          Found in packages/util-crypto/src/ed25519/verify.ts - 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 u8aToNumber has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          export function u8aToNumber (value: Uint8Array, { isLe = true, isNegative = false }: ToBnOptions = {}): number {
            // slice + reverse is expensive, however SCALE is LE by default so this is the path
            // we are most interested in (the BE is added for the sake of being comprehensive)
            if (!isLe) {
              value = value.slice().reverse();
          Severity: Minor
          Found in packages/util/src/u8a/toNumber.ts - 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 nSqrt has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          export function nSqrt <ExtToBn extends ToBn | ToBigInt> (value: ExtToBn | BN | bigint | string | number | null): bigint {
            const n = nToBigInt(value);
          
            if (n < _0n) {
              throw new Error('square root of negative numbers is not supported');
          Severity: Minor
          Found in packages/util/src/bi/sqrt.ts - 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 mnemonicToEntropy has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          export function mnemonicToEntropy (mnemonic: string, wordlist: string[] = DEFAULT_WORDLIST): Uint8Array {
            const words = normalize(mnemonic).split(' ');
          
            if (words.length % 3 !== 0) {
              throw new Error(INVALID_MNEMONIC);
          Severity: Minor
          Found in packages/util-crypto/src/mnemonic/bip39.ts - 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 memoize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          export function memoize <T, F extends (...args: any[]) => T> (fn: F, { getInstanceId = defaultGetId }: Options = {}): Memoized<F> {
            const cache: Record<string, Record<string, T>> = {};
          
            const memoized = (...args: unknown[]): T => {
              const stringParams = stringify(args);
          Severity: Minor
          Found in packages/util/src/memoize.ts - 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 hexToU8a has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          export function hexToU8a (_value?: string | null, bitLength = -1): Uint8Array {
            if (!_value) {
              return new Uint8Array();
            }
          
          
          Severity: Minor
          Found in packages/util/src/hex/toU8aBuffer.ts - 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 randomWords has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          const randomWords = arrayRange(256).map((): [string] => {
            let result = '';
          
            for (let i = 0; i < 6; i++) {
              let word = words[randomAsNumber() % words.length];
          Severity: Minor
          Found in packages/util/src/string/camelCase.spec.ts - 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 lazyMethod has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          export function lazyMethod <T, K, S> (result: Record<string, T> | AnyFn, item: K, creator: (item: K, index: number, self: S) => T, getName?: (item: K, index: number) => string, index = 0): void {
            const name = getName
              ? getName(item, index)
              : (item as WithToString).toString();
            let value: T | undefined;
          Severity: Minor
          Found in packages/util/src/lazy.ts - 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 arrayFlatten has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          export function arrayFlatten <T> (arrays: readonly T[][]): T[] {
            const num = arrays.length;
          
            // shortcuts for the empty & single-entry case
            if (num === 0) {
          Severity: Minor
          Found in packages/util/src/array/flatten.ts - 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 hexAddPrefix has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          export function hexAddPrefix (value?: string | null): HexString {
            return value && hexHasPrefix(value)
              ? value
              : `0x${value && value.length % 2 === 1 ? '0' : ''}${value || ''}`;
          }
          Severity: Minor
          Found in packages/util/src/hex/addPrefix.ts - 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 detectPackage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          export function detectPackage ({ name, path, type, version }: PackageInfo, pathOrFn?: FnString | string | false | null, deps: PackageInfo[] = []): void {
            if (!name.startsWith('@polkadot')) {
              throw new Error(`Invalid package descriptor ${name}`);
            }
          
          
          Severity: Minor
          Found in packages/util/src/detectPackage.ts - 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