Skip to content

Commit 5589761

Browse files
committed
Code quality improvements from JSHint
1 parent 21df85a commit 5589761

18 files changed

+125
-90
lines changed

.jshintrc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
// Environment settings
3+
"browser": true,
4+
"typed": true,
5+
"devel": true,
6+
"globalstrict": true,
7+
8+
"globals": {
9+
"$" : false,
10+
"jQuery" : false,
11+
"THREE" : false,
12+
"Modernizr" : false,
13+
14+
"ArrayDataStream" : true,
15+
"Craft2D" : true,
16+
"Craft3D" : true,
17+
"ExpoCurve" : true,
18+
"FIFOCache" : true,
19+
"FlightLog" : true,
20+
"FlightLogEvent" : true,
21+
"FlightLogGrapher" : true,
22+
"FlightLogParser" : true,
23+
"FlightLogFieldPresenter" : true,
24+
"FlightLogIndex" : true,
25+
"GraphConfig" : true,
26+
"GraphLegend" : true,
27+
"IMU" : true,
28+
"SeekBar" : true
29+
}
30+
}

js/cache.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use strict";
2+
13
/**
24
* A FIFO cache to hold key-pair mappings. Its capacity will be at least the intialCapacity
35
* supplied on creation, which you can increase by increasing the "capacity" property.

js/craft_3d.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function Craft3D(flightLog, canvas, propColors) {
3030
};
3131

3232
for (var i = 0; i < NUM_PROP_LEVELS; i++) {
33-
if (i == 0) {
33+
if (i === 0) {
3434
props[i] = new THREE.Geometry();
3535
} else {
3636
var
@@ -112,7 +112,7 @@ function Craft3D(flightLog, canvas, propColors) {
112112
armStart = i / numMotors * Math.PI * 2 - ARM_WIDTH_RADIANS,
113113
armEnd = armStart + ARM_WIDTH_RADIANS * 2;
114114

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

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

224224
propShells[i] = propShell;
225225

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

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

291291
renderer.render(scene, camera);
292292
};

js/datastream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var ArrayDataStream;
1515
this.start = start === undefined ? 0 : start;
1616
this.end = end === undefined ? data.length : end;
1717
this.pos = this.start;
18-
}
18+
};
1919

2020
/**
2121
* Read a single byte from the string and turn it into a JavaScript string (assuming ASCII).

js/decoders.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use strict";
2+
13
/**
24
* Extend ArrayDataStream with decoders for advanced formats.
35
*/
@@ -81,7 +83,7 @@ ArrayDataStream.prototype.readTag8_4S16_v1 = function(values) {
8183
var
8284
selector, combinedChar,
8385
char1, char2,
84-
i;
86+
i,
8587

8688
FIELD_ZERO = 0,
8789
FIELD_4BIT = 1,
@@ -119,7 +121,7 @@ ArrayDataStream.prototype.readTag8_4S16_v1 = function(values) {
119121

120122
selector >>= 2;
121123
}
122-
}
124+
};
123125

124126
ArrayDataStream.prototype.readTag8_4S16_v2 = function(values) {
125127
var
@@ -143,7 +145,7 @@ ArrayDataStream.prototype.readTag8_4S16_v2 = function(values) {
143145
values[i] = 0;
144146
break;
145147
case FIELD_4BIT:
146-
if (nibbleIndex == 0) {
148+
if (nibbleIndex === 0) {
147149
buffer = this.readByte();
148150
values[i] = signExtend4Bit(buffer >> 4);
149151
nibbleIndex = 1;
@@ -153,7 +155,7 @@ ArrayDataStream.prototype.readTag8_4S16_v2 = function(values) {
153155
}
154156
break;
155157
case FIELD_8BIT:
156-
if (nibbleIndex == 0) {
158+
if (nibbleIndex === 0) {
157159
values[i] = signExtend8Bit(this.readByte());
158160
} else {
159161
char1 = (buffer & 0x0F) << 4;
@@ -164,7 +166,7 @@ ArrayDataStream.prototype.readTag8_4S16_v2 = function(values) {
164166
}
165167
break;
166168
case FIELD_16BIT:
167-
if (nibbleIndex == 0) {
169+
if (nibbleIndex === 0) {
168170
char1 = this.readByte();
169171
char2 = this.readByte();
170172

js/expo.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
*/
88
function ExpoCurve(offset, power, inputRange, outputRange, steps) {
99
var
10-
curve,
11-
inputRange, outputRange, inputScale;
10+
curve, inputScale;
1211

1312
function lookupStraightLine(input) {
1413
return (input + offset) * inputScale;
@@ -60,7 +59,7 @@ function ExpoCurve(offset, power, inputRange, outputRange, steps) {
6059
}
6160

6261
// If steps argument isn't supplied, use a reasonable default
63-
if (steps == undefined) {
62+
if (steps === undefined) {
6463
steps = 12;
6564
}
6665

js/flightlog.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function FlightLog(logData) {
9494
*/
9595
this.getLogIndex = function() {
9696
return logIndex;
97-
}
97+
};
9898

9999
this.getLogCount = function() {
100100
return logIndexes.getLogCount();
@@ -161,7 +161,7 @@ function FlightLog(logData) {
161161
i;
162162

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

166166
fieldNames.push("heading[0]", "heading[1]", "heading[2]");
167167
fieldNames.push("axisSum[0]", "axisSum[1]", "axisSum[2]");
@@ -193,7 +193,7 @@ function FlightLog(logData) {
193193
found = false;
194194

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

204204
numCells = i;
205205
}
206-
};
206+
}
207207

208208
this.getNumCellsEstimate = function() {
209209
return numCells;
@@ -413,7 +413,7 @@ function FlightLog(logData) {
413413
[fieldNameToIndex["axisP[1]"], fieldNameToIndex["axisI[1]"], fieldNameToIndex["axisD[1]"]],
414414
[fieldNameToIndex["axisP[2]"], fieldNameToIndex["axisI[2]"], fieldNameToIndex["axisD[2]"]]];
415415

416-
if (destChunks.length == 0) {
416+
if (destChunks.length === 0) {
417417
return;
418418
}
419419

@@ -471,7 +471,7 @@ function FlightLog(logData) {
471471
}
472472
}
473473
}
474-
};
474+
}
475475

476476
/**
477477
* Add timestamps to events that getChunksInRange was unable to compute, because at the time it had trailing
@@ -537,7 +537,7 @@ function FlightLog(logData) {
537537
this.getSmoothedChunksInTimeRange = function(startTime, endTime) {
538538
var
539539
sourceChunks,
540-
resultChunks, resultChunk,
540+
resultChunks,
541541
chunkAlreadyDone, allDone,
542542
timeFieldIndex = FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME;
543543

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

688688
//Try moving it left
689-
if (leftFrameIndex == 0) {
689+
if (leftFrameIndex === 0) {
690690
leftChunkIndex--;
691691
leftFrameIndex = sourceChunks[leftChunkIndex].frames.length - 1;
692692
} else {
@@ -773,7 +773,7 @@ function FlightLog(logData) {
773773
}
774774
}
775775

776-
addMissingEventTimes(sourceChunks, trailingROChunks == 0);
776+
addMissingEventTimes(sourceChunks, trailingROChunks === 0);
777777

778778
verifyChunkIndexes(sourceChunks);
779779
verifyChunkIndexes(resultChunks);

js/flightlog_fielddefs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use strict";
2+
13
var
24
FlightLogEvent = {
35
SYNC_BEEP: 0,
@@ -12,4 +14,4 @@ var
1214
// Make read-only if browser supports it:
1315
if (Object.freeze) {
1416
FlightLogEvent = Object.freeze(FlightLogEvent);
15-
}
17+
}

js/flightlog_fields_presenter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
function FlightlogFieldPresenter() {
3+
function FlightLogFieldPresenter() {
44
}
55

66
(function() {
@@ -69,7 +69,7 @@ function FlightlogFieldPresenter() {
6969
* @param fieldName Name of the field
7070
* @param value Value of the field
7171
*/
72-
FlightlogFieldPresenter.decodeFieldToFriendly = function(flightLog, fieldName, value) {
72+
FlightLogFieldPresenter.decodeFieldToFriendly = function(flightLog, fieldName, value) {
7373
if (value === undefined)
7474
return "";
7575

@@ -105,7 +105,7 @@ function FlightlogFieldPresenter() {
105105
}
106106
};
107107

108-
FlightlogFieldPresenter.fieldNameToFriendly = function(fieldName) {
108+
FlightLogFieldPresenter.fieldNameToFriendly = function(fieldName) {
109109
if (FRIENDLY_FIELD_NAMES[fieldName]) {
110110
return FRIENDLY_FIELD_NAMES[fieldName];
111111
}

js/flightlog_index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function FlightLogIndex(logData) {
7373
// Only attempt to parse the log if the header wasn't corrupt
7474
if (parsedHeader) {
7575
sysConfig = parser.sysConfig;
76-
mainFrameDef = parser.frameDefs["I"];
76+
mainFrameDef = parser.frameDefs.I;
7777

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

108108
if (frameType == 'I') {
109109
// Start a new chunk on every 4th I-frame
110-
if (iframeCount % 4 == 0) {
110+
if (iframeCount % 4 === 0) {
111111
// Log the beginning of the new chunk
112112
intraIndex.times.push(frameTime);
113113
intraIndex.offsets.push(frameOffset);

0 commit comments

Comments
 (0)