polkadot-js/api

View on GitHub

Showing 173 of 2,507 total issues

Function sections has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      .reduce((all: Section[], _sectionName): Section[] => {
        const section = definitions[_sectionName as 'babe'];

        Object
          .keys(section.rpc || {})
Severity: Minor
Found in packages/typegen/src/metadataMd.ts - About 1 hr to fix

    Function _decodeFixedVec has 36 lines of code (exceeds 25 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 1 hr to fix

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

      function getStashInfo (api: DeriveApi, stashIds: AccountId[], activeEra: EraIndex, { withClaimedRewardsEras, withController, withDestination, withExposure, withExposureErasStakersLegacy, withExposureMeta, withLedger, withNominations, withPrefs }: StakingQueryFlags, page: u32 | AnyNumber): Observable<[(Option<AccountId> | null)[], Option<PalletStakingNominations>[], Option<PalletStakingRewardDestination>[], PalletStakingValidatorPrefs[], Option<SpStakingExposurePage>[], Option<SpStakingPagedExposureMetadata>[], number[][], SpStakingExposure[]]> {
        const emptyNoms = api.registry.createType<Option<PalletStakingNominations>>('Option<Nominations>');
        const emptyRewa = api.registry.createType<Option<PalletStakingRewardDestination>>('RewardDestination');
        const emptyExpoEraStakers = api.registry.createType<SpStakingExposure>('Exposure');
        const emptyPrefs = api.registry.createType<PalletStakingValidatorPrefs>('ValidatorPrefs');
      Severity: Minor
      Found in packages/api-derive/src/staking/query.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 _membersCurr has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function _membersCurr (api: DeriveApi, accountIds: AccountId[]): Observable<DeriveSocietyMember[]> {
        return combineLatest([
          of(accountIds),
          api.query.society.members.multi(accountIds),
          api.query.society.payouts.multi(accountIds),
      Severity: Minor
      Found in packages/api-derive/src/society/members.ts - About 1 hr to fix

        Function setImports has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function setImports (allDefs: Record<string, ModuleTypes>, imports: TypeImports, types: (string | null | undefined)[]): void {
          const { codecTypes, extrinsicTypes, genericTypes, ignoredTypes, localTypes, metadataTypes, primitiveTypes, typesTypes } = imports;
        
          types.filter((t): t is string => !!t).forEach((type): void => {
            if (ignoredTypes.includes(type)) {
        Severity: Minor
        Found in packages/typegen/src/util/imports.ts - About 1 hr to fix

          Function findSiType has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function findSiType (registry: Registry, type: string): PortableType | undefined {
            let portable = findSiPrimitive(registry, type);
          
            // some types are either Sequence or Arrays, cater for these
            // specifically (these all come from the base substrate known keys)
          Severity: Minor
          Found in packages/types/src/metadata/decorate/storage/util.ts - About 1 hr to fix

            Function parseDetails has 11 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            function parseDetails (api: DeriveApi, stashId: AccountId, controllerIdOpt: Option<AccountId> | null, nominatorsOpt: Option<PalletStakingNominations>, rewardDestinationOpts: Option<PalletStakingRewardDestination> | PalletStakingRewardDestination, validatorPrefs: PalletStakingValidatorPrefs, exposure: Option<SpStakingExposurePage>, stakingLedgerOpt: Option<PalletStakingStakingLedger>, exposureMeta: Option<SpStakingPagedExposureMetadata>, claimedRewards: number[], exposureEraStakers: SpStakingExposure): DeriveStakingQuery {
            Severity: Major
            Found in packages/api-derive/src/staking/query.ts - About 1 hr to fix

              Function renderPage has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function renderPage (page: Page): string {
                let md = `---\ntitle: ${page.title}\n---\n\n`;
              
                if (page.description) {
                  md += `${page.description}\n\n`;
              Severity: Minor
              Found in packages/typegen/src/metadataMd.ts - About 1 hr to fix

                Function mainPromise has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                async function mainPromise (): Promise<void> {
                  const { endpoint, output, package: pkg, strict: isStrict } = yargs(hideBin(process.argv)).strict().options({
                    endpoint: {
                      description: 'The endpoint to connect to (e.g. wss://kusama-rpc.polkadot.io) or relative path to a file containing the JSON output of an RPC state_getMetadata call',
                      required: true,
                Severity: Minor
                Found in packages/typegen/src/fromChain.ts - About 1 hr to fix

                  Function sections has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                        .reduce((all: Section[], _sectionName): Section[] => {
                          Object
                            .entries(definitions[_sectionName as 'babe'].runtime || {})
                            .forEach(([apiName, versions]) => {
                              versions
                  Severity: Minor
                  Found in packages/typegen/src/metadataMd.ts - About 1 hr to fix

                    Function getDefs has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function getDefs (apis: Apis | null, defs: Record<string, Definitions>): Record<string, Record<string, DefinitionCallNamed>> {
                      const named: Record<string, Record<string, DefinitionCallNamed>> = {};
                      const all = Object.values(defs);
                    
                      for (let j = 0, jcount = all.length; j < jcount; j++) {
                    Severity: Minor
                    Found in packages/typegen/src/generate/runtime.ts - About 1 hr to fix

                      Function getFakeChain has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function getFakeChain (spec: string, callback: Sc.JsonRpcCallback): MockChain {
                        const _receivedRequests: string[] = [];
                        let _isTerminated = false;
                      
                        let terminateInterceptor = Function.prototype;
                      Severity: Minor
                      Found in packages/rpc-provider/src/substrate-connect/index.spec.ts - About 1 hr to fix

                        Function generateLookupTypes has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        function generateLookupTypes (registry: Registry, filtered: [PortableType, TypeDef][], destDir: string, subPath?: string): void {
                          const imports = {
                            ...createImports(
                              { '@polkadot/types/interfaces': defaultDefinitions },
                              { types: {} }
                        Severity: Minor
                        Found in packages/typegen/src/generate/lookup.ts - About 1 hr to fix

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

                          function queryScheduler (api: DeriveApi): Observable<DeriveDispatch[]> {
                            return schedulerEntries(api).pipe(
                              switchMap(([blockNumbers, agendas]): Observable<[SchedulerInfo[], (DeriveProposalImage | undefined)[]]> => {
                                const result: SchedulerInfo[] = [];
                          
                          
                          Severity: Minor
                          Found in packages/api-derive/src/democracy/dispatchQueue.ts - About 1 hr to fix

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

                            async function mainPromise (): Promise<void> {
                              const { endpoint, input, package: pkg } = yargs(hideBin(process.argv)).strict().options({
                                endpoint: {
                                  description: 'The endpoint to connect to (e.g. wss://kusama-rpc.polkadot.io) or relative path to a file containing the JSON output of an RPC state_getMetadata call',
                                  type: 'string'
                            Severity: Minor
                            Found in packages/typegen/src/fromDefs.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 entrySignature has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                            Open

                            function entrySignature (lookup: PortableRegistry, allDefs: Record<string, ModuleTypes>, registry: Registry, section: string, storageEntry: StorageEntryMetadataLatest, imports: TypeImports): [boolean, string, string, string] {
                              try {
                                const outputType = lookup.getTypeDef(unwrapStorageSi(storageEntry.type));
                            
                                if (storageEntry.type.isPlain) {
                            Severity: Minor
                            Found in packages/typegen/src/generate/query.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 getImages has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            function getImages (api: DeriveApi, bounded: (FrameSupportPreimagesBounded | Uint8Array | string)[]): Observable<(DeriveProposalImage | undefined)[]> {
                              const hashes = bounded.map((b) => getImageHashBounded(b));
                              const bytesType = api.registry.lookup.getTypeDef(api.query.preimage.preimageFor.creator.meta.type.asMap.key).type;
                            
                              return api.query.preimage.statusFor.multi(hashes).pipe(
                            Severity: Minor
                            Found in packages/api-derive/src/democracy/preimages.ts - About 1 hr to fix

                              Function typeSplit has 30 lines of code (exceeds 25 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 1 hr to fix

                                Function formatFailure has 9 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                function formatFailure (registry: Registry, fn: 'decodeU8a' | 'decodeU8aStruct' | 'decodeU8aVec', _result: unknown[], { message }: Error, u8a: Uint8Array, i: number, count: number, Type: CodecClass, key?: string): string {
                                Severity: Major
                                Found in packages/types-codec/src/utils/decodeU8a.ts - About 1 hr to fix

                                  Function generateLookupDefs has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                  function generateLookupDefs (registry: Registry, filtered: [PortableType, TypeDef][], destDir: string, subPath?: string): void {
                                    writeFile(path.join(destDir, `${subPath || 'definitions'}.ts`), (): string => {
                                      const all = filtered.map(([{ id, type: { params, path } }, typeDef]) => {
                                        const typeLookup = registry.createLookupType(id);
                                        const def = expandDefToString(typeDef, subPath ? 2 : 4);
                                  Severity: Minor
                                  Found in packages/typegen/src/generate/lookup.ts - About 1 hr to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language