From 4fe264e9246de1ea878428ec091528dd38b091f7 Mon Sep 17 00:00:00 2001
From: Paul Kaplan <pkaplan@media.mit.edu>
Date: Sun, 13 Aug 2017 12:58:59 -0400
Subject: [PATCH] Fix all lint warnings except todo comments (including a bug!)

---
 .../audio-trimmer/audio-trimmer.jsx           | 10 +++++-----
 src/components/meter/meter.jsx                |  6 +++---
 .../record-modal/recording-step.jsx           |  2 +-
 src/containers/audio-trimmer.jsx              |  2 +-
 src/lib/audio/audio-buffer-player.js          |  2 +-
 src/lib/audio/audio-effects.js                |  2 +-
 src/lib/audio/effects/robot-effect.js         |  6 +++---
 src/lib/audio/shared-audio-context.js         |  5 ++++-
 src/lib/blocks.js                             |  5 +++++
 src/lib/monitor-adapter.js                    | 19 ++++++++++++++-----
 src/lib/opcode-labels.js                      |  5 +++++
 test/helpers/selenium-helpers.js              |  2 +-
 test/unit/util/audio-util.test.js             |  6 +++---
 13 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/src/components/audio-trimmer/audio-trimmer.jsx b/src/components/audio-trimmer/audio-trimmer.jsx
index fc216063a..b7bbe380f 100644
--- a/src/components/audio-trimmer/audio-trimmer.jsx
+++ b/src/components/audio-trimmer/audio-trimmer.jsx
@@ -10,7 +10,7 @@ const AudioTrimmer = props => (
         className={styles.absolute}
         ref={props.containerRef}
     >
-        {props.trimStart !== null ? (
+        {props.trimStart === null ? null : (
             <Box
                 className={classNames(styles.absolute, styles.trimBackground, styles.startTrimBackground)}
                 style={{
@@ -28,7 +28,7 @@ const AudioTrimmer = props => (
                     </Box>
                 </Box>
             </Box>
-        ) : null}
+        )}
 
         {props.playhead ? (
             <Box
@@ -39,12 +39,12 @@ const AudioTrimmer = props => (
             />
         ) : null}
 
-        {props.trimEnd !== null ? (
+        {props.trimEnd === null ? null : (
             <Box
                 className={classNames(styles.absolute, styles.trimBackground, styles.endTrimBackground)}
                 style={{
                     left: `${100 * props.trimEnd}%`,
-                    width: `${100 - 100 * props.trimEnd}%`
+                    width: `${100 - (100 * props.trimEnd)}%`
                 }}
                 onMouseDown={props.onTrimEndMouseDown}
             >
@@ -58,7 +58,7 @@ const AudioTrimmer = props => (
                     </Box>
                 </Box>
             </Box>
-        ) : null }
+        )}
     </div>
 );
 
diff --git a/src/components/meter/meter.jsx b/src/components/meter/meter.jsx
index b2878a8dd..8c378037c 100644
--- a/src/components/meter/meter.jsx
+++ b/src/components/meter/meter.jsx
@@ -17,7 +17,7 @@ const Meter = props => {
 
     const barSpacing = 2.5;
     const barRounding = 3;
-    const barHeight = (height - barSpacing * (nBars + 1)) / nBars;
+    const barHeight = (height - (barSpacing * (nBars + 1))) / nBars;
 
     const nBarsToMask = nBars - Math.floor(level * nBars);
 
@@ -38,12 +38,12 @@ const Meter = props => {
                         ry={barRounding}
                         width={width - 2}
                         x={1}
-                        y={height - (barSpacing + barHeight) * (index + 1)}
+                        y={height - ((barSpacing + barHeight) * (index + 1))}
                     />
                 ))}
             <rect
                 fill="white"
-                height={nBarsToMask * (barHeight + barSpacing) + barSpacing / 2}
+                height={(nBarsToMask * (barHeight + barSpacing)) + (barSpacing / 2)}
                 opacity="0.75"
                 width={width}
                 x={0}
diff --git a/src/components/record-modal/recording-step.jsx b/src/components/record-modal/recording-step.jsx
index 624a2e2b2..315696ab6 100644
--- a/src/components/record-modal/recording-step.jsx
+++ b/src/components/record-modal/recording-step.jsx
@@ -57,7 +57,7 @@ const RecordingStep = props => (
                             className={styles.recordButtonCircleOutline}
                             cx="26"
                             cy="26"
-                            r={27 + props.level * 5}
+                            r={27 + (props.level * 5)}
                         />
                     </svg>
                 )}
diff --git a/src/containers/audio-trimmer.jsx b/src/containers/audio-trimmer.jsx
index 03e91443e..db85370b8 100644
--- a/src/containers/audio-trimmer.jsx
+++ b/src/containers/audio-trimmer.jsx
@@ -52,7 +52,7 @@ class AudioTrimmer extends React.Component {
     render () {
         return (
             <AudioTrimmerComponent
-                containerRef={el => (this.containerElement = el)}
+                containerRef={el => (this.containerElement = el)} // eslint-disable-line react/jsx-no-bind
                 playhead={this.props.playhead}
                 trimEnd={this.props.trimEnd}
                 trimStart={this.props.trimStart}
diff --git a/src/lib/audio/audio-buffer-player.js b/src/lib/audio/audio-buffer-player.js
index 39affdfd3..e9e89c787 100644
--- a/src/lib/audio/audio-buffer-player.js
+++ b/src/lib/audio/audio-buffer-player.js
@@ -20,7 +20,7 @@ class AudioBufferPlayer {
         this.startTime = Date.now();
 
         const trimStartTime = this.buffer.duration * trimStart;
-        const trimmedDuration = this.buffer.duration * trimEnd - trimStartTime;
+        const trimmedDuration = (this.buffer.duration * trimEnd) - trimStartTime;
 
         this.source = this.audioContext.createBufferSource();
         this.source.onended = onEnded;
diff --git a/src/lib/audio/audio-effects.js b/src/lib/audio/audio-effects.js
index b7ba65cb2..187c6ce6b 100644
--- a/src/lib/audio/audio-effects.js
+++ b/src/lib/audio/audio-effects.js
@@ -24,7 +24,7 @@ class AudioEffects {
         let playbackRate = 1;
         switch (name) {
         case effectTypes.ECHO:
-            sampleCount = buffer.length + 0.25 * 3 * buffer.sampleRate;
+            sampleCount = buffer.length + (0.25 * 3 * buffer.sampleRate);
             break;
         case effectTypes.FASTER:
             playbackRate = pitchRatio;
diff --git a/src/lib/audio/effects/robot-effect.js b/src/lib/audio/effects/robot-effect.js
index d530b9e6e..472668d53 100644
--- a/src/lib/audio/effects/robot-effect.js
+++ b/src/lib/audio/effects/robot-effect.js
@@ -18,15 +18,15 @@ class RobotEffect {
             // Piecewise function given by (2) in Parker paper
             const transform = (v, vb = 0.2, vl = 0.4, h = 0.65) => {
                 if (v <= vb) return 0;
-                if (v <= vl) return h * (Math.pow(v - vb, 2) / (2 * vl - 2 * vb));
-                return h * v - h * vl + h * (Math.pow(v - vb, 2) / (2 * vl - 2 * vb));
+                if (v <= vl) return h * (Math.pow(v - vb, 2) / ((2 * vl) - (2 * vb)));
+                return (h * v) - (h * vl) + (h * (Math.pow(v - vb, 2) / ((2 * vl) - (2 * vb))));
             };
 
             // Create the waveshaper curve with the voltage transform above
             const bufferLength = 1024;
             const curve = new Float32Array(bufferLength);
             for (let i = 0; i < bufferLength; i++) {
-                const voltage = 2 * (i / bufferLength) - 1;
+                const voltage = (2 * (i / bufferLength)) - 1;
                 curve[i] = transform(voltage);
             }
             node.curve = curve;
diff --git a/src/lib/audio/shared-audio-context.js b/src/lib/audio/shared-audio-context.js
index f0b5c3ccf..f125aa722 100644
--- a/src/lib/audio/shared-audio-context.js
+++ b/src/lib/audio/shared-audio-context.js
@@ -1,6 +1,9 @@
-// Wrap browser AudioContext because we shouldn't create more than one
 const AUDIO_CONTEXT = new (window.AudioContext || window.webkitAudioContext)();
 
+/**
+ * Wrap browser AudioContext because we shouldn't create more than one
+ * @return {AudioContext} The singleton AudioContext
+ */
 export default function () {
     return AUDIO_CONTEXT;
 }
diff --git a/src/lib/blocks.js b/src/lib/blocks.js
index 7c6b10b21..662eb245f 100644
--- a/src/lib/blocks.js
+++ b/src/lib/blocks.js
@@ -1,5 +1,10 @@
 import ScratchBlocks from 'scratch-blocks';
 
+/**
+ * Connect scratch blocks with the vm
+ * @param {VirtualMachine} vm - The scratch vm
+ * @return {ScratchBlocks} ScratchBlocks connected with the vm
+ */
 export default function (vm) {
 
     const jsonForMenuBlock = function (name, menuOptionsFn, colors, start) {
diff --git a/src/lib/monitor-adapter.js b/src/lib/monitor-adapter.js
index 4a05cf328..69f362b5c 100644
--- a/src/lib/monitor-adapter.js
+++ b/src/lib/monitor-adapter.js
@@ -1,8 +1,3 @@
-/**
- * Convert monitors from VM format to what the GUI needs to render.
- * - Convert opcode to a label and a category
- * - Add missing XY position data if needed
- */
 import OpcodeLabels from './opcode-labels.js';
 
 const PADDING = 5;
@@ -10,6 +5,20 @@ const MONITOR_HEIGHT = 23;
 
 const isUndefined = a => typeof a === 'undefined';
 
+/**
+ * Convert monitors from VM format to what the GUI needs to render.
+ * - Convert opcode to a label and a category
+ * - Add missing XY position data if needed
+ * @param {object} block - The monitor block
+ * @param {string} block.id - The id of the monitor block
+ * @param {number} block.index - The index of the monitor
+ * @param {string} block.opcode - The opcode of the monitor
+ * @param {object} block.params - Extra params to the monitor block
+ * @param {string} block.value - The monitor value
+ * @param {number} x - The monitor x position
+ * @param {number} y - The monitor y position
+ * @return {object} The adapted monitor with label and category
+ */
 export default function ({id, index, opcode, params, value, x, y}) {
     let {label, category, labelFn} = OpcodeLabels(opcode);
 
diff --git a/src/lib/opcode-labels.js b/src/lib/opcode-labels.js
index 6acc4109b..d36842c68 100644
--- a/src/lib/opcode-labels.js
+++ b/src/lib/opcode-labels.js
@@ -66,6 +66,11 @@ const opcodeMap = {
     }
 };
 
+/**
+ * Get the label for an opcode
+ * @param {string} opcode the opcode you want a label for
+ * @return {object} object with label and category
+ */
 export default function (opcode) {
     if (opcode in opcodeMap) return opcodeMap[opcode];
     return {
diff --git a/test/helpers/selenium-helpers.js b/test/helpers/selenium-helpers.js
index 5ee0af01e..909f3a155 100644
--- a/test/helpers/selenium-helpers.js
+++ b/test/helpers/selenium-helpers.js
@@ -42,8 +42,8 @@ const getLogs = (whitelist) => {
                         console.warn('Ignoring non-SEVERE entry: ' + message);
                         return false;
                     }
-                    return true;
                 }
+                return true;
             });
         });
 };
diff --git a/test/unit/util/audio-util.test.js b/test/unit/util/audio-util.test.js
index 714381db6..743a5b1c4 100644
--- a/test/unit/util/audio-util.test.js
+++ b/test/unit/util/audio-util.test.js
@@ -9,7 +9,7 @@ describe('computeRMS', () => {
         const unity = 0.5;
         const samples = [3, 2, 1];
         expect(computeRMS(samples, unity)).toEqual(
-            Math.sqrt(Math.sqrt((3 * 3 + 2 * 2 + 1 * 1) / 3) / 0.5)
+            Math.sqrt(Math.sqrt(((3 * 3) + (2 * 2) + (1 * 1)) / 3) / 0.5)
         );
     });
     test('uses a default unity value of 0.55', () => {
@@ -28,8 +28,8 @@ describe('computeChunkedRMS', () => {
         // rms scaled with default unity of 0.55
         expect(chunkedLevels.length).toEqual(3);
         expect(chunkedLevels).toEqual([
-            Math.sqrt(Math.sqrt((2 * 2 + 1 * 1) / 2) / 0.55),
-            Math.sqrt(Math.sqrt((3 * 3 + 2 * 2) / 2) / 0.55),
+            Math.sqrt(Math.sqrt(((2 * 2) + (1 * 1)) / 2) / 0.55),
+            Math.sqrt(Math.sqrt(((3 * 3) + (2 * 2)) / 2) / 0.55),
             Math.sqrt(Math.sqrt((5 * 5) / 1) / 0.55)
         ]);
     });
-- 
GitLab