Skip to content

Commit

Permalink
tools: enable no-else-return lint rule
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lpinca authored and codebytere committed Jul 14, 2020
1 parent ce4d73c commit 248f9af
Show file tree
Hide file tree
Showing 39 changed files with 151 additions and 204 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ module.exports = {
'no-dupe-else-if': 'error',
'no-duplicate-case': 'error',
'no-duplicate-imports': 'error',
'no-else-return': ['error', { allowElseIf: true }],
'no-empty-character-class': 'error',
'no-ex-assign': 'error',
'no-extra-boolean-cast': 'error',
Expand Down
7 changes: 3 additions & 4 deletions benchmark/es/spread-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ function makeTest(count, rest) {
return function test(...args) {
assert.strictEqual(count, args.length);
};
} else {
return function test() {
assert.strictEqual(count, arguments.length);
};
}
return function test() {
assert.strictEqual(count, arguments.length);
};
}

function main({ n, context, count, rest, method }) {
Expand Down
3 changes: 1 addition & 2 deletions benchmark/scatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ let printHeader = true;
function csvEncodeValue(value) {
if (typeof value === 'number') {
return value.toString();
} else {
return `"${value.replace(/"/g, '""')}"`;
}
return `"${value.replace(/"/g, '""')}"`;
}

(function recursive(i) {
Expand Down
3 changes: 1 addition & 2 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,8 @@ function matchKnownFields(field, lowercased) {
}
if (lowercased) {
return '\u0000' + field;
} else {
return matchKnownFields(field.toLowerCase(), true);
}
return matchKnownFields(field.toLowerCase(), true);
}
// Add the given (field, value) pair to the message
//
Expand Down
3 changes: 1 addition & 2 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ function howMuchToRead(n, state) {
// Only flow one buffer at a time
if (state.flowing && state.length)
return state.buffer.first().length;
else
return state.length;
return state.length;
}
if (n <= state.length)
return n;
Expand Down
9 changes: 4 additions & 5 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1518,12 +1518,11 @@ function onConnectSecure() {
if (options.rejectUnauthorized) {
this.destroy(verifyError);
return;
} else {
debug('client emit secureConnect. rejectUnauthorized: %s, ' +
'authorizationError: %s', options.rejectUnauthorized,
this.authorizationError);
this.emit('secureConnect');
}
debug('client emit secureConnect. rejectUnauthorized: %s, ' +
'authorizationError: %s', options.rejectUnauthorized,
this.authorizationError);
this.emit('secureConnect');
} else {
this.authorized = true;
debug('client emit secureConnect. authorized:', this.authorized);
Expand Down
3 changes: 1 addition & 2 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,8 @@ function resolve(hostname, rrtype, callback) {

if (typeof resolver === 'function') {
return resolver.call(this, hostname, callback);
} else {
throw new ERR_INVALID_OPT_VALUE('rrtype', rrtype);
}
throw new ERR_INVALID_OPT_VALUE('rrtype', rrtype);
}

function defaultResolverSetServers(servers) {
Expand Down
3 changes: 1 addition & 2 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,8 @@ EventEmitter.prototype.rawListeners = function rawListeners(type) {
EventEmitter.listenerCount = function(emitter, type) {
if (typeof emitter.listenerCount === 'function') {
return emitter.listenerCount(type);
} else {
return listenerCount.call(emitter, type);
}
return listenerCount.call(emitter, type);
};

EventEmitter.prototype.listenerCount = listenerCount;
Expand Down
3 changes: 1 addition & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1515,9 +1515,8 @@ function encodeRealpathResult(result, options) {
const asBuffer = Buffer.from(result);
if (options.encoding === 'buffer') {
return asBuffer;
} else {
return asBuffer.toString(options.encoding);
}
return asBuffer.toString(options.encoding);
}

// Finds the next portion of a (partial) path, up to the next path delimiter
Expand Down
24 changes: 11 additions & 13 deletions lib/internal/crypto/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,13 @@ function prepareAsymmetricKey(key, ctx) {
const isPublic =
(ctx === kConsumePrivate || ctx === kCreatePrivate) ? false : undefined;
return { data, ...parseKeyEncoding(key, undefined, isPublic) };
} else {
throw new ERR_INVALID_ARG_TYPE(
'key',
['string', 'Buffer', 'TypedArray', 'DataView',
...(ctx !== kCreatePrivate ? ['KeyObject'] : [])],
key
);
}
throw new ERR_INVALID_ARG_TYPE(
'key',
['string', 'Buffer', 'TypedArray', 'DataView',
...(ctx !== kCreatePrivate ? ['KeyObject'] : [])],
key
);
}

function preparePrivateKey(key) {
Expand All @@ -301,13 +300,12 @@ function prepareSecretKey(key, bufferOnly = false) {
if (key.type !== 'secret')
throw new ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE(key.type, 'secret');
return key[kHandle];
} else {
throw new ERR_INVALID_ARG_TYPE(
'key',
['Buffer', 'TypedArray', 'DataView',
...(bufferOnly ? [] : ['string', 'KeyObject'])],
key);
}
throw new ERR_INVALID_ARG_TYPE(
'key',
['Buffer', 'TypedArray', 'DataView',
...(bufferOnly ? [] : ['string', 'KeyObject'])],
key);
}
return key;
}
Expand Down
6 changes: 2 additions & 4 deletions lib/internal/crypto/sig.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ function getDSASignatureEncoding(options) {
return kSigEncDER;
else if (dsaEncoding === 'ieee-p1363')
return kSigEncP1363;
else
throw new ERR_INVALID_OPT_VALUE('dsaEncoding', dsaEncoding);
throw new ERR_INVALID_OPT_VALUE('dsaEncoding', dsaEncoding);
}

return kSigEncDER;
Expand All @@ -82,9 +81,8 @@ function getIntOption(name, options) {
if (value !== undefined) {
if (value === value >> 0) {
return value;
} else {
throw new ERR_INVALID_OPT_VALUE(name, value);
}
throw new ERR_INVALID_OPT_VALUE(name, value);
}
return undefined;
}
Expand Down
27 changes: 11 additions & 16 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1106,10 +1106,9 @@ E('ERR_INVALID_MODULE_SPECIFIER', (pkgPath, subpath, base = undefined) => {
assert(subpath !== '.');
return `Package subpath '${subpath}' is not a valid module request for ` +
`the "exports" resolution of ${pkgPath}${sep}package.json`;
} else {
return `Package subpath '${subpath}' is not a valid module request for ` +
`the "exports" resolution of ${pkgPath} imported from ${base}`;
}
return `Package subpath '${subpath}' is not a valid module request for ` +
`the "exports" resolution of ${pkgPath} imported from ${base}`;
}, TypeError);
E('ERR_INVALID_OPT_VALUE', (name, value) =>
`The value "${String(value)}" is invalid for option "${name}"`,
Expand All @@ -1120,8 +1119,7 @@ E('ERR_INVALID_OPT_VALUE_ENCODING',
E('ERR_INVALID_PACKAGE_CONFIG', (path, message, hasMessage = true) => {
if (hasMessage)
return `Invalid package config ${path}${sep}package.json, ${message}`;
else
return `Invalid JSON in ${path} imported from ${message}`;
return `Invalid JSON in ${path} imported from ${message}`;
}, Error);
E('ERR_INVALID_PACKAGE_TARGET',
(pkgPath, key, subpath, target, base = undefined) => {
Expand All @@ -1132,11 +1130,10 @@ E('ERR_INVALID_PACKAGE_TARGET',
return `Invalid "exports" target ${JSONStringify(target)} defined ` +
`for '${subpath}' in the package config ${pkgPath} imported from ` +
`${base}.${relError ? '; targets must start with "./"' : ''}`;
} else {
return `Invalid "exports" main target ${target} defined in the ` +
`package config ${pkgPath} imported from ${base}${relError ?
'; targets must start with "./"' : ''}`;
}
return `Invalid "exports" main target ${target} defined in the ` +
`package config ${pkgPath} imported from ${base}${relError ?
'; targets must start with "./"' : ''}`;
} else if (key === '.') {
return `Invalid "exports" main target ${JSONStringify(target)} defined ` +
`in the package config ${pkgPath}${sep}package.json${relError ?
Expand All @@ -1146,11 +1143,10 @@ E('ERR_INVALID_PACKAGE_TARGET',
StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` +
`package config ${pkgPath}${sep}package.json; ` +
'targets must start with "./"';
} else {
return `Invalid "exports" target ${JSONStringify(target)} defined for '${
StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` +
`package config ${pkgPath}${sep}package.json`;
}
return `Invalid "exports" target ${JSONStringify(target)} defined for '${
StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` +
`package config ${pkgPath}${sep}package.json`;
}, Error);
E('ERR_INVALID_PERFORMANCE_MARK',
'The "%s" performance mark has not been set', Error);
Expand Down Expand Up @@ -1305,10 +1301,9 @@ E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath, base = undefined) => {
} else if (base === undefined) {
return `Package subpath '${subpath}' is not defined by "exports" in ${
pkgPath}${sep}package.json`;
} else {
return `Package subpath '${subpath}' is not defined by "exports" in ${
pkgPath} imported from ${base}`;
}
return `Package subpath '${subpath}' is not defined by "exports" in ${
pkgPath} imported from ${base}`;
}, Error);
E('ERR_REQUIRE_ESM',
(filename, parentPath = null, packageJsonPath = null) => {
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/fs/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,8 @@ WriteStream.prototype.close = function(cb) {
if (this.closed) {
process.nextTick(cb);
return;
} else {
this.on('close', cb);
}
this.on('close', cb);
}

// If we are not autoClosing, we should call
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/modules/esm/get_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ async function defaultGetSource(url, { format } = {}, defaultGetSource) {
return {
source: Buffer.from(body, base64 ? 'base64' : 'utf8')
};
} else {
throw new ERR_INVALID_URL_SCHEME(['file', 'data']);
}
throw new ERR_INVALID_URL_SCHEME(['file', 'data']);
}
exports.defaultGetSource = defaultGetSource;
15 changes: 6 additions & 9 deletions lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,9 @@ function packageMainResolve(packageJSONUrl, packageConfig, base, conditions) {
if (packageConfig.main !== undefined) {
return finalizeResolution(
new URL(packageConfig.main, packageJSONUrl), base);
} else {
return finalizeResolution(
new URL('index', packageJSONUrl), base);
}
return finalizeResolution(
new URL('index', packageJSONUrl), base);
}
return legacyMainResolve(packageJSONUrl, packageConfig);
}
Expand Down Expand Up @@ -553,10 +552,9 @@ function packageResolve(specifier, base, conditions) {
} else if (packageSubpath === '') {
return packageMainResolve(packageJSONUrl, packageConfig, base,
conditions);
} else {
return packageExportsResolve(
packageJSONUrl, packageSubpath, packageConfig, base, conditions);
}
return packageExportsResolve(
packageJSONUrl, packageSubpath, packageConfig, base, conditions);
}
}

Expand Down Expand Up @@ -585,10 +583,9 @@ function packageResolve(specifier, base, conditions) {
} else if (packageConfig.exports !== undefined) {
return packageExportsResolve(
packageJSONUrl, packageSubpath, packageConfig, base, conditions);
} else {
return finalizeResolution(
new URL(packageSubpath, packageJSONUrl), base);
}
return finalizeResolution(
new URL(packageSubpath, packageJSONUrl), base);
// Cross-platform root check.
} while (packageJSONPath.length !== lastPath.length);

Expand Down
41 changes: 20 additions & 21 deletions lib/internal/policy/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,32 +145,31 @@ class Manifest {
const dependencyRedirectList = (toSpecifier) => {
if (toSpecifier in dependencyMap !== true) {
return null;
} else {
const to = dependencyMap[toSpecifier];
if (to === true) {
return true;
}
if (parsedURLs.has(to)) {
return parsedURLs.get(to);
} else if (canBeRequiredByUsers(to)) {
const href = `node:${to}`;
const resolvedURL = new URL(href);
parsedURLs.set(to, resolvedURL);
parsedURLs.set(href, resolvedURL);
return resolvedURL;
} else if (RegExpPrototypeTest(kRelativeURLStringPattern, to)) {
const resolvedURL = new URL(to, manifestURL);
const href = resourceURL.href;
parsedURLs.set(to, resolvedURL);
parsedURLs.set(href, resolvedURL);
return resolvedURL;
}
const resolvedURL = new URL(to);
}
const to = dependencyMap[toSpecifier];
if (to === true) {
return true;
}
if (parsedURLs.has(to)) {
return parsedURLs.get(to);
} else if (canBeRequiredByUsers(to)) {
const href = `node:${to}`;
const resolvedURL = new URL(href);
parsedURLs.set(to, resolvedURL);
parsedURLs.set(href, resolvedURL);
return resolvedURL;
} else if (RegExpPrototypeTest(kRelativeURLStringPattern, to)) {
const resolvedURL = new URL(to, manifestURL);
const href = resourceURL.href;
parsedURLs.set(to, resolvedURL);
parsedURLs.set(href, resolvedURL);
return resolvedURL;
}
const resolvedURL = new URL(to);
const href = resourceURL.href;
parsedURLs.set(to, resolvedURL);
parsedURLs.set(href, resolvedURL);
return resolvedURL;
};
dependencies.set(resourceHREF, dependencyRedirectList);
} else if (dependencyMap === true) {
Expand Down
15 changes: 7 additions & 8 deletions lib/internal/source_map/source_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,14 @@ class SourceMap {
return {};
} else if (!entry) {
return {};
} else {
return {
generatedLine: entry[0],
generatedColumn: entry[1],
originalSource: entry[2],
originalLine: entry[3],
originalColumn: entry[4]
};
}
return {
generatedLine: entry[0],
generatedColumn: entry[1],
originalSource: entry[2],
originalLine: entry[3],
originalColumn: entry[4]
};
}

/**
Expand Down
6 changes: 2 additions & 4 deletions lib/internal/source_map/source_map_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ function sourceMapCacheToObject() {

if (ObjectKeys(obj).length === 0) {
return undefined;
} else {
return obj;
}
return obj;
}

// Since WeakMap can't be iterated over, we use Module._cache's
Expand Down Expand Up @@ -243,9 +242,8 @@ function findSourceMap(uri, error) {
}
if (sourceMap && sourceMap.data) {
return new SourceMap(sourceMap.data);
} else {
return undefined;
}
return undefined;
}

module.exports = {
Expand Down
Loading

0 comments on commit 248f9af

Please sign in to comment.