tools: refactor tools JS code

* standardize on arrow functions for callbacks
* standaradize on trailing commas for multiline arrays

PR-URL: https://github.com/nodejs/node/pull/26394
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Masashi Hirano <shisama07@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Rich Trott 2019-03-01 22:47:47 -08:00
parent c7e628f8b3
commit 5fa642a917
8 changed files with 17 additions and 29 deletions

View File

@ -81,7 +81,7 @@ ${files[name].replace(
target_name: 'addon', target_name: 'addon',
sources: files.map(({ name }) => name), sources: files.map(({ name }) => name),
includes: ['../common.gypi'], includes: ['../common.gypi'],
} },
] ]
}) })
}); });

View File

@ -41,7 +41,7 @@ let nodeVersion = null;
let outputDir = null; let outputDir = null;
let apilinks = {}; let apilinks = {};
args.forEach(function(arg) { args.forEach((arg) => {
if (!arg.startsWith('--')) { if (!arg.startsWith('--')) {
filename = arg; filename = arg;
} else if (arg.startsWith('--node-version=')) { } else if (arg.startsWith('--node-version=')) {

View File

@ -413,7 +413,7 @@ function altDocs(filename, docCreated) {
{ num: '5.x' }, { num: '5.x' },
{ num: '4.x' }, { num: '4.x' },
{ num: '0.12.x' }, { num: '0.12.x' },
{ num: '0.10.x' } { num: '0.10.x' },
]; ];
const getHref = (versionNum) => const getHref = (versionNum) =>

View File

@ -71,11 +71,9 @@ module.exports = function(context) {
'Program:exit'(node) { 'Program:exit'(node) {
if (foundModules.length < requiredModules.length) { if (foundModules.length < requiredModules.length) {
var missingModules = requiredModules.filter( var missingModules = requiredModules.filter(
function(module) { (module) => foundModules.indexOf(module) === -1
return foundModules.indexOf(module) === -1;
}
); );
missingModules.forEach(function(moduleName) { missingModules.forEach((moduleName) => {
context.report( context.report(
node, node,
'Mandatory module "{{moduleName}}" must be loaded.', 'Mandatory module "{{moduleName}}" must be loaded.',

View File

@ -69,7 +69,7 @@ module.exports.inSkipBlock = function(node) {
node.test.operator === '!') { node.test.operator === '!') {
const consequent = node.consequent; const consequent = node.consequent;
if (consequent.body) { if (consequent.body) {
consequent.body.some(function(expressionStatement) { consequent.body.some((expressionStatement) => {
if (hasSkip(expressionStatement.expression)) { if (hasSkip(expressionStatement.expression)) {
return hasSkipBlock = true; return hasSkipBlock = true;
} }

View File

@ -222,20 +222,12 @@ function rtfEscape(string) {
} }
return string return string
.replace(/[\\{}]/g, function(m) { .replace(/[\\{}]/g, (m) => `\\${m}`)
return `\\${m}`; .replace(/\t/g, () => '\\tab ')
})
.replace(/\t/g, function() {
return '\\tab ';
})
// eslint-disable-next-line no-control-regex // eslint-disable-next-line no-control-regex
.replace(/[\x00-\x1f\x7f-\xff]/g, function(m) { .replace(/[\x00-\x1f\x7f-\xff]/g, (m) => `\\'${toHex(m.charCodeAt(0), 2)}`)
return `\\'${toHex(m.charCodeAt(0), 2)}`;
})
.replace(/\ufeff/g, '') .replace(/\ufeff/g, '')
.replace(/[\u0100-\uffff]/g, function(m) { .replace(/[\u0100-\uffff]/g, (m) => `\\u${toHex(m.charCodeAt(0), 4)}?`);
return `\\u${toHex(m.charCodeAt(0), 4)}?`;
});
} }
/* /*

View File

@ -86,9 +86,7 @@ if (cluster.isMaster) {
outFn = function(str) { outFn = function(str) {
fs.writeSync(fd, str, 'utf8'); fs.writeSync(fd, str, 'utf8');
}; };
process.on('exit', function() { process.on('exit', () => { fs.closeSync(fd); });
fs.closeSync(fd);
});
} else { } else {
outFn = function(str) { outFn = function(str) {
process.stdout.write(str); process.stdout.write(str);
@ -117,20 +115,20 @@ if (cluster.isMaster) {
if (showProgress) { if (showProgress) {
// Start the progress display update timer when the first worker is ready // Start the progress display update timer when the first worker is ready
cluster.once('online', function() { cluster.once('online', () => {
startTime = process.hrtime(); startTime = process.hrtime();
setInterval(printProgress, 1000).unref(); setInterval(printProgress, 1000).unref();
printProgress(); printProgress();
}); });
} }
cluster.on('online', function(worker) { cluster.on('online', (worker) => {
// Configure worker and give it some initial work to do // Configure worker and give it some initial work to do
worker.send(workerConfig); worker.send(workerConfig);
sendWork(worker); sendWork(worker);
}); });
process.on('exit', function(code) { process.on('exit', (code) => {
if (showProgress) { if (showProgress) {
curPath = 'Done'; curPath = 'Done';
printProgress(); printProgress();
@ -232,7 +230,7 @@ if (cluster.isMaster) {
// Worker // Worker
var config = {}; var config = {};
process.on('message', function(files) { process.on('message', (files) => {
if (files instanceof Array) { if (files instanceof Array) {
// Lint some files // Lint some files
const report = cli.executeOnFiles(files); const report = cli.executeOnFiles(files);

View File

@ -14,7 +14,7 @@ const args = {
description: cli.description, description: cli.description,
version: [ version: [
proc.name + ': ' + proc.version, proc.name + ': ' + proc.version,
cli.name + ': ' + cli.version cli.name + ': ' + cli.version,
].join(', '), ].join(', '),
ignoreName: '.' + proc.name + 'ignore', ignoreName: '.' + proc.name + 'ignore',
extensions: extensions extensions: extensions
@ -23,7 +23,7 @@ const config = options(process.argv.slice(2), args);
config.detectConfig = false; config.detectConfig = false;
config.plugins = plugins; config.plugins = plugins;
engine(config, function done(err, code) { engine(config, (err, code) => {
if (err) console.error(err); if (err) console.error(err);
process.exit(code); process.exit(code);
}); });