Skip to content

tools: enable no-else-return ESLint rule #11159

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

Closed
wants to merge 2 commits 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
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ rules:
# Best Practices
# http://eslint.org/docs/rules/#best-practices
dot-location: [2, property]
no-else-return: 2
no-fallthrough: 2
no-global-assign: 2
no-multi-spaces: 2
Expand Down
6 changes: 2 additions & 4 deletions benchmark/_http-benchmarkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ AutocannonBenchmarker.prototype.processResults = function(output) {
}
if (!result || !result.requests || !result.requests.average) {
return undefined;
} else {
return result.requests.average;
}
return result.requests.average;
};

function WrkBenchmarker() {
Expand All @@ -63,9 +62,8 @@ WrkBenchmarker.prototype.processResults = function(output) {
const result = match && +match[1];
if (!isFinite(result)) {
return undefined;
} else {
return result;
}
return result;
};

const http_benchmarkers = [new WrkBenchmarker(), new AutocannonBenchmarker()];
Expand Down
3 changes: 1 addition & 2 deletions benchmark/scatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ let printHeader = true;
function csvEncodeValue(value) {
if (typeof value === 'number') {
return value.toString();
} else {
return '"' + value.replace(/"/g, '""') + '"';
}
return '"' + value.replace(/"/g, '""') + '"';
}

(function recursive(i) {
Expand Down
3 changes: 1 addition & 2 deletions lib/_http_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ function parserOnHeadersComplete(versionMajor, versionMinor, headers, method,

if (typeof skipBody !== 'number')
return skipBody ? 1 : 0;
else
return skipBody;
return skipBody;
}

// XXX This is a mess.
Expand Down
24 changes: 11 additions & 13 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ function prependListener(emitter, event, fn) {
// event emitter implementation with them.
if (typeof emitter.prependListener === 'function') {
return emitter.prependListener(event, fn);
} else {
// This is a hack to make sure that our error handler is attached before any
// userland ones. NEVER DO THIS. This is here only because this code needs
// to continue to work with older versions of Node.js that do not include
// the prependListener() method. The goal is to eventually remove this hack.
if (!emitter._events || !emitter._events[event])
emitter.on(event, fn);
else if (Array.isArray(emitter._events[event]))
emitter._events[event].unshift(fn);
else
emitter._events[event] = [fn, emitter._events[event]];
}
// This is a hack to make sure that our error handler is attached before any
// userland ones. NEVER DO THIS. This is here only because this code needs
// to continue to work with older versions of Node.js that do not include
// the prependListener() method. The goal is to eventually remove this hack.
if (!emitter._events || !emitter._events[event])
emitter.on(event, fn);
else if (Array.isArray(emitter._events[event]))
emitter._events[event].unshift(fn);
else
emitter._events[event] = [fn, emitter._events[event]];
}

function ReadableState(options, stream) {
Expand Down Expand Up @@ -251,8 +250,7 @@ function howMuchToRead(n, state) {
// Only flow one buffer at a time
if (state.flowing && state.length)
return state.buffer.head.data.length;
else
return state.length;
return state.length;
}
// If we're asking for more than the current hwm, then raise the hwm.
if (n > state.highWaterMark)
Expand Down
12 changes: 4 additions & 8 deletions lib/_tls_legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,8 @@ CryptoStream.prototype.isSessionReused = function() {
CryptoStream.prototype.getCipher = function(err) {
if (this.pair.ssl) {
return this.pair.ssl.getCurrentCipher();
} else {
return null;
}
return null;
};


Expand Down Expand Up @@ -490,9 +489,8 @@ Object.defineProperty(CryptoStream.prototype, 'readyState', {
return 'readOnly';
} else if (!this.readable && this.writable) {
return 'writeOnly';
} else {
return 'closed';
}
return 'closed';
}
});

Expand Down Expand Up @@ -521,9 +519,8 @@ util.inherits(CleartextStream, CryptoStream);
CleartextStream.prototype._internallyPendingBytes = function() {
if (this.pair.ssl) {
return this.pair.ssl.clearPending();
} else {
return 0;
}
return 0;
};


Expand Down Expand Up @@ -581,9 +578,8 @@ util.inherits(EncryptedStream, CryptoStream);
EncryptedStream.prototype._internallyPendingBytes = function() {
if (this.pair.ssl) {
return this.pair.ssl.encPending();
} else {
return 0;
}
return 0;
};


Expand Down
15 changes: 6 additions & 9 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,11 @@ function requestOCSP(self, hello, ctx, cb) {

if (self.server.listenerCount('OCSPRequest') === 0) {
return cb(null);
} else {
self.server.emit('OCSPRequest',
ctx.getCertificate(),
ctx.getIssuer(),
onOCSP);
}
self.server.emit('OCSPRequest',
ctx.getCertificate(),
ctx.getIssuer(),
onOCSP);

var once = false;
function onOCSP(err, response) {
Expand Down Expand Up @@ -655,9 +654,8 @@ TLSSocket.prototype.isSessionReused = function() {
TLSSocket.prototype.getCipher = function(err) {
if (this._handle) {
return this._handle.getCurrentCipher();
} else {
return null;
}
return null;
};

TLSSocket.prototype.getEphemeralKeyInfo = function() {
Expand Down Expand Up @@ -1090,9 +1088,8 @@ exports.connect = function(...args /* [port,] [host,] [options,] [cb] */) {
if (options.rejectUnauthorized) {
socket.destroy(verifyError);
return;
} else {
socket.emit('secureConnect');
}
socket.emit('secureConnect');
} else {
socket.authorized = true;
socket.emit('secureConnect');
Expand Down
21 changes: 10 additions & 11 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,20 @@ function _deepEqual(actual, expected, strict, memos) {
// (although not necessarily the same order), equivalent values for every
// corresponding key, and an identical 'prototype' property. Note: this
// accounts for both named and indexed properties on Arrays.
} else {
memos = memos || {actual: [], expected: []};
}
memos = memos || {actual: [], expected: []};

const actualIndex = memos.actual.indexOf(actual);
if (actualIndex !== -1) {
if (actualIndex === memos.expected.indexOf(expected)) {
return true;
}
const actualIndex = memos.actual.indexOf(actual);
if (actualIndex !== -1) {
if (actualIndex === memos.expected.indexOf(expected)) {
return true;
}
}

memos.actual.push(actual);
memos.expected.push(expected);
memos.actual.push(actual);
memos.expected.push(expected);

return objEquiv(actual, expected, strict, memos);
}
return objEquiv(actual, expected, strict, memos);
}

function isArguments(object) {
Expand Down
9 changes: 3 additions & 6 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,8 @@ function allocate(size) {
poolOffset += size;
alignPool();
return b;
} else {
return createUnsafeBuffer(size);
}
return createUnsafeBuffer(size);
}


Expand Down Expand Up @@ -817,9 +816,8 @@ Buffer.prototype.toJSON = function() {
for (var i = 0; i < this.length; ++i)
data[i] = this[i];
return { type: 'Buffer', data };
} else {
return { type: 'Buffer', data: [] };
}
return { type: 'Buffer', data: [] };
};


Expand All @@ -832,9 +830,8 @@ function adjustOffset(offset, length) {
} else if (offset < 0) {
offset += length;
return offset > 0 ? offset : 0;
} else {
return offset < length ? offset : length;
}
return offset < length ? offset : length;
}


Expand Down
3 changes: 1 addition & 2 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,8 @@ exports.resolve = function resolve(hostname, type_, callback_) {

if (typeof resolver === 'function') {
return resolver(hostname, callback);
} else {
throw new Error(`Unknown type "${type_}"`);
}
throw new Error(`Unknown type "${type_}"`);
};


Expand Down
6 changes: 2 additions & 4 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,8 @@ EventEmitter.prototype.removeListener =
if (--this._eventsCount === 0) {
this._events = new EventHandlers();
return this;
} else {
delete events[type];
}
delete events[type];
} else if (position === 0) {
list.shift();
} else {
Expand Down Expand Up @@ -447,9 +446,8 @@ EventEmitter.prototype.listeners = function listeners(type) {
EventEmitter.listenerCount = function(emitter, type) {
if (typeof emitter.listenerCount === 'function') {
return emitter.listenerCount(type);
} else {
return listenerCount.call(emitter, type);
}
return listenerCount.call(emitter, type);
};

EventEmitter.prototype.listenerCount = listenerCount;
Expand Down
8 changes: 3 additions & 5 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,10 +899,9 @@ function preprocessSymlinkDestination(path, type, linkPath) {
// A relative target is relative to the link's parent directory.
path = pathModule.resolve(linkPath, '..', path);
return pathModule._makeLong(path);
} else {
// Windows symlinks don't tolerate forward slashes.
return ('' + path).replace(/\//g, '\\');
}
// Windows symlinks don't tolerate forward slashes.
return ('' + path).replace(/\//g, '\\');
}

fs.symlink = function(target, path, type_, callback_) {
Expand Down Expand Up @@ -1460,9 +1459,8 @@ function encodeRealpathResult(result, options) {
const asBuffer = Buffer.from(result);
if (options.encoding === 'buffer') {
return asBuffer;
} else {
return asBuffer.toString(options.encoding);
}
return asBuffer.toString(options.encoding);
}

fs.realpathSync = function realpathSync(p, options) {
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,8 @@ class URLSearchParams {
return `${this.constructor.name} {\n ${output.join(',\n ')} }`;
} else if (output.length) {
return `${this.constructor.name} { ${output.join(separator)} }`;
} else {
return `${this.constructor.name} {}`;
}
return `${this.constructor.name} {}`;
}
}

Expand Down
6 changes: 2 additions & 4 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,8 @@ Object.defineProperty(Socket.prototype, 'readyState', {
return 'readOnly';
} else if (!this.readable && this.writable) {
return 'writeOnly';
} else {
return 'closed';
}
return 'closed';
}
});

Expand Down Expand Up @@ -1415,9 +1414,8 @@ Server.prototype.address = function() {
return out;
} else if (this._pipeName) {
return this._pipeName;
} else {
return null;
}
return null;
};

function onconnection(err, clientHandle) {
Expand Down
Loading