codeforthailand/election-live

View on GitHub

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

    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

            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

                Function onlyPassThroughPropsWhilePageIsVisible has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                export default function onlyPassThroughPropsWhilePageIsVisible(BaseComponent) {
                  return class UpdateBlocker extends React.Component {
                    componentWillUnmount() {
                      if (this.listener) {
                        const Visibility = require("visibilityjs")
                Severity: Minor
                Found in src/components/onlyPassThroughPropsWhilePageIsVisible.js - 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 MainLayout has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                export default function MainLayout({ children, activeNavBarSection }) {
                  const [navBarActive, toggleNavBar] = useReducer(state => !state, false)
                
                  const [active, setActive] = useState(false)
                  const [tooltipPayload, setTooltipPayload] = useState({})
                Severity: Minor
                Found in src/components/MainLayout.js - 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 DataInspector has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                function DataInspector() {
                  const latestDirectoryState = useLatestDirectoryState()
                  const summaryState = useSummaryData()
                  return (
                    <ContentWrapper>
                Severity: Minor
                Found in src/pages/dev/inspect.js - 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 renderScore has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                  renderScore() {
                    let cumulative = 0
                    let inputParties = this.data()
                    // prepare dimension and scales
                    const margin = this.options().margin
                Severity: Minor
                Found in src/components/DesktopScoreBar.js - 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 getWinningConstituencyCandidates has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                function getWinningConstituencyCandidates(summaryState, partyId) {
                  if (!summaryState.completed) {
                    return []
                  } else {
                    const summary = summaryState.data
                Severity: Minor
                Found in src/components/PerPartyMemberVoteResult.js - 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 ZonePageContainer has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                function ZonePageContainer({ pageContext, location }) {
                  /** @type {ZoneFilterName | null} */
                  const filterNameFromRoute = pageContext.zoneView
                    ? null
                    : pageContext.filterName || "all"
                Severity: Minor
                Found in src/pages/index.js - 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 ZoneCandidateList has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                function ZoneCandidateList({ provinceId, zoneNo, zoneStats }) {
                  const dataState = usePerZoneData(provinceId, zoneNo)
                  if (!dataState.completed || !zoneStats) {
                    if (dataState.failed) {
                      return <LoadingError />
                Severity: Minor
                Found in src/components/PerZoneView.js - 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 getLatestDirectoryState has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                function getLatestDirectoryState() {
                  if (overrideDirectory.get()) {
                    return {
                      completed: true,
                      data: overrideDirectory.get(),
                Severity: Minor
                Found in src/models/LiveDataSubscription.js - 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 getMapData has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                function getMapData(summaryState, filter) {
                  if (!summaryState.completed) {
                    return electionMapLoadingData
                  } else {
                    /** @type {ElectionDataSource.SummaryJSON} */
                Severity: Minor
                Found in src/components/ElectionMapContainer.js - 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 getMapData has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                function getMapData(summaryState, partyId) {
                  if (!summaryState.completed) {
                    return electionMapLoadingData
                  } else {
                    /** @type {ElectionDataSource.SummaryJSON} */
                Severity: Minor
                Found in src/components/PerPartyMapContainer.js - 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

                Severity
                Category
                Status
                Source
                Language