polkadot-js/api

View on GitHub

Showing 12 of 96 total issues

Function parseRewards has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function parseRewards (api: ApiInterfaceRx, stashId: AccountId, [, erasPoints, erasPrefs, erasRewards]: ErasResult, exposures: DeriveStakerExposure[]): DeriveStakerReward[] {
  return exposures.map(({ era, isEmpty, isValidator, nominating, validators: eraValidators }): DeriveStakerReward => {
    const { eraPoints, validators: allValPoints } = erasPoints.find((p) => p.era.eq(era)) || { eraPoints: ZERO, validators: {} };
    const { eraReward } = erasRewards.find((r) => r.era.eq(era)) || { eraReward: api.registry.createType('Balance') };
    const { validators: allValPrefs } = erasPrefs.find((p) => p.era.eq(era)) || { validators: {} as DeriveEraValPrefs };
Severity: Minor
Found in packages/api-derive/src/staking/stakerRewards.ts - About 1 hr to fix

    Function _decodeAddress has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      private static _decodeAddress (registry: Registry, value: AnyAddress): GenericAccountId | GenericAccountIndex {
        return value instanceof GenericLookupSource
          ? value._raw
          : value instanceof GenericAccountId || value instanceof GenericAccountIndex
            ? value
    Severity: Minor
    Found in packages/types/src/generic/LookupSource.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 _decodeExtrinsicEra has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      private static _decodeExtrinsicEra (value: IExtrinsicEra | MortalMethod | MortalEnumDef | ImmortalEnumDef | Uint8Array | string = new Uint8Array()): Uint8Array | Object | undefined {
        if (value instanceof GenericExtrinsicEra) {
          return GenericExtrinsicEra._decodeExtrinsicEra(value.toU8a());
        } else if (isHex(value)) {
          return GenericExtrinsicEra._decodeExtrinsicEra(hexToU8a(value));
    Severity: Minor
    Found in packages/types/src/extrinsic/ExtrinsicEra.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 _decodeAddress has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      private static _decodeAddress (registry: Registry, value: AnyAddress): GenericEthereumAccountId | GenericAccountIndex {
        return value instanceof GenericEthereumLookupSource
          ? value._raw
          : value instanceof GenericEthereumAccountId || value instanceof GenericAccountIndex
            ? value
    Severity: Minor
    Found in packages/types/src/ethereum/LookupSource.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 refCountDelay has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function refCountDelay <T> (delay = 1750): MonoTypeOperatorFunction<T> {
      return (source: Observable<T>): Observable<T> => {
        // state: 0 = disconnected, 1 = disconnecting, 2 = connecting, 3 = connected
        let [state, refCount, connection, scheduler] = [0, 0, Subscription.EMPTY, Subscription.EMPTY];
    
    
    Severity: Minor
    Found in packages/rpc-core/src/util/refCountDelay.ts - About 1 hr to fix

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

      export function createFunction (registry: Registry, itemFn: CreateItemFn, options: CreateItemOptions): StorageEntry {
        const { meta: { type } } = itemFn;
        const [hasher, key2Hasher] = getHashers(itemFn);
      
        // Can only have zero or one argument:
      Severity: Minor
      Found in packages/metadata/src/decorate/storage/createFunction.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 calcBalances has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBalance, frozenFee, frozenMisc, reservedBalance, votingBalance }, bestNumber, [vesting, locks]]: Result): DeriveBalancesAll {
        const { allLocked, lockedBalance, lockedBreakdown, vestingLocked } = calcLocked(api, bestNumber, locks);
        // Calculate the vesting balances,
        //  - offset = balance locked at startingBlock
        //  - perBlock is the unlock amount
      Severity: Minor
      Found in packages/api-derive/src/balances/all.ts - About 35 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 compareRationals has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      export function compareRationals (n1: BN, d1: BN, n2: BN, d2: BN): boolean {
        while (true) {
          const q1 = n1.div(d1);
          const q2 = n2.div(d2);
      
      
      Severity: Minor
      Found in packages/api-derive/src/democracy/util.ts - About 35 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 findClosing has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      export function findClosing (value: string, start: number): number {
        let depth = 0;
      
        for (let index = start; index < value.length; index++) {
          if (value[index] === '>') {
      Severity: Minor
      Found in packages/types/src/create/sanitize.ts - About 35 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

      Avoid too many return statements within this function.
      Open

        return decodeMultiU8a(registry, value);
      Severity: Major
      Found in packages/types/src/generic/MultiAddress.ts - About 30 mins to fix

        Function parseDetails has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        function parseDetails (stashId: AccountId, [controllerIdOpt, nominatorsOpt, rewardDestination, validatorPrefs, exposure]: MultiResult, stakingLedgerOpt: Option<StakingLedger>): DeriveStakingQuery {
          const nominators = nominatorsOpt && nominatorsOpt.unwrapOr(null);
        
          return {
            accountId: stashId,
        Severity: Minor
        Found in packages/api-derive/src/staking/query.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 decodeMultiU8a has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        function decodeMultiU8a (registry: Registry, value?: unknown): unknown {
          if (isU8a(value) && value.length <= 32) {
            if (value.length === 32) {
              return { id: value };
            } else if (value.length === 20) {
        Severity: Minor
        Found in packages/types/src/generic/MultiAddress.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