Skip to content

Commit cb916a4

Browse files
committed
benchmark,lib,test,tools: remove else after return
If there is a `return` in an `if` block, an `else` block is unnecessary. It can simply be moved after the `if` block. This is in preparation for a lint rule to enforce this practice.
1 parent 8fc362e commit cb916a4

26 files changed

Lines changed: 136 additions & 192 deletions

benchmark/_http-benchmarkers.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ AutocannonBenchmarker.prototype.processResults = function(output) {
3535
}
3636
if (!result || !result.requests || !result.requests.average) {
3737
return undefined;
38-
} else {
39-
return result.requests.average;
4038
}
39+
return result.requests.average;
4140
};
4241

4342
function WrkBenchmarker() {
@@ -63,9 +62,8 @@ WrkBenchmarker.prototype.processResults = function(output) {
6362
const result = match && +match[1];
6463
if (!isFinite(result)) {
6564
return undefined;
66-
} else {
67-
return result;
6865
}
66+
return result;
6967
};
7068

7169
const http_benchmarkers = [new WrkBenchmarker(), new AutocannonBenchmarker()];

benchmark/scatter.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ let printHeader = true;
3333
function csvEncodeValue(value) {
3434
if (typeof value === 'number') {
3535
return value.toString();
36-
} else {
37-
return '"' + value.replace(/"/g, '""') + '"';
3836
}
37+
return '"' + value.replace(/"/g, '""') + '"';
3938
}
4039

4140
(function recursive(i) {

lib/_http_common.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ function parserOnHeadersComplete(versionMajor, versionMinor, headers, method,
101101

102102
if (typeof skipBody !== 'number')
103103
return skipBody ? 1 : 0;
104-
else
105-
return skipBody;
104+
return skipBody;
106105
}
107106

108107
// XXX This is a mess.

lib/_stream_readable.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@ function prependListener(emitter, event, fn) {
1818
// event emitter implementation with them.
1919
if (typeof emitter.prependListener === 'function') {
2020
return emitter.prependListener(event, fn);
21-
} else {
22-
// This is a hack to make sure that our error handler is attached before any
23-
// userland ones. NEVER DO THIS. This is here only because this code needs
24-
// to continue to work with older versions of Node.js that do not include
25-
// the prependListener() method. The goal is to eventually remove this hack.
26-
if (!emitter._events || !emitter._events[event])
27-
emitter.on(event, fn);
28-
else if (Array.isArray(emitter._events[event]))
29-
emitter._events[event].unshift(fn);
30-
else
31-
emitter._events[event] = [fn, emitter._events[event]];
3221
}
22+
// This is a hack to make sure that our error handler is attached before any
23+
// userland ones. NEVER DO THIS. This is here only because this code needs
24+
// to continue to work with older versions of Node.js that do not include
25+
// the prependListener() method. The goal is to eventually remove this hack.
26+
if (!emitter._events || !emitter._events[event])
27+
emitter.on(event, fn);
28+
else if (Array.isArray(emitter._events[event]))
29+
emitter._events[event].unshift(fn);
30+
else
31+
emitter._events[event] = [fn, emitter._events[event]];
3332
}
3433

3534
function ReadableState(options, stream) {
@@ -251,8 +250,7 @@ function howMuchToRead(n, state) {
251250
// Only flow one buffer at a time
252251
if (state.flowing && state.length)
253252
return state.buffer.head.data.length;
254-
else
255-
return state.length;
253+
return state.length;
256254
}
257255
// If we're asking for more than the current hwm, then raise the hwm.
258256
if (n > state.highWaterMark)

lib/_tls_legacy.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,8 @@ CryptoStream.prototype.isSessionReused = function() {
386386
CryptoStream.prototype.getCipher = function(err) {
387387
if (this.pair.ssl) {
388388
return this.pair.ssl.getCurrentCipher();
389-
} else {
390-
return null;
391389
}
390+
return null;
392391
};
393392

394393

@@ -490,9 +489,8 @@ Object.defineProperty(CryptoStream.prototype, 'readyState', {
490489
return 'readOnly';
491490
} else if (!this.readable && this.writable) {
492491
return 'writeOnly';
493-
} else {
494-
return 'closed';
495492
}
493+
return 'closed';
496494
}
497495
});
498496

@@ -521,9 +519,8 @@ util.inherits(CleartextStream, CryptoStream);
521519
CleartextStream.prototype._internallyPendingBytes = function() {
522520
if (this.pair.ssl) {
523521
return this.pair.ssl.clearPending();
524-
} else {
525-
return 0;
526522
}
523+
return 0;
527524
};
528525

529526

@@ -581,9 +578,8 @@ util.inherits(EncryptedStream, CryptoStream);
581578
EncryptedStream.prototype._internallyPendingBytes = function() {
582579
if (this.pair.ssl) {
583580
return this.pair.ssl.encPending();
584-
} else {
585-
return 0;
586581
}
582+
return 0;
587583
};
588584

589585

lib/_tls_wrap.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,11 @@ function requestOCSP(self, hello, ctx, cb) {
115115

116116
if (self.server.listenerCount('OCSPRequest') === 0) {
117117
return cb(null);
118-
} else {
119-
self.server.emit('OCSPRequest',
120-
ctx.getCertificate(),
121-
ctx.getIssuer(),
122-
onOCSP);
123118
}
119+
self.server.emit('OCSPRequest',
120+
ctx.getCertificate(),
121+
ctx.getIssuer(),
122+
onOCSP);
124123

125124
var once = false;
126125
function onOCSP(err, response) {
@@ -655,9 +654,8 @@ TLSSocket.prototype.isSessionReused = function() {
655654
TLSSocket.prototype.getCipher = function(err) {
656655
if (this._handle) {
657656
return this._handle.getCurrentCipher();
658-
} else {
659-
return null;
660657
}
658+
return null;
661659
};
662660

663661
TLSSocket.prototype.getEphemeralKeyInfo = function() {
@@ -1090,9 +1088,8 @@ exports.connect = function(...args /* [port,] [host,] [options,] [cb] */) {
10901088
if (options.rejectUnauthorized) {
10911089
socket.destroy(verifyError);
10921090
return;
1093-
} else {
1094-
socket.emit('secureConnect');
10951091
}
1092+
socket.emit('secureConnect');
10961093
} else {
10971094
socket.authorized = true;
10981095
socket.emit('secureConnect');

lib/assert.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,21 +195,20 @@ function _deepEqual(actual, expected, strict, memos) {
195195
// (although not necessarily the same order), equivalent values for every
196196
// corresponding key, and an identical 'prototype' property. Note: this
197197
// accounts for both named and indexed properties on Arrays.
198-
} else {
199-
memos = memos || {actual: [], expected: []};
198+
}
199+
memos = memos || {actual: [], expected: []};
200200

201-
const actualIndex = memos.actual.indexOf(actual);
202-
if (actualIndex !== -1) {
203-
if (actualIndex === memos.expected.indexOf(expected)) {
204-
return true;
205-
}
201+
const actualIndex = memos.actual.indexOf(actual);
202+
if (actualIndex !== -1) {
203+
if (actualIndex === memos.expected.indexOf(expected)) {
204+
return true;
206205
}
206+
}
207207

208-
memos.actual.push(actual);
209-
memos.expected.push(expected);
208+
memos.actual.push(actual);
209+
memos.expected.push(expected);
210210

211-
return objEquiv(actual, expected, strict, memos);
212-
}
211+
return objEquiv(actual, expected, strict, memos);
213212
}
214213

215214
function isArguments(object) {

lib/buffer.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,8 @@ function allocate(size) {
191191
poolOffset += size;
192192
alignPool();
193193
return b;
194-
} else {
195-
return createUnsafeBuffer(size);
196194
}
195+
return createUnsafeBuffer(size);
197196
}
198197

199198

@@ -817,9 +816,8 @@ Buffer.prototype.toJSON = function() {
817816
for (var i = 0; i < this.length; ++i)
818817
data[i] = this[i];
819818
return { type: 'Buffer', data };
820-
} else {
821-
return { type: 'Buffer', data: [] };
822819
}
820+
return { type: 'Buffer', data: [] };
823821
};
824822

825823

@@ -832,9 +830,8 @@ function adjustOffset(offset, length) {
832830
} else if (offset < 0) {
833831
offset += length;
834832
return offset > 0 ? offset : 0;
835-
} else {
836-
return offset < length ? offset : length;
837833
}
834+
return offset < length ? offset : length;
838835
}
839836

840837

lib/dns.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,8 @@ exports.resolve = function resolve(hostname, type_, callback_) {
278278

279279
if (typeof resolver === 'function') {
280280
return resolver(hostname, callback);
281-
} else {
282-
throw new Error(`Unknown type "${type_}"`);
283281
}
282+
throw new Error(`Unknown type "${type_}"`);
284283
};
285284

286285

lib/events.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,8 @@ EventEmitter.prototype.removeListener =
358358
if (--this._eventsCount === 0) {
359359
this._events = new EventHandlers();
360360
return this;
361-
} else {
362-
delete events[type];
363361
}
362+
delete events[type];
364363
} else if (position === 0) {
365364
list.shift();
366365
} else {
@@ -447,9 +446,8 @@ EventEmitter.prototype.listeners = function listeners(type) {
447446
EventEmitter.listenerCount = function(emitter, type) {
448447
if (typeof emitter.listenerCount === 'function') {
449448
return emitter.listenerCount(type);
450-
} else {
451-
return listenerCount.call(emitter, type);
452449
}
450+
return listenerCount.call(emitter, type);
453451
};
454452

455453
EventEmitter.prototype.listenerCount = listenerCount;

0 commit comments

Comments
 (0)