polkadot-js/api

View on GitHub

Showing 179 of 2,612 total issues

Function querySystemAccount has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function querySystemAccount (api: DeriveApi, accountId: AccountId): Observable<Result> {
  // AccountInfo is current, support old, eg. Edgeware
  return api.query.system.account<AccountInfo | FrameSystemAccountInfo | ITuple<[Index, AccountData]>>(accountId).pipe(
    map((infoOrTuple): Result => {
      const data = (infoOrTuple as AccountInfo).nonce
Severity: Minor
Found in packages/api-derive/src/balances/account.ts - About 1 hr to fix

    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

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

            async function getWsData <T> (endpoint: string, method: 'rpc_methods' | 'state_getMetadata' | 'state_getRuntimeVersion'): Promise<T> {
              return new Promise((resolve, reject): void => {
                const tracker = promiseTracker<T>(resolve, reject);
            
                try {
            Severity: Minor
            Found in packages/typegen/src/util/wsMeta.ts - About 1 hr to fix

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

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

                function generateForMeta (meta: Metadata, dest: string, isStrict: boolean): void {
                  writeFile(dest, (): string => {
                    const imports = createImports({});
                    const { lookup, pallets } = meta.asLatest;
                    const modules = pallets
                Severity: Minor
                Found in packages/typegen/src/generate/errors.ts - About 1 hr to fix

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

                    export function bounties (instanceId: string, api: DeriveApi): () => Observable<DeriveBounties> {
                      const bountyBase = api.query.bounties || api.query.treasury;
                    
                      return memo(instanceId, (): Observable<DeriveBounties> =>
                        bountyBase.bounties
                    Severity: Minor
                    Found in packages/api-derive/src/bounties/bounties.ts - About 1 hr to fix

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

                      function testTypes (type: string, typeNames: string[]): void {
                        describe(`${type}`, (): void => {
                          describe(`${type}:: default creation`, (): void => {
                            typeNames.forEach((name): void => {
                              it(`creates an empty ${name}`, (): void => {
                      Severity: Minor
                      Found in packages/types/src/index.spec.ts - About 1 hr to fix

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

                        async function mainPromise (): Promise<void> {
                          const { chain, endpoint } = yargs(hideBin(process.argv)).strict().options({
                            chain: {
                              description: 'The chain name to use for the output (defaults to "Substrate")',
                              type: 'string'
                        Severity: Minor
                        Found in packages/typegen/src/metadataMd.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 addRuntime has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                        Open

                        function addRuntime (_runtimeDesc: string, apis?: ApiDef[]): string {
                          return renderPage({
                            description: 'The following section contains known runtime calls that may be available on specific runtimes (depending on configuration and available pallets). These call directly into the WASM runtime for queries and operations.',
                            sections: Object
                              .keys(definitions)
                        Severity: Minor
                        Found in packages/typegen/src/metadataMd.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 getAuthorDetailsWithAt has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                        Open

                        function getAuthorDetailsWithAt (header: Header, queryAt: QueryableStorage<'rxjs'>): Observable<[Header, Vec<AccountId> | null, AccountId | null]> {
                          const validators = queryAt.session?.validators
                            ? queryAt.session.validators()
                            : of(null);
                        
                        
                        Severity: Minor
                        Found in packages/api-derive/src/chain/util.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 addStorage has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                        Open

                        function addStorage (runtimeDesc: string, { lookup, pallets, registry }: MetadataLatest): string {
                          const { substrate } = getSubstrateStorage(registry);
                          const moduleSections = pallets
                            .sort(sortByName)
                            .filter((moduleMetadata) => !moduleMetadata.storage.isNone)
                        Severity: Minor
                        Found in packages/typegen/src/metadataMd.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 findSiType has a Cognitive Complexity of 10 (exceeds 5 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

                        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 decodeValue has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                        Open

                        function decodeValue (registry: Registry, key: string, value: unknown): unknown {
                          return key === 'ss58Format'
                            ? createValue(registry, 'Option<u32>', value, false)
                            : key === 'tokenDecimals'
                              ? createValue(registry, 'Option<Vec<u32>>' as 'Vec<u32>', value)
                        Severity: Minor
                        Found in packages/types/src/generic/ChainProperties.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 getFakeClient has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        function getFakeClient () {
                          const chains: MockChain[] = [];
                          let addChainInterceptor: Promise<void> = Promise.resolve();
                          let addWellKnownChainInterceptor: Promise<void> = Promise.resolve();
                        
                        
                        Severity: Minor
                        Found in packages/rpc-provider/src/substrate-connect/index.spec.ts - About 1 hr to fix

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

                          export function account (instanceId: string, api: DeriveApi): (address: AccountIndex | AccountId | Address | string) => Observable<DeriveBalancesAccount> {
                            const balanceInstances = api.registry.getModuleInstances(api.runtimeVersion.specName, 'balances');
                            const nonDefaultBalances = balanceInstances && balanceInstances[0] !== 'balances';
                          
                            return memo(instanceId, (address: AccountIndex | AccountId | Address | string): Observable<DeriveBalancesAccount> =>
                          Severity: Minor
                          Found in packages/api-derive/src/balances/account.ts - About 1 hr to fix

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

                            export function _ownExposures (instanceId: string, api: DeriveApi): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean, page: u32 | AnyNumber) => Observable<DeriveOwnExposure[]> {
                              return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean, page: u32 | AnyNumber): Observable<DeriveOwnExposure[]> => {
                                const emptyStakingExposure = api.registry.createType<SpStakingExposure>('Exposure');
                                // The reason we don't explicitly make the actual types is for compatibility. If the chain doesn't have the noted type it will fail
                                // on construction. Therefore we just make an empty option.
                            Severity: Minor
                            Found in packages/api-derive/src/staking/ownExposure.ts - About 1 hr to fix
                              Severity
                              Category
                              Status
                              Source
                              Language