Skip to content

Commit a131c72

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

39 files changed

+151
-204
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
@@ -239,9 +239,8 @@ function matchKnownFields(field, lowercased) {
239239
}
240240
if (lowercased) {
241241
return '\u0000' + field;
242-
} else {
243-
return matchKnownFields(field.toLowerCase(), true);
244242
}
243+
return matchKnownFields(field.toLowerCase(), true);
245244
}
246245
// Add the given (field, value) pair to the message
247246
//

lib/_stream_readable.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@ function howMuchToRead(n, state) {
365365
// Only flow one buffer at a time
366366
if (state.flowing && state.length)
367367
return state.buffer.first().length;
368-
else
369-
return state.length;
368+
return state.length;
370369
}
371370
if (n <= state.length)
372371
return n;

lib/_tls_wrap.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,12 +1518,11 @@ function onConnectSecure() {
15181518
if (options.rejectUnauthorized) {
15191519
this.destroy(verifyError);
15201520
return;
1521-
} else {
1522-
debug('client emit secureConnect. rejectUnauthorized: %s, ' +
1523-
'authorizationError: %s', options.rejectUnauthorized,
1524-
this.authorizationError);
1525-
this.emit('secureConnect');
15261521
}
1522+
debug('client emit secureConnect. rejectUnauthorized: %s, ' +
1523+
'authorizationError: %s', options.rejectUnauthorized,
1524+
this.authorizationError);
1525+
this.emit('secureConnect');
15271526
} else {
15281527
this.authorized = true;
15291528
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
@@ -1515,9 +1515,8 @@ function encodeRealpathResult(result, options) {
15151515
const asBuffer = Buffer.from(result);
15161516
if (options.encoding === 'buffer') {
15171517
return asBuffer;
1518-
} else {
1519-
return asBuffer.toString(options.encoding);
15201518
}
1519+
return asBuffer.toString(options.encoding);
15211520
}
15221521

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

lib/internal/crypto/keys.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,13 @@ function prepareAsymmetricKey(key, ctx) {
277277
const isPublic =
278278
(ctx === kConsumePrivate || ctx === kCreatePrivate) ? false : undefined;
279279
return { data, ...parseKeyEncoding(key, undefined, isPublic) };
280-
} else {
281-
throw new ERR_INVALID_ARG_TYPE(
282-
'key',
283-
['string', 'Buffer', 'TypedArray', 'DataView',
284-
...(ctx !== kCreatePrivate ? ['KeyObject'] : [])],
285-
key
286-
);
287280
}
281+
throw new ERR_INVALID_ARG_TYPE(
282+
'key',
283+
['string', 'Buffer', 'TypedArray', 'DataView',
284+
...(ctx !== kCreatePrivate ? ['KeyObject'] : [])],
285+
key
286+
);
288287
}
289288

290289
function preparePrivateKey(key) {
@@ -301,13 +300,12 @@ function prepareSecretKey(key, bufferOnly = false) {
301300
if (key.type !== 'secret')
302301
throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE(key.type, 'secret');
303302
return key[kHandle];
304-
} else {
305-
throw new ERR_INVALID_ARG_TYPE(
306-
'key',
307-
['Buffer', 'TypedArray', 'DataView',
308-
...(bufferOnly ? [] : ['string', 'KeyObject'])],
309-
key);
310303
}
304+
throw new ERR_INVALID_ARG_TYPE(
305+
'key',
306+
['Buffer', 'TypedArray', 'DataView',
307+
...(bufferOnly ? [] : ['string', 'KeyObject'])],
308+
key);
311309
}
312310
return key;
313311
}

0 commit comments

Comments
 (0)