Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: lint for strict equality for non null checks #5116

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ rules:
no-fallthrough: 2
## disallow declaring the same variable more than once
no-redeclare: 2
## enforce using strict comparison besides equal null checks
eqeqeq: [2, "allow-null"]

# Stylistic Issues
# list: https://github.com/eslint/eslint/tree/master/docs/rules#stylistic-issues
Expand Down
37 changes: 20 additions & 17 deletions lib/_debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Client.prototype._addScript = function(desc) {
this.scripts[desc.id] = desc;
if (desc.name) {
desc.isNative = (desc.name.replace('.js', '') in natives) ||
desc.name == 'node.js';
desc.name === 'node.js';
}
};

Expand All @@ -202,7 +202,7 @@ Client.prototype._onResponse = function(res) {
var index = -1;

this._reqCallbacks.some(function(fn, i) {
if (fn.request_seq == res.body.request_seq) {
if (fn.request_seq === res.body.request_seq) {
cb = fn;
index = i;
return true;
Expand All @@ -212,25 +212,25 @@ Client.prototype._onResponse = function(res) {
var self = this;
var handled = false;

if (res.headers.Type == 'connect') {
if (res.headers.Type === 'connect') {
// Request a list of scripts for our own storage.
self.reqScripts();
self.emit('ready');
handled = true;

} else if (res.body && res.body.event == 'break') {
} else if (res.body && res.body.event === 'break') {
this.emit('break', res.body);
handled = true;

} else if (res.body && res.body.event == 'exception') {
} else if (res.body && res.body.event === 'exception') {
this.emit('exception', res.body);
handled = true;

} else if (res.body && res.body.event == 'afterCompile') {
} else if (res.body && res.body.event === 'afterCompile') {
this._addHandle(res.body.body.script);
handled = true;

} else if (res.body && res.body.event == 'scriptCollected') {
} else if (res.body && res.body.event === 'scriptCollected') {
// ???
this._removeScript(res.body.body.script);
handled = true;
Expand Down Expand Up @@ -328,7 +328,7 @@ Client.prototype.reqScopes = function(cb) {
Client.prototype.reqEval = function(expression, cb) {
var self = this;

if (this.currentFrame == NO_FRAME) {
if (this.currentFrame === NO_FRAME) {
// Only need to eval in global scope.
this.reqFrameEval(expression, NO_FRAME, cb);
return;
Expand Down Expand Up @@ -358,7 +358,7 @@ Client.prototype.reqEval = function(expression, cb) {

// Finds the first scope in the array in which the expression evals.
Client.prototype._reqFramesEval = function(expression, evalFrames, cb) {
if (evalFrames.length == 0) {
if (evalFrames.length === 0) {
// Just eval in global scope.
this.reqFrameEval(expression, NO_FRAME, cb);
return;
Expand All @@ -382,7 +382,7 @@ Client.prototype.reqFrameEval = function(expression, frame, cb) {
arguments: { expression: expression }
};

if (frame == NO_FRAME) {
if (frame === NO_FRAME) {
req.arguments.global = true;
} else {
req.arguments.frame = frame;
Expand Down Expand Up @@ -529,9 +529,9 @@ Client.prototype.mirrorObject = function(handle, depth, cb) {
var mirror;
var waiting = 1;

if (handle.className == 'Array') {
if (handle.className === 'Array') {
mirror = [];
} else if (handle.className == 'Date') {
} else if (handle.className === 'Date') {
mirror = new Date(handle.value);
} else {
mirror = {};
Expand Down Expand Up @@ -1103,7 +1103,7 @@ Interface.prototype.list = function(delta) {
for (var i = 0; i < lines.length; i++) {
var lineno = res.fromLine + i + 1;
if (lineno < from || lineno > to) continue;

/* eslint-disable eqeqeq */
const current = lineno == 1 + client.currentSourceLine;
const breakpoint = client.breakpoints.some(function(bp) {
return (bp.scriptReq === client.currentScript ||
Expand All @@ -1119,6 +1119,7 @@ Interface.prototype.list = function(delta) {

client.currentSourceColumn -= wrapper.length;
}
/* eslint-enable eqeqeq */

// Highlight executing statement
var line;
Expand Down Expand Up @@ -1158,7 +1159,7 @@ Interface.prototype.backtrace = function() {
return;
}

if (bt.totalFrames == 0) {
if (bt.totalFrames === 0) {
self.print('(empty stack)');
} else {
const trace = [];
Expand Down Expand Up @@ -1200,10 +1201,10 @@ Interface.prototype.scripts = function() {
var script = client.scripts[id];
if (script !== null && typeof script === 'object' && script.name) {
if (displayNatives ||
script.name == client.currentScript ||
script.name === client.currentScript ||
!script.isNative) {
scripts.push(
(script.name == client.currentScript ? '* ' : ' ') +
(script.name === client.currentScript ? '* ' : ' ') +
id + ': ' +
path.basename(script.name)
);
Expand Down Expand Up @@ -1363,7 +1364,9 @@ Interface.prototype.setBreakpoint = function(script, line,
};
} else {
// setBreakpoint('scriptname')
if (script != +script && !this.client.scripts[script]) {
if (script != +script && // eslint-disable-line eqeqeq
!this.client.scripts[script]
) {
var scripts = this.client.scripts;
for (var id in scripts) {
if (scripts[id] &&
Expand Down
4 changes: 2 additions & 2 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function IncomingMessage(socket) {
this.socket = socket;
this.connection = socket;

this.httpVersionMajor = null;
this.httpVersionMinor = null;
this.httpVersionMajor = 0;
this.httpVersionMinor = 0;
this.httpVersion = null;
this.complete = false;
this.headers = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ function connectionListener(socket) {
}

if (req.headers.expect !== undefined &&
(req.httpVersionMajor == 1 && req.httpVersionMinor == 1)) {
(req.httpVersionMajor === 1 && req.httpVersionMinor === 1)) {
if (continueExpression.test(req.headers.expect)) {
res._expect_continue = true;

Expand Down
2 changes: 1 addition & 1 deletion lib/_stream_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function done(stream, er) {
var ts = stream._transformState;

if (ws.length)
throw new Error('Calling transform done when ws.length != 0');
throw new Error('Calling transform done when ws.length !== 0');

if (ts.transforming)
throw new Error('Calling transform done when still transforming');
Expand Down
2 changes: 1 addition & 1 deletion lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ TLSSocket.prototype.renegotiate = function(options, callback) {
};

TLSSocket.prototype.setMaxSendFragment = function setMaxSendFragment(size) {
return this._handle.setMaxSendFragment(size) == 1;
return this._handle.setMaxSendFragment(size) === 1;
};

TLSSocket.prototype.getTLSTicket = function getTLSTicket() {
Expand Down
7 changes: 4 additions & 3 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
/* eslint-disable eqeqeq */

// UTILITY
const compare = process.binding('buffer').compare;
Expand Down Expand Up @@ -164,7 +165,7 @@ function _deepEqual(actual, expected, strict) {
actual.lastIndex === expected.lastIndex &&
actual.ignoreCase === expected.ignoreCase;

// 7.4. Other pairs that do not both pass typeof value == 'object',
// 7.4. Other pairs that do not both pass typeof value === 'object',
// equivalence is determined by ==.
} else if ((actual === null || typeof actual !== 'object') &&
(expected === null || typeof expected !== 'object')) {
Expand All @@ -187,7 +188,7 @@ function _deepEqual(actual, expected, strict) {
}

function isArguments(object) {
return Object.prototype.toString.call(object) == '[object Arguments]';
return Object.prototype.toString.call(object) === '[object Arguments]';
}

function objEquiv(a, b, strict) {
Expand Down Expand Up @@ -271,7 +272,7 @@ function expectedException(actual, expected) {
return false;
}

if (Object.prototype.toString.call(expected) == '[object RegExp]') {
if (Object.prototype.toString.call(expected) === '[object RegExp]') {
return expected.test(actual);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Object.setPrototypeOf(Buffer, Uint8Array);


function SlowBuffer(length) {
if (+length != length)
if (+length != length) // eslint-disable-line eqeqeq
length = 0;
if (length > 0)
flags[kNoZeroFill] = 1;
Expand Down
12 changes: 6 additions & 6 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ function lookup6(address, callback) {


function newHandle(type) {
if (type == 'udp4') {
if (type === 'udp4') {
const handle = new UDP();
handle.lookup = lookup4;
return handle;
}

if (type == 'udp6') {
if (type === 'udp6') {
const handle = new UDP();
handle.lookup = lookup6;
handle.bind = handle.bind6;
handle.send = handle.send6;
return handle;
}

if (type == 'unix_dgram')
if (type === 'unix_dgram')
throw new Error('"unix_dgram" type sockets are not supported any more');

throw new Error('Bad socket type specified. Valid types are: udp4, udp6');
Expand Down Expand Up @@ -140,7 +140,7 @@ Socket.prototype.bind = function(port_ /*, address, callback*/) {

self._healthCheck();

if (this._bindState != BIND_STATE_UNBOUND)
if (this._bindState !== BIND_STATE_UNBOUND)
throw new Error('Socket is already bound');

this._bindState = BIND_STATE_BINDING;
Expand Down Expand Up @@ -326,12 +326,12 @@ Socket.prototype.send = function(buffer,

self._healthCheck();

if (self._bindState == BIND_STATE_UNBOUND)
if (self._bindState === BIND_STATE_UNBOUND)
self.bind({port: 0, exclusive: true}, null);

// If the socket hasn't been bound yet, push the outbound packet onto the
// send queue and send after binding is complete.
if (self._bindState != BIND_STATE_BOUND) {
if (self._bindState !== BIND_STATE_BOUND) {
enqueue(self, [buffer, port, address, callback]);
return;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1113,9 +1113,11 @@ fs.chownSync = function(path, uid, gid) {

// converts Date or number to a fractional UNIX timestamp
function toUnixTimestamp(time) {
/* eslint-disable eqeqeq */
if (typeof time === 'string' && +time == time) {
return +time;
}
/* eslint-enable eqeqeq */
if (typeof time === 'number') {
if (!Number.isFinite(time) || time < 0) {
return Date.now() / 1000;
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ function getSocketList(type, slave, key) {
function maybeClose(subprocess) {
subprocess._closesGot++;

if (subprocess._closesGot == subprocess._closesNeeded) {
if (subprocess._closesGot === subprocess._closesNeeded) {
subprocess.emit('close', subprocess.exitCode, subprocess.signalCode);
}
}
2 changes: 1 addition & 1 deletion lib/internal/linkedlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports.init = init;

// show the most idle item
function peek(list) {
if (list._idlePrev == list) return null;
if (list._idlePrev === list) return null;
return list._idlePrev;
}
exports.peek = peek;
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/v8_prof_polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const os = {
// Filter out vdso and vsyscall entries.
const arg = args[args.length - 1];
if (arg === '[vdso]' ||
arg == '[vsyscall]' ||
arg === '[vsyscall]' ||
/^[0-9a-f]+-[0-9a-f]+$/.test(arg)) {
return '';
}
Expand Down
8 changes: 4 additions & 4 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function Socket(options) {
} else if (options.fd !== undefined) {
this._handle = createHandle(options.fd);
this._handle.open(options.fd);
if ((options.fd == 1 || options.fd == 2) &&
if ((options.fd === 1 || options.fd === 2) &&
(this._handle instanceof Pipe) &&
process.platform === 'win32') {
// Make stdout and stderr blocking on Windows
Expand Down Expand Up @@ -503,7 +503,7 @@ Socket.prototype.destroy = function(exception) {
function onread(nread, buffer) {
var handle = this;
var self = handle.owner;
assert(handle === self._handle, 'handle != self._handle');
assert(handle === self._handle, 'handle !== self._handle');

self._unrefTimer();

Expand Down Expand Up @@ -678,7 +678,7 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {

// If it was entirely flushed, we can write some more right now.
// However, if more is left in the queue, then wait until that clears.
if (req.async && this._handle.writeQueueSize != 0)
if (req.async && this._handle.writeQueueSize !== 0)
req.cb = cb;
else
cb();
Expand Down Expand Up @@ -1034,7 +1034,7 @@ function afterConnect(status, handle, req, readable, writable) {
self._connecting = false;
self._sockname = null;

if (status == 0) {
if (status === 0) {
self.readable = readable;
self.writable = writable;
self._unrefTimer();
Expand Down
12 changes: 6 additions & 6 deletions lib/punycode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
;(function(root) {

/** Detect free variables */
var freeExports = typeof exports == 'object' && exports &&
var freeExports = typeof exports === 'object' && exports &&
!exports.nodeType && exports;
var freeModule = typeof module == 'object' && module &&
var freeModule = typeof module === 'object' && module &&
!module.nodeType && module;
var freeGlobal = typeof global == 'object' && global;
var freeGlobal = typeof global === 'object' && global;
if (
freeGlobal.global === freeGlobal ||
freeGlobal.window === freeGlobal ||
Expand Down Expand Up @@ -206,7 +206,7 @@
function digitToBasic(digit, flag) {
// 0..25 map to ASCII a..z or A..Z
// 26..35 map to ASCII 0..9
return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
return digit + 22 + 75 * (digit < 26) - ((flag !== 0) << 5);
}

/**
Expand Down Expand Up @@ -508,8 +508,8 @@
// Some AMD build optimizers, like r.js, check for specific condition patterns
// like the following:
if (
typeof define == 'function' &&
typeof define.amd == 'object' &&
typeof define === 'function' &&
typeof define.amd === 'object' &&
define.amd
) {
define('punycode', function() {
Expand Down
Loading