codeforthailand/election-live

View on GitHub

Showing 91 of 91 total issues

File MainLayout.js has 514 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { keyframes } from "@emotion/core"
import { Location } from "@reach/router"
import axios from "axios"
import { Link } from "gatsby"
import _ from "lodash"
Severity: Major
Found in src/components/MainLayout.js - About 1 day to fix

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

          this.svg
            .append("defs")
            .selectAll("pattern")
            .data(uniqueColors, c => c)
            .enter()
    Severity: Major
    Found in src/components/ElectionMap.js and 1 other location - About 4 hrs to fix
    src/components/ElectionMap.js on lines 115..127

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

    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

          this.svg
            .append("defs")
            .selectAll("pattern")
            .data(uniqueColors, c => c)
            .enter()
    Severity: Major
    Found in src/components/ElectionMap.js and 1 other location - About 4 hrs to fix
    src/components/ElectionMap.js on lines 133..145

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

    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

        {
          name: "ประมาณ ส.ส. เขต (350 ที่)",
          title: "ประมาณจำนวน ส.ส. เขต",
          maxCount: 350,
          description:
    Severity: Major
    Found in src/components/DesktopScoreBarContainer.js and 1 other location - About 4 hrs to fix
    src/components/DesktopScoreBarContainer.js on lines 54..72

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

    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

        {
          name: "ประมาณ ส.ส. บัญชีรายชื่อ (150 ที่)",
          title: "ประมาณจำนวน ส.ส. บัญชีรายชื่อ",
          maxCount: 150,
          description:
    Severity: Major
    Found in src/components/DesktopScoreBarContainer.js and 1 other location - About 4 hrs to fix
    src/components/DesktopScoreBarContainer.js on lines 35..53

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

    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

    File ZoneMasterView.js has 345 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import { faSearch, faChevronDown } from "@fortawesome/free-solid-svg-icons"
    import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
    import React, { useCallback, useState } from "react"
    import {
      buttonStyle,
    Severity: Minor
    Found in src/components/ZoneMasterView.js - About 4 hrs to fix

      File ElectionMap.js has 342 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import { keyBy, uniq, uniqBy } from "lodash"
      import {
        quadtree,
        event as d3Event,
        mouse as d3Mouse,
      Severity: Minor
      Found in src/components/ElectionMap.js - About 4 hrs to fix

        Function partyStatsFromSummaryJSON has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
        Open

        export function partyStatsFromSummaryJSON(
          summary,
          {
            filter = filters.all,
            fillAllSeats = false,
        Severity: Minor
        Found in src/models/PartyStats.js - About 3 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

        File DesktopScoreBar.js has 327 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        /* eslint-disable no-magic-numbers */
        import { transition as d3Transition } from "d3"
        import { scaleBand, scaleLinear } from "d3-scale"
        import { SvgChart, helper } from "d3kit"
        import _ from "lodash"
        Severity: Minor
        Found in src/components/DesktopScoreBar.js - About 3 hrs to fix

          File TimeMachine.js has 320 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import React, { useEffect, useState, useRef } from "react"
          import { useDirectoryOverride } from "../models/TimeTraveling"
          import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
          import {
            faHistory,
          Severity: Minor
          Found in src/components/TimeMachine.js - About 3 hrs to fix

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

                        <div css={{ marginLeft: "5px", fontFamily: DISPLAY_FONT }}>
                          <div css={{ fontWeight: "bold" }}>
                            {item.firstName} {item.lastName}
                          </div>
                          <div css={{ fontSize: "0.8em" }}>{item.zone}</div>
            Severity: Major
            Found in src/components/PerPartyMemberVoteResult.js and 1 other location - About 3 hrs to fix
            src/components/PerPartyMemberVoteResult.js on lines 117..122

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

            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

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

                        <div css={{ marginLeft: "5px", fontFamily: DISPLAY_FONT }}>
                          <div css={{ fontWeight: "bold" }}>
                            {item.firstName} {item.lastName}
                          </div>
                          <div css={{ fontSize: "0.8em" }}>{item.zone}</div>
            Severity: Major
            Found in src/components/PerPartyMemberVoteResult.js and 1 other location - About 3 hrs to fix
            src/components/PerPartyMemberVoteResult.js on lines 155..160

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

            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

            Function ElectionMapTooltip has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

            export default function ElectionMapTooltip({ positionId, positions }) {
              const memo = useMemo(() => {
                const position = _.find(positions, p => p.id == positionId)
                if (!position) return {}
            
            
            Severity: Minor
            Found in src/components/ElectionMapTooltip.js - 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 TimeMachine has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

            export function TimeMachine() {
              const styles = {
                button: {
                  cursor: "pointer",
                  border: 0,
            Severity: Minor
            Found in src/components/TimeMachine.js - 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

            File DesktopScoreBarContainer.js has 277 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            import React, { useState, useEffect } from "react"
            import _ from "lodash"
            import DesktopScoreBar from "./DesktopScoreBar"
            import HelpTooltip from "./HelpTooltip"
            import { nationwidePartyStatsFromSummaryJSON } from "../models/PartyStats"
            Severity: Minor
            Found in src/components/DesktopScoreBarContainer.js - About 2 hrs to fix

              File PerZoneView.js has 270 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import { navigate } from "gatsby"
              import _ from "lodash"
              import React, { useContext } from "react"
              import CandidateStatsRow from "./CandidateStatsRow"
              import CloseButton from "./CloseButton"
              Severity: Minor
              Found in src/components/PerZoneView.js - About 2 hrs to fix

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

                  return _(parties)
                    .flatMap(party => {
                      return {
                        id: party.id,
                        electedMemberCount: constituencySeatCount[party.id] || 0,
                Severity: Major
                Found in src/components/__fixtures__/DesktopScoreBarMockData.js and 1 other location - About 2 hrs to fix
                src/models/PartyStats.js on lines 123..143

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

                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

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

                      for (let i = 0; i < row.partyListSeats; i++) {
                        partylist.push({
                          id: `pl-${partylist.length + 1}`,
                          partyId: row.party.id,
                          complete: true,
                Severity: Major
                Found in src/components/ElectionMapContainer.js and 1 other location - About 2 hrs to fix
                src/components/PerPartyMapContainer.js on lines 40..47

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

                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

                  const partyStatsBasis = _(parties)
                    .map(party => {
                      return {
                        id: party.id,
                        electedMemberCount: constituencySeatCount[party.id] || 0,
                Severity: Major
                Found in src/models/PartyStats.js and 1 other location - About 2 hrs to fix
                src/components/__fixtures__/DesktopScoreBarMockData.js on lines 13..22

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

                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

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

                    for (let i = 0; i < row.partyListSeats; i++) {
                      partylist.push({
                        id: `pl-${partylist.length + 1}`,
                        partyId: row.party.id,
                        complete: true,
                Severity: Major
                Found in src/components/PerPartyMapContainer.js and 1 other location - About 2 hrs to fix
                src/components/ElectionMapContainer.js on lines 38..45

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

                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

                Severity
                Category
                Status
                Source
                Language