Strilanc/Quirk

View on GitHub
src/ui/DisplayedCircuit.js

Summary

Maintainability
F
1 wk
Test Coverage

File DisplayedCircuit.js has 1126 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * Copyright 2017 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
Severity: Major
Found in src/ui/DisplayedCircuit.js - About 2 days to fix

    DisplayedCircuit has 61 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class DisplayedCircuit {
        /**
         *
         * @param {!number} top
         * @param {!CircuitDefinition} circuitDefinition
    Severity: Major
    Found in src/ui/DisplayedCircuit.js - About 1 day to fix

      Function _drawWires has 53 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          _drawWires(painter, showLabels, hand) {
              let drawnWireCount = Math.min(this.circuitDefinition.numWires, (this._extraWireStartIndex || Infinity) + 1);
      
              // Initial value labels
              if (showLabels) {
      Severity: Major
      Found in src/ui/DisplayedCircuit.js - About 2 hrs to fix

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

            _drawWires(painter, showLabels, hand) {
                let drawnWireCount = Math.min(this.circuitDefinition.numWires, (this._extraWireStartIndex || Infinity) + 1);
        
                // Initial value labels
                if (showLabels) {
        Severity: Minor
        Found in src/ui/DisplayedCircuit.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 _drawHintLabels has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            _drawHintLabels(painter, stats) {
                let gridRect = this._rectForSuperpositionDisplay();
        
                // Amplitude hint.
                painter.print(
        Severity: Minor
        Found in src/ui/DisplayedCircuit.js - About 1 hr to fix

          Function _drawColumnSurvivalRate has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              _drawColumnSurvivalRate(painter, gateColumn, col, stats) {
                  if (gateColumn.indexOfNonUnitaryGate() === undefined) {
                      return;
                  }
          
          
          Severity: Minor
          Found in src/ui/DisplayedCircuit.js - About 1 hr to fix

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

                _drawHintLabels(painter, stats) {
                    let gridRect = this._rectForSuperpositionDisplay();
            
                    // Amplitude hint.
                    painter.print(
            Severity: Minor
            Found in src/ui/DisplayedCircuit.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 _previewDropMovedGate has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                _previewDropMovedGate(hand) {
                    let modificationPoint = this.findModificationIndex(hand);
                    if (modificationPoint === undefined) {
                        return this;
                    }
            Severity: Minor
            Found in src/ui/DisplayedCircuit.js - About 1 hr to fix

              Function fromTextDiagram has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  static fromTextDiagram(gateMap, diagramText) {
                      let lines = diagramText.split('\n').map(e => {
                          let p = e.split('|');
                          if (p.length !== 2) {
                              throw new DetailedError('Bad diagram', {diagramText, gateMap});
              Severity: Minor
              Found in src/ui/DisplayedCircuit.js - About 1 hr to fix

                Function _highlightStatusAt has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    _highlightStatusAt(col, row, focusPosPts) {
                        if (this._highlightedSlot !== undefined) {
                            if (this._highlightedSlot.col === col && this._highlightedSlot.row === row) {
                                return {
                                    isResizeShowing: true,
                Severity: Minor
                Found in src/ui/DisplayedCircuit.js - About 1 hr to fix

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

                      _drawColumn(painter, gateColumn, col, hand, stats) {
                          this._drawColumnControlWires(painter, col);
                          this._drawColumnDragHighlight(painter, col);
                  
                          for (let row = 0; row < this.circuitDefinition.numWires; row++) {
                  Severity: Minor
                  Found in src/ui/DisplayedCircuit.js - About 1 hr to fix

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

                    function drawCircuitTooltip(painter, circuitDefinition, rect, showWires, time) {
                        let displayed = new DisplayedCircuit(
                            0,
                            circuitDefinition,
                            undefined,
                    Severity: Minor
                    Found in src/ui/DisplayedCircuit.js - About 1 hr to fix

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

                          _previewResizedGate(hand) {
                              if (hand.resizingGateSlot === undefined || hand.pos === undefined) {
                                  return this;
                              }
                              let gate = this.circuitDefinition.gateInSlot(hand.resizingGateSlot.x, hand.resizingGateSlot.y);
                      Severity: Minor
                      Found in src/ui/DisplayedCircuit.js - About 1 hr to fix

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

                            _tryGrabGate(hand, duplicate, alt) {
                                if (hand.isBusy() || hand.pos === undefined) {
                                    return undefined;
                                }
                        
                        
                        Severity: Minor
                        Found in src/ui/DisplayedCircuit.js - About 1 hr to fix

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

                              _tryGrabResizeTab(hand) {
                                  if (hand.isBusy() || hand.pos === undefined) {
                                      return undefined;
                                  }
                          
                          
                          Severity: Minor
                          Found in src/ui/DisplayedCircuit.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 _drawColumnSurvivalRate has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                          Open

                              _drawColumnSurvivalRate(painter, gateColumn, col, stats) {
                                  if (gateColumn.indexOfNonUnitaryGate() === undefined) {
                                      return;
                                  }
                          
                          
                          Severity: Minor
                          Found in src/ui/DisplayedCircuit.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 _drawLabelsReasonablyFast has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          function _drawLabelsReasonablyFast(painter, dy, n, labeller, boundingWidth) {
                              let ctx = painter.ctx;
                              ctx.save();
                              ctx.textAlign = 'left';
                              ctx.textBaseline = 'middle';
                          Severity: Minor
                          Found in src/ui/DisplayedCircuit.js - About 1 hr to fix

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

                                _highlightStatusAt(col, row, focusPosPts) {
                                    if (this._highlightedSlot !== undefined) {
                                        if (this._highlightedSlot.col === col && this._highlightedSlot.row === row) {
                                            return {
                                                isResizeShowing: true,
                            Severity: Minor
                            Found in src/ui/DisplayedCircuit.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 _previewDropMovedRow has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                            Open

                                _previewDropMovedRow(hand) {
                                    if (hand.pos === undefined) {
                                        return this;
                                    }
                                    let handWire = this.wireIndexAt(hand.pos.y);
                            Severity: Minor
                            Found in src/ui/DisplayedCircuit.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 findModificationIndex has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                                findModificationIndex(hand) {
                                    let loc = this._findModificationIndex_helperColRow(hand);
                                    if (loc === undefined) {
                                        return undefined;
                                    }
                            Severity: Minor
                            Found in src/ui/DisplayedCircuit.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

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

                                _drawColumn(painter, gateColumn, col, hand, stats) {
                                    this._drawColumnControlWires(painter, col);
                                    this._drawColumnDragHighlight(painter, col);
                            
                                    for (let row = 0; row < this.circuitDefinition.numWires; row++) {
                            Severity: Minor
                            Found in src/ui/DisplayedCircuit.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

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

                            function _drawLabelsReasonablyFast(painter, dy, n, labeller, boundingWidth) {
                            Severity: Minor
                            Found in src/ui/DisplayedCircuit.js - About 35 mins to fix

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

                              function drawCircuitTooltip(painter, circuitDefinition, rect, showWires, time) {
                              Severity: Minor
                              Found in src/ui/DisplayedCircuit.js - About 35 mins to fix

                                Function _previewDropMovedGateColumn has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    _previewDropMovedGateColumn(hand) {
                                        if (hand.pos === undefined) {
                                            return this;
                                        }
                                        let handWire = this.wireIndexAt(hand.pos.y);
                                Severity: Minor
                                Found in src/ui/DisplayedCircuit.js - 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 _shiftAndSpliceColumn has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    _shiftAndSpliceColumn(rowShift, gatesOfCol, insertCol, isInsert) {
                                        // Move gates upward.
                                        while (rowShift < 0 && gatesOfCol[0] === undefined) {
                                            gatesOfCol.shift();
                                            gatesOfCol.push(undefined);
                                Severity: Minor
                                Found in src/ui/DisplayedCircuit.js - 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 previewDrop has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    previewDrop(hand) {
                                        return hand.heldRow !== undefined ? this._previewDropMovedRow(hand) :
                                            hand.heldColumn !== undefined ? this._previewDropMovedGateColumn(hand) :
                                            hand.heldGate !== undefined ? this._previewDropMovedGate(hand) :
                                            this._previewResizedGate(hand);
                                Severity: Minor
                                Found in src/ui/DisplayedCircuit.js - 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 GATE_CIRCUIT_DRAWER has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                let GATE_CIRCUIT_DRAWER = args => {
                                    let circuit = args.gate.knownCircuit;
                                    if (circuit === undefined || args.gate.symbol !== '') {
                                        if (args.gate.stableDuration() === Infinity) {
                                            GatePainting.DEFAULT_DRAWER(args);
                                Severity: Minor
                                Found in src/ui/DisplayedCircuit.js - 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 tryGrab has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    tryGrab(hand, duplicate=false, wholeColumn=false, ignoreResizeTabs=false, alt=false) {
                                        if (wholeColumn) {
                                            let grabRowResult = this._tryGrabRow(hand, alt);
                                            if (grabRowResult !== undefined) {
                                                return grabRowResult;
                                Severity: Minor
                                Found in src/ui/DisplayedCircuit.js - 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

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

                                            if (measured) {
                                                painter.strokeLine(new Point(x+1, y1), new Point(x+1, y2));
                                                painter.strokeLine(new Point(x-1, y1), new Point(x-1, y2));
                                            } else {
                                                painter.strokeLine(new Point(x, y1), new Point(x, y2));
                                Severity: Major
                                Found in src/ui/DisplayedCircuit.js and 1 other location - About 2 hrs to fix
                                src/gates/Detector.js on lines 334..339

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

                                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

                                    if (args.isHighlighted) {
                                        args.painter.ctx.save();
                                        args.painter.ctx.globalAlpha *= 0.9;
                                        args.painter.fillRect(args.rect, Config.HIGHLIGHTED_GATE_FILL_COLOR);
                                        args.painter.ctx.restore();
                                Severity: Major
                                Found in src/ui/DisplayedCircuit.js and 1 other location - About 2 hrs to fix
                                src/draw/GatePainting.js on lines 354..359

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

                                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

                                            (c, r, v) => `mag²:${(v.norm2()*100).toFixed(4)}%, phase:${forceSign(v.phase() * 180 / Math.PI)}°`);
                                Severity: Major
                                Found in src/ui/DisplayedCircuit.js and 1 other location - About 1 hr to fix
                                src/gates/AmplitudeDisplay.js on lines 273..273

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

                                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