Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a131c72

Browse files
lpincacodebytere
authored andcommittedJul 13, 2020
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

+1
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

+3-4
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

+1-2
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

+1-2
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

+1-2
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

+4-5
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

+1-2
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

+1-2
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

+1-2
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

+11-13
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
}

‎lib/internal/crypto/sig.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ function getDSASignatureEncoding(options) {
7070
return kSigEncDER;
7171
else if (dsaEncoding === 'ieee-p1363')
7272
return kSigEncP1363;
73-
else
74-
throw new ERR_INVALID_OPT_VALUE('dsaEncoding', dsaEncoding);
73+
throw new ERR_INVALID_OPT_VALUE('dsaEncoding', dsaEncoding);
7574
}
7675

7776
return kSigEncDER;
@@ -82,9 +81,8 @@ function getIntOption(name, options) {
8281
if (value !== undefined) {
8382
if (value === value >> 0) {
8483
return value;
85-
} else {
86-
throw new ERR_INVALID_OPT_VALUE(name, value);
8784
}
85+
throw new ERR_INVALID_OPT_VALUE(name, value);
8886
}
8987
return undefined;
9088
}

‎lib/internal/errors.js

+11-16
Original file line numberDiff line numberDiff line change
@@ -1106,10 +1106,9 @@ E('ERR_INVALID_MODULE_SPECIFIER', (pkgPath, subpath, base = undefined) => {
11061106
assert(subpath !== '.');
11071107
return `Package subpath '${subpath}' is not a valid module request for ` +
11081108
`the "exports" resolution of ${pkgPath}${sep}package.json`;
1109-
} else {
1110-
return `Package subpath '${subpath}' is not a valid module request for ` +
1111-
`the "exports" resolution of ${pkgPath} imported from ${base}`;
11121109
}
1110+
return `Package subpath '${subpath}' is not a valid module request for ` +
1111+
`the "exports" resolution of ${pkgPath} imported from ${base}`;
11131112
}, TypeError);
11141113
E('ERR_INVALID_OPT_VALUE', (name, value) =>
11151114
`The value "${String(value)}" is invalid for option "${name}"`,
@@ -1120,8 +1119,7 @@ E('ERR_INVALID_OPT_VALUE_ENCODING',
11201119
E('ERR_INVALID_PACKAGE_CONFIG', (path, message, hasMessage = true) => {
11211120
if (hasMessage)
11221121
return `Invalid package config ${path}${sep}package.json, ${message}`;
1123-
else
1124-
return `Invalid JSON in ${path} imported from ${message}`;
1122+
return `Invalid JSON in ${path} imported from ${message}`;
11251123
}, Error);
11261124
E('ERR_INVALID_PACKAGE_TARGET',
11271125
(pkgPath, key, subpath, target, base = undefined) => {
@@ -1132,11 +1130,10 @@ E('ERR_INVALID_PACKAGE_TARGET',
11321130
return `Invalid "exports" target ${JSONStringify(target)} defined ` +
11331131
`for '${subpath}' in the package config ${pkgPath} imported from ` +
11341132
`${base}.${relError ? '; targets must start with "./"' : ''}`;
1135-
} else {
1136-
return `Invalid "exports" main target ${target} defined in the ` +
1137-
`package config ${pkgPath} imported from ${base}${relError ?
1138-
'; targets must start with "./"' : ''}`;
11391133
}
1134+
return `Invalid "exports" main target ${target} defined in the ` +
1135+
`package config ${pkgPath} imported from ${base}${relError ?
1136+
'; targets must start with "./"' : ''}`;
11401137
} else if (key === '.') {
11411138
return `Invalid "exports" main target ${JSONStringify(target)} defined ` +
11421139
`in the package config ${pkgPath}${sep}package.json${relError ?
@@ -1146,11 +1143,10 @@ E('ERR_INVALID_PACKAGE_TARGET',
11461143
StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` +
11471144
`package config ${pkgPath}${sep}package.json; ` +
11481145
'targets must start with "./"';
1149-
} else {
1150-
return `Invalid "exports" target ${JSONStringify(target)} defined for '${
1151-
StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` +
1152-
`package config ${pkgPath}${sep}package.json`;
11531146
}
1147+
return `Invalid "exports" target ${JSONStringify(target)} defined for '${
1148+
StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` +
1149+
`package config ${pkgPath}${sep}package.json`;
11541150
}, Error);
11551151
E('ERR_INVALID_PERFORMANCE_MARK',
11561152
'The "%s" performance mark has not been set', Error);
@@ -1305,10 +1301,9 @@ E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath, base = undefined) => {
13051301
} else if (base === undefined) {
13061302
return `Package subpath '${subpath}' is not defined by "exports" in ${
13071303
pkgPath}${sep}package.json`;
1308-
} else {
1309-
return `Package subpath '${subpath}' is not defined by "exports" in ${
1310-
pkgPath} imported from ${base}`;
13111304
}
1305+
return `Package subpath '${subpath}' is not defined by "exports" in ${
1306+
pkgPath} imported from ${base}`;
13121307
}, Error);
13131308
E('ERR_REQUIRE_ESM',
13141309
(filename, parentPath = null, packageJsonPath = null) => {

‎lib/internal/fs/streams.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,8 @@ WriteStream.prototype.close = function(cb) {
452452
if (this.closed) {
453453
process.nextTick(cb);
454454
return;
455-
} else {
456-
this.on('close', cb);
457455
}
456+
this.on('close', cb);
458457
}
459458

460459
// If we are not autoClosing, we should call

‎lib/internal/modules/esm/get_source.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ async function defaultGetSource(url, { format } = {}, defaultGetSource) {
2828
return {
2929
source: Buffer.from(body, base64 ? 'base64' : 'utf8')
3030
};
31-
} else {
32-
throw new ERR_INVALID_URL_SCHEME(['file', 'data']);
3331
}
32+
throw new ERR_INVALID_URL_SCHEME(['file', 'data']);
3433
}
3534
exports.defaultGetSource = defaultGetSource;

‎lib/internal/modules/esm/resolve.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,9 @@ function packageMainResolve(packageJSONUrl, packageConfig, base, conditions) {
430430
if (packageConfig.main !== undefined) {
431431
return finalizeResolution(
432432
new URL(packageConfig.main, packageJSONUrl), base);
433-
} else {
434-
return finalizeResolution(
435-
new URL('index', packageJSONUrl), base);
436433
}
434+
return finalizeResolution(
435+
new URL('index', packageJSONUrl), base);
437436
}
438437
return legacyMainResolve(packageJSONUrl, packageConfig);
439438
}
@@ -553,10 +552,9 @@ function packageResolve(specifier, base, conditions) {
553552
} else if (packageSubpath === '') {
554553
return packageMainResolve(packageJSONUrl, packageConfig, base,
555554
conditions);
556-
} else {
557-
return packageExportsResolve(
558-
packageJSONUrl, packageSubpath, packageConfig, base, conditions);
559555
}
556+
return packageExportsResolve(
557+
packageJSONUrl, packageSubpath, packageConfig, base, conditions);
560558
}
561559
}
562560

@@ -585,10 +583,9 @@ function packageResolve(specifier, base, conditions) {
585583
} else if (packageConfig.exports !== undefined) {
586584
return packageExportsResolve(
587585
packageJSONUrl, packageSubpath, packageConfig, base, conditions);
588-
} else {
589-
return finalizeResolution(
590-
new URL(packageSubpath, packageJSONUrl), base);
591586
}
587+
return finalizeResolution(
588+
new URL(packageSubpath, packageJSONUrl), base);
592589
// Cross-platform root check.
593590
} while (packageJSONPath.length !== lastPath.length);
594591

‎lib/internal/policy/manifest.js

+20-21
Original file line numberDiff line numberDiff line change
@@ -145,32 +145,31 @@ class Manifest {
145145
const dependencyRedirectList = (toSpecifier) => {
146146
if (toSpecifier in dependencyMap !== true) {
147147
return null;
148-
} else {
149-
const to = dependencyMap[toSpecifier];
150-
if (to === true) {
151-
return true;
152-
}
153-
if (parsedURLs.has(to)) {
154-
return parsedURLs.get(to);
155-
} else if (canBeRequiredByUsers(to)) {
156-
const href = `node:${to}`;
157-
const resolvedURL = new URL(href);
158-
parsedURLs.set(to, resolvedURL);
159-
parsedURLs.set(href, resolvedURL);
160-
return resolvedURL;
161-
} else if (RegExpPrototypeTest(kRelativeURLStringPattern, to)) {
162-
const resolvedURL = new URL(to, manifestURL);
163-
const href = resourceURL.href;
164-
parsedURLs.set(to, resolvedURL);
165-
parsedURLs.set(href, resolvedURL);
166-
return resolvedURL;
167-
}
168-
const resolvedURL = new URL(to);
148+
}
149+
const to = dependencyMap[toSpecifier];
150+
if (to === true) {
151+
return true;
152+
}
153+
if (parsedURLs.has(to)) {
154+
return parsedURLs.get(to);
155+
} else if (canBeRequiredByUsers(to)) {
156+
const href = `node:${to}`;
157+
const resolvedURL = new URL(href);
158+
parsedURLs.set(to, resolvedURL);
159+
parsedURLs.set(href, resolvedURL);
160+
return resolvedURL;
161+
} else if (RegExpPrototypeTest(kRelativeURLStringPattern, to)) {
162+
const resolvedURL = new URL(to, manifestURL);
169163
const href = resourceURL.href;
170164
parsedURLs.set(to, resolvedURL);
171165
parsedURLs.set(href, resolvedURL);
172166
return resolvedURL;
173167
}
168+
const resolvedURL = new URL(to);
169+
const href = resourceURL.href;
170+
parsedURLs.set(to, resolvedURL);
171+
parsedURLs.set(href, resolvedURL);
172+
return resolvedURL;
174173
};
175174
dependencies.set(resourceHREF, dependencyRedirectList);
176175
} else if (dependencyMap === true) {

‎lib/internal/source_map/source_map.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,14 @@ class SourceMap {
196196
return {};
197197
} else if (!entry) {
198198
return {};
199-
} else {
200-
return {
201-
generatedLine: entry[0],
202-
generatedColumn: entry[1],
203-
originalSource: entry[2],
204-
originalLine: entry[3],
205-
originalColumn: entry[4]
206-
};
207199
}
200+
return {
201+
generatedLine: entry[0],
202+
generatedColumn: entry[1],
203+
originalSource: entry[2],
204+
originalLine: entry[3],
205+
originalColumn: entry[4]
206+
};
208207
}
209208

210209
/**

‎lib/internal/source_map/source_map_cache.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,8 @@ function sourceMapCacheToObject() {
192192

193193
if (ObjectKeys(obj).length === 0) {
194194
return undefined;
195-
} else {
196-
return obj;
197195
}
196+
return obj;
198197
}
199198

200199
// Since WeakMap can't be iterated over, we use Module._cache's
@@ -243,9 +242,8 @@ function findSourceMap(uri, error) {
243242
}
244243
if (sourceMap && sourceMap.data) {
245244
return new SourceMap(sourceMap.data);
246-
} else {
247-
return undefined;
248245
}
246+
return undefined;
249247
}
250248

251249
module.exports = {

‎lib/internal/url.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,8 @@ class URLSearchParams {
228228
return `${this.constructor.name} {\n ${output.join(',\n ')} }`;
229229
} else if (output.length) {
230230
return `${this.constructor.name} { ${output.join(separator)} }`;
231-
} else {
232-
return `${this.constructor.name} {}`;
233231
}
232+
return `${this.constructor.name} {}`;
234233
}
235234
}
236235

@@ -1315,16 +1314,15 @@ function getPathFromURLWin32(url) {
13151314
// already taken care of that for us. Note that this only
13161315
// causes IDNs with an appropriate `xn--` prefix to be decoded.
13171316
return `\\\\${domainToUnicode(hostname)}${pathname}`;
1318-
} else {
1319-
// Otherwise, it's a local path that requires a drive letter
1320-
const letter = pathname.codePointAt(1) | 0x20;
1321-
const sep = pathname[2];
1322-
if (letter < CHAR_LOWERCASE_A || letter > CHAR_LOWERCASE_Z || // a..z A..Z
1323-
(sep !== ':')) {
1324-
throw new ERR_INVALID_FILE_URL_PATH('must be absolute');
1325-
}
1326-
return pathname.slice(1);
13271317
}
1318+
// Otherwise, it's a local path that requires a drive letter
1319+
const letter = pathname.codePointAt(1) | 0x20;
1320+
const sep = pathname[2];
1321+
if (letter < CHAR_LOWERCASE_A || letter > CHAR_LOWERCASE_Z || // a..z A..Z
1322+
(sep !== ':')) {
1323+
throw new ERR_INVALID_FILE_URL_PATH('must be absolute');
1324+
}
1325+
return pathname.slice(1);
13281326
}
13291327

13301328
function getPathFromURLPosix(url) {

‎lib/net.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,8 @@ ObjectDefineProperty(Socket.prototype, 'readyState', {
543543
return 'readOnly';
544544
} else if (!this.readable && this.writable) {
545545
return 'writeOnly';
546-
} else {
547-
return 'closed';
548546
}
547+
return 'closed';
549548
}
550549
});
551550

@@ -1520,9 +1519,8 @@ Server.prototype.address = function() {
15201519
return out;
15211520
} else if (this._pipeName) {
15221521
return this._pipeName;
1523-
} else {
1524-
return null;
15251522
}
1523+
return null;
15261524
};
15271525

15281526
function onconnection(err, clientHandle) {

‎lib/repl.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,8 @@ function REPLServer(prompt,
781781
self[kBufferedCommandSymbol] += cmd + '\n';
782782
self.displayPrompt();
783783
return;
784-
} else {
785-
self._domain.emit('error', e.err || e);
786784
}
785+
self._domain.emit('error', e.err || e);
787786
}
788787

789788
// Clear buffer if no SyntaxErrors

‎lib/v8.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,13 @@ class DefaultDeserializer extends Deserializer {
251251
return new ctor(this.buffer.buffer,
252252
offset,
253253
byteLength / BYTES_PER_ELEMENT);
254-
} else {
255-
// Copy to an aligned buffer first.
256-
const buffer_copy = Buffer.allocUnsafe(byteLength);
257-
copy(this.buffer, buffer_copy, 0, byteOffset, byteOffset + byteLength);
258-
return new ctor(buffer_copy.buffer,
259-
buffer_copy.byteOffset,
260-
byteLength / BYTES_PER_ELEMENT);
261254
}
255+
// Copy to an aligned buffer first.
256+
const buffer_copy = Buffer.allocUnsafe(byteLength);
257+
copy(this.buffer, buffer_copy, 0, byteOffset, byteOffset + byteLength);
258+
return new ctor(buffer_copy.buffer,
259+
buffer_copy.byteOffset,
260+
byteLength / BYTES_PER_ELEMENT);
262261
}
263262
}
264263

‎lib/vm.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ class Script extends ContextifyScript {
116116
const { breakOnSigint, args } = getRunInContextArgs(options);
117117
if (breakOnSigint && process.listenerCount('SIGINT') > 0) {
118118
return sigintHandlersWrap(super.runInThisContext, this, args);
119-
} else {
120-
return super.runInThisContext(...args);
121119
}
120+
return super.runInThisContext(...args);
122121
}
123122

124123
runInContext(contextifiedObject, options) {
@@ -127,9 +126,8 @@ class Script extends ContextifyScript {
127126
if (breakOnSigint && process.listenerCount('SIGINT') > 0) {
128127
return sigintHandlersWrap(super.runInContext, this,
129128
[contextifiedObject, ...args]);
130-
} else {
131-
return super.runInContext(contextifiedObject, ...args);
132129
}
130+
return super.runInContext(contextifiedObject, ...args);
133131
}
134132

135133
runInNewContext(contextObject, options) {

‎lib/zlib.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -763,15 +763,14 @@ function createConvenienceMethod(ctor, sync) {
763763
return function syncBufferWrapper(buffer, opts) {
764764
return zlibBufferSync(new ctor(opts), buffer);
765765
};
766-
} else {
767-
return function asyncBufferWrapper(buffer, opts, callback) {
768-
if (typeof opts === 'function') {
769-
callback = opts;
770-
opts = {};
771-
}
772-
return zlibBuffer(new ctor(opts), buffer, callback);
773-
};
774766
}
767+
return function asyncBufferWrapper(buffer, opts, callback) {
768+
if (typeof opts === 'function') {
769+
callback = opts;
770+
opts = {};
771+
}
772+
return zlibBuffer(new ctor(opts), buffer, callback);
773+
};
775774
}
776775

777776
const kMaxBrotliParam = MathMax(...ObjectKeys(constants).map((key) => {

‎test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ assert.throws(() => {
3838
name: 'Error'
3939
})(e);
4040
return true;
41-
} else {
42-
return true;
4341
}
42+
return true;
4443
});
4544

4645
assert.throws(() => {

‎test/async-hooks/init-hooks.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,13 @@ class ActivityCollector {
165165
// Worker threads start main script execution inside of an AsyncWrap
166166
// callback, so we don't yield errors for these.
167167
return null;
168-
} else {
169-
const err = new Error(`Found a handle whose ${hook}` +
170-
' hook was invoked but not its init hook');
171-
// Don't throw if we see invocations due to an assertion in a test
172-
// failing since we want to list the assertion failure instead
173-
if (/process\._fatalException/.test(err.stack)) return null;
174-
throw err;
175168
}
169+
const err = new Error(`Found a handle whose ${hook}` +
170+
' hook was invoked but not its init hook');
171+
// Don't throw if we see invocations due to an assertion in a test
172+
// failing since we want to list the assertion failure instead
173+
if (/process\._fatalException/.test(err.stack)) return null;
174+
throw err;
176175
}
177176
return h;
178177
}

‎test/common/dns.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,15 @@ function readDomainFromPacket(buffer, offset) {
3636
nread: 1 + length + nread,
3737
domain: domain ? `${chunk}.${domain}` : chunk
3838
};
39-
} else {
40-
// Pointer to another part of the packet.
41-
assert.strictEqual(length & 0xC0, 0xC0);
42-
// eslint-disable-next-line space-infix-ops, space-unary-ops
43-
const pointeeOffset = buffer.readUInt16BE(offset) &~ 0xC000;
44-
return {
45-
nread: 2,
46-
domain: readDomainFromPacket(buffer, pointeeOffset)
47-
};
4839
}
40+
// Pointer to another part of the packet.
41+
assert.strictEqual(length & 0xC0, 0xC0);
42+
// eslint-disable-next-line space-infix-ops, space-unary-ops
43+
const pointeeOffset = buffer.readUInt16BE(offset) &~ 0xC000;
44+
return {
45+
nread: 2,
46+
domain: readDomainFromPacket(buffer, pointeeOffset)
47+
};
4948
}
5049

5150
function parseDNSPacket(buffer) {

‎test/common/index.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,9 @@ function runCallChecks(exitCode) {
309309
if ('minimum' in context) {
310310
context.messageSegment = `at least ${context.minimum}`;
311311
return context.actual < context.minimum;
312-
} else {
313-
context.messageSegment = `exactly ${context.exact}`;
314-
return context.actual !== context.exact;
315312
}
313+
context.messageSegment = `exactly ${context.exact}`;
314+
return context.actual !== context.exact;
316315
});
317316

318317
failed.forEach(function(context) {
@@ -468,9 +467,8 @@ function nodeProcessAborted(exitCode, signal) {
468467
// the expected exit codes or signals.
469468
if (signal !== null) {
470469
return expectedSignals.includes(signal);
471-
} else {
472-
return expectedExitCodes.includes(exitCode);
473470
}
471+
return expectedExitCodes.includes(exitCode);
474472
}
475473

476474
function isAlive(pid) {

‎test/common/inspector-helper.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,8 @@ class InspectorSession {
217217
return Promise
218218
.all(commands.map((command) => this._sendMessage(command)))
219219
.then(() => {});
220-
} else {
221-
return this._sendMessage(commands);
222220
}
221+
return this._sendMessage(commands);
223222
}
224223

225224
waitForNotification(methodOrPredicate, description) {

‎test/common/shared-lib-util.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ function getSharedLibPath() {
3636
return path.join(kExecPath, 'node.dll');
3737
} else if (common.isOSX) {
3838
return path.join(kExecPath, `libnode.${kShlibSuffix}`);
39-
} else {
40-
return path.join(kExecPath, 'lib.target', `libnode.${kShlibSuffix}`);
4139
}
40+
return path.join(kExecPath, 'lib.target', `libnode.${kShlibSuffix}`);
4241
}
4342

4443
// Get the binary path of stack frames.

‎test/common/wpt.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ class ResourceLoader {
7373
text() { return data.toString(); }
7474
};
7575
});
76-
} else {
77-
return fs.readFileSync(file, 'utf8');
7876
}
77+
return fs.readFileSync(file, 'utf8');
7978
}
8079
}
8180

@@ -603,24 +602,23 @@ class WPTRunner {
603602
const matches = code.match(/\/\/ META: .+/g);
604603
if (!matches) {
605604
return {};
606-
} else {
607-
const result = {};
608-
for (const match of matches) {
609-
const parts = match.match(/\/\/ META: ([^=]+?)=(.+)/);
610-
const key = parts[1];
611-
const value = parts[2];
612-
if (key === 'script') {
613-
if (result[key]) {
614-
result[key].push(value);
615-
} else {
616-
result[key] = [value];
617-
}
605+
}
606+
const result = {};
607+
for (const match of matches) {
608+
const parts = match.match(/\/\/ META: ([^=]+?)=(.+)/);
609+
const key = parts[1];
610+
const value = parts[2];
611+
if (key === 'script') {
612+
if (result[key]) {
613+
result[key].push(value);
618614
} else {
619-
result[key] = value;
615+
result[key] = [value];
620616
}
617+
} else {
618+
result[key] = value;
621619
}
622-
return result;
623620
}
621+
return result;
624622
}
625623

626624
buildQueue() {

‎test/parallel/test-fs-mkdir-mode-mask.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@ const assert = require('assert');
77
const path = require('path');
88
const fs = require('fs');
99

10-
let mode;
11-
1210
if (common.isWindows) {
1311
common.skip('mode is not supported in mkdir on Windows');
1412
return;
15-
} else {
16-
mode = 0o644;
1713
}
1814

15+
const mode = 0o644;
1916
const maskToIgnore = 0o10000;
2017

2118
const tmpdir = require('../common/tmpdir');

‎test/parallel/test-fs-utimes.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ tmpdir.refresh();
3131
function stat_resource(resource) {
3232
if (typeof resource === 'string') {
3333
return fs.statSync(resource);
34-
} else {
35-
const stats = fs.fstatSync(resource);
36-
// Ensure mtime has been written to disk
37-
// except for directories on AIX where it cannot be synced
38-
if (common.isAIX && stats.isDirectory())
39-
return stats;
40-
fs.fsyncSync(resource);
41-
return fs.fstatSync(resource);
4234
}
35+
const stats = fs.fstatSync(resource);
36+
// Ensure mtime has been written to disk
37+
// except for directories on AIX where it cannot be synced
38+
if (common.isAIX && stats.isDirectory())
39+
return stats;
40+
fs.fsyncSync(resource);
41+
return fs.fstatSync(resource);
4342
}
4443

4544
function check_mtime(resource, mtime) {

‎test/parallel/test-net-pingpong.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ function pingPongTest(port, host) {
103103
assert.strictEqual(client.writable, false);
104104
assert.strictEqual(client.readable, true);
105105
return;
106-
} else {
107-
assert.strictEqual(client.writable, true);
108-
assert.strictEqual(client.readable, true);
109106
}
107+
assert.strictEqual(client.writable, true);
108+
assert.strictEqual(client.readable, true);
110109

111110
if (count < N) {
112111
client.write('PING');

‎test/parallel/test-stream2-readable-empty-buffer-no-eof.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ function test2() {
9595
r._read = function(n) {
9696
if (!reads--)
9797
return r.push(null); // EOF
98-
else
99-
return r.push(Buffer.from('x'));
98+
return r.push(Buffer.from('x'));
10099
};
101100

102101
const results = [];

‎test/parallel/test-trace-events-api.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ function getEnabledCategoriesFromCommandLine() {
2525
const indexOfCatFlag = process.execArgv.indexOf('--trace-event-categories');
2626
if (indexOfCatFlag === -1) {
2727
return undefined;
28-
} else {
29-
return process.execArgv[indexOfCatFlag + 1];
3028
}
29+
return process.execArgv[indexOfCatFlag + 1];
3130
}
3231

3332
const isChild = process.argv[2] === 'child';

‎test/pummel/test-net-pingpong.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ function pingPongTest(host, on_complete) {
8888
if (sent_final_ping) {
8989
assert.strictEqual(client.readyState, 'readOnly');
9090
return;
91-
} else {
92-
assert.strictEqual(client.readyState, 'open');
9391
}
92+
assert.strictEqual(client.readyState, 'open');
9493

9594
if (count < N) {
9695
client.write('PING');

‎tools/doc/json.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,7 @@ function textJoin(nodes, file) {
506506
return `_${textJoin(node.children, file)}_`;
507507
} else if (node.children) {
508508
return textJoin(node.children, file);
509-
} else {
510-
return node.value;
511509
}
510+
return node.value;
512511
}).join('');
513512
}

‎tools/test-npm-package.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ function spawnCopyDeepSync(source, destination) {
3232
if (common.isWindows) {
3333
mkdirSync(destination); // Prevent interactive prompt
3434
return spawnSync('xcopy.exe', ['/E', source, destination]);
35-
} else {
36-
return spawnSync('cp', ['-r', `${source}/`, destination]);
3735
}
36+
return spawnSync('cp', ['-r', `${source}/`, destination]);
3837
}
3938

4039
function runNPMPackageTests({ srcDir, install, rebuild, testArgs, logfile }) {

0 commit comments

Comments
 (0)
Please sign in to comment.