polkadot-js/api

View on GitHub

Showing 179 of 2,612 total issues

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

    const modules = callKeys.map((section) => {
      const calls = definitions[section];

      const allMethods = Object.keys(calls).sort().map((methodName) => {
        const def = calls[methodName];
Severity: Minor
Found in packages/typegen/src/generate/runtime.ts - About 1 hr to fix

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

    function calcVesting (bestNumber: BlockNumber, shared: DeriveBalancesAllAccountData, _vesting: PalletVestingVestingInfo[] | null): DeriveBalancesAllVesting {
      // Calculate the vesting balances,
      //  - offset = balance locked at startingBlock
      //  - perBlock is the unlock amount
      const vesting = _vesting || [];
    Severity: Minor
    Found in packages/api-derive/src/balances/all.ts - About 1 hr to fix

      Consider simplifying this complex logical expression.
      Open

            if (type === 'Bytes') {
              portable = registry.lookup.types.find((t) =>
                (
                  t.type.def.isSequence &&
                  t.type.def.asSequence.type.eq(u8.id)
      Severity: Major
      Found in packages/types/src/metadata/decorate/storage/util.ts - About 1 hr to fix

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

        export function getWSErrorString (code: number): string {
          if (code >= 0 && code <= 999) {
            return '(Unused)';
          } else if (code >= 1016) {
            if (code <= 1999) {
        Severity: Minor
        Found in packages/rpc-provider/src/ws/errors.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 calcShared has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        function calcShared (api: DeriveApi, bestNumber: BlockNumber, data: DeriveBalancesAccountData, locks: (PalletBalancesBalanceLock | BalanceLockTo212)[]): DeriveBalancesAllAccountData {
          const { allLocked, lockedBalance, lockedBreakdown, vestingLocked } = calcLocked(api, bestNumber, locks);
          let transferable = null;
        
          if (data?.frameSystemAccountInfo?.frozen) {
        Severity: Minor
        Found in packages/api-derive/src/balances/all.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 typeSplit has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        export function typeSplit (type: string): string[] {
          const result: string[] = [];
        
          // these are the depths of the various tokens: <, [, {, (
          let c = 0;
        Severity: Minor
        Found in packages/types-create/src/util/typeSplit.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 createValue has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        function createValue (registry: Registry, type: string, value: unknown, asArray = true): Option<Codec> {
          // We detect codec here as well - when found, generally this is constructed from itself
          if (value && isFunction((value as Option<Codec>).unwrapOrDefault)) {
            return value as Option<Codec>;
          }
        Severity: Minor
        Found in packages/types/src/generic/ChainProperties.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 _decodeFixedVec has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        function _decodeFixedVec (value: TypeDef, type: string, _: string, count: number): TypeDef {
          const max = type.length - 1;
          let index = -1;
          let inner = 0;
        
        
        Severity: Minor
        Found in packages/types-create/src/util/getTypeDef.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 generateCallTypes has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        export function generateCallTypes (registry: Registry, meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
        Severity: Minor
        Found in packages/typegen/src/generate/runtime.ts - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                    if (ver) {
                      const methods = Object.entries(ver.methods);
                      const mcount = methods.length;
          
                      if (mcount) {
          Severity: Major
          Found in packages/typegen/src/generate/runtime.ts - About 45 mins to fix

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

            function getModules (api: DeriveApi): [string, string | null] {
              const [council] = api.registry.getModuleInstances(api.runtimeVersion.specName, 'council') || ['council'];
              const elections = api.query['phragmenElection']
                ? 'phragmenElection'
                : api.query['electionsPhragmen']
            Severity: Minor
            Found in packages/api-derive/src/elections/info.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 splitAlternatives has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            function splitAlternatives (type: string): string[] {
              const alternatives = [];
              let beginOfAlternative = 1;
              let level = 0;
            
            
            Severity: Minor
            Found in packages/typegen/src/util/imports.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 filterEvents has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            export function filterEvents (txHash: H256, { block: { extrinsics, header } }: SignedBlock, allEvents: EventRecord[], status: ExtrinsicStatus): { events?: EventRecord[], txIndex?: number, blockNumber?: BlockNumber } {
              // extrinsics to hashes
              for (const [txIndex, x] of extrinsics.entries()) {
                if (x.hash.eq(txHash)) {
                  return {
            Severity: Minor
            Found in packages/api/src/util/filterEvents.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 dualParamsNotation has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            function dualParamsNotation (registry: Registry, wrapper: string, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean): string {
            Severity: Minor
            Found in packages/typegen/src/util/formatting.ts - About 45 mins to fix

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

              export function extractStorageArgs (registry: Registry, creator: StorageEntry, _args: unknown[]): [StorageEntry, unknown[]] {
                const args = _args.filter((a) => !isUndefined(a));
              
                if (creator.meta.type.isPlain) {
                  if (args.length !== 0) {
              Severity: Minor
              Found in packages/api/src/util/validate.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 generateForMeta has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              function generateForMeta (registry: Registry, meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
              Severity: Minor
              Found in packages/typegen/src/generate/query.ts - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                  if (!skipInspectType) {
                                    it(`output ${type} is known`, (): void => {
                                      expect(() => inspectType(type)).not.toThrow();
                                    });
                                  }
                Severity: Major
                Found in packages/types/src/interfaces/definitions.spec.ts - About 45 mins to fix

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

                  function singleParamNotation (registry: Registry, wrapper: string, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean): string {
                  Severity: Minor
                  Found in packages/typegen/src/util/formatting.ts - About 45 mins to fix

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

                    function tsResultGetter (registry: Registry, definitions: Record<string, ModuleTypes>, resultName = '', getter: 'Ok' | 'Err', def: TypeDef, imports: TypeImports): string {
                    Severity: Minor
                    Found in packages/typegen/src/generate/tsDef.ts - About 45 mins to fix

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

                      function entrySignature (lookup: PortableRegistry, allDefs: Record<string, ModuleTypes>, registry: Registry, section: string, storageEntry: StorageEntryMetadataLatest, imports: TypeImports): [boolean, string, string, string] {
                      Severity: Minor
                      Found in packages/typegen/src/generate/query.ts - About 45 mins to fix
                        Severity
                        Category
                        Status
                        Source
                        Language