Skip to content

Commit b533fb3

Browse files
committed
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 1cb80d1 commit b533fb3

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
@@ -249,9 +249,8 @@ function matchKnownFields(field, lowercased) {
249249
}
250250
if (lowercased) {
251251
return '\u0000' + field;
252-
} else {
253-
return matchKnownFields(field.toLowerCase(), true);
254252
}
253+
return matchKnownFields(field.toLowerCase(), true);
255254
}
256255
// Add the given (field, value) pair to the message
257256
//

lib/_stream_readable.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,7 @@ function howMuchToRead(n, state) {
375375
// Only flow one buffer at a time.
376376
if (state.flowing && state.length)
377377
return state.buffer.first().length;
378-
else
379-
return state.length;
378+
return state.length;
380379
}
381380
if (n <= state.length)
382381
return n;

lib/_stream_writable.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,9 @@ Writable.prototype.write = function(chunk, encoding, cb) {
304304
process.nextTick(cb, err);
305305
errorOrDestroy(this, err, true);
306306
return false;
307-
} else {
308-
state.pendingcb++;
309-
return writeOrBuffer(this, state, chunk, encoding, cb);
310307
}
308+
state.pendingcb++;
309+
return writeOrBuffer(this, state, chunk, encoding, cb);
311310
};
312311

313312
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)