polkadot-js/api

View on GitHub

Showing 39 of 146 total issues

Extrinsic has 28 functions (exceeds 20 allowed). Consider refactoring.
Open

export default class Extrinsic extends Base<ExtrinsicVx | ExtrinsicUnknown> implements IExtrinsic {
  constructor (value: Extrinsic | ExtrinsicValue | AnyU8a | Call | undefined, { version }: CreateOptions = {}) {
    super(Extrinsic.decodeExtrinsic(value, version));
  }

Severity: Minor
Found in packages/types/src/primitive/Extrinsic/Extrinsic.ts - About 3 hrs to fix

    File MetaRegistry.ts has 281 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    // Copyright 2017-2019 @polkadot/api-contract 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 { MetaRegistryItem, MetaRegistryJson, MetaTypeDefClikeEnum, MetaType, MetaTypeDefEnum, MetaTypeDefEnumVariant, MetaTypeDefEnumVariantStruct, MetaTypeDefEnumVariantTupleStruct, MetaTypeDefEnumVariantUnit, MetaTypeDefStruct, MetaTypeDefStructField, MetaTypeDefTupleStruct, MetaTypeDefUnion, MetaTypeIdCustom, MetaTypeIdVec, MetaTypeIdVecFixed, MetaTypeInfo, StringIndex, TypeDef, TypeDefInfo, TypeIndex } from '@polkadot/types/types';
    Severity: Minor
    Found in packages/api-contract/src/MetaRegistry.ts - About 2 hrs to fix

      Function decorateStorageEntryLinked has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

        private decorateStorageEntryLinked<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): ReturnType<DecorateMethod<ApiType>> {
          const result: Map<Codec, [Codec, Linkage<Codec>]> = new Map();
          let subject: BehaviorSubject<LinkageResult>;
          let head: Codec | null = null;
      
      
      Severity: Minor
      Found in packages/api/src/base/Decorate.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 createMethodSubscribe has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private createMethodSubscribe (method: RpcMethod): RpcInterfaceMethod {
          const [updateType, subMethod, unsubMethod] = method.pubsub;
          const subName = `${method.section}_${subMethod}`;
          const unsubName = `${method.section}_${unsubMethod}`;
          const subType = `${method.section}_${updateType}`;
      Severity: Minor
      Found in packages/rpc-core/src/index.ts - About 1 hr to fix

        Function decorateStorageEntryLinked has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private decorateStorageEntryLinked<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): ReturnType<DecorateMethod<ApiType>> {
            const result: Map<Codec, [Codec, Linkage<Codec>]> = new Map();
            let subject: BehaviorSubject<LinkageResult>;
            let head: Codec | null = null;
        
        
        Severity: Minor
        Found in packages/api/src/base/Decorate.ts - About 1 hr to fix

          Function call has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              const call = (...values: any[]): Observable<any> => {
                return new Observable((observer: Observer<any>): VoidCallback => {
                  // Have at least an empty promise, as used in the unsubscribe
                  let subscriptionPromise: Promise<number | void> = Promise.resolve();
                  const errorHandler = (error: Error): void => {
          Severity: Minor
          Found in packages/rpc-core/src/index.ts - About 1 hr to fix

            Function decodeExtrinsicEra has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              private static decodeExtrinsicEra (value: IExtrinsicEra | MortalMethod | MortalEnumDef | ImmortalEnumDef | Uint8Array | string = new Uint8Array()): Uint8Array | Object | undefined {
                if (!value) {
                  return new Uint8Array([0]);
                } else if (value instanceof ExtrinsicEra) {
                  return ExtrinsicEra.decodeExtrinsicEra(value.toU8a());
            Severity: Minor
            Found in packages/types/src/primitive/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 typeDefDefFields has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              private typeDefDefFields (metaType: MetaType, typeIndex?: TypeIndex): Pick<TypeDef, never> {
                let typeDef;
            
                switch (detectedType(metaType)) {
                  case MetaTypeInfo.BuiltinPlain:
            Severity: Minor
            Found in packages/api-contract/src/MetaRegistry.ts - About 1 hr to fix

              Function refCountDelayInner has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function refCountDelayInner <T> (source: Observable<T>): Observable<T> {
                let connected = 0; // 0 = disconnected, 1 = disconnecting, 2 = connecting, 3 = connected
                let refCount = 0;
                let con = Subscription.EMPTY;
                let sched = Subscription.EMPTY;
              Severity: Minor
              Found in packages/rpc-core/src/rxjs/refCountDelay.ts - About 1 hr to fix

                Function decorateStorageEntry has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                  private decorateStorageEntry<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): QueryableStorageEntry<ApiType> {
                    // get the storage arguments, with DoubleMap as an array entry, otherwise spread
                    const getArgs = (...args: any[]): any[] => creator.meta.type.isDoubleMap
                      ? [creator, args]
                      : [creator, ...args];
                Severity: Minor
                Found in packages/api/src/base/Decorate.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 call has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  public call<CallType extends ContractCallTypes> (as: CallType, message: string, value: BN | number, gasLimit: BN | number, ...params: any[]): ContractCall<ApiType, CallType> {
                    const { fn, def } = this.getMessage(message);
                
                    return {
                      send: this.decorateMethod(
                Severity: Minor
                Found in packages/api-contract/src/base/Contract.ts - About 1 hr to fix

                  Function decorateStorageEntry has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    private decorateStorageEntry<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): QueryableStorageEntry<ApiType> {
                      // get the storage arguments, with DoubleMap as an array entry, otherwise spread
                      const getArgs = (...args: any[]): any[] => creator.meta.type.isDoubleMap
                        ? [creator, args]
                        : [creator, ...args];
                  Severity: Minor
                  Found in packages/api/src/base/Decorate.ts - About 1 hr to fix

                    Function calcBalances has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function calcBalances ([accountId, bestNumber, [freeBalance, reservedBalance, locks, vesting], accountNonce]: Result): DerivedBalances {
                      let lockedBalance = createType('Balance');
                      let lockedBreakdown: BalanceLock[] = [];
                    
                      if (Array.isArray(locks)) {
                    Severity: Minor
                    Found in packages/api-derive/src/balances/all.ts - About 1 hr to fix

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

                        private formatStorageSet (key: StorageKey, changes: [string, string | null][], witCache: boolean): Codec {
                          // Fallback to Data (i.e. just the encoding) if we don't have a specific type
                          const type = key.outputType || 'Data';
                          const hexKey = key.toHex();
                          const meta = key.meta || EMPTY_META;
                      Severity: Minor
                      Found in packages/rpc-core/src/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 derivePhragmen has 7 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                      function derivePhragmen (candidates: AccountId[], members: [AccountId, Balance][], runnersUp: [AccountId, Balance][], candidacyBond: Balance, desiredSeats: u32, termDuration: BlockNumber, votingBond: Balance): DerivedElectionsInfo {
                      Severity: Major
                      Found in packages/api-derive/src/elections/info.ts - About 50 mins to fix

                        Function formatStorageData has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                          private formatStorageData (key: StorageKey, value: string | null): Codec {
                            // single return value (via state.getStorage), decode the value based on the
                            // outputType that we have specified. Fallback to Data on nothing
                            const type = key.outputType || 'Data';
                            const meta = key.meta || EMPTY_META;
                        Severity: Minor
                        Found in packages/rpc-core/src/index.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 eq has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                          public eq (other?: any): boolean {
                            // cater for the case where we only pass the enum index
                            if (isNumber(other)) {
                              return this.toNumber() === other;
                            } else if (this._isBasic && isString(other)) {
                        Severity: Minor
                        Found in packages/types/src/codec/Enum.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

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

                        Function decodeVote has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                          private static decodeVote (value?: InputTypes): Uint8Array {
                            if (isUndefined(value)) {
                              return Vote.decodeVoteBool(false);
                            } else if (value instanceof Boolean || isBoolean(value)) {
                              return Vote.decodeVoteBool(new Bool(value).isTrue);
                        Severity: Minor
                        Found in packages/types/src/primitive/Generic/Vote.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 createMethodSubscribe has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                          private createMethodSubscribe (method: RpcMethod): RpcInterfaceMethod {
                            const [updateType, subMethod, unsubMethod] = method.pubsub;
                            const subName = `${method.section}_${subMethod}`;
                            const unsubName = `${method.section}_${unsubMethod}`;
                            const subType = `${method.section}_${updateType}`;
                        Severity: Minor
                        Found in packages/rpc-core/src/index.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

                        Severity
                        Category
                        Status
                        Source
                        Language