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 <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>
1 parent 61baa45 commit 580ae56

8 files changed

Lines changed: 17 additions & 29 deletions

File tree

‎tools/doc/addon-verify.js‎

Lines changed: 1 addition & 1 deletion
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
});

‎tools/doc/generate.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ let nodeVersion = null;
4141
letoutputDir=null;
4242
letapilinks={};
4343

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

‎tools/doc/html.js‎

Lines changed: 1 addition & 1 deletion
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
constgetHref=(versionNum)=>

‎tools/eslint-rules/required-modules.js‎

Lines changed: 2 additions & 4 deletions
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
varmissingModules=requiredModules.filter(
74-
function(module){
75-
returnfoundModules.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.',

‎tools/eslint-rules/rules-utils.js‎

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

‎tools/license2rtf.js‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,12 @@ function rtfEscape(string) {
222222
}
223223

224224
returnstring
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
/*

‎tools/lint-js.js‎

Lines changed: 5 additions & 7 deletions
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
varconfig={};
235-
process.on('message',function(files){
233+
process.on('message',(files)=>{
236234
if(filesinstanceofArray){
237235
// Lint some files
238236
constreport=cli.executeOnFiles(files);

‎tools/node-lint-md-cli-rollup/src/cli-entry.js‎

Lines changed: 2 additions & 2 deletions
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,functiondone(err,code){
26+
engine(config,(err,code)=>{
2727
if(err)console.error(err);
2828
process.exit(code);
2929
});

0 commit comments

Comments
 (0)