polkadot-js/apps

View on GitHub
packages/page-referenda/src/util.ts

Summary

Maintainability
C
1 day
Test Coverage

Function curveDelay has 64 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function curveDelay (curve: PalletReferendaCurve, input: BN, div: BN): BN {
  try {
    // if divisor is zero, we return the max
    if (div.isZero()) {
      return BN_BILLION;
Severity: Major
Found in packages/page-referenda/src/util.ts - About 2 hrs to fix

    Function curveDelay has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    export function curveDelay (curve: PalletReferendaCurve, input: BN, div: BN): BN {
      try {
        // if divisor is zero, we return the max
        if (div.isZero()) {
          return BN_BILLION;
    Severity: Minor
    Found in packages/page-referenda/src/util.ts - About 2 hrs 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 curveThreshold has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function curveThreshold (curve: PalletReferendaCurve, input: BN, div: BN): BN {
      // if divisor is zero, we return the max
      if (div.isZero()) {
        return BN_BILLION;
      }
    Severity: Minor
    Found in packages/page-referenda/src/util.ts - About 1 hr to fix

      Function getTrackInfo has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      export function getTrackInfo (api: ApiPromise, specName: string, palletReferenda: string, tracks: TrackDescription[], trackId?: number): TrackInfoExt | undefined {
        let info: TrackInfoExt | undefined;
      
        if (tracks && trackId !== undefined && trackId !== -1) {
          const originMap = getGovernanceTracks(api, specName, palletReferenda);
      Severity: Minor
      Found in packages/page-referenda/src/util.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 getTrackInfo has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      export function getTrackInfo (api: ApiPromise, specName: string, palletReferenda: string, tracks: TrackDescription[], trackId?: number): TrackInfoExt | undefined {
      Severity: Minor
      Found in packages/page-referenda/src/util.ts - About 35 mins to fix

        Avoid too many return statements within this function.
        Open

            return bnMin(
              BN_BILLION,
              factor
                .mul(BN_BILLION)
                .div(div)
        Severity: Major
        Found in packages/page-referenda/src/util.ts - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                return bnMin(
                  BN_BILLION,
                  bnMax(
                    BN_ZERO,
                    factor
          Severity: Major
          Found in packages/page-referenda/src/util.ts - About 30 mins to fix

            Function curveThreshold has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            export function curveThreshold (curve: PalletReferendaCurve, input: BN, div: BN): BN {
              // if divisor is zero, we return the max
              if (div.isZero()) {
                return BN_BILLION;
              }
            Severity: Minor
            Found in packages/page-referenda/src/util.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

            There are no issues that match your filters.

            Category
            Status