Skip to content
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

Replaced string concats with template literals #15858

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 25 additions & 38 deletions tools/lint-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.


const cli = new CLIEngine(cliOptions);

Expand All @@ -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');
Expand All @@ -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
Expand All @@ -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');
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One here yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About to board my plane so other edits will have to wait until I get home (unless my plane has internet).

});

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') {
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the added parentheses so the order of operations is immediately clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another prettier auto-change. My mistake.

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;
Expand All @@ -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 {
Expand All @@ -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
Expand Down