polkadot-js/api

View on GitHub

Showing 173 of 2,510 total issues

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

                  Function account has 26 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

                      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

                        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 _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

                          Severity
                          Category
                          Status
                          Source
                          Language