polkadot-js/api

View on GitHub

Showing 19 of 136 total issues

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

// Copyright 2017-2020 @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, Registry, StringIndex, TypeDef, TypeDefInfo, TypeIndex } from '@polkadot/types/types';
Severity: Minor
Found in packages/api-contract/src/MetaRegistry.ts - About 2 hrs to fix

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

    function votesCurr (api: ApiInterfaceRx, referendumId: BN): Observable<DeriveReferendumVote[]> {
      return api.query.democracy.votingOf.entries<Voting>().pipe(
        map((allVoting): DeriveReferendumVote[] => {
          const mapped = allVoting.map(([key, voting]): [AccountId, Voting] => [key.args[0] as AccountId, voting]);
          const votes = mapped
    Severity: Minor
    Found in packages/api-derive/src/democracy/referendumsInfo.ts - About 1 hr to fix

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

      export default function createFunction (registry: Registry, itemFn: CreateItemFn, options: CreateItemOptions): StorageEntry {
        const { meta: { type } } = itemFn;
        const stringKey = expandKey(itemFn, options);
        const [hasher, key2Hasher] = getHashers(itemFn);
      
      

      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 = -1): 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 calcVotesPrev has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function calcVotesPrev (votesFor: DeriveReferendumVote[]): DeriveReferendumVoteState {
          return votesFor.reduce((state: DeriveReferendumVoteState, derived): DeriveReferendumVoteState => {
            const { balance, vote } = derived;
            const isDefault = vote.conviction.index === 0;
            const counted = balance
        Severity: Minor
        Found in packages/api-derive/src/democracy/util.ts - About 1 hr to fix

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

          function refCountDelayInner <T> (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];
          
            return new Observable((ob): TeardownLogic => {
          Severity: Minor
          Found in packages/rpc-core/src/rxjs/refCountDelay.ts - About 1 hr to fix

            Function extendLinkedMap has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            function extendLinkedMap (registry: Registry, itemFn: CreateItemFn, storageFn: StorageEntry, stringKey: string, hasher: HasherFunction, metaVersion: number): StorageEntry {
            Severity: Minor
            Found in packages/metadata/src/Decorated/storage/fromMetadata/createFunction.ts - About 45 mins to fix

              Function createKey has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              function createKey (registry: Registry, itemFn: CreateItemFn, stringKey: string, arg: CreateArgType, hasher: (value: Uint8Array) => Uint8Array, metaVersion: number): Uint8Array {
              Severity: Minor
              Found in packages/metadata/src/Decorated/storage/fromMetadata/createFunction.ts - About 45 mins to fix

                Function createKeyDoubleMap has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                function createKeyDoubleMap (registry: Registry, itemFn: CreateItemFn, stringKey: string, args: [CreateArgType, CreateArgType], [hasher1, hasher2]: [HasherFunction, HasherFunction?], metaVersion: number): Uint8Array {
                Severity: Minor
                Found in packages/metadata/src/Decorated/storage/fromMetadata/createFunction.ts - About 45 mins to fix

                  Function createDescriptor has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  export default function createDescriptor (registry: Registry, section: string, sectionIndex: number, methodIndex: number, callMetadata: RegistryMetadataCall): CallFunction {

                    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 decodeString(registry, value);
                    Severity: Major
                    Found in packages/types/src/generic/Address.ts - About 30 mins to fix

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

                        private static _decodeAddress (registry: Registry, value: AnyAddress): AccountId | AccountIndex {
                          if (value instanceof AccountId || value instanceof AccountIndex) {
                            return value;
                          } else if (value instanceof Address) {
                            return value._raw;
                      Severity: Minor
                      Found in packages/types/src/generic/Address.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 parseLock has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                      function parseLock (api: ApiInterfaceRx, [referendumId, accountVote]: VotingDirectVote, referendum: ReferendumInfo): DeriveDemocracyLock {
                        const { balance, vote } = accountVote.asStandard;
                        let unlockAt = ZERO;
                      
                        if (referendum.isFinished) {
                      Severity: Minor
                      Found in packages/api-derive/src/democracy/locks.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 decodeDataU8a has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                      function decodeDataU8a (registry: Registry, value: Uint8Array): [any, number | undefined] {
                        if (!value.length) {
                          return [undefined, undefined];
                        }
                      
                      
                      Severity: Minor
                      Found in packages/types/src/primitive/Data.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 toLatest has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                      export default function toLatest (registry: Registry, { extrinsic, modules }: MetadataV11): MetadataLatest {
                        return registry.createType('MetadataLatest', {
                          extrinsic,
                          modules: modules.map((mod): ModuleMetadataLatest => {
                            const calls = mod.calls.unwrapOr(null);
                      Severity: Minor
                      Found in packages/metadata/src/Metadata/v11/toLatest.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 decodeVote has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                      function decodeVote (registry: Registry, value?: InputTypes): Uint8Array {
                        if (isUndefined(value) || value instanceof Boolean || isBoolean(value)) {
                          return decodeVoteBool(new Bool(registry, value).isTrue);
                        } else if (isNumber(value)) {
                          return decodeVoteBool(value < 0);
                      Severity: Minor
                      Found in packages/types/src/generic/Vote.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 calcPassing has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                      export function calcPassing (threshold: VoteThreshold, sqrtElectorate: BN, { votedAye, votedNay, votedTotal }: ApproxState): boolean {
                        const sqrtVoters = bnSqrt(votedTotal);
                      
                        return sqrtVoters.isZero()
                          ? false
                      Severity: Minor
                      Found in packages/api-derive/src/democracy/util.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