Skip to content

Commit

Permalink
Chore: enable no-else-return on ESLint codebase (#7986)
Browse files Browse the repository at this point in the history
* Chore: enable no-else-return on ESLint codebase

* Move a comment after a brace
  • Loading branch information
not-an-aardvark authored and vitorbal committed Jan 28, 2017
1 parent c59a0ba commit 62fb054
Show file tree
Hide file tree
Showing 32 changed files with 169 additions and 167 deletions.
4 changes: 2 additions & 2 deletions Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -995,9 +995,9 @@ function time(cmd, runs, runNumber, results, cb) {
echo(` Performance Run #${runNumber}: %dms`, actual);
if (runs > 1) {
return time(cmd, runs - 1, runNumber + 1, results, cb);
} else {
return cb(results);
}
return cb(results);

});

}
Expand Down
4 changes: 2 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ const cli = {
}

return (report.errorCount || tooManyWarnings) ? 1 : 0;
} else {
return 1;
}
return 1;


}

Expand Down
34 changes: 17 additions & 17 deletions lib/config/config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,24 +461,24 @@ function normalizePackageName(name, prefix) {
function resolve(filePath, relativeTo) {
if (isFilePath(filePath)) {
return { filePath: path.resolve(relativeTo || "", filePath) };
} else {
let normalizedPackageName;

if (filePath.indexOf("plugin:") === 0) {
const packagePath = filePath.substr(7, filePath.lastIndexOf("/") - 7);
const configName = filePath.substr(filePath.lastIndexOf("/") + 1, filePath.length - filePath.lastIndexOf("/") - 1);

normalizedPackageName = normalizePackageName(packagePath, "eslint-plugin");
debug(`Attempting to resolve ${normalizedPackageName}`);
filePath = resolver.resolve(normalizedPackageName, getLookupPath(relativeTo));
return { filePath, configName };
} else {
normalizedPackageName = normalizePackageName(filePath, "eslint-config");
debug(`Attempting to resolve ${normalizedPackageName}`);
filePath = resolver.resolve(normalizedPackageName, getLookupPath(relativeTo));
return { filePath };
}
}
let normalizedPackageName;

if (filePath.indexOf("plugin:") === 0) {
const packagePath = filePath.substr(7, filePath.lastIndexOf("/") - 7);
const configName = filePath.substr(filePath.lastIndexOf("/") + 1, filePath.length - filePath.lastIndexOf("/") - 1);

normalizedPackageName = normalizePackageName(packagePath, "eslint-plugin");
debug(`Attempting to resolve ${normalizedPackageName}`);
filePath = resolver.resolve(normalizedPackageName, getLookupPath(relativeTo));
return { filePath, configName };
}
normalizedPackageName = normalizePackageName(filePath, "eslint-config");
debug(`Attempting to resolve ${normalizedPackageName}`);
filePath = resolver.resolve(normalizedPackageName, getLookupPath(relativeTo));
return { filePath };



}

Expand Down
12 changes: 6 additions & 6 deletions lib/config/config-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ function getRuleOptionsSchema(id) {
minItems: 0,
maxItems: schema.length
};
} else {
return {
type: "array",
minItems: 0,
maxItems: 0
};
}
return {
type: "array",
minItems: 0,
maxItems: 0
};

}

// Given a full schema, leave it alone
Expand Down
28 changes: 14 additions & 14 deletions lib/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,9 @@ function createStubRule(message) {

if (message) {
return createRuleModule;
} else {
throw new Error("No message passed to stub rule");
}
throw new Error("No message passed to stub rule");

}

/**
Expand Down Expand Up @@ -660,9 +660,9 @@ module.exports = (function() {
try {
if (typeof parser.parseForESLint === "function") {
return parser.parseForESLint(text, parserOptions);
} else {
return parser.parse(text, parserOptions);
}
return parser.parse(text, parserOptions);

} catch (ex) {

// If the message includes a leading line number, strip it:
Expand Down Expand Up @@ -695,9 +695,9 @@ module.exports = (function() {
return ruleConfig;
} else if (Array.isArray(ruleConfig)) {
return ruleConfig[0];
} else {
return 0;
}
return 0;

}

/**
Expand All @@ -708,9 +708,9 @@ module.exports = (function() {
function getRuleOptions(ruleConfig) {
if (Array.isArray(ruleConfig)) {
return ruleConfig.slice(1);
} else {
return [];
}
return [];

}

// set unlimited listeners (see https://github.com/eslint/eslint/issues/524)
Expand Down Expand Up @@ -939,9 +939,9 @@ module.exports = (function() {

if (lineDiff === 0) {
return a.column - b.column;
} else {
return lineDiff;
}
return lineDiff;

});

return messages;
Expand Down Expand Up @@ -1109,9 +1109,9 @@ module.exports = (function() {
if (scope) {
if (scope.type === "function-expression-name") {
return scope.childScopes[0];
} else {
return scope;
}
return scope;

}

}
Expand Down Expand Up @@ -1161,9 +1161,9 @@ module.exports = (function() {
api.getFilename = function() {
if (typeof currentFilename === "string") {
return currentFilename;
} else {
return "<input>";
}
return "<input>";

};

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/formatters/checkstyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const xmlEscape = require("../util/xml-escape");
function getMessageType(message) {
if (message.fatal || message.severity === 2) {
return "error";
} else {
return "warning";
}
return "warning";

}

//------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions lib/formatters/compact.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
function getMessageType(message) {
if (message.fatal || message.severity === 2) {
return "Error";
} else {
return "Warning";
}
return "Warning";

}


Expand Down
4 changes: 2 additions & 2 deletions lib/formatters/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const xmlEscape = require("../util/xml-escape");
function getMessageType(message) {
if (message.fatal || message.severity === 2) {
return "Error";
} else {
return "Warning";
}
return "Warning";

}

//------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions lib/formatters/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const yaml = require("js-yaml");
function getMessageType(message) {
if (message.fatal || message.severity === 2) {
return "error";
} else {
return "warning";
}
return "warning";

}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/formatters/unix.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
function getMessageType(message) {
if (message.fatal || message.severity === 2) {
return "Error";
} else {
return "Warning";
}
return "Warning";

}


Expand Down
4 changes: 2 additions & 2 deletions lib/formatters/visualstudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
function getMessageType(message) {
if (message.fatal || message.severity === 2) {
return "error";
} else {
return "warning";
}
return "warning";

}


Expand Down
4 changes: 2 additions & 2 deletions lib/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ function importPlugin(plugin, pluginName) {
function getHandler(ruleId) {
if (typeof rules[ruleId] === "string") {
return require(rules[ruleId]);
} else {
return rules[ruleId];
}
return rules[ruleId];

}

/**
Expand Down
26 changes: 13 additions & 13 deletions lib/rules/comma-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@ module.exports = {
if (options[dir]) {
if (dir === "before") {
return fixer.insertTextBefore(node, " ");
} else {
return fixer.insertTextAfter(node, " ");
}
} else {
let start, end;
const newText = "";
return fixer.insertTextAfter(node, " ");

if (dir === "before") {
start = otherNode.range[1];
end = node.range[0];
} else {
start = node.range[1];
end = otherNode.range[0];
}
}
let start, end;
const newText = "";

return fixer.replaceTextRange([start, end], newText);
if (dir === "before") {
start = otherNode.range[1];
end = node.range[0];
} else {
start = node.range[1];
end = otherNode.range[0];
}

return fixer.replaceTextRange([start, end], newText);

},
message: options[dir] ?
"A space is required {{dir}} ','." :
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/global-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ function findReference(scope, node) {
/* istanbul ignore else: correctly returns null */
if (references.length === 1) {
return references[0];
} else {
return null;
}
return null;

}

/**
Expand Down
26 changes: 13 additions & 13 deletions lib/rules/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,9 @@ module.exports = {
function isFirstArrayElementOnSameLine(node) {
if (node.type === "ArrayExpression" && node.elements[0]) {
return node.elements[0].loc.start.line === node.loc.start.line && node.elements[0].type === "ObjectExpression";
} else {
return false;
}
return false;

}

/**
Expand Down Expand Up @@ -936,20 +936,20 @@ module.exports = {

if (caseIndentStore[switchNode.loc.start.line]) {
return caseIndentStore[switchNode.loc.start.line];
}
if (typeof switchIndent === "undefined") {
switchIndent = getNodeIndent(switchNode).goodChar;
}

if (switchNode.cases.length > 0 && options.SwitchCase === 0) {
caseIndent = switchIndent;
} else {
if (typeof switchIndent === "undefined") {
switchIndent = getNodeIndent(switchNode).goodChar;
}
caseIndent = switchIndent + (indentSize * options.SwitchCase);
}

if (switchNode.cases.length > 0 && options.SwitchCase === 0) {
caseIndent = switchIndent;
} else {
caseIndent = switchIndent + (indentSize * options.SwitchCase);
}
caseIndentStore[switchNode.loc.start.line] = caseIndent;
return caseIndent;

caseIndentStore[switchNode.loc.start.line] = caseIndent;
return caseIndent;
}
}

/**
Expand Down
15 changes: 8 additions & 7 deletions lib/rules/key-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,16 @@ module.exports = {
}
};

} else { // Obey beforeColon and afterColon in each property as configured
}

// Obey beforeColon and afterColon in each property as configured
return {
Property(node) {
verifySpacing(node, isSingleLine(node.parent) ? singleLineOptions : multiLineOptions);
}
};

return {
Property(node) {
verifySpacing(node, isSingleLine(node.parent) ? singleLineOptions : multiLineOptions);
}
};

}

}
};
4 changes: 2 additions & 2 deletions lib/rules/new-cap.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ module.exports = {
return "non-alpha";
} else if (firstChar === firstCharLower) {
return "lower";
} else {
return "upper";
}
return "upper";

}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/newline-before-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ module.exports = {
return isPrecededByTokens(node, ["do"]);
} else if (parentType === "SwitchCase") {
return isPrecededByTokens(node, [":"]);
} else {
return isPrecededByTokens(node, [")"]);
}
return isPrecededByTokens(node, [")"]);

}

/**
Expand Down
Loading

0 comments on commit 62fb054

Please sign in to comment.