Skip to content

Commit 62fb054

Browse files
not-an-aardvarkvitorbal
authored andcommitted
Chore: enable no-else-return on ESLint codebase (#7986)
* Chore: enable no-else-return on ESLint codebase * Move a comment after a brace
1 parent c59a0ba commit 62fb054

32 files changed

+169
-167
lines changed

Makefile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -995,9 +995,9 @@ function time(cmd, runs, runNumber, results, cb) {
995995
echo(` Performance Run #${runNumber}: %dms`, actual);
996996
if (runs > 1) {
997997
return time(cmd, runs - 1, runNumber + 1, results, cb);
998-
} else {
999-
return cb(results);
1000998
}
999+
return cb(results);
1000+
10011001
});
10021002

10031003
}

lib/cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ const cli = {
188188
}
189189

190190
return (report.errorCount || tooManyWarnings) ? 1 : 0;
191-
} else {
192-
return 1;
193191
}
192+
return 1;
193+
194194

195195
}
196196

lib/config/config-file.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -461,24 +461,24 @@ function normalizePackageName(name, prefix) {
461461
function resolve(filePath, relativeTo) {
462462
if (isFilePath(filePath)) {
463463
return { filePath: path.resolve(relativeTo || "", filePath) };
464-
} else {
465-
let normalizedPackageName;
466-
467-
if (filePath.indexOf("plugin:") === 0) {
468-
const packagePath = filePath.substr(7, filePath.lastIndexOf("/") - 7);
469-
const configName = filePath.substr(filePath.lastIndexOf("/") + 1, filePath.length - filePath.lastIndexOf("/") - 1);
470-
471-
normalizedPackageName = normalizePackageName(packagePath, "eslint-plugin");
472-
debug(`Attempting to resolve ${normalizedPackageName}`);
473-
filePath = resolver.resolve(normalizedPackageName, getLookupPath(relativeTo));
474-
return { filePath, configName };
475-
} else {
476-
normalizedPackageName = normalizePackageName(filePath, "eslint-config");
477-
debug(`Attempting to resolve ${normalizedPackageName}`);
478-
filePath = resolver.resolve(normalizedPackageName, getLookupPath(relativeTo));
479-
return { filePath };
480-
}
481464
}
465+
let normalizedPackageName;
466+
467+
if (filePath.indexOf("plugin:") === 0) {
468+
const packagePath = filePath.substr(7, filePath.lastIndexOf("/") - 7);
469+
const configName = filePath.substr(filePath.lastIndexOf("/") + 1, filePath.length - filePath.lastIndexOf("/") - 1);
470+
471+
normalizedPackageName = normalizePackageName(packagePath, "eslint-plugin");
472+
debug(`Attempting to resolve ${normalizedPackageName}`);
473+
filePath = resolver.resolve(normalizedPackageName, getLookupPath(relativeTo));
474+
return { filePath, configName };
475+
}
476+
normalizedPackageName = normalizePackageName(filePath, "eslint-config");
477+
debug(`Attempting to resolve ${normalizedPackageName}`);
478+
filePath = resolver.resolve(normalizedPackageName, getLookupPath(relativeTo));
479+
return { filePath };
480+
481+
482482

483483
}
484484

lib/config/config-validator.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ function getRuleOptionsSchema(id) {
4040
minItems: 0,
4141
maxItems: schema.length
4242
};
43-
} else {
44-
return {
45-
type: "array",
46-
minItems: 0,
47-
maxItems: 0
48-
};
4943
}
44+
return {
45+
type: "array",
46+
minItems: 0,
47+
maxItems: 0
48+
};
49+
5050
}
5151

5252
// Given a full schema, leave it alone

lib/eslint.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,9 @@ function createStubRule(message) {
528528

529529
if (message) {
530530
return createRuleModule;
531-
} else {
532-
throw new Error("No message passed to stub rule");
533531
}
532+
throw new Error("No message passed to stub rule");
533+
534534
}
535535

536536
/**
@@ -660,9 +660,9 @@ module.exports = (function() {
660660
try {
661661
if (typeof parser.parseForESLint === "function") {
662662
return parser.parseForESLint(text, parserOptions);
663-
} else {
664-
return parser.parse(text, parserOptions);
665663
}
664+
return parser.parse(text, parserOptions);
665+
666666
} catch (ex) {
667667

668668
// If the message includes a leading line number, strip it:
@@ -695,9 +695,9 @@ module.exports = (function() {
695695
return ruleConfig;
696696
} else if (Array.isArray(ruleConfig)) {
697697
return ruleConfig[0];
698-
} else {
699-
return 0;
700698
}
699+
return 0;
700+
701701
}
702702

703703
/**
@@ -708,9 +708,9 @@ module.exports = (function() {
708708
function getRuleOptions(ruleConfig) {
709709
if (Array.isArray(ruleConfig)) {
710710
return ruleConfig.slice(1);
711-
} else {
712-
return [];
713711
}
712+
return [];
713+
714714
}
715715

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

940940
if (lineDiff === 0) {
941941
return a.column - b.column;
942-
} else {
943-
return lineDiff;
944942
}
943+
return lineDiff;
944+
945945
});
946946

947947
return messages;
@@ -1109,9 +1109,9 @@ module.exports = (function() {
11091109
if (scope) {
11101110
if (scope.type === "function-expression-name") {
11111111
return scope.childScopes[0];
1112-
} else {
1113-
return scope;
11141112
}
1113+
return scope;
1114+
11151115
}
11161116

11171117
}
@@ -1161,9 +1161,9 @@ module.exports = (function() {
11611161
api.getFilename = function() {
11621162
if (typeof currentFilename === "string") {
11631163
return currentFilename;
1164-
} else {
1165-
return "<input>";
11661164
}
1165+
return "<input>";
1166+
11671167
};
11681168

11691169
/**

lib/formatters/checkstyle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const xmlEscape = require("../util/xml-escape");
1919
function getMessageType(message) {
2020
if (message.fatal || message.severity === 2) {
2121
return "error";
22-
} else {
23-
return "warning";
2422
}
23+
return "warning";
24+
2525
}
2626

2727
//------------------------------------------------------------------------------

lib/formatters/compact.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
function getMessageType(message) {
1818
if (message.fatal || message.severity === 2) {
1919
return "Error";
20-
} else {
21-
return "Warning";
2220
}
21+
return "Warning";
22+
2323
}
2424

2525

lib/formatters/junit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const xmlEscape = require("../util/xml-escape");
1919
function getMessageType(message) {
2020
if (message.fatal || message.severity === 2) {
2121
return "Error";
22-
} else {
23-
return "Warning";
2422
}
23+
return "Warning";
24+
2525
}
2626

2727
//------------------------------------------------------------------------------

lib/formatters/tap.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const yaml = require("js-yaml");
1818
function getMessageType(message) {
1919
if (message.fatal || message.severity === 2) {
2020
return "error";
21-
} else {
22-
return "warning";
2321
}
22+
return "warning";
23+
2424
}
2525

2626
/**

lib/formatters/unix.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
function getMessageType(message) {
1717
if (message.fatal || message.severity === 2) {
1818
return "Error";
19-
} else {
20-
return "Warning";
2119
}
20+
return "Warning";
21+
2222
}
2323

2424

0 commit comments

Comments
 (0)