Skip to content

Commit a180259

Browse files
committed
test,lib,doc: use function declarations
Replace function expressions with function declarations in preparation for a lint rule requiring function declarations. PR-URL: #12711 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
1 parent dd20e68 commit a180259

39 files changed

+127
-131
lines changed

doc/api/util.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ Returns `true` if the given `object` is a `Function`. Otherwise, returns
592592
const util = require('util');
593593

594594
function Foo() {}
595-
const Bar = function() {};
595+
const Bar = () => {};
596596

597597
util.isFunction({});
598598
// Returns: false

lib/_tls_legacy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,9 @@ CryptoStream.prototype.destroySoon = function(err) {
448448
// was written on this side was read from the other side.
449449
var self = this;
450450
var waiting = 1;
451-
var finish = function() {
451+
function finish() {
452452
if (--waiting === 0) self.destroy();
453-
};
453+
}
454454
this._opposite.once('end', finish);
455455
if (!this._finished) {
456456
this.once('finish', finish);

lib/crypto.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,11 @@ function pbkdf2(password, salt, iterations, keylen, digest, callback) {
645645
// at this point, we need to handle encodings.
646646
var encoding = exports.DEFAULT_ENCODING;
647647
if (callback) {
648-
var next = function(er, ret) {
648+
function next(er, ret) {
649649
if (ret)
650650
ret = ret.toString(encoding);
651651
callback(er, ret);
652-
};
652+
}
653653
binding.PBKDF2(password, salt, iterations, keylen, digest, next);
654654
} else {
655655
var ret = binding.PBKDF2(password, salt, iterations, keylen, digest);

lib/internal/util.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ function cachedResult(fn) {
143143
// B() instanceof A // true
144144
// B() instanceof B // true
145145
function createClassWrapper(type) {
146-
const fn = function(...args) {
146+
function fn(...args) {
147147
return Reflect.construct(type, args, new.target || type);
148-
};
148+
}
149149
// Mask the wrapper function name and length values
150150
Object.defineProperties(fn, {
151151
name: {value: type.name},

test/addons-napi/test_async/test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const test_async = require(`./build/${common.buildType}/test_async`);
66
test_async.Test(5, common.mustCall(function(err, val) {
77
assert.strictEqual(err, null);
88
assert.strictEqual(val, 10);
9-
process.nextTick(common.mustCall(function() {}));
9+
process.nextTick(common.mustCall());
1010
}));
1111

12-
const cancelSuceeded = function() {};
13-
test_async.TestCancel(common.mustCall(cancelSuceeded));
12+
test_async.TestCancel(common.mustCall());

test/addons-napi/test_exception/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ const common = require('../../common');
44
const test_exception = require(`./build/${common.buildType}/test_exception`);
55
const assert = require('assert');
66
const theError = new Error('Some error');
7-
const throwTheError = function() {
7+
function throwTheError() {
88
throw theError;
9-
};
9+
}
1010
let caughtError;
1111

12-
const throwNoError = function() {};
12+
const throwNoError = common.noop;
1313

1414
// Test that the native side successfully captures the exception
1515
let returnedError = test_exception.returnException(throwTheError);

test/addons-napi/test_instanceof/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ if (typeof Symbol !== 'undefined' && 'hasInstance' in Symbol &&
5757
(theObject instanceof theConstructor));
5858
}
5959

60-
const MyClass = function MyClass() {};
60+
function MyClass() {}
6161
Object.defineProperty(MyClass, Symbol.hasInstance, {
6262
value: function(candidate) {
6363
return 'mark' in candidate;
6464
}
6565
});
6666

67-
const MySubClass = function MySubClass() {};
67+
function MySubClass() {}
6868
MySubClass.prototype = new MyClass();
6969

7070
let x = new MySubClass();

test/addons/make-callback/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ const forward = vm.runInNewContext(`
5757
})
5858
`);
5959
// Runs in outer context.
60-
const endpoint = function($Object) {
60+
function endpoint($Object) {
6161
if (Object === $Object)
6262
throw new Error('bad');
6363
return Object;
64-
};
64+
}
6565
assert.strictEqual(Object, makeCallback(process, forward, endpoint));

test/inspector/inspector-helper.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function timeout(message, multiplicator) {
122122
TIMEOUT * (multiplicator || 1));
123123
}
124124

125-
const TestSession = function(socket, harness) {
125+
function TestSession(socket, harness) {
126126
this.mainScriptPath = harness.mainScriptPath;
127127
this.mainScriptId = null;
128128

@@ -147,7 +147,7 @@ const TestSession = function(socket, harness) {
147147
buffer = buffer.slice(consumed);
148148
} while (consumed);
149149
}).on('close', () => assert(this.expectClose_, 'Socket closed prematurely'));
150-
};
150+
}
151151

152152
TestSession.prototype.scriptUrlForId = function(id) {
153153
return this.scripts_[id];
@@ -304,7 +304,7 @@ TestSession.prototype.testHttpResponse = function(path, check) {
304304
};
305305

306306

307-
const Harness = function(port, childProcess) {
307+
function Harness(port, childProcess) {
308308
this.port = port;
309309
this.mainScriptPath = mainScript;
310310
this.stderrFilters_ = [];
@@ -329,7 +329,7 @@ const Harness = function(port, childProcess) {
329329
this.returnCode_ = code;
330330
this.running_ = false;
331331
});
332-
};
332+
}
333333

334334
Harness.prototype.addStderrFilter = function(regexp, callback) {
335335
this.stderrFilters_.push((message) => {

test/parallel/test-assert.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ a.throws(makeBlock(thrower, TypeError), function(err) {
449449

450450
AnotherErrorType = class extends Error {};
451451

452-
const functionThatThrows = function() {
452+
const functionThatThrows = () => {
453453
throw new AnotherErrorType('foo');
454454
};
455455

@@ -493,6 +493,7 @@ a.throws(makeBlock(a.deepEqual, args, []));
493493

494494
// more checking that arguments objects are handled correctly
495495
{
496+
// eslint-disable-next-line func-style
496497
const returnArguments = function() { return arguments; };
497498

498499
const someArgs = returnArguments('a');

test/parallel/test-child-process-fork-dgram.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ if (process.argv[2] === 'child') {
7878
});
7979
});
8080

81-
const sendMessages = function() {
81+
function sendMessages() {
8282
const serverPort = parentServer.address().port;
8383

8484
const timer = setInterval(function() {
@@ -102,7 +102,7 @@ if (process.argv[2] === 'child') {
102102
);
103103
}
104104
}, 1);
105-
};
105+
}
106106

107107
parentServer.bind(0, '127.0.0.1');
108108

test/parallel/test-child-process-fork-net.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ if (process.argv[2] === 'child') {
8787
}));
8888

8989
// send net.Server to child and test by connecting
90-
const testServer = function(callback) {
90+
function testServer(callback) {
9191

9292
// destroy server execute callback when done
9393
const progress = new ProgressTracker(2, function() {
@@ -116,7 +116,7 @@ if (process.argv[2] === 'child') {
116116
server.listen(0);
117117

118118
// handle client messages
119-
const messageHandlers = function(msg) {
119+
function messageHandlers(msg) {
120120

121121
if (msg.what === 'listening') {
122122
// make connections
@@ -138,13 +138,13 @@ if (process.argv[2] === 'child') {
138138
child.removeListener('message', messageHandlers);
139139
callback();
140140
}
141-
};
141+
}
142142

143143
child.on('message', messageHandlers);
144-
};
144+
}
145145

146146
// send net.Socket to child
147-
const testSocket = function(callback) {
147+
function testSocket(callback) {
148148

149149
// create a new server and connect to it,
150150
// but the socket will be handled by the child
@@ -179,7 +179,7 @@ if (process.argv[2] === 'child') {
179179
server.close();
180180
});
181181
});
182-
};
182+
}
183183

184184
// create server and send it to child
185185
let serverSuccess = false;

test/parallel/test-child-process-fork-net2.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ if (process.argv[2] === 'child') {
144144

145145
server.listen(0, '127.0.0.1');
146146

147-
const closeServer = function() {
147+
function closeServer() {
148148
server.close();
149149

150150
setTimeout(function() {
@@ -153,7 +153,7 @@ if (process.argv[2] === 'child') {
153153
child2.send('close');
154154
child3.disconnect();
155155
}, 200);
156-
};
156+
}
157157

158158
process.on('exit', function() {
159159
assert.strictEqual(disconnected, count);

test/parallel/test-child-process-spawn-typeerror.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ assert.throws(function() {
8989
// Argument types for combinatorics
9090
const a = [];
9191
const o = {};
92-
const c = function c() {};
92+
function c() {}
9393
const s = 'string';
9494
const u = undefined;
9595
const n = null;

test/parallel/test-cluster-disconnect.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if (cluster.isWorker) {
3838
const servers = 2;
3939

4040
// test a single TCP server
41-
const testConnection = function(port, cb) {
41+
const testConnection = (port, cb) => {
4242
const socket = net.connect(port, '127.0.0.1', () => {
4343
// buffer result
4444
let result = '';
@@ -52,7 +52,7 @@ if (cluster.isWorker) {
5252
};
5353

5454
// test both servers created in the cluster
55-
const testCluster = function(cb) {
55+
const testCluster = (cb) => {
5656
let done = 0;
5757

5858
for (let i = 0; i < servers; i++) {
@@ -67,7 +67,7 @@ if (cluster.isWorker) {
6767
};
6868

6969
// start two workers and execute callback when both is listening
70-
const startCluster = function(cb) {
70+
const startCluster = (cb) => {
7171
const workers = 8;
7272
let online = 0;
7373

@@ -81,7 +81,7 @@ if (cluster.isWorker) {
8181
}
8282
};
8383

84-
const test = function(again) {
84+
const test = (again) => {
8585
//1. start cluster
8686
startCluster(common.mustCall(() => {
8787
//2. test cluster

test/parallel/test-cluster-master-error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ if (cluster.isWorker) {
101101
// Check that the cluster died accidentally (non-zero exit code)
102102
masterExited = !!code;
103103

104-
const pollWorkers = function() {
104+
const pollWorkers = () => {
105105
// When master is dead all workers should be dead too
106106
let alive = false;
107107
workers.forEach((pid) => alive = common.isAlive(pid));

test/parallel/test-cluster-master-kill.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ if (cluster.isWorker) {
6868
assert.strictEqual(code, 0);
6969

7070
// check worker process status
71-
const pollWorker = function() {
71+
const pollWorker = () => {
7272
alive = common.isAlive(pid);
7373
if (alive) {
7474
setTimeout(pollWorker, 50);

test/parallel/test-cluster-message.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ if (cluster.isWorker) {
8080

8181

8282
let client;
83-
const check = function(type, result) {
83+
const check = (type, result) => {
8484
checks[type].receive = true;
8585
checks[type].correct = result;
8686
console.error('check', checks);

test/parallel/test-cluster-worker-exit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ if (cluster.isWorker) {
103103
}
104104
}));
105105

106-
const finish_test = function() {
106+
const finish_test = () => {
107107
try {
108108
checkResults(expected_results, results);
109109
} catch (exc) {

test/parallel/test-console-not-call-toString.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
require('../common');
2424
const assert = require('assert');
2525

26-
const func = function() {};
26+
function func() {}
2727
let toStringCalled = false;
2828
func.toString = function() {
2929
toStringCalled = true;

test/parallel/test-event-emitter-add-listeners.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ const EventEmitter = require('events');
6868
}
6969

7070
{
71-
const listen1 = function listen1() {};
72-
const listen2 = function listen2() {};
71+
const listen1 = () => {};
72+
const listen2 = () => {};
7373
const ee = new EventEmitter();
7474

7575
ee.once('newListener', function() {

test/parallel/test-event-emitter-once.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ e.emit('hello', 'a', 'b');
3333
e.emit('hello', 'a', 'b');
3434
e.emit('hello', 'a', 'b');
3535

36-
const remove = function() {
36+
function remove() {
3737
assert.fail('once->foo should not be emitted');
38-
};
38+
}
3939

4040
e.once('foo', remove);
4141
e.removeListener('foo', remove);

test/parallel/test-fs-access.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const doesNotExist = path.join(common.tmpDir, '__this_should_not_exist');
77
const readOnlyFile = path.join(common.tmpDir, 'read_only_file');
88
const readWriteFile = path.join(common.tmpDir, 'read_write_file');
99

10-
const createFileWithPerms = function(file, mode) {
10+
function createFileWithPerms(file, mode) {
1111
fs.writeFileSync(file, '');
1212
fs.chmodSync(file, mode);
13-
};
13+
}
1414

1515
common.refreshTmpDir();
1616
createFileWithPerms(readOnlyFile, 0o444);

test/parallel/test-fs-link.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ const srcPath = path.join(common.tmpDir, 'hardlink-target.txt');
1111
const dstPath = path.join(common.tmpDir, 'link1.js');
1212
fs.writeFileSync(srcPath, 'hello world');
1313

14-
const callback = function(err) {
14+
function callback(err) {
1515
assert.ifError(err);
1616
const dstContent = fs.readFileSync(dstPath, 'utf8');
1717
assert.strictEqual('hello world', dstContent);
18-
};
18+
}
1919

2020
fs.link(srcPath, dstPath, common.mustCall(callback));
2121

test/parallel/test-fs-read-stream-fd-leak.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function testLeak(endFn, callback) {
2929
let i = 0;
3030
let check = 0;
3131

32-
const checkFunction = function() {
32+
function checkFunction() {
3333
if (openCount !== 0 && check < totalCheck) {
3434
check++;
3535
setTimeout(checkFunction, 100);
@@ -44,7 +44,7 @@ function testLeak(endFn, callback) {
4444

4545
openCount = 0;
4646
callback && setTimeout(callback, 100);
47-
};
47+
}
4848

4949
setInterval(function() {
5050
const s = fs.createReadStream(emptyTxt);

0 commit comments

Comments
 (0)