-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
Replaced string concats with template literals #15858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,12 +16,11 @@ const glob = require('./eslint/node_modules/glob'); | |
| const cwd = process.cwd(); | ||
| const cliOptions = { | ||
| rulePaths: rulesDirs, | ||
| extensions: extensions, | ||
| extensions: extensions | ||
| }; | ||
|
|
||
| // Check if we should fix errors that are fixable | ||
| if (process.argv.indexOf('-F') !== -1) | ||
| cliOptions.fix = true; | ||
| if (process.argv.indexOf('-F') !== -1) cliOptions.fix = true; | ||
|
|
||
| const cli = new CLIEngine(cliOptions); | ||
|
|
||
|
|
@@ -46,14 +45,12 @@ if (cluster.isMaster) { | |
| var i; | ||
|
|
||
| // Check if spreading work among all cores/cpus | ||
| if (process.argv.indexOf('-J') !== -1) | ||
| numCPUs = totalCPUs; | ||
| if (process.argv.indexOf('-J') !== -1) numCPUs = totalCPUs; | ||
|
|
||
| // Check if spreading work among an explicit number of cores/cpus | ||
| i = process.argv.indexOf('-j'); | ||
| if (i !== -1) { | ||
| if (!process.argv[i + 1]) | ||
| throw new Error('Missing parallel job count'); | ||
| if (!process.argv[i + 1]) throw new Error('Missing parallel job count'); | ||
| numCPUs = parseInt(process.argv[i + 1], 10); | ||
| if (!isFinite(numCPUs) || numCPUs <= 0) | ||
| throw new Error('Bad parallel job count'); | ||
|
|
@@ -62,12 +59,10 @@ if (cluster.isMaster) { | |
| // Check for custom ESLint report formatter | ||
| i = process.argv.indexOf('-f'); | ||
| if (i !== -1) { | ||
| if (!process.argv[i + 1]) | ||
| throw new Error('Missing format name'); | ||
| if (!process.argv[i + 1]) throw new Error('Missing format name'); | ||
| const format = process.argv[i + 1]; | ||
| formatter = cli.getFormatter(format); | ||
| if (!formatter) | ||
| throw new Error('Invalid format name'); | ||
| if (!formatter) throw new Error('Invalid format name'); | ||
| // Automatically disable progress display | ||
| showProgress = false; | ||
| // Tell worker to send all results, not just linter errors | ||
|
|
@@ -80,11 +75,9 @@ if (cluster.isMaster) { | |
| // Check if outputting ESLint report to a file instead of stdout | ||
| i = process.argv.indexOf('-o'); | ||
| if (i !== -1) { | ||
| if (!process.argv[i + 1]) | ||
| throw new Error('Missing output filename'); | ||
| if (!process.argv[i + 1]) throw new Error('Missing output filename'); | ||
| var outPath = process.argv[i + 1]; | ||
| if (!path.isAbsolute(outPath)) | ||
| outPath = path.join(cwd, outPath); | ||
| if (!path.isAbsolute(outPath)) outPath = path.join(cwd, outPath); | ||
| fd = fs.openSync(outPath, 'w'); | ||
| outFn = function(str) { | ||
| fs.writeSync(fd, str, 'utf8'); | ||
|
|
@@ -114,8 +107,7 @@ if (cluster.isMaster) { | |
| paths.push(process.argv[i]); | ||
| } | ||
|
|
||
| if (paths.length === 0) | ||
| return; | ||
| if (paths.length === 0) return; | ||
| totalPaths = paths.length; | ||
|
|
||
| if (showProgress) { | ||
|
|
@@ -139,12 +131,14 @@ if (cluster.isMaster) { | |
| printProgress(); | ||
| outFn('\r\n'); | ||
| } | ||
| if (code === 0) | ||
| process.exit(failures ? 1 : 0); | ||
| if (code === 0) process.exit(failures ? 1 : 0); | ||
|
||
| }); | ||
|
|
||
| for (i = 0; i < numCPUs; ++i) | ||
| cluster.fork().on('message', onWorkerMessage).on('exit', onWorkerExit); | ||
| cluster | ||
| .fork() | ||
| .on('message', onWorkerMessage) | ||
| .on('exit', onWorkerExit); | ||
|
|
||
| function onWorkerMessage(results) { | ||
| if (typeof results !== 'number') { | ||
|
|
@@ -155,7 +149,7 @@ if (cluster.isMaster) { | |
| } else { | ||
| failures += results.length; | ||
| } | ||
| outFn(formatter(results) + '\r\n'); | ||
| outFn(`${formatter(results)}\r\n`); | ||
| printProgress(); | ||
| } else { | ||
| successes += results; | ||
|
|
@@ -165,8 +159,7 @@ if (cluster.isMaster) { | |
| } | ||
|
|
||
| function onWorkerExit(code, signal) { | ||
| if (code !== 0 || signal) | ||
| process.exit(2); | ||
| if (code !== 0 || signal) process.exit(2); | ||
| } | ||
|
|
||
| function sendWork(worker) { | ||
|
|
@@ -176,13 +169,11 @@ if (cluster.isMaster) { | |
| while (paths.length) { | ||
| var dir = paths.shift(); | ||
| curPath = dir; | ||
| if (dir.indexOf('/') > 0) | ||
| dir = path.join(cwd, dir); | ||
| if (dir.indexOf('/') > 0) dir = path.join(cwd, dir); | ||
| const patterns = cli.resolveFileGlobPatterns([dir]); | ||
| dir = path.resolve(patterns[0]); | ||
| files = glob.sync(dir, globOptions); | ||
| if (files.length) | ||
| break; | ||
| if (files.length) break; | ||
| } | ||
| if ((!files || !files.length) && !paths.length) { | ||
| // We exhausted all input paths and thus have nothing left to do, so end | ||
|
|
@@ -207,26 +198,24 @@ if (cluster.isMaster) { | |
| } | ||
|
|
||
| function printProgress() { | ||
| if (!showProgress) | ||
| return; | ||
| if (!showProgress) return; | ||
|
|
||
| // Clear line | ||
| outFn('\r' + ' '.repeat(lastLineLen) + '\r'); | ||
| outFn(`\r ${' '.repeat(lastLineLen)}\r`); | ||
|
|
||
| // Calculate and format the data for displaying | ||
| const elapsed = process.hrtime(startTime)[0]; | ||
| const mins = padString(Math.floor(elapsed / 60), 2, '0'); | ||
| const secs = padString(elapsed % 60, 2, '0'); | ||
| const passed = padString(successes, 6, ' '); | ||
| const failed = padString(failures, 6, ' '); | ||
| var pct = Math.ceil(((totalPaths - paths.length) / totalPaths) * 100); | ||
| var pct = Math.ceil((totalPaths - paths.length) / totalPaths * 100); | ||
|
||
| pct = padString(pct, 3, ' '); | ||
|
|
||
| var line = `[${mins}:${secs}|%${pct}|+${passed}|-${failed}]: ${curPath}`; | ||
|
|
||
| // Truncate line like cpplint does in case it gets too long | ||
| if (line.length > 75) | ||
| line = line.slice(0, 75) + '...'; | ||
| if (line.length > 75) line = `${line.slice(0, 75)}...`; | ||
|
|
||
| // Store the line length so we know how much to erase the next time around | ||
| lastLineLen = line.length; | ||
|
|
@@ -235,9 +224,8 @@ if (cluster.isMaster) { | |
| } | ||
|
|
||
| function padString(str, len, chr) { | ||
| str = '' + str; | ||
| if (str.length >= len) | ||
| return str; | ||
| str = `${str}`; | ||
| if (str.length >= len) return str; | ||
| return chr.repeat(len - str.length) + str; | ||
| } | ||
| } else { | ||
|
|
@@ -250,8 +238,7 @@ if (cluster.isMaster) { | |
| const report = cli.executeOnFiles(files); | ||
|
|
||
| // If we were asked to fix the fixable issues, do so. | ||
| if (cliOptions.fix) | ||
| CLIEngine.outputFixes(report); | ||
| if (cliOptions.fix) CLIEngine.outputFixes(report); | ||
|
|
||
| if (config.sendAll) { | ||
| // Return both success and error results | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 I think these kinds of changes make things less readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I apologize I think prettier made these changes automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok. There are other instances of this in this file that should also be reverted.