Skip to content

Commit

Permalink
Code quality improvements from JSHint
Browse files Browse the repository at this point in the history
  • Loading branch information
thenickdude committed May 17, 2015
1 parent 21df85a commit 5589761
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 90 deletions.
30 changes: 30 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
// Environment settings
"browser": true,
"typed": true,
"devel": true,
"globalstrict": true,

"globals": {
"$" : false,
"jQuery" : false,
"THREE" : false,
"Modernizr" : false,

"ArrayDataStream" : true,
"Craft2D" : true,
"Craft3D" : true,
"ExpoCurve" : true,
"FIFOCache" : true,
"FlightLog" : true,
"FlightLogEvent" : true,
"FlightLogGrapher" : true,
"FlightLogParser" : true,
"FlightLogFieldPresenter" : true,
"FlightLogIndex" : true,
"GraphConfig" : true,
"GraphLegend" : true,
"IMU" : true,
"SeekBar" : true
}
}
2 changes: 2 additions & 0 deletions js/cache.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

/**
* A FIFO cache to hold key-pair mappings. Its capacity will be at least the intialCapacity
* supplied on creation, which you can increase by increasing the "capacity" property.
Expand Down
8 changes: 4 additions & 4 deletions js/craft_3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function Craft3D(flightLog, canvas, propColors) {
};

for (var i = 0; i < NUM_PROP_LEVELS; i++) {
if (i == 0) {
if (i === 0) {
props[i] = new THREE.Geometry();
} else {
var
Expand Down Expand Up @@ -112,7 +112,7 @@ function Craft3D(flightLog, canvas, propColors) {
armStart = i / numMotors * Math.PI * 2 - ARM_WIDTH_RADIANS,
armEnd = armStart + ARM_WIDTH_RADIANS * 2;

if (i == 0) {
if (i === 0) {
path.moveTo(Math.cos(armStart) * HUB_RADIUS, Math.sin(armStart) * HUB_RADIUS);
} else {
path.lineTo(Math.cos(armStart) * HUB_RADIUS, Math.sin(armStart) * HUB_RADIUS);
Expand Down Expand Up @@ -219,7 +219,7 @@ function Craft3D(flightLog, canvas, propColors) {
for (var i = 0; i < numMotors; i++) {
propMaterials[i] = new THREE.MeshLambertMaterial({color: propColors[i]});

var propShell = new THREE.Mesh(propGeometry[propGeometry.length - 1], propShellMaterial)
var propShell = new THREE.Mesh(propGeometry[propGeometry.length - 1], propShellMaterial);

propShells[i] = propShell;

Expand Down Expand Up @@ -286,7 +286,7 @@ function Craft3D(flightLog, canvas, propColors) {
craftParent.rotation.x = -frame[frameFieldIndexes['heading[1]']] /*- Math.PI / 2*/; // pitch
craftParent.rotation.y = frame[frameFieldIndexes['heading[0]']]; // roll

//craftParent.rotation.z = -frame[flightLog.getMainFieldIndexByName('heading[2]')]; // yaw
//craftParent.rotation.z = -frame[frameFieldIndexes['heading[2]']]; // yaw

renderer.render(scene, camera);
};
Expand Down
2 changes: 1 addition & 1 deletion js/datastream.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var ArrayDataStream;
this.start = start === undefined ? 0 : start;
this.end = end === undefined ? data.length : end;
this.pos = this.start;
}
};

/**
* Read a single byte from the string and turn it into a JavaScript string (assuming ASCII).
Expand Down
12 changes: 7 additions & 5 deletions js/decoders.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

/**
* Extend ArrayDataStream with decoders for advanced formats.
*/
Expand Down Expand Up @@ -81,7 +83,7 @@ ArrayDataStream.prototype.readTag8_4S16_v1 = function(values) {
var
selector, combinedChar,
char1, char2,
i;
i,

FIELD_ZERO = 0,
FIELD_4BIT = 1,
Expand Down Expand Up @@ -119,7 +121,7 @@ ArrayDataStream.prototype.readTag8_4S16_v1 = function(values) {

selector >>= 2;
}
}
};

ArrayDataStream.prototype.readTag8_4S16_v2 = function(values) {
var
Expand All @@ -143,7 +145,7 @@ ArrayDataStream.prototype.readTag8_4S16_v2 = function(values) {
values[i] = 0;
break;
case FIELD_4BIT:
if (nibbleIndex == 0) {
if (nibbleIndex === 0) {
buffer = this.readByte();
values[i] = signExtend4Bit(buffer >> 4);
nibbleIndex = 1;
Expand All @@ -153,7 +155,7 @@ ArrayDataStream.prototype.readTag8_4S16_v2 = function(values) {
}
break;
case FIELD_8BIT:
if (nibbleIndex == 0) {
if (nibbleIndex === 0) {
values[i] = signExtend8Bit(this.readByte());
} else {
char1 = (buffer & 0x0F) << 4;
Expand All @@ -164,7 +166,7 @@ ArrayDataStream.prototype.readTag8_4S16_v2 = function(values) {
}
break;
case FIELD_16BIT:
if (nibbleIndex == 0) {
if (nibbleIndex === 0) {
char1 = this.readByte();
char2 = this.readByte();

Expand Down
5 changes: 2 additions & 3 deletions js/expo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/
function ExpoCurve(offset, power, inputRange, outputRange, steps) {
var
curve,
inputRange, outputRange, inputScale;
curve, inputScale;

function lookupStraightLine(input) {
return (input + offset) * inputScale;
Expand Down Expand Up @@ -60,7 +59,7 @@ function ExpoCurve(offset, power, inputRange, outputRange, steps) {
}

// If steps argument isn't supplied, use a reasonable default
if (steps == undefined) {
if (steps === undefined) {
steps = 12;
}

Expand Down
20 changes: 10 additions & 10 deletions js/flightlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function FlightLog(logData) {
*/
this.getLogIndex = function() {
return logIndex;
}
};

this.getLogCount = function() {
return logIndexes.getLogCount();
Expand Down Expand Up @@ -161,7 +161,7 @@ function FlightLog(logData) {
i;

// Make an independent copy
fieldNames = parser.frameDefs["I"].name.slice(0);
fieldNames = parser.frameDefs.I.name.slice(0);

fieldNames.push("heading[0]", "heading[1]", "heading[2]");
fieldNames.push("axisSum[0]", "axisSum[1]", "axisSum[2]");
Expand Down Expand Up @@ -193,7 +193,7 @@ function FlightLog(logData) {
found = false;

//Are we even logging VBAT?
if (!fieldNameToIndex['vbatLatest']) {
if (!fieldNameToIndex.vbatLatest) {
numCells = false;
} else {
for (i = 1; i < 8; i++) {
Expand All @@ -203,7 +203,7 @@ function FlightLog(logData) {

numCells = i;
}
};
}

this.getNumCellsEstimate = function() {
return numCells;
Expand Down Expand Up @@ -413,7 +413,7 @@ function FlightLog(logData) {
[fieldNameToIndex["axisP[1]"], fieldNameToIndex["axisI[1]"], fieldNameToIndex["axisD[1]"]],
[fieldNameToIndex["axisP[2]"], fieldNameToIndex["axisI[2]"], fieldNameToIndex["axisD[2]"]]];

if (destChunks.length == 0) {
if (destChunks.length === 0) {
return;
}

Expand Down Expand Up @@ -471,7 +471,7 @@ function FlightLog(logData) {
}
}
}
};
}

/**
* Add timestamps to events that getChunksInRange was unable to compute, because at the time it had trailing
Expand Down Expand Up @@ -537,7 +537,7 @@ function FlightLog(logData) {
this.getSmoothedChunksInTimeRange = function(startTime, endTime) {
var
sourceChunks,
resultChunks, resultChunk,
resultChunks,
chunkAlreadyDone, allDone,
timeFieldIndex = FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME;

Expand Down Expand Up @@ -680,13 +680,13 @@ function FlightLog(logData) {
* to prime our history window. Move the left&right indexes to the left so the main loop will read
* those earlier values.
*/
while (leftFrameIndex > 0 || leftFrameIndex == 0 && leftChunkIndex > 0) {
while (leftFrameIndex > 0 || leftFrameIndex === 0 && leftChunkIndex > 0) {
var
oldleftChunkIndex = leftChunkIndex,
oldleftFrameIndex = leftFrameIndex;

//Try moving it left
if (leftFrameIndex == 0) {
if (leftFrameIndex === 0) {
leftChunkIndex--;
leftFrameIndex = sourceChunks[leftChunkIndex].frames.length - 1;
} else {
Expand Down Expand Up @@ -773,7 +773,7 @@ function FlightLog(logData) {
}
}

addMissingEventTimes(sourceChunks, trailingROChunks == 0);
addMissingEventTimes(sourceChunks, trailingROChunks === 0);

verifyChunkIndexes(sourceChunks);
verifyChunkIndexes(resultChunks);
Expand Down
4 changes: 3 additions & 1 deletion js/flightlog_fielddefs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

var
FlightLogEvent = {
SYNC_BEEP: 0,
Expand All @@ -12,4 +14,4 @@ var
// Make read-only if browser supports it:
if (Object.freeze) {
FlightLogEvent = Object.freeze(FlightLogEvent);
}
}
6 changes: 3 additions & 3 deletions js/flightlog_fields_presenter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

function FlightlogFieldPresenter() {
function FlightLogFieldPresenter() {
}

(function() {
Expand Down Expand Up @@ -69,7 +69,7 @@ function FlightlogFieldPresenter() {
* @param fieldName Name of the field
* @param value Value of the field
*/
FlightlogFieldPresenter.decodeFieldToFriendly = function(flightLog, fieldName, value) {
FlightLogFieldPresenter.decodeFieldToFriendly = function(flightLog, fieldName, value) {
if (value === undefined)
return "";

Expand Down Expand Up @@ -105,7 +105,7 @@ function FlightlogFieldPresenter() {
}
};

FlightlogFieldPresenter.fieldNameToFriendly = function(fieldName) {
FlightLogFieldPresenter.fieldNameToFriendly = function(fieldName) {
if (FRIENDLY_FIELD_NAMES[fieldName]) {
return FRIENDLY_FIELD_NAMES[fieldName];
}
Expand Down
4 changes: 2 additions & 2 deletions js/flightlog_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function FlightLogIndex(logData) {
// Only attempt to parse the log if the header wasn't corrupt
if (parsedHeader) {
sysConfig = parser.sysConfig;
mainFrameDef = parser.frameDefs["I"];
mainFrameDef = parser.frameDefs.I;

gyroData = [mainFrameDef.nameToIndex["gyroData[0]"], mainFrameDef.nameToIndex["gyroData[1]"], mainFrameDef.nameToIndex["gyroData[2]"]];
accSmooth = [mainFrameDef.nameToIndex["accSmooth[0]"], mainFrameDef.nameToIndex["accSmooth[1]"], mainFrameDef.nameToIndex["accSmooth[2]"]];
Expand Down Expand Up @@ -107,7 +107,7 @@ function FlightLogIndex(logData) {

if (frameType == 'I') {
// Start a new chunk on every 4th I-frame
if (iframeCount % 4 == 0) {
if (iframeCount % 4 === 0) {
// Log the beginning of the new chunk
intraIndex.times.push(frameTime);
intraIndex.offsets.push(frameOffset);
Expand Down
Loading

0 comments on commit 5589761

Please sign in to comment.