Skip to content

Commit 580ae56

Browse files
TrottBridgeAR
authored andcommitted
tools: refactor tools JS code
* standardize on arrow functions for callbacks * standaradize on trailing commas for multiline arrays PR-URL: #26394 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Masashi Hirano <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 61baa45 commit 580ae56

File tree

8 files changed

+17
-29
lines changed

8 files changed

+17
-29
lines changed

Diff for: tools/doc/addon-verify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ ${files[name].replace(
8181
target_name: 'addon',
8282
sources: files.map(({ name }) => name),
8383
includes: ['../common.gypi'],
84-
}
84+
},
8585
]
8686
})
8787
});

Diff for: tools/doc/generate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ let nodeVersion = null;
4141
let outputDir = null;
4242
let apilinks = {};
4343

44-
args.forEach(function(arg) {
44+
args.forEach((arg) => {
4545
if (!arg.startsWith('--')) {
4646
filename = arg;
4747
} else if (arg.startsWith('--node-version=')) {

Diff for: tools/doc/html.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ function altDocs(filename, docCreated) {
413413
{ num: '5.x' },
414414
{ num: '4.x' },
415415
{ num: '0.12.x' },
416-
{ num: '0.10.x' }
416+
{ num: '0.10.x' },
417417
];
418418

419419
const getHref = (versionNum) =>

Diff for: tools/eslint-rules/required-modules.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ module.exports = function(context) {
7171
'Program:exit'(node) {
7272
if (foundModules.length < requiredModules.length) {
7373
var missingModules = requiredModules.filter(
74-
function(module) {
75-
return foundModules.indexOf(module) === -1;
76-
}
74+
(module) => foundModules.indexOf(module) === -1
7775
);
78-
missingModules.forEach(function(moduleName) {
76+
missingModules.forEach((moduleName) => {
7977
context.report(
8078
node,
8179
'Mandatory module "{{moduleName}}" must be loaded.',

Diff for: tools/eslint-rules/rules-utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module.exports.inSkipBlock = function(node) {
6969
node.test.operator === '!') {
7070
const consequent = node.consequent;
7171
if (consequent.body) {
72-
consequent.body.some(function(expressionStatement) {
72+
consequent.body.some((expressionStatement) => {
7373
if (hasSkip(expressionStatement.expression)) {
7474
return hasSkipBlock = true;
7575
}

Diff for: tools/license2rtf.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,12 @@ function rtfEscape(string) {
222222
}
223223

224224
return string
225-
.replace(/[\\{}]/g, function(m) {
226-
return `\\${m}`;
227-
})
228-
.replace(/\t/g, function() {
229-
return '\\tab ';
230-
})
225+
.replace(/[\\{}]/g, (m) => `\\${m}`)
226+
.replace(/\t/g, () => '\\tab ')
231227
// eslint-disable-next-line no-control-regex
232-
.replace(/[\x00-\x1f\x7f-\xff]/g, function(m) {
233-
return `\\'${toHex(m.charCodeAt(0), 2)}`;
234-
})
228+
.replace(/[\x00-\x1f\x7f-\xff]/g, (m) => `\\'${toHex(m.charCodeAt(0), 2)}`)
235229
.replace(/\ufeff/g, '')
236-
.replace(/[\u0100-\uffff]/g, function(m) {
237-
return `\\u${toHex(m.charCodeAt(0), 4)}?`;
238-
});
230+
.replace(/[\u0100-\uffff]/g, (m) => `\\u${toHex(m.charCodeAt(0), 4)}?`);
239231
}
240232

241233
/*

Diff for: tools/lint-js.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ if (cluster.isMaster) {
8686
outFn = function(str) {
8787
fs.writeSync(fd, str, 'utf8');
8888
};
89-
process.on('exit', function() {
90-
fs.closeSync(fd);
91-
});
89+
process.on('exit', () => { fs.closeSync(fd); });
9290
} else {
9391
outFn = function(str) {
9492
process.stdout.write(str);
@@ -117,20 +115,20 @@ if (cluster.isMaster) {
117115

118116
if (showProgress) {
119117
// Start the progress display update timer when the first worker is ready
120-
cluster.once('online', function() {
118+
cluster.once('online', () => {
121119
startTime = process.hrtime();
122120
setInterval(printProgress, 1000).unref();
123121
printProgress();
124122
});
125123
}
126124

127-
cluster.on('online', function(worker) {
125+
cluster.on('online', (worker) => {
128126
// Configure worker and give it some initial work to do
129127
worker.send(workerConfig);
130128
sendWork(worker);
131129
});
132130

133-
process.on('exit', function(code) {
131+
process.on('exit', (code) => {
134132
if (showProgress) {
135133
curPath = 'Done';
136134
printProgress();
@@ -232,7 +230,7 @@ if (cluster.isMaster) {
232230
// Worker
233231

234232
var config = {};
235-
process.on('message', function(files) {
233+
process.on('message', (files) => {
236234
if (files instanceof Array) {
237235
// Lint some files
238236
const report = cli.executeOnFiles(files);

Diff for: tools/node-lint-md-cli-rollup/src/cli-entry.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const args = {
1414
description: cli.description,
1515
version: [
1616
proc.name + ': ' + proc.version,
17-
cli.name + ': ' + cli.version
17+
cli.name + ': ' + cli.version,
1818
].join(', '),
1919
ignoreName: '.' + proc.name + 'ignore',
2020
extensions: extensions
@@ -23,7 +23,7 @@ const config = options(process.argv.slice(2), args);
2323
config.detectConfig = false;
2424
config.plugins = plugins;
2525

26-
engine(config, function done(err, code) {
26+
engine(config, (err, code) => {
2727
if (err) console.error(err);
2828
process.exit(code);
2929
});

0 commit comments

Comments
 (0)