Skip to content

Commit 9119344

Browse files
lpincacodebytere
authored andcommitted
tools: enable no-else-return lint rule
Refs: #32644 Refs: #32662 PR-URL: #32667 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent e53de96 commit 9119344

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+158
-214
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ module.exports = {
129129
'no-dupe-else-if': 'error',
130130
'no-duplicate-case': 'error',
131131
'no-duplicate-imports': 'error',
132+
'no-else-return': ['error', { allowElseIf: true }],
132133
'no-empty-character-class': 'error',
133134
'no-ex-assign': 'error',
134135
'no-extra-boolean-cast': 'error',

benchmark/es/spread-bench.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ function makeTest(count, rest) {
1616
return function test(...args) {
1717
assert.strictEqual(count, args.length);
1818
};
19-
} else {
20-
return function test() {
21-
assert.strictEqual(count, arguments.length);
22-
};
2319
}
20+
return function test() {
21+
assert.strictEqual(count, arguments.length);
22+
};
2423
}
2524

2625
function main({ n, context, count, rest, method }) {

benchmark/scatter.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ let printHeader = true;
3030
function csvEncodeValue(value) {
3131
if (typeof value === 'number') {
3232
return value.toString();
33-
} else {
34-
return `"${value.replace(/"/g, '""')}"`;
3533
}
34+
return `"${value.replace(/"/g, '""')}"`;
3635
}
3736

3837
(function recursive(i) {

lib/_http_incoming.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,8 @@ function matchKnownFields(field, lowercased) {
248248
}
249249
if (lowercased) {
250250
return '\u0000' + field;
251-
} else {
252-
return matchKnownFields(field.toLowerCase(), true);
253251
}
252+
return matchKnownFields(field.toLowerCase(), true);
254253
}
255254
// Add the given (field, value) pair to the message
256255
//

lib/_stream_readable.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ function howMuchToRead(n, state) {
372372
// Only flow one buffer at a time.
373373
if (state.flowing && state.length)
374374
return state.buffer.first().length;
375-
else
376-
return state.length;
375+
return state.length;
377376
}
378377
if (n <= state.length)
379378
return n;

lib/_stream_writable.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,9 @@ Writable.prototype.write = function(chunk, encoding, cb) {
298298
process.nextTick(cb, err);
299299
errorOrDestroy(this, err, true);
300300
return false;
301-
} else {
302-
state.pendingcb++;
303-
return writeOrBuffer(this, state, chunk, encoding, cb);
304301
}
302+
state.pendingcb++;
303+
return writeOrBuffer(this, state, chunk, encoding, cb);
305304
};
306305

307306
Writable.prototype.cork = function() {

lib/_tls_wrap.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,13 +1503,12 @@ function onConnectSecure() {
15031503
if (options.rejectUnauthorized) {
15041504
this.destroy(verifyError);
15051505
return;
1506-
} else {
1507-
debug('client emit secureConnect. rejectUnauthorized: %s, ' +
1508-
'authorizationError: %s', options.rejectUnauthorized,
1509-
this.authorizationError);
1510-
this.secureConnecting = false;
1511-
this.emit('secureConnect');
15121506
}
1507+
debug('client emit secureConnect. rejectUnauthorized: %s, ' +
1508+
'authorizationError: %s', options.rejectUnauthorized,
1509+
this.authorizationError);
1510+
this.secureConnecting = false;
1511+
this.emit('secureConnect');
15131512
} else {
15141513
this.authorized = true;
15151514
debug('client emit secureConnect. authorized:', this.authorized);

lib/dns.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,8 @@ function resolve(hostname, rrtype, callback) {
261261

262262
if (typeof resolver === 'function') {
263263
return resolver.call(this, hostname, callback);
264-
} else {
265-
throw new ERR_INVALID_OPT_VALUE('rrtype', rrtype);
266264
}
265+
throw new ERR_INVALID_OPT_VALUE('rrtype', rrtype);
267266
}
268267

269268
function defaultResolverSetServers(servers) {

lib/events.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,8 @@ EventEmitter.prototype.rawListeners = function rawListeners(type) {
577577
EventEmitter.listenerCount = function(emitter, type) {
578578
if (typeof emitter.listenerCount === 'function') {
579579
return emitter.listenerCount(type);
580-
} else {
581-
return listenerCount.call(emitter, type);
582580
}
581+
return listenerCount.call(emitter, type);
583582
};
584583

585584
EventEmitter.prototype.listenerCount = listenerCount;

lib/fs.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,9 +1545,8 @@ function encodeRealpathResult(result, options) {
15451545
const asBuffer = Buffer.from(result);
15461546
if (options.encoding === 'buffer') {
15471547
return asBuffer;
1548-
} else {
1549-
return asBuffer.toString(options.encoding);
15501548
}
1549+
return asBuffer.toString(options.encoding);
15511550
}
15521551

15531552
// Finds the next portion of a (partial) path, up to the next path delimiter

0 commit comments

Comments
 (0)