Skip to content

Commit

Permalink
make code jshint compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
janpieper committed Oct 23, 2013
1 parent e9857de commit fa68d99
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"laxbreak": true
}
18 changes: 9 additions & 9 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Client(options) {
this._udpControl = options.udpControl || new Client.UdpControl(options);
this._udpNavdatasStream = options.udpNavdataStream || new Client.UdpNavdataStream(options);
this._pngStream = null;
this._tcpStream = null;
this._tcpVideoStream = null;
this._interval = null;
this._ref = {};
this._pcmd = {};
Expand Down Expand Up @@ -49,18 +49,18 @@ Client.prototype.createPngStream = function() {
};

Client.prototype.getPngStream = function() {
if (this._pngStream == null) {
if (this._pngStream === null) {
this._pngStream = this._newPngStream();
}
return this._pngStream;
}
};

Client.prototype.getVideoStream = function() {
if (this._tcpVideoStream == null) {
if (this._tcpVideoStream === null) {
this._tcpVideoStream = this._newTcpVideoStream();
}
return this._tcpVideoStream;
}
};

Client.prototype._newTcpVideoStream = function() {
var stream = new Client.TcpVideoStream(this._options);
Expand All @@ -72,12 +72,12 @@ Client.prototype._newTcpVideoStream = function() {
stream.connect(callback);
}, 1000);
}
}
};

stream.connect(callback);
stream.on('error', callback);
return stream;
}
};

Client.prototype._newPngStream = function() {
var videoStream = this.getVideoStream();
Expand All @@ -88,7 +88,7 @@ Client.prototype._newPngStream = function() {
});

return pngEncoder;
}
};

Client.prototype.resume = function() {
// Reset config ACK.
Expand Down Expand Up @@ -265,7 +265,7 @@ var pcmdOptions = [
['left', 'right'],
['front', 'back'],
['clockwise', 'counterClockwise'],
]
];

pcmdOptions.forEach(function(pair) {
Client.prototype[pair[0]] = function(speed) {
Expand Down
2 changes: 1 addition & 1 deletion lib/control/AtCommandCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ AtCommandCreator.prototype.ctrl = function(a, b) {
// TMP: Used to send FTRIM
AtCommandCreator.prototype.ftrim = function() {
return this.raw('FTRIM');
}
};

AtCommandCreator.prototype.animateLeds = function(name, hz, duration) {
// Default animation
Expand Down
2 changes: 1 addition & 1 deletion lib/control/UdpControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ UdpControl.prototype._sendCommands = function(commands) {
debug(serialized.replace('\r', '|'));
var buffer = new Buffer(serialized);
this._socket.send(buffer, 0, buffer.length, this._port, this._ip);
}
};

UdpControl.prototype._concat = function(commands) {
var self = this;
Expand Down
4 changes: 3 additions & 1 deletion lib/navdata/UdpNavdataStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ UdpNavdataStream.prototype._setTimeout = function() {
};

UdpNavdataStream.prototype._handleMessage = function(buffer) {
var navdata = {};

try {
var navdata = this._parseNavdata(buffer);
navdata = this._parseNavdata(buffer);
} catch (err) {
// avoid 'error' causing an exception when nobody is listening
if (this.listeners('error').length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/navdata/maskingFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports.NAVDATA_NUM_TAGS = Object.keys(constants.options).length;
exports.NAVDATA_OPTION_FULL_MASK = (1<<exports.NAVDATA_NUM_TAGS) - 1;

exports.TAG_TYPE_MASK = function (tagtype) {
return (tagtype == 0) ? 0 : 1 << (tagtype - 1);
return (tagtype === 0) ? 0 : 1 << (tagtype - 1);
};

exports.NAVDATA_OPTION_MASK = function (option) {
Expand Down
2 changes: 1 addition & 1 deletion lib/video/PngSplitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ PngSplitter.prototype.write = function(buffer) {
break;
}

this._state = 'chunk.header'
this._state = 'chunk.header';
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/video/TcpVideoStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function TcpVideoStream(options) {
options = options || {};

this.readable = true;
this._socket = options.socket || new net.Socket;
this._socket = options.socket || new net.Socket();
this._port = options.port || constants.ports.VIDEO;
this._ip = options.ip || constants.DEFAULT_DRONE_IP;
this._timeout = options.timeout || 1 * 1000;
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"main": "./index",
"scripts": {
"pretest": "node_modules/jshint/bin/jshint -c .jshintrc lib/ test/ index.js",
"test": "node test/run.js"
},
"dependencies": {
Expand All @@ -19,7 +20,8 @@
"devDependencies": {
"utest": "0.0.6",
"urun": "0.0.6",
"sinon": "1.4.2"
"sinon": "1.4.2",
"jshint": "2.3.0"
},
"optionalDependencies": {},
"engines": {
Expand Down
22 changes: 11 additions & 11 deletions test/unit/control/test-AtCommandCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ test('AtCommandCreator', {
assert(!cmd.callback);

var options = { timeout: 10 };
var cmd = this.creator.raw('FOO', [1, 2], true, options);
cmd = this.creator.raw('FOO', [1, 2], true, options);
assert.equal(cmd.type, 'FOO');
assert.deepEqual(cmd.args, [1, 2]);
assert.equal(cmd.blocks, true);
assert.deepEqual(cmd.options, options);
assert(!cmd.callback);

var options = { timeout: 10 };
options = { timeout: 10 };
var callback = function() {};
var cmd = this.creator.raw('FOO', [1, 2], true, options, callback);
cmd = this.creator.raw('FOO', [1, 2], true, options, callback);
assert.equal(cmd.type, 'FOO');
assert.deepEqual(cmd.args, [1, 2]);
assert.equal(cmd.blocks, true);
Expand All @@ -54,12 +54,12 @@ test('AtCommandCreator', {
assert.equal(cmd.blocks, false);
assert.deepEqual(cmd.options, {});

var cmd = this.creator.ref({fly: true});
cmd = this.creator.ref({fly: true});
assert.ok(cmd.args[0] & AtCommandCreator.REF_FLAGS.takeoff);
assert.equal(cmd.blocks, false);
assert.deepEqual(cmd.options, {});

var cmd = this.creator.ref({emergency: true});
cmd = this.creator.ref({emergency: true});
assert.ok(cmd.args[0] & AtCommandCreator.REF_FLAGS.emergency);
assert.equal(cmd.blocks, false);
assert.deepEqual(cmd.options, {});
Expand All @@ -85,16 +85,16 @@ test('AtCommandCreator', {
assert.equal(this.creator.pcmd({counterClockwise: val}).args[4], at.floatString(-val));

// test multiple aliases togeter
var cmd = this.creator.pcmd({left: 0.1, clockwise: 0.3});
cmd = this.creator.pcmd({left: 0.1, clockwise: 0.3});
assert.equal(cmd.args[1], at.floatString(-0.1));
assert.equal(cmd.args[4], at.floatString(0.3));

// test progressive bit being unset when no aliases are provided
var cmd = this.creator.pcmd();
cmd = this.creator.pcmd();
assert.equal(cmd.args[0] & AtCommandCreator.PCMD_FLAGS.progressive, false);

// test progressive bit being set automatically
var cmd = this.creator.pcmd({left: 0.1});
cmd = this.creator.pcmd({left: 0.1});
assert.ok(cmd.args[0] & (1 << 0));
},

Expand Down Expand Up @@ -122,7 +122,7 @@ test('AtCommandCreator', {
assert.deepEqual(cmd.options, {});

var callback = function() {};
var cmd = this.creator.config('foo', 'bar', callback);
cmd = this.creator.config('foo', 'bar', callback);
assert.equal(cmd.type, 'CONFIG');
assert.equal(cmd.args.length, 2);
assert.equal(cmd.args[0], '"foo"');
Expand All @@ -131,14 +131,14 @@ test('AtCommandCreator', {
assert.deepEqual(cmd.options, {});
assert.equal(cmd.callback, callback);

var cmd = this.creator.config({key: 'foo', value: 'bar'});
cmd = this.creator.config({key: 'foo', value: 'bar'});
assert.equal(cmd.type, 'CONFIG');
assert.equal(cmd.args.length, 2);
assert.equal(cmd.args[0], '"foo"');
assert.equal(cmd.args[1], '"bar"');
assert.equal(cmd.blocks, true);

var cmd = this.creator.config({key: 'foo', value: 'bar', timeout: 1}, callback);
cmd = this.creator.config({key: 'foo', value: 'bar', timeout: 1}, callback);
assert.equal(cmd.type, 'CONFIG');
assert.equal(cmd.args.length, 2);
assert.equal(cmd.args[0], '"foo"');
Expand Down
40 changes: 20 additions & 20 deletions test/unit/control/test-UdpControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ test('UdpControl', {


// Should have sent a single non-blocking command second.
var sendArgs = fakeSocket.send.getCall(1).args;
var buffer = sendArgs.shift();
var offset = sendArgs.shift();
var length = sendArgs.shift();
var port = sendArgs.shift();
var ip = sendArgs.shift();
sendArgs = fakeSocket.send.getCall(1).args;
buffer = sendArgs.shift();
offset = sendArgs.shift();
length = sendArgs.shift();
port = sendArgs.shift();
ip = sendArgs.shift();

assert.equal(Buffer.isBuffer(buffer), true);
assert.deepEqual(buffer.toString(), config1.serialize(2));
Expand All @@ -158,13 +158,13 @@ test('UdpControl', {
control.ack();
control.flush();

var ctrl = new AtCommand('CTRL', [5, 0]);
var sendArgs = fakeSocket.send.getCall(2).args;
var buffer = sendArgs.shift();
var offset = sendArgs.shift();
var length = sendArgs.shift();
var port = sendArgs.shift();
var ip = sendArgs.shift();
ctrl = new AtCommand('CTRL', [5, 0]);
sendArgs = fakeSocket.send.getCall(2).args;
buffer = sendArgs.shift();
offset = sendArgs.shift();
length = sendArgs.shift();
port = sendArgs.shift();
ip = sendArgs.shift();

assert.equal(Buffer.isBuffer(buffer), true);
assert.deepEqual(buffer.toString(), ctrl.serialize(3));
Expand All @@ -178,12 +178,12 @@ test('UdpControl', {
control.ackReset();
control.flush();

var sendArgs = fakeSocket.send.getCall(3).args;
var buffer = sendArgs.shift();
var offset = sendArgs.shift();
var length = sendArgs.shift();
var port = sendArgs.shift();
var ip = sendArgs.shift();
sendArgs = fakeSocket.send.getCall(3).args;
buffer = sendArgs.shift();
offset = sendArgs.shift();
length = sendArgs.shift();
port = sendArgs.shift();
ip = sendArgs.shift();

assert.equal(Buffer.isBuffer(buffer), true);
assert.deepEqual(buffer.toString(), config2.serialize(4));
Expand All @@ -208,5 +208,5 @@ test('UdpControl', {

control.close();
assert.equal(fakeSocket.close.callCount, 1);
},
}
});
4 changes: 2 additions & 2 deletions test/unit/navdata/test-parseNavdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ test('parseNavdata', {
fixtureCopy[23] = fixtureCopy[23] + 1;

assert.throws(function() {
parseNavdata(fixtureCopy)
parseNavdata(fixtureCopy);
}, /checksum/i);
},

Expand All @@ -848,7 +848,7 @@ test('parseNavdata', {
]);

assert.throws(function() {
parseNavdata(incompleteFixture)
parseNavdata(incompleteFixture);
}, /beyond/i);
},
});
2 changes: 1 addition & 1 deletion test/unit/test-Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test('Client', {
this.fakeUdpControl.pcmd = sinon.stub();
this.fakeUdpControl.ref = sinon.stub();

this.fakeUdpNavdataStream = new EventEmitter;
this.fakeUdpNavdataStream = new EventEmitter();
this.fakeUdpNavdataStream.resume = sinon.stub();

this.pngEncoder = new PngEncoder();
Expand Down

0 comments on commit fa68d99

Please sign in to comment.