polkadot-js/api

View on GitHub
packages/typegen/src/metadataMd.ts

Summary

Maintainability
F
3 days
Test Coverage

File metadataMd.ts has 435 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// Copyright 2017-2024 @polkadot/typegen authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { MetadataLatest, SiLookupTypeId } from '@polkadot/types/interfaces';
import type { PortableRegistry } from '@polkadot/types/metadata';
Severity: Minor
Found in packages/typegen/src/metadataMd.ts - About 6 hrs to fix

    Function mainPromise has 49 lines of code (exceeds 25 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

      Function addRpc has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function addRpc (_runtimeDesc: string, rpcMethods?: string[]): string {
        return renderPage({
          description: 'The following sections contain known RPC methods that may be available on specific nodes (depending on configuration and available pallets) and allow you to interact with the actual node, query, and submit.',
          sections: Object
            .keys(definitions)
      Severity: Minor
      Found in packages/typegen/src/metadataMd.ts - About 1 hr to fix

        Function addRuntime has 44 lines of code (exceeds 25 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

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

                function docsVecToMarkdown (docLines: Vec<Text>, indent = 0): string {
                  const md = docLines
                    .map((docLine) =>
                      docLine
                        .toString()
                Severity: Minor
                Found in packages/typegen/src/metadataMd.ts - About 25 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

                Identical blocks of code found in 3 locations. Consider refactoring.
                Open

                export function main (): void {
                  mainPromise().catch((error) => {
                    console.error();
                    console.error(error);
                    console.error();
                Severity: Major
                Found in packages/typegen/src/metadataMd.ts and 2 other locations - About 2 hrs to fix
                packages/typegen/src/fromChain.ts on lines 116..123
                packages/typegen/src/fromDefs.ts on lines 99..106

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 77.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    sections: Object
                      .keys(definitions)
                      .filter((key) => Object.keys(definitions[key as 'babe'].rpc || {}).length !== 0)
                      .sort()
                      .reduce((all: Section[], _sectionName): Section[] => {
                Severity: Major
                Found in packages/typegen/src/metadataMd.ts and 1 other location - About 1 hr to fix
                packages/typegen/src/metadataMd.ts on lines 224..272

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 68.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    sections: Object
                      .keys(definitions)
                      .filter((key) => Object.keys(definitions[key as 'babe'].runtime || {}).length !== 0)
                      .sort()
                      .reduce((all: Section[], _sectionName): Section[] => {
                Severity: Major
                Found in packages/typegen/src/metadataMd.ts and 1 other location - About 1 hr to fix
                packages/typegen/src/metadataMd.ts on lines 161..215

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 68.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    md += section.link
                      ? `<h2 id="#${section.link}">${section.name}</h2>\n`
                      : `## ${section.name}\n`;
                Severity: Minor
                Found in packages/typegen/src/metadataMd.ts and 1 other location - About 50 mins to fix
                packages/typegen/src/metadataMd.ts on lines 123..125

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 51.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                      md += item.link
                        ? `<h3 id="#${item.link}">${item.name}</h3>`
                        : `### ${item.name}`;
                Severity: Minor
                Found in packages/typegen/src/metadataMd.ts and 1 other location - About 50 mins to fix
                packages/typegen/src/metadataMd.ts on lines 113..115

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 51.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                        items: lookup.getSiType(meta.events.unwrap().type).def.asVariant.variants
                          .sort(sortByName)
                          .map(({ docs, fields, name }) => {
                            const methodName = name.toString();
                            const args = fields.map(({ type }) =>
                Severity: Minor
                Found in packages/typegen/src/metadataMd.ts and 1 other location - About 40 mins to fix
                packages/typegen/src/metadataMd.ts on lines 435..441

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 49.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                        items: lookup.getSiType(moduleMetadata.errors.unwrap().type).def.asVariant.variants
                          .sort(sortByName)
                          .map((error) => ({
                            interface: '`' + `api.errors.${stringCamelCase(moduleMetadata.name)}.${error.name.toString()}.is` + '`',
                            name: error.name.toString(),
                Severity: Minor
                Found in packages/typegen/src/metadataMd.ts and 1 other location - About 40 mins to fix
                packages/typegen/src/metadataMd.ts on lines 407..420

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 49.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                There are no issues that match your filters.

                Category
                Status