Skip to content

Commit

Permalink
Enforce === rule
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacov committed Mar 6, 2017
1 parent a37119f commit 2049ab2
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
}
],
"eol-last": "error",
"eqeqeq": "off",
"eqeqeq": "error",
"func-call-spacing": "error",
"func-name-matching": "error",
"func-names": "off",
Expand Down
14 changes: 7 additions & 7 deletions apis/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var addConnctionAPI = function(Modbus) {
*/
cl.connectRTU = function(path, options, next) {
// check if we have options
if (typeof(next) == 'undefined' && typeof(options) == 'function') {
if (typeof(next) === 'undefined' && typeof(options) === 'function') {
next = options;
options = {};
}
Expand All @@ -83,7 +83,7 @@ var addConnctionAPI = function(Modbus) {
*/
cl.connectTCP = function(ip, options, next) {
// check if we have options
if (typeof(next) == 'undefined' && typeof(options) == 'function') {
if (typeof(next) === 'undefined' && typeof(options) === 'function') {
next = options;
options = {};
}
Expand All @@ -105,7 +105,7 @@ var addConnctionAPI = function(Modbus) {
*/
cl.connectTcpRTUBuffered = function(ip, options, next) {
// check if we have options
if (typeof(next) == 'undefined' && typeof(options) == 'function') {
if (typeof(next) === 'undefined' && typeof(options) === 'function') {
next = options;
options = {};
}
Expand All @@ -126,7 +126,7 @@ var addConnctionAPI = function(Modbus) {
*/
cl.connectTelnet = function(ip, options, next) {
// check if we have options
if (typeof(next) == 'undefined' && typeof(options) == 'function') {
if (typeof(next) === 'undefined' && typeof(options) === 'function') {
next = options;
options = {};
}
Expand All @@ -148,7 +148,7 @@ var addConnctionAPI = function(Modbus) {
*/
cl.connectC701 = function(ip, options, next) {
// check if we have options
if (typeof(next) == 'undefined' && typeof(options) == 'function') {
if (typeof(next) === 'undefined' && typeof(options) === 'function') {
next = options;
options = {};
}
Expand All @@ -170,7 +170,7 @@ var addConnctionAPI = function(Modbus) {
*/
cl.connectRTUBuffered = function(path, options, next) {
// check if we have options
if (typeof(next) == 'undefined' && typeof(options) == 'function') {
if (typeof(next) === 'undefined' && typeof(options) === 'function') {
next = options;
options = {};
}
Expand All @@ -192,7 +192,7 @@ var addConnctionAPI = function(Modbus) {
*/
cl.connectAsciiSerial = function(path, options, next) {
// check if we have options
if (typeof(next) == 'undefined' && typeof(options) == 'function') {
if (typeof(next) === 'undefined' && typeof(options) === 'function') {
next = options;
options = {};
}
Expand Down
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function _readFC2(data, next) {
var reg = data[i + 3];

for (var j = 0; j < 8; j++) {
contents.push((reg & 1) == 1);
contents.push((reg & 1) === 1);
reg = reg >> 1;
}
}
Expand Down Expand Up @@ -87,7 +87,7 @@ function _readFC5(data, next) {
var state = data.readUInt16BE(4);

if (next)
next(null, { "address": dataAddress, "state": (state == 0xff00) });
next(null, { "address": dataAddress, "state": (state === 0xff00) });
}

/**
Expand Down Expand Up @@ -227,7 +227,7 @@ ModbusRTU.prototype.open = function(callback) {
* if CRC is bad raise an error
*/
var crcIn = data.readUInt16LE(data.length - 2);
if (crcIn != crc16(data.slice(0, -2))) {
if (crcIn !== crc16(data.slice(0, -2))) {
error = "CRC error";
if (transaction.next)
transaction.next(new Error(error));
Expand All @@ -240,8 +240,8 @@ ModbusRTU.prototype.open = function(callback) {

/* check for modbus exception
*/
if (data.length == 5 &&
code == (0x80 | transaction.nextCode)) {
if (data.length === 5 &&
code === (0x80 | transaction.nextCode)) {
error = "Modbus exception " + data.readUInt8(2);
if (transaction.next)
transaction.next(new Error(error));
Expand All @@ -252,7 +252,7 @@ ModbusRTU.prototype.open = function(callback) {
* if we do not expect this data
* raise an error
*/
if (data.length != transaction.nextLength) {
if (data.length !== transaction.nextLength) {
error = "Data length error, expected " +
transaction.nextLength + " got " + data.length;
if (transaction.next)
Expand All @@ -264,7 +264,7 @@ ModbusRTU.prototype.open = function(callback) {
* if we do not expect this message
* raise an error
*/
if (address != transaction.nextAddress || code != transaction.nextCode) {
if (address !== transaction.nextAddress || code !== transaction.nextCode) {
error = "Unexpected data error, expected " +
transaction.nextAddress + " got " + address;
if (transaction.next)
Expand Down
10 changes: 5 additions & 5 deletions ports/asciiport.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function asciiDecodeResponseBuffer(bufAscii) {

// check the lrc is true
var lrcIn = bufDecoded.readUInt8(bufDecoded.length - 2);
if(calculateLrc(bufDecoded.slice(0, -2)) != lrcIn) {
if(calculateLrc(bufDecoded.slice(0, -2)) !== lrcIn) {
// return null if lrc error
return null;
}
Expand All @@ -78,11 +78,11 @@ function asciiDecodeResponseBuffer(bufAscii) {
*/
function checkData(modbus, buf) {
// check buffer size
if (buf.length != modbus._length && buf.length != 5) return false;
if (buf.length !== modbus._length && buf.length !== 5) return false;

// check buffer unit-id and command
return (buf[0] == modbus._id &&
(0x7f & buf[1]) == modbus._cmd);
return (buf[0] === modbus._id &&
(0x7f & buf[1]) === modbus._cmd);
}

/**
Expand Down Expand Up @@ -130,7 +130,7 @@ var AsciiPort = function(path, options) {
if(modbus._buffer.includes('\r\n', 1, 'ascii') === true) {
// check there is no excess data after end delimiters
var edIndex = modbus._buffer.indexOf(0x0A); // ascii for '\n'
if(edIndex != modbus._buffer.length - 1) {
if(edIndex !== modbus._buffer.length - 1) {
// if there is, remove it
modbus._buffer = modbus._buffer.slice(0, edIndex + 1);
}
Expand Down
12 changes: 6 additions & 6 deletions ports/c701port.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ var C701_PORT = 0x7002;
*/
function checkData(modbus, buf) {
// check buffer size
if (buf.length != modbus._length && buf.length != 5) return false;
if (buf.length !== modbus._length && buf.length !== 5) return false;

// calculate crc16
var crcIn = buf.readUInt16LE(buf.length - 2);

// check buffer unit-id, command and crc
return (buf[0] == modbus._id &&
(0x7f & buf[1]) == modbus._cmd &&
crcIn == crc16(buf.slice(0, -2)));
return (buf[0] === modbus._id &&
(0x7f & buf[1]) === modbus._cmd &&
crcIn === crc16(buf.slice(0, -2)));
}

/**
Expand All @@ -42,7 +42,7 @@ var UdpPort = function(ip, options) {
this.openFlag = false;

// options
if (typeof(options) == 'undefined') options = {};
if (typeof(options) === 'undefined') options = {};
this.port = options.port || C701_PORT; // C701 port

// create a socket
Expand All @@ -59,7 +59,7 @@ var UdpPort = function(ip, options) {
if (data.length < (116 + 5)) return;

// check the C701 packet magic
if (data.readUInt16LE(2) != 602) return;
if (data.readUInt16LE(2) !== 602) return;

// check for modbus valid answer
// get the serial data from the C701 packet
Expand Down
2 changes: 1 addition & 1 deletion ports/rtubufferedport.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var RTUBufferedPort = function(path, options) {
var self = this;

// options
if (typeof(options) == 'undefined') options = {};
if (typeof(options) === 'undefined') options = {};

// disable auto open, as we handle the open
options.autoOpen = false;
Expand Down
2 changes: 1 addition & 1 deletion ports/tcpport.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var TcpPort = function(ip, options) {
this.callback = null;

// options
if (typeof(options) == 'undefined') options = {};
if (typeof(options) === 'undefined') options = {};
this.port = options.port || MODBUS_PORT; // modbus port

// handle callback - call a callback function only once, for the first event
Expand Down
2 changes: 1 addition & 1 deletion ports/tcprtubufferedport.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var TcpRTUBufferedPort = function(ip, options) {
this.callback = null;

// options
if (typeof(options) == 'undefined') options = {};
if (typeof(options) === 'undefined') options = {};
this.port = options.port || MODBUS_PORT;
this.removeCrc = options.removeCrc;

Expand Down
2 changes: 1 addition & 1 deletion ports/telnetport.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var TelnetPort = function(ip, options) {
this.callback = null;

// options
if (typeof(options) == 'undefined') options = {};
if (typeof(options) === 'undefined') options = {};
this.port = options.port || TELNET_PORT; // telnet server port

// internal buffer
Expand Down
34 changes: 17 additions & 17 deletions ports/testport.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ TestPort.prototype.write = function(data) {
var crc = data[data.length - 2] + data[data.length - 1] * 0x100;

// if crc is bad, ignore message
if (crc != crc16(data.slice(0, -2))) {
if (crc !== crc16(data.slice(0, -2))) {
return;
}

// function code 1 and 2
if (functionCode == 1 || functionCode == 2) {
if (functionCode === 1 || functionCode === 2) {
address = data.readUInt16BE(2);
length = data.readUInt16BE(4);

// if length is bad, ignore message
if (data.length != 8) {
if (data.length !== 8) {
return;
}

Expand All @@ -101,12 +101,12 @@ TestPort.prototype.write = function(data) {
}

// function code 3
if (functionCode == 3) {
if (functionCode === 3) {
address = data.readUInt16BE(2);
length = data.readUInt16BE(4);

// if length is bad, ignore message
if (data.length != 8) {
if (data.length !== 8) {
return;
}

Expand All @@ -121,12 +121,12 @@ TestPort.prototype.write = function(data) {
}

// function code 4
if (functionCode == 4) {
if (functionCode === 4) {
address = data.readUInt16BE(2);
length = data.readUInt16BE(4);

// if length is bad, ignore message
if (data.length != 8) {
if (data.length !== 8) {
return;
}

Expand All @@ -141,12 +141,12 @@ TestPort.prototype.write = function(data) {
}

// function code 5
if (functionCode == 5) {
if (functionCode === 5) {
address = data.readUInt16BE(2);
state = data.readUInt16BE(4);

// if length is bad, ignore message
if (data.length != 8) {
if (data.length !== 8) {
return;
}

Expand All @@ -156,19 +156,19 @@ TestPort.prototype.write = function(data) {
buffer.writeUInt16BE(state, 4);

// write coil
if (state == 0xff00) {
if (state === 0xff00) {
this._coils |= (1 << address);
} else {
this._coils &= ~(1 << address);
}
}

// function code 6
if (functionCode == 6) {
if (functionCode === 6) {
address = data.readUInt16BE(2);
value = data.readUInt16BE(4);
// if length is bad, ignore message
if (data.length != (6 + 2)) {
if (data.length !== (6 + 2)) {
return;
}

Expand All @@ -181,12 +181,12 @@ TestPort.prototype.write = function(data) {
}

// function code 15
if (functionCode == 15) {
if (functionCode === 15) {
address = data.readUInt16BE(2);
length = data.readUInt16BE(4);

// if length is bad, ignore message
if (data.length != 7 + Math.ceil(length / 8) + 2) {
if (data.length !== 7 + Math.ceil(length / 8) + 2) {
return;
}

Expand All @@ -208,12 +208,12 @@ TestPort.prototype.write = function(data) {
}

// function code 16
if (functionCode == 16) {
if (functionCode === 16) {
address = data.readUInt16BE(2);
length = data.readUInt16BE(4);

// if length is bad, ignore message
if (data.length != (7 + length * 2 + 2)) {
if (data.length !== (7 + length * 2 + 2)) {
return;
}

Expand Down Expand Up @@ -263,7 +263,7 @@ TestPort.prototype.write = function(data) {
buffer.writeUInt16LE(crc, buffer.length - 2);

// unit 3: answers with bad crc
if (unitNumber == 3) {
if (unitNumber === 3) {
buffer.writeUInt16LE(crc + 1, buffer.length - 2);
}

Expand Down
Loading

0 comments on commit 2049ab2

Please sign in to comment.