polkadot-js/common

View on GitHub

Showing 7 of 9 total issues

Function nToBigInt has a Cognitive Complexity of 21 (exceeds 7 allowed). Consider refactoring.
Open

export function nToBigInt <ExtToBn extends ToBigInt | ToBn> (value?: HexString | ExtToBn | BN | bigint | string | number | null): bigint {
  return typeof value === 'bigint'
    ? value
    : !value
      ? BigInt(0)
Severity: Minor
Found in packages/util/src/bi/toBigInt.ts - About 2 hrs 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 bnToBn has a Cognitive Complexity of 21 (exceeds 7 allowed). Consider refactoring.
Open

export function bnToBn <ExtToBn extends ToBigInt | ToBn> (value?: HexString | ExtToBn | BN | bigint | string | number | null): BN {
  return BN.isBN(value)
    ? value
    : !value
      ? new BN(0)
Severity: Minor
Found in packages/util/src/bn/toBn.ts - About 2 hrs 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 createPair has a Cognitive Complexity of 20 (exceeds 7 allowed). Consider refactoring.
Open

export function createPair ({ toSS58, type }: Setup, { publicKey, secretKey }: PairInfo, meta: KeyringPair$Meta = {}, encoded: Uint8Array | null = null, encTypes?: EncryptedJsonEncoding[]): KeyringPair {
  const decodePkcs8 = (passphrase?: string, userEncoded?: Uint8Array | null): void => {
    const decoded = decodePair(passphrase, userEncoded || encoded, encTypes);

    if (decoded.secretKey.length === 64) {
Severity: Minor
Found in packages/keyring/src/pair/index.ts - About 2 hrs 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 getUnits has a Cognitive Complexity of 18 (exceeds 7 allowed). Consider refactoring.
Open

function getUnits (si: SiDef, withSi: boolean, withSiFull: boolean, withUnit: boolean | string): string {
  const unit = isBoolean(withUnit)
    ? SI[SI_MID].text
    : withUnit;

Severity: Minor
Found in packages/util/src/format/formatBalance.ts - About 2 hrs 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 u8aEq has a Cognitive Complexity of 11 (exceeds 7 allowed). Consider refactoring.
Open

export function u8aEq (a: HexString | Uint8Array | string, b: HexString | Uint8Array | string): boolean {
  const u8aa = u8aToU8a(a);
  const u8ab = u8aToU8a(b);

  if (u8aa.length === u8ab.length) {
Severity: Minor
Found in packages/util/src/u8a/eq.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 u8aToU8a has a Cognitive Complexity of 11 (exceeds 7 allowed). Consider refactoring.
Open

export function u8aToU8a (value?: U8aLike | null): Uint8Array {
  return !value
    ? new Uint8Array()
    : Array.isArray(value) || isBuffer(value)
      ? new Uint8Array(value)
Severity: Minor
Found in packages/util/src/u8a/toU8a.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 u8aCmp has a Cognitive Complexity of 10 (exceeds 7 allowed). Consider refactoring.
Open

export function u8aCmp (a: HexString | Uint8Array | string, b: HexString | Uint8Array | string): number {
  const u8aa = u8aToU8a(a);
  const u8ab = u8aToU8a(b);
  let i = 0;

Severity: Minor
Found in packages/util/src/u8a/cmp.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