polkadot-js/api

View on GitHub

Showing 173 of 2,509 total issues

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 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/tx.ts - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

        if (Array.isArray(subDef)) {
          const subs = subDef.map(({ type }) => getSimilarTypes(registry, definitions, type, imports).join(' | '));
    
          possibleTypes.push(`[${subs.join(', ')}]`);
        }
    Severity: Major
    Found in packages/typegen/src/util/derived.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

        Avoid deeply nested control flow statements.
        Open

                          if (params.length) {
                            describe('params', (): void => {
                              for (const { name, type } of params) {
                                if (skipInspectTypes.includes(type)) {
                                  continue;
        Severity: Major
        Found in packages/types/src/interfaces/definitions.spec.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 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

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

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

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

                        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 formatType has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        export function formatType (registry: Registry, definitions: Record<string, ModuleTypes>, type: AnyString | TypeDef, imports: TypeImports, withShortcut = false): string {
                        Severity: Minor
                        Found in packages/typegen/src/util/formatting.ts - About 35 mins to fix

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

                          function getBatch (api: DeriveApi, activeEra: EraIndex, stashIds: AccountId[], flags: StakingQueryFlags, page: u32 | AnyNumber): Observable<DeriveStakingQuery[]> {
                          Severity: Minor
                          Found in packages/api-derive/src/staking/query.ts - About 35 mins to fix

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

                            export function exportInterface (lookupIndex = -1, name = '', base: string, body = '', withShortcut = false): string {
                            Severity: Minor
                            Found in packages/typegen/src/util/formatting.ts - About 35 mins to fix
                              Severity
                              Category
                              Status
                              Source
                              Language