Skip to content

Commit b3c4265

Browse files
aduh95danielleadams
authored andcommitted
test: remove unnecessary noop function args to mustCall()
RefsL #45027 PR-URL: #45047 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
1 parent 868b4a3 commit b3c4265

24 files changed

+32
-38
lines changed

test/.eslintrc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ rules:
4646
message: Use Number.isNaN() instead of the global isNaN() function.
4747
- selector: VariableDeclarator > CallExpression:matches([callee.name='debuglog'], [callee.property.name='debuglog']):not([arguments.0.value='test'])
4848
message: Use 'test' as debuglog value in tests.
49+
- selector: CallExpression:matches([callee.object.name="common"][callee.property.name=/^mustCall/],[callee.name="mustCall"],[callee.name="mustCallAtLeast"])>:first-child[type=/FunctionExpression$/][body.body.length=0]
50+
message: Do not use an empty function, omit the parameter altogether.
4951

5052
# Custom rules in tools/eslint-rules
5153
node-core/prefer-assert-iferror: error

test/async-hooks/test-http-agent-handle-reuse-parallel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const verifyRequest = (idx) => (res) => {
3434
socket = res.socket;
3535
}
3636

37-
res.on('data', common.mustCallAtLeast(() => {}));
37+
res.on('data', common.mustCallAtLeast());
3838
res.on('end', common.mustCall(() => {
3939
if (++responses === 2) {
4040
// Clean up to let the event loop stop.

test/async-hooks/test-http-agent-handle-reuse-serial.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const server = http.createServer(common.mustCall((req, res) => {
4747
// Check that request and response share their socket.
4848
assert.strictEqual(r1.socket, socket);
4949

50-
res.on('data', common.mustCallAtLeast(() => {}));
50+
res.on('data', common.mustCallAtLeast());
5151
res.on('end', common.mustCall(() => {
5252
// setImmediate() to give the agent time to register the freed socket.
5353
setImmediate(common.mustCall(() => {
@@ -70,7 +70,7 @@ const server = http.createServer(common.mustCall((req, res) => {
7070
// Empty payload, to hit the “right” code path.
7171
r2.end('');
7272

73-
res.on('data', common.mustCallAtLeast(() => {}));
73+
res.on('data', common.mustCallAtLeast());
7474
res.on('end', common.mustCall(() => {
7575
// Clean up to let the event loop stop.
7676
server.close();

test/known_issues/test-http-path-contains-unicode.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ assert.strictEqual(expected, '/caf\u{e9}\u{1f436}');
1414

1515
const server = http.createServer(common.mustCall(function(req, res) {
1616
assert.strictEqual(req.url, expected);
17-
req.on('data', common.mustCall(function() {
18-
})).on('end', common.mustCall(function() {
17+
req.on('data', common.mustCall()).on('end', common.mustCall(function() {
1918
server.close();
2019
res.writeHead(200);
2120
res.end('hello world\n');

test/parallel/test-async-hooks-http-agent-destroy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const server = http.createServer(common.mustCall((req, res) => {
5050
// Check that request and response share their socket.
5151
assert.strictEqual(r1.socket, socket);
5252

53-
res.on('data', common.mustCallAtLeast(() => {}));
53+
res.on('data', common.mustCallAtLeast());
5454
res.on('end', common.mustCall(() => {
5555
// setImmediate() to give the agent time to register the freed socket.
5656
setImmediate(common.mustCall(() => {
@@ -66,7 +66,7 @@ const server = http.createServer(common.mustCall((req, res) => {
6666
// Empty payload, to hit the “right” code path.
6767
r2.end('');
6868

69-
res.on('data', common.mustCallAtLeast(() => {}));
69+
res.on('data', common.mustCallAtLeast());
7070
res.on('end', common.mustCall(() => {
7171
// Clean up to let the event loop stop.
7272
server.close();

test/parallel/test-async-hooks-http-agent.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const server = http.createServer(common.mustCall((req, res) => {
4040
// Check that request and response share their socket.
4141
assert.strictEqual(r1.socket, socket);
4242

43-
res.on('data', common.mustCallAtLeast(() => {}));
43+
res.on('data', common.mustCallAtLeast());
4444
res.on('end', common.mustCall(() => {
4545
// setImmediate() to give the agent time to register the freed socket.
4646
setImmediate(common.mustCall(() => {
@@ -62,7 +62,7 @@ const server = http.createServer(common.mustCall((req, res) => {
6262
// Empty payload, to hit the “right” code path.
6363
r2.end('');
6464

65-
res.on('data', common.mustCallAtLeast(() => {}));
65+
res.on('data', common.mustCallAtLeast());
6666
res.on('end', common.mustCall(() => {
6767
// Clean up to let the event loop stop.
6868
server.close();

test/parallel/test-cluster-fork-windowsHide.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ if (!process.argv[2]) {
2020
{ detached: true, stdio: ['ignore', 'ignore', 'ignore', 'ipc'] });
2121

2222
const messageHandlers = {
23-
workerOnline: common.mustCall((msg) => {
24-
}),
23+
workerOnline: common.mustCall(),
2524
mainWindowHandle: common.mustCall((msg) => {
2625
assert.match(msg.value, /0\s*/);
2726
}),

test/parallel/test-cluster-ipc-throw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (cluster.isPrimary) {
1717
}));
1818
} else {
1919
assert(process.env.PORT);
20-
process.on('uncaughtException', common.mustCall((e) => {}));
20+
process.on('uncaughtException', common.mustCall());
2121
server.listen(process.env.PORT);
2222
server.on('error', common.mustCall((e) => {
2323
cluster.worker.disconnect();

test/parallel/test-cluster-worker-kill-signal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (cluster.isWorker) {
1313
const http = require('http');
1414
const server = http.Server(() => { });
1515

16-
server.once('listening', common.mustCall(() => { }));
16+
server.once('listening', common.mustCall());
1717
server.listen(0, '127.0.0.1');
1818

1919
} else if (cluster.isMaster) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ if (cluster.isWorker) {
3535
const http = require('http');
3636
const server = http.Server(() => { });
3737

38-
server.once('listening', common.mustCall(() => { }));
38+
server.once('listening', common.mustCall());
3939
server.listen(0, '127.0.0.1');
4040

4141
} else if (cluster.isPrimary) {

test/parallel/test-common.js

+3
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ const { join } = require('path');
5151

5252
// common.mustCall() tests
5353
assert.throws(function() {
54+
// eslint-disable-next-line no-restricted-syntax
5455
common.mustCall(function() {}, 'foo');
5556
}, /^TypeError: Invalid exact value: foo$/);
5657

5758
assert.throws(function() {
59+
// eslint-disable-next-line no-restricted-syntax
5860
common.mustCall(function() {}, /foo/);
5961
}, /^TypeError: Invalid exact value: \/foo\/$/);
6062

6163
assert.throws(function() {
64+
// eslint-disable-next-line no-restricted-syntax
6265
common.mustCallAtLeast(function() {}, /foo/);
6366
}, /^TypeError: Invalid minimum value: \/foo\/$/);
6467

test/parallel/test-domain-multi.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ const server = http.createServer((req, res) => {
7373
res.pipe(process.stdout);
7474
});
7575

76-
c.on('error', common.mustCall((er) => { }));
76+
c.on('error', common.mustCall());
7777
});

test/parallel/test-fs-watchfile-bigint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ const watcher =
6666

6767
// 'stop' should only be emitted once - stopping a stopped watcher should
6868
// not trigger a 'stop' event.
69-
watcher.on('stop', common.mustCall(function onStop() {}));
69+
watcher.on('stop', common.mustCall());

test/parallel/test-fs-watchfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const watcher =
8080

8181
// 'stop' should only be emitted once - stopping a stopped watcher should
8282
// not trigger a 'stop' event.
83-
watcher.on('stop', common.mustCall(function onStop() {}));
83+
watcher.on('stop', common.mustCall());
8484

8585
// Watch events should callback with a filename on supported systems.
8686
// Omitting AIX. It works but not reliably.

test/parallel/test-http2-socket-proxy-handler-for-has.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ server.listen(common.mustCall(() => {
2929
const req = client.request({});
3030
req.on('response', common.mustCall((headers, flags) => {
3131
console.log(headers);
32-
server.close(common.mustCall(() => {
33-
}));
32+
server.close(common.mustCall());
3433
}));
3534
req.on('end', common.mustCall(() => {
3635
client.close();

test/parallel/test-https-max-header-size-per-stream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const certFixture = {
9898

9999
// clientError may be emitted multiple times when header is larger than
100100
// maxHeaderSize.
101-
server.on('clientError', common.mustCallAtLeast(() => {}, 1));
101+
server.on('clientError', common.mustCallAtLeast(1));
102102

103103
server.listen(0, common.mustCall(() => {
104104
const client = tls.connect({

test/parallel/test-spawn-cmd-named-pipe.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ if (!process.argv[2]) {
1717
const stdoutPipeName = `\\\\.\\pipe\\${pipeNamePrefix}.stdout`;
1818

1919
const stdinPipeServer = net.createServer(function(c) {
20-
c.on('end', common.mustCall(function() {
21-
}));
20+
c.on('end', common.mustCall());
2221
c.end('hello');
2322
});
2423
stdinPipeServer.listen(stdinPipeName);

test/parallel/test-stream-pipeline-with-empty-string.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async function runTest() {
1111
await pipeline(
1212
'',
1313
new PassThrough({ objectMode: true }),
14-
common.mustCall(() => { })
14+
common.mustCall(),
1515
);
1616
}
1717

test/parallel/test-tls-client-reject.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ function unauthorized() {
5959
}));
6060
socket.on('end', () => rejectUnauthorized());
6161
}));
62-
socket.once('session', common.mustCall(() => {
63-
}));
62+
socket.once('session', common.mustCall());
6463
socket.on('error', common.mustNotCall());
6564
socket.end('ok');
6665
}

test/parallel/test-tls-client-resume.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ server.listen(0, common.mustCall(function() {
6161
reconnect();
6262
}));
6363

64-
client1.on('data', common.mustCall((d) => {
65-
}));
64+
client1.on('data', common.mustCall());
6665

6766
client1.once('session', common.mustCall((session) => {
6867
console.log('session1');

test/parallel/test-tls-disable-renegotiation.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ server.listen(0, common.mustCall(() => {
8888
}));
8989
}));
9090
assert.strictEqual(ok, true);
91-
client.on('secureConnect', common.mustCall(() => {
92-
}));
93-
client.on('secure', common.mustCall(() => {
94-
}));
91+
client.on('secureConnect', common.mustCall());
92+
client.on('secure', common.mustCall());
9593
}));
9694
}));

test/parallel/test-tls-getprotocol.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ const serverConfig = {
2323
cert: fixtures.readKey('agent2-cert.pem')
2424
};
2525

26-
const server = tls.createServer(serverConfig, common.mustCall(function() {
27-
28-
}, clientConfigs.length)).listen(0, common.localhostIPv4, function() {
26+
const server = tls.createServer(serverConfig, common.mustCall(clientConfigs.length))
27+
.listen(0, common.localhostIPv4, function() {
2928
let connected = 0;
3029
clientConfigs.forEach(function(v) {
3130
tls.connect({

test/parallel/test-tls-ocsp-callback.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function test(testOptions, cb) {
8787
requestOCSP: testOptions.ocsp,
8888
secureOptions: testOptions.ocsp ? 0 : SSL_OP_NO_TICKET,
8989
rejectUnauthorized: false
90-
}, common.mustCall(() => { }, requestCount));
90+
}, common.mustCall(requestCount));
9191

9292
client.on('OCSPResponse', common.mustCall((resp) => {
9393
if (testOptions.response) {

test/parallel/test-x509-escaping.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,6 @@ const { hasOpenSSL3 } = common;
499499
tls.connect(port, {
500500
ca: cert,
501501
servername,
502-
}, common.mustCall(() => {
503-
// Do nothing, the server will close the connection.
504-
}));
502+
}, common.mustCall());
505503
}));
506504
}

0 commit comments

Comments
 (0)