Skip to content

Commit

Permalink
tools: enable no-else-return lint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed May 15, 2020
1 parent 23a61eb commit af70a1c
Show file tree
Hide file tree
Showing 42 changed files with 158 additions and 214 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 @@ -249,9 +249,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 @@ -375,8 +375,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
5 changes: 2 additions & 3 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,9 @@ Writable.prototype.write = function(chunk, encoding, cb) {
process.nextTick(cb, err);
errorOrDestroy(this, err, true);
return false;
} else {
state.pendingcb++;
return writeOrBuffer(this, state, chunk, encoding, cb);
}
state.pendingcb++;
return writeOrBuffer(this, state, chunk, encoding, cb);
};

Writable.prototype.cork = function() {
Expand Down
11 changes: 5 additions & 6 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1503,13 +1503,12 @@ function onConnectSecure() {
if (options.rejectUnauthorized) {
this.destroy(verifyError);
return;
} else {
debug('client emit secureConnect. rejectUnauthorized: %s, ' +
'authorizationError: %s', options.rejectUnauthorized,
this.authorizationError);
this.secureConnecting = false;
this.emit('secureConnect');
}
debug('client emit secureConnect. rejectUnauthorized: %s, ' +
'authorizationError: %s', options.rejectUnauthorized,
this.authorizationError);
this.secureConnecting = false;
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 @@ -1545,9 +1545,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 @@ -77,8 +77,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 @@ -89,9 +88,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 @@ -1087,10 +1087,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 @@ -1101,8 +1100,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 @@ -1113,11 +1111,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 @@ -1127,11 +1124,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 @@ -1286,10 +1282,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 @@ -478,9 +478,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
5 changes: 2 additions & 3 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,9 @@ function preprocessSymlinkDestination(path, type, linkPath) {
// A relative target is relative to the link's parent directory.
path = pathModule.resolve(linkPath, '..', path);
return pathModule.toNamespacedPath(path);
} else {
// Windows symlinks don't tolerate forward slashes.
return ('' + path).replace(/\//g, '\\');
}
// Windows symlinks don't tolerate forward slashes.
return ('' + path).replace(/\//g, '\\');
}

// Constructor for file stats.
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 @@ -448,10 +448,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 @@ -571,10 +570,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 @@ -604,10 +602,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
Loading

0 comments on commit af70a1c

Please sign in to comment.