Showing 43 of 130 total issues

Function round has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  protected round(
    candidates: string[],
    idx: number,
  ): {
    eliminated: string[]
Severity: Minor
Found in votes/src/methods/two-round-runoff/index.ts - About 1 hr to fix

    Function useStore has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      subscribeWithSelector((set): Store => {
        const updateCandidateCount = (desiredLength: number) =>
          set(({ ballots, candidates, drawRate }) => {
            const newCandidates = updateCandidateList(desiredLength, candidates)
            return {
    Severity: Minor
    Found in demo/src/store/index.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 Render has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      function Render(props: Omit<T, 'width'>): React.ReactElement {
        const ref = useRef<HTMLDivElement>(null)
        const [componentSize, setComponentSize] = useState<number | null>(null)
        const seet = useCallback(() => {
          if (ref.current) {
    Severity: Minor
    Found in demo/src/react-ranker/use-width.tsx - About 1 hr to fix

      Function render has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        render(): React.ReactElement {
          return (
            <Html>
              <Head>
                <link
      Severity: Minor
      Found in demo/pages/_document.tsx - About 1 hr to fix

        Function boxes has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          const boxes: (BoxMeta & BoxPosition & WithColor)[] = useMemo(() => {
            if (!scale) return []
            if (step === Step.TREEMAP) {
              return boxTreemap({
                boxes: bboxes,
        Severity: Minor
        Found in demo/src/methods/borda/viz-borda.tsx - About 1 hr to fix

          Function useWidth has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export default function useWidth(ref: RefObject<HTMLDivElement>) {
            const [ComponentSize, setComponentSize] = useState(getSize(ref.current))
            const seet = useCallback(() => {
              if (ref.current) {
                setComponentSize(getSize(ref.current))
          Severity: Minor
          Found in demo/src/react-ranker/use-width.tsx - About 1 hr to fix

            Function VizFptp has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export const VizFptp: React.FC = () => {
              const ballots = useStore(selectBallots)
              const candidatesById = useCandidatesById()
              const candidatesStrings = useCandidatesString()
              const width = useStore(selectWidth)
            Severity: Minor
            Found in demo/src/methods/fptp/viz-fptp.tsx - About 1 hr to fix

              Function matrixFromBallots has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

              export const matrixFromBallots = (
                ballots: Ballot[],
                candidates: string[],
              ): Matrix => {
                const array: number[][] = times(candidates.length, () =>
              Severity: Minor
              Found in votes/src/utils/make-matrix.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 round has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              const round = (
                candidates: string[],
                _ballots: Ballot[],
              ): {
                qualified: string[]
              Severity: Minor
              Found in votes/src/methods/coombs/index.ts - About 1 hr to fix

                Function setPos has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                const setPos = (
                  oldRanking: string[][],
                  elementToMoveId: string,
                  newPos: number,
                ): string[][] => {
                Severity: Minor
                Found in demo/src/edit-ballot-rank.tsx - 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

                Avoid deeply nested control flow statements.
                Open

                          if (i !== k && j !== k)
                            p[j][k] = Math.max(p[j][k], Math.min(p[j][i], p[i][k]))
                Severity: Major
                Found in votes/src/methods/schulze/index.ts - About 45 mins to fix

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

                  export const getMedian = (arr: number[]): number => {
                    const sumWeights = _.sum(arr)
                  
                    let s = 0
                    let i = 0
                  Severity: Minor
                  Found in votes/src/methods/majority-judgment/index.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 WithWidth has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                  export const WithWidth = <T extends { width: number }>(
                    Comp: React.ComponentType<T>,
                  ) =>
                    function Render(props: Omit<T, 'width'>): React.ReactElement {
                      const ref = useRef<HTMLDivElement>(null)
                  Severity: Minor
                  Found in demo/src/react-ranker/use-width.tsx - 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 computeFromMatrix has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                  const computeFromMatrix = (matrix: Matrix): ScoreObject => {
                    const allEdges: Edge[] = matrix.array.flatMap(
                      (row, from) =>
                        row
                          .map((value, to) =>
                  Severity: Minor
                  Found in votes/src/methods/ranked-pairs/index.ts - About 35 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 randomRankingFromSores has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  const randomRankingFromSores = (
                    scoreObject: ScoreObject,
                    random: () => number,
                  ): string[] => {
                    const candidates = Object.keys(scoreObject)
                  Severity: Minor
                  Found in votes/src/classes/random-matrix-method.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

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

                  const isZero = (matrix: number[][]): boolean => {
                    for (let i = 0; i < matrix.length; i++)
                      for (let j = 0; j < matrix.length; j++) if (matrix[i][j] !== 0) return false
                    return true
                  }
                  Severity: Minor
                  Found in votes/src/simplex/find-nash-equilibrium.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

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

                  export const findNashEquilibrium = (matrix: SkewSymmetricMatrix): number[] => {
                    if (isZero(matrix)) return matrix.map(() => 1 / matrix.length)
                  
                    const constraints: Record<string, Record<string, number>> = {
                      sum: { equal: 1 },
                  Severity: Minor
                  Found in votes/src/simplex/find-nash-equilibrium.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

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

                  const computeScores = (
                    candidates: string[],
                    _ballots: Ballot[],
                  ): ScoreObject => {
                    const scores = scoresZero(candidates)
                  Severity: Minor
                  Found in votes/src/methods/borda/index.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

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

                  const computeFromMatrix = (matrix: Matrix) => {
                    const n = matrix.candidates.length
                  
                    const p: number[][] = _.range(n).map(() => _.range(n).map(() => 0))
                    for (let i = 0; i < n; i++) {
                  Severity: Minor
                  Found in votes/src/methods/copeland/index.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

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

                  export const updateBuckets = (
                    buckets: { id: string; elements: number[] }[],
                    item: number,
                    newRank: number,
                  ) => {
                  Severity: Minor
                  Found in demo/src/react-ranker/helper.tsx - 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

                  Severity
                  Category
                  Status
                  Source
                  Language