polkadot-js/apps

View on GitHub
packages/page-referenda/src/Referenda/Referendum.tsx

Summary

Maintainability
F
4 days
Test Coverage

File Referendum.tsx has 426 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

import type { ChartOptions, ChartTypeRegistry, TooltipItem } from 'chart.js';
import type { PalletConvictionVotingTally, PalletRankedCollectiveTally, PalletReferendaReferendumInfoConvictionVotingTally, PalletReferendaReferendumInfoRankedCollectiveTally, PalletReferendaTrackInfo } from '@polkadot/types/lookup';
Severity: Minor
Found in packages/page-referenda/src/Referenda/Referendum.tsx - About 6 hrs to fix

    Function getChartResult has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

    function getChartResult (totalEligible: BN, isConvictionVote: boolean, info: PalletReferendaReferendumInfoConvictionVotingTally | PalletReferendaReferendumInfoRankedCollectiveTally, track: PalletReferendaTrackInfo, trackGraph: CurveGraph): ChartResultExt[] | null {
      if (totalEligible && isConvictionVote && info.isOngoing) {
        const ongoing = info.asOngoing;
    
        if (ongoing.deciding.isSome) {
    Severity: Minor
    Found in packages/page-referenda/src/Referenda/Referendum.tsx - About 6 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 Referendum has 125 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function Referendum (props: Props): React.ReactElement<Props> {
      const { t } = useTranslation();
      const bestNumber = useBestNumber();
      const blockInterval = useBlockInterval();
      const { activeIssuance, className = '', palletReferenda, value: { id, info, isConvictionVote, track, trackGraph } } = props;
    Severity: Major
    Found in packages/page-referenda/src/Referenda/Referendum.tsx - About 5 hrs to fix

      Function getChartProps has 116 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function getChartProps (bestNumber: BN, blockInterval: BN, chartProps: ChartResultExt[], refId: BN, track: PalletReferendaTrackInfo, t: (key: string, options?: { replace: Record<string, unknown> }) => string): ChartProps[] {
        const changeXMax = chartProps.reduce((max, { changeX }) =>
          max === -1 || changeX === -1
            ? -1
            : Math.max(max, changeX),
      Severity: Major
      Found in packages/page-referenda/src/Referenda/Referendum.tsx - About 4 hrs to fix

        Function getChartResult has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function getChartResult (totalEligible: BN, isConvictionVote: boolean, info: PalletReferendaReferendumInfoConvictionVotingTally | PalletReferendaReferendumInfoRankedCollectiveTally, track: PalletReferendaTrackInfo, trackGraph: CurveGraph): ChartResultExt[] | null {
          if (totalEligible && isConvictionVote && info.isOngoing) {
            const ongoing = info.asOngoing;
        
            if (ongoing.deciding.isSome) {
        Severity: Major
        Found in packages/page-referenda/src/Referenda/Referendum.tsx - About 2 hrs to fix

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

          function extractInfo (info: PalletReferendaReferendumInfoConvictionVotingTally | PalletReferendaReferendumInfoRankedCollectiveTally, track?: PalletReferendaTrackInfo): { confirmEnd: BN | null, enactAt: { at: boolean, blocks: BN, end: BN | null } | null, nextAlarm: null | BN, submittedIn: null | BN } {
            let confirmEnd: BN | null = null;
            let enactAt: { at: boolean, blocks: BN, end: BN | null } | null = null;
            let nextAlarm: BN | null = null;
            let submittedIn: BN | null = null;
          Severity: Minor
          Found in packages/page-referenda/src/Referenda/Referendum.tsx - 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 extractInfo has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function extractInfo (info: PalletReferendaReferendumInfoConvictionVotingTally | PalletReferendaReferendumInfoRankedCollectiveTally, track?: PalletReferendaTrackInfo): { confirmEnd: BN | null, enactAt: { at: boolean, blocks: BN, end: BN | null } | null, nextAlarm: null | BN, submittedIn: null | BN } {
            let confirmEnd: BN | null = null;
            let enactAt: { at: boolean, blocks: BN, end: BN | null } | null = null;
            let nextAlarm: BN | null = null;
            let submittedIn: BN | null = null;
          Severity: Minor
          Found in packages/page-referenda/src/Referenda/Referendum.tsx - About 1 hr to fix

            Function getChartProps has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            function getChartProps (bestNumber: BN, blockInterval: BN, chartProps: ChartResultExt[], refId: BN, track: PalletReferendaTrackInfo, t: (key: string, options?: { replace: Record<string, unknown> }) => string): ChartProps[] {
            Severity: Minor
            Found in packages/page-referenda/src/Referenda/Referendum.tsx - About 45 mins to fix

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

              function getChartResult (totalEligible: BN, isConvictionVote: boolean, info: PalletReferendaReferendumInfoConvictionVotingTally | PalletReferendaReferendumInfoRankedCollectiveTally, track: PalletReferendaTrackInfo, trackGraph: CurveGraph): ChartResultExt[] | null {
              Severity: Minor
              Found in packages/page-referenda/src/Referenda/Referendum.tsx - About 35 mins to fix

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

                              <Columar.Column>
                                <Chart.Line
                                  legends={chartLegend[0]}
                                  title={t('approval / {{percent}}%', { replace: { percent: chartProps[0].progress.percent.toFixed(1) } })}
                                  {...chartProps[0]}
                Severity: Major
                Found in packages/page-referenda/src/Referenda/Referendum.tsx and 1 other location - About 2 hrs to fix
                packages/page-referenda/src/Referenda/Referendum.tsx on lines 414..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 94.

                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

                              <Columar.Column>
                                <Chart.Line
                                  legends={chartLegend[1]}
                                  title={t('support / {{percent}}%', { replace: { percent: chartProps[1].progress.percent.toFixed(1) } })}
                                  {...chartProps[1]}
                Severity: Major
                Found in packages/page-referenda/src/Referenda/Referendum.tsx and 1 other location - About 2 hrs to fix
                packages/page-referenda/src/Referenda/Referendum.tsx on lines 407..413

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

                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

                                  conf: {
                                    backgroundColor: BOX_COLORS.conf,
                                    borderWidth: 0,
                                    type: 'box',
                                    xMax: blockToX(confirmX[1]),
                Severity: Major
                Found in packages/page-referenda/src/Referenda/Referendum.tsx and 1 other location - About 1 hr to fix
                packages/page-referenda/src/Referenda/Referendum.tsx on lines 246..254

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

                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

                                  enac: {
                                    backgroundColor: BOX_COLORS.enac,
                                    borderWidth: 0,
                                    type: 'box',
                                    xMax: blockToX(confirmX[2]),
                Severity: Major
                Found in packages/page-referenda/src/Referenda/Referendum.tsx and 1 other location - About 1 hr to fix
                packages/page-referenda/src/Referenda/Referendum.tsx on lines 237..245

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

                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