Skip to content

Commit 183def6

Browse files
not-an-aardvarkilyavolodin
authored andcommitted
Chore: enable prefer-arrow-callback on ESLint codebase (fixes #6407) (#7503)
* Chore: enable `prefer-arrow-callback` on ESLint codebase (fixes #6407) * Move some complex expressions onto multiple lines * Use `.returns(value)` instead of `() => value` with sinon
1 parent 4f1fa67 commit 183def6

File tree

143 files changed

+2652
-2907
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+2652
-2907
lines changed

Makefile.js

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ function getTestFilePatterns() {
9090
testTemplatesPath = "tests/templates/",
9191
testBinPath = "tests/bin/";
9292

93-
return ls(testLibPath).filter(function(pathToCheck) {
94-
return test("-d", testLibPath + pathToCheck);
95-
}).reduce(function(initialValue, currentValues) {
93+
return ls(testLibPath).filter(pathToCheck => test("-d", testLibPath + pathToCheck)).reduce((initialValue, currentValues) => {
9694
if (currentValues !== "rules") {
9795
initialValue.push(`"${testLibPath + currentValues}/**/*.js"`);
9896
}
@@ -135,7 +133,7 @@ function generateRulesIndex(basedir) {
135133

136134
output += " var rules = Object.create(null);\n";
137135

138-
find(`${basedir}rules/`).filter(fileType("js")).forEach(function(filename) {
136+
find(`${basedir}rules/`).filter(fileType("js")).forEach(filename => {
139137
const basename = path.basename(filename, ".js");
140138

141139
output += ` rules["${basename}"] = require("./rules/${basename}");\n`;
@@ -204,7 +202,7 @@ function generateRuleIndexPage(basedir) {
204202
categoryList = "conf/category-list.json",
205203
categoriesData = JSON.parse(cat(path.resolve(categoryList)));
206204

207-
find(path.join(basedir, "/lib/rules/")).filter(fileType("js")).forEach(function(filename) {
205+
find(path.join(basedir, "/lib/rules/")).filter(fileType("js")).forEach(filename => {
208206
const rule = require(filename);
209207
const basename = path.basename(filename, ".js");
210208

@@ -324,7 +322,7 @@ function getTagOfFirstOccurrence(filePath) {
324322
let tags = execSilent(`git tag --contains ${firstCommit}`);
325323

326324
tags = splitCommandResultToLines(tags);
327-
return tags.reduce(function(list, version) {
325+
return tags.reduce((list, version) => {
328326
version = semver.valid(version.trim());
329327
if (version) {
330328
list.push(version);
@@ -363,12 +361,8 @@ function getFirstVersionOfDeletion(filePath) {
363361
tags = execSilent(`git tag --contains ${deletionCommit}`);
364362

365363
return splitCommandResultToLines(tags)
366-
.map(function(version) {
367-
return semver.valid(version.trim());
368-
})
369-
.filter(function(version) {
370-
return version;
371-
})
364+
.map(version => semver.valid(version.trim()))
365+
.filter(version => version)
372366
.sort(semver.compare)[0];
373367
}
374368

@@ -476,7 +470,7 @@ function getFormatterResults() {
476470
].join("\n"),
477471
rawMessages = cli.executeOnText(codeString, "fullOfProblems.js", true);
478472

479-
return formatterFiles.reduce(function(data, filename) {
473+
return formatterFiles.reduce((data, filename) => {
480474
const fileExt = path.extname(filename),
481475
name = path.basename(filename, fileExt);
482476

@@ -594,9 +588,7 @@ target.gensite = function(prereleaseVersion) {
594588

595589
// append version
596590
if (prereleaseVersion) {
597-
docFiles = docFiles.map(function(docFile) {
598-
return `/${prereleaseVersion}${docFile}`;
599-
});
591+
docFiles = docFiles.map(docFile => `/${prereleaseVersion}${docFile}`);
600592
}
601593

602594
// 1. create temp and build directory
@@ -605,7 +597,7 @@ target.gensite = function(prereleaseVersion) {
605597
}
606598

607599
// 2. remove old files from the site
608-
docFiles.forEach(function(filePath) {
600+
docFiles.forEach(filePath => {
609601
const fullPath = path.join(DOCS_DIR, filePath),
610602
htmlFullPath = fullPath.replace(".md", ".html");
611603

@@ -632,7 +624,7 @@ target.gensite = function(prereleaseVersion) {
632624
}
633625

634626
// 4. Loop through all files in temporary directory
635-
find(TEMP_DIR).forEach(function(filename) {
627+
find(TEMP_DIR).forEach(filename => {
636628
if (test("-f", filename) && path.extname(filename) === ".md") {
637629

638630
const rulesUrl = "https://github.com/eslint/eslint/tree/master/lib/rules/",
@@ -763,7 +755,7 @@ target.checkRuleFiles = function() {
763755
const ruleFiles = find("lib/rules/").filter(fileType("js"));
764756
let errors = 0;
765757

766-
ruleFiles.forEach(function(filename) {
758+
ruleFiles.forEach(filename => {
767759
const basename = path.basename(filename, ".js");
768760
const docFilename = `docs/rules/${basename}.md`;
769761

@@ -838,35 +830,27 @@ target.checkLicenses = function() {
838830
const licenses = dependency.licenses;
839831

840832
if (Array.isArray(licenses)) {
841-
return licenses.some(function(license) {
842-
return isPermissible({
843-
name: dependency.name,
844-
licenses: license
845-
});
846-
});
833+
return licenses.some(license => isPermissible({
834+
name: dependency.name,
835+
licenses: license
836+
}));
847837
}
848838

849-
return OPEN_SOURCE_LICENSES.some(function(license) {
850-
return license.test(licenses);
851-
});
839+
return OPEN_SOURCE_LICENSES.some(license => license.test(licenses));
852840
}
853841

854842
echo("Validating licenses");
855843

856844
checker.init({
857845
start: __dirname
858-
}, function(deps) {
859-
const impermissible = Object.keys(deps).map(function(dependency) {
860-
return {
861-
name: dependency,
862-
licenses: deps[dependency].licenses
863-
};
864-
}).filter(function(dependency) {
865-
return !isPermissible(dependency);
866-
});
846+
}, deps => {
847+
const impermissible = Object.keys(deps).map(dependency => ({
848+
name: dependency,
849+
licenses: deps[dependency].licenses
850+
})).filter(dependency => !isPermissible(dependency));
867851

868852
if (impermissible.length) {
869-
impermissible.forEach(function(dependency) {
853+
impermissible.forEach(dependency => {
870854
console.error("%s license for %s is impermissible.",
871855
dependency.licenses,
872856
dependency.name
@@ -960,9 +944,7 @@ function createConfigForPerformanceTest() {
960944

961945
content.push.apply(
962946
content,
963-
ls("lib/rules").map(function(fileName) {
964-
return ` ${path.basename(fileName, ".js")}: 1`;
965-
})
947+
ls("lib/rules").map(fileName => ` ${path.basename(fileName, ".js")}: 1`)
966948
);
967949

968950
content.join("\n").to(PERF_ESLINTRC);
@@ -981,7 +963,7 @@ function createConfigForPerformanceTest() {
981963
function time(cmd, runs, runNumber, results, cb) {
982964
const start = process.hrtime();
983965

984-
exec(cmd, { silent: true }, function(code, stdout, stderr) {
966+
exec(cmd, { silent: true }, (code, stdout, stderr) => {
985967
const diff = process.hrtime(start),
986968
actual = (diff[0] * 1e3 + diff[1] / 1e6); // ms
987969

@@ -1026,14 +1008,12 @@ function runPerformanceTest(title, targets, multiplier, cb) {
10261008
echo(title);
10271009
echo(" CPU Speed is %d with multiplier %d", cpuSpeed, multiplier);
10281010

1029-
time(cmd, 5, 1, [], function(results) {
1011+
time(cmd, 5, 1, [], results => {
10301012
if (!results || results.length === 0) { // No results? Something is wrong.
10311013
throw new Error("Performance test failed.");
10321014
}
10331015

1034-
results.sort(function(a, b) {
1035-
return a - b;
1036-
});
1016+
results.sort((a, b) => a - b);
10371017

10381018
const median = results[~~(results.length / 2)];
10391019

@@ -1068,9 +1048,7 @@ function loadPerformance() {
10681048
results.push(loadPerfData.loadTime);
10691049
}
10701050

1071-
results.sort(function(a, b) {
1072-
return a - b;
1073-
});
1051+
results.sort((a, b) => a - b);
10741052
const median = results[~~(results.length / 2)];
10751053

10761054
echo("");
@@ -1079,7 +1057,7 @@ function loadPerformance() {
10791057
}
10801058

10811059
target.perf = function() {
1082-
downloadMultifilesTestTarget(function() {
1060+
downloadMultifilesTestTarget(() => {
10831061
createConfigForPerformanceTest();
10841062

10851063
loadPerformance();
@@ -1088,7 +1066,7 @@ target.perf = function() {
10881066
"Single File:",
10891067
"tests/performance/jshint.js",
10901068
PERF_MULTIPLIER,
1091-
function() {
1069+
() => {
10921070

10931071
// Count test target files.
10941072
const count = glob.sync(
@@ -1101,7 +1079,7 @@ target.perf = function() {
11011079
`Multi Files (${count} files):`,
11021080
PERF_MULTIFILES_TARGETS,
11031081
3 * PERF_MULTIPLIER,
1104-
function() {}
1082+
() => {}
11051083
);
11061084
}
11071085
);

bin/eslint.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const concat = require("concat-stream"),
3636
// Execution
3737
//------------------------------------------------------------------------------
3838

39-
process.on("uncaughtException", function(err) {
39+
process.on("uncaughtException", err => {
4040

4141
// lazy load
4242
const lodash = require("lodash");
@@ -55,13 +55,13 @@ process.on("uncaughtException", function(err) {
5555
});
5656

5757
if (useStdIn) {
58-
process.stdin.pipe(concat({ encoding: "string" }, function(text) {
58+
process.stdin.pipe(concat({ encoding: "string" }, text => {
5959
process.exitCode = cli.execute(process.argv, text);
6060
}));
6161
} else if (init) {
6262
const configInit = require("../lib/config/config-initializer");
6363

64-
configInit.initializeConfig(function(err) {
64+
configInit.initializeConfig(err => {
6565
if (err) {
6666
process.exitCode = 1;
6767
console.error(err.message);

lib/ast-utils.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ function hasJSDocThisTag(node, sourceCode) {
176176
// because callbacks don't have its JSDoc comment.
177177
// e.g.
178178
// sinon.test(/* @this sinon.Sandbox */function() { this.spy(); });
179-
return sourceCode.getComments(node).leading.some(function(comment) {
180-
return thisTagPattern.test(comment.value);
181-
});
179+
return sourceCode.getComments(node).leading.some(comment => thisTagPattern.test(comment.value));
182180
}
183181

184182
/**

lib/cli-engine.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const debug = require("debug")("eslint:cli-engine");
9090
* @private
9191
*/
9292
function calculateStatsPerFile(messages) {
93-
return messages.reduce(function(stat, message) {
93+
return messages.reduce((stat, message) => {
9494
if (message.fatal || message.severity === 2) {
9595
stat.errorCount++;
9696
} else {
@@ -110,7 +110,7 @@ function calculateStatsPerFile(messages) {
110110
* @private
111111
*/
112112
function calculateStatsPerRun(results) {
113-
return results.reduce(function(stat, result) {
113+
return results.reduce((stat, result) => {
114114
stat.errorCount += result.errorCount;
115115
stat.warningCount += result.warningCount;
116116
return stat;
@@ -241,7 +241,7 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
241241
const parsedBlocks = processor.preprocess(text, filename);
242242
const unprocessedMessages = [];
243243

244-
parsedBlocks.forEach(function(block) {
244+
parsedBlocks.forEach(block => {
245245
unprocessedMessages.push(eslint.verify(block, config, {
246246
filename,
247247
allowInlineConfig
@@ -466,15 +466,15 @@ function CLIEngine(options) {
466466
if (this.options.rulePaths) {
467467
const cwd = this.options.cwd;
468468

469-
this.options.rulePaths.forEach(function(rulesdir) {
469+
this.options.rulePaths.forEach(rulesdir => {
470470
debug(`Loading rules from ${rulesdir}`);
471471
rules.load(rulesdir, cwd);
472472
});
473473
}
474474

475-
Object.keys(this.options.rules || {}).forEach(function(name) {
475+
Object.keys(this.options.rules || {}).forEach(name => {
476476
validator.validateRuleOptions(name, this.options.rules[name], "CLI");
477-
}.bind(this));
477+
});
478478
}
479479

480480
/**
@@ -526,7 +526,7 @@ CLIEngine.getFormatter = function(format) {
526526
CLIEngine.getErrorResults = function(results) {
527527
const filtered = [];
528528

529-
results.forEach(function(result) {
529+
results.forEach(result => {
530530
const filteredMessages = result.messages.filter(isErrorMessage);
531531

532532
if (filteredMessages.length > 0) {
@@ -549,9 +549,7 @@ CLIEngine.getErrorResults = function(results) {
549549
* @returns {void}
550550
*/
551551
CLIEngine.outputFixes = function(report) {
552-
report.results.filter(function(result) {
553-
return result.hasOwnProperty("output");
554-
}).forEach(function(result) {
552+
report.results.filter(result => result.hasOwnProperty("output")).forEach(result => {
555553
fs.writeFileSync(result.filePath, result.output);
556554
});
557555
};
@@ -708,7 +706,7 @@ CLIEngine.prototype = {
708706
patterns = this.resolveFileGlobPatterns(patterns);
709707
const fileList = globUtil.listFilesToProcess(patterns, options);
710708

711-
fileList.forEach(function(fileInfo) {
709+
fileList.forEach(fileInfo => {
712710
executeOnFile(fileInfo.filename, fileInfo.ignored);
713711
});
714712

lib/code-path-analysis/debug-helpers.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ module.exports = {
108108
}
109109

110110
if (segment.internal.nodes.length > 0) {
111-
text += segment.internal.nodes.map(function(node) {
111+
text += segment.internal.nodes.map(node => {
112112
switch (node.type) {
113113
case "Identifier": return `${node.type} (${node.name})`;
114114
case "Literal": return `${node.type} (${node.value})`;
115115
default: return node.type;
116116
}
117117
}).join("\\n");
118118
} else if (segment.internal.exitNodes.length > 0) {
119-
text += segment.internal.exitNodes.map(function(node) {
119+
text += segment.internal.exitNodes.map(node => {
120120
switch (node.type) {
121121
case "Identifier": return `${node.type}:exit (${node.name})`;
122122
case "Literal": return `${node.type}:exit (${node.value})`;
@@ -176,7 +176,7 @@ module.exports = {
176176
stack.push([nextSegment, 0]);
177177
}
178178

179-
codePath.returnedSegments.forEach(function(finalSegment) {
179+
codePath.returnedSegments.forEach(finalSegment => {
180180
if (lastId === finalSegment.id) {
181181
text += "->final";
182182
} else {
@@ -185,7 +185,7 @@ module.exports = {
185185
lastId = null;
186186
});
187187

188-
codePath.thrownSegments.forEach(function(finalSegment) {
188+
codePath.thrownSegments.forEach(finalSegment => {
189189
if (lastId === finalSegment.id) {
190190
text += "->thrown";
191191
} else {

lib/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ function Config(options) {
197197

198198
this.useEslintrc = (options.useEslintrc !== false);
199199

200-
this.env = (options.envs || []).reduce(function(envs, name) {
200+
this.env = (options.envs || []).reduce((envs, name) => {
201201
envs[name] = true;
202202
return envs;
203203
}, {});
@@ -208,7 +208,7 @@ function Config(options) {
208208
* whether global is writable.
209209
* If user declares "foo", convert to "foo:false".
210210
*/
211-
this.globals = (options.globals || []).reduce(function(globals, def) {
211+
this.globals = (options.globals || []).reduce((globals, def) => {
212212
const parts = def.split(":");
213213

214214
globals[parts[0]] = (parts.length > 1 && parts[1] === "true");

0 commit comments

Comments
 (0)