diff --git a/test/.eslintrc.yaml b/test/.eslintrc.yaml index e8295cd3e23621..b79009fb9c8591 100644 --- a/test/.eslintrc.yaml +++ b/test/.eslintrc.yaml @@ -46,6 +46,8 @@ rules: message: Use Number.isNaN() instead of the global isNaN() function. - selector: VariableDeclarator > CallExpression:matches([callee.name='debuglog'], [callee.property.name='debuglog']):not([arguments.0.value='test']) message: Use 'test' as debuglog value in tests. + - 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] + message: Do not use an empty function, omit the parameter altogether. # Custom rules in tools/eslint-rules node-core/prefer-assert-iferror: error diff --git a/test/async-hooks/test-http-agent-handle-reuse-parallel.js b/test/async-hooks/test-http-agent-handle-reuse-parallel.js index cd73b3ed2cb61c..844ba1e9f9bf78 100644 --- a/test/async-hooks/test-http-agent-handle-reuse-parallel.js +++ b/test/async-hooks/test-http-agent-handle-reuse-parallel.js @@ -34,7 +34,7 @@ const verifyRequest = (idx) => (res) => { socket = res.socket; } - res.on('data', common.mustCallAtLeast(() => {})); + res.on('data', common.mustCallAtLeast()); res.on('end', common.mustCall(() => { if (++responses === 2) { // Clean up to let the event loop stop. diff --git a/test/async-hooks/test-http-agent-handle-reuse-serial.js b/test/async-hooks/test-http-agent-handle-reuse-serial.js index bbc7183d6e72ca..fbd1d43378555e 100644 --- a/test/async-hooks/test-http-agent-handle-reuse-serial.js +++ b/test/async-hooks/test-http-agent-handle-reuse-serial.js @@ -47,7 +47,7 @@ const server = http.createServer(common.mustCall((req, res) => { // Check that request and response share their socket. assert.strictEqual(r1.socket, socket); - res.on('data', common.mustCallAtLeast(() => {})); + res.on('data', common.mustCallAtLeast()); res.on('end', common.mustCall(() => { // setImmediate() to give the agent time to register the freed socket. setImmediate(common.mustCall(() => { @@ -70,7 +70,7 @@ const server = http.createServer(common.mustCall((req, res) => { // Empty payload, to hit the “right” code path. r2.end(''); - res.on('data', common.mustCallAtLeast(() => {})); + res.on('data', common.mustCallAtLeast()); res.on('end', common.mustCall(() => { // Clean up to let the event loop stop. server.close(); diff --git a/test/known_issues/test-http-path-contains-unicode.js b/test/known_issues/test-http-path-contains-unicode.js index d899fab07c43bb..8373f1d2159e01 100644 --- a/test/known_issues/test-http-path-contains-unicode.js +++ b/test/known_issues/test-http-path-contains-unicode.js @@ -14,8 +14,7 @@ assert.strictEqual(expected, '/caf\u{e9}\u{1f436}'); const server = http.createServer(common.mustCall(function(req, res) { assert.strictEqual(req.url, expected); - req.on('data', common.mustCall(function() { - })).on('end', common.mustCall(function() { + req.on('data', common.mustCall()).on('end', common.mustCall(function() { server.close(); res.writeHead(200); res.end('hello world\n'); diff --git a/test/parallel/test-async-hooks-http-agent-destroy.js b/test/parallel/test-async-hooks-http-agent-destroy.js index 637f2c511410e7..4d90cb7d350787 100644 --- a/test/parallel/test-async-hooks-http-agent-destroy.js +++ b/test/parallel/test-async-hooks-http-agent-destroy.js @@ -50,7 +50,7 @@ const server = http.createServer(common.mustCall((req, res) => { // Check that request and response share their socket. assert.strictEqual(r1.socket, socket); - res.on('data', common.mustCallAtLeast(() => {})); + res.on('data', common.mustCallAtLeast()); res.on('end', common.mustCall(() => { // setImmediate() to give the agent time to register the freed socket. setImmediate(common.mustCall(() => { @@ -66,7 +66,7 @@ const server = http.createServer(common.mustCall((req, res) => { // Empty payload, to hit the “right” code path. r2.end(''); - res.on('data', common.mustCallAtLeast(() => {})); + res.on('data', common.mustCallAtLeast()); res.on('end', common.mustCall(() => { // Clean up to let the event loop stop. server.close(); diff --git a/test/parallel/test-async-hooks-http-agent.js b/test/parallel/test-async-hooks-http-agent.js index a55858947337b2..337bab65d9dfef 100644 --- a/test/parallel/test-async-hooks-http-agent.js +++ b/test/parallel/test-async-hooks-http-agent.js @@ -40,7 +40,7 @@ const server = http.createServer(common.mustCall((req, res) => { // Check that request and response share their socket. assert.strictEqual(r1.socket, socket); - res.on('data', common.mustCallAtLeast(() => {})); + res.on('data', common.mustCallAtLeast()); res.on('end', common.mustCall(() => { // setImmediate() to give the agent time to register the freed socket. setImmediate(common.mustCall(() => { @@ -62,7 +62,7 @@ const server = http.createServer(common.mustCall((req, res) => { // Empty payload, to hit the “right” code path. r2.end(''); - res.on('data', common.mustCallAtLeast(() => {})); + res.on('data', common.mustCallAtLeast()); res.on('end', common.mustCall(() => { // Clean up to let the event loop stop. server.close(); diff --git a/test/parallel/test-cluster-fork-windowsHide.js b/test/parallel/test-cluster-fork-windowsHide.js index 3eb89f208883c0..2b90713ceb0a74 100644 --- a/test/parallel/test-cluster-fork-windowsHide.js +++ b/test/parallel/test-cluster-fork-windowsHide.js @@ -20,8 +20,7 @@ if (!process.argv[2]) { { detached: true, stdio: ['ignore', 'ignore', 'ignore', 'ipc'] }); const messageHandlers = { - workerOnline: common.mustCall((msg) => { - }), + workerOnline: common.mustCall(), mainWindowHandle: common.mustCall((msg) => { assert.match(msg.value, /0\s*/); }), diff --git a/test/parallel/test-cluster-ipc-throw.js b/test/parallel/test-cluster-ipc-throw.js index ec979448ddb96e..c9640a23fcffb6 100644 --- a/test/parallel/test-cluster-ipc-throw.js +++ b/test/parallel/test-cluster-ipc-throw.js @@ -17,7 +17,7 @@ if (cluster.isPrimary) { })); } else { assert(process.env.PORT); - process.on('uncaughtException', common.mustCall((e) => {})); + process.on('uncaughtException', common.mustCall()); server.listen(process.env.PORT); server.on('error', common.mustCall((e) => { cluster.worker.disconnect(); diff --git a/test/parallel/test-cluster-worker-kill-signal.js b/test/parallel/test-cluster-worker-kill-signal.js index b0bf8995cb33a6..53e3739eba1679 100644 --- a/test/parallel/test-cluster-worker-kill-signal.js +++ b/test/parallel/test-cluster-worker-kill-signal.js @@ -13,7 +13,7 @@ if (cluster.isWorker) { const http = require('http'); const server = http.Server(() => { }); - server.once('listening', common.mustCall(() => { })); + server.once('listening', common.mustCall()); server.listen(0, '127.0.0.1'); } else if (cluster.isMaster) { diff --git a/test/parallel/test-cluster-worker-kill.js b/test/parallel/test-cluster-worker-kill.js index 9fcb924149704e..7307a93e1bebcb 100644 --- a/test/parallel/test-cluster-worker-kill.js +++ b/test/parallel/test-cluster-worker-kill.js @@ -35,7 +35,7 @@ if (cluster.isWorker) { const http = require('http'); const server = http.Server(() => { }); - server.once('listening', common.mustCall(() => { })); + server.once('listening', common.mustCall()); server.listen(0, '127.0.0.1'); } else if (cluster.isPrimary) { diff --git a/test/parallel/test-common.js b/test/parallel/test-common.js index 3e98e76d0e6f2b..54e851fce1abdb 100644 --- a/test/parallel/test-common.js +++ b/test/parallel/test-common.js @@ -51,14 +51,17 @@ const { join } = require('path'); // common.mustCall() tests assert.throws(function() { + // eslint-disable-next-line no-restricted-syntax common.mustCall(function() {}, 'foo'); }, /^TypeError: Invalid exact value: foo$/); assert.throws(function() { + // eslint-disable-next-line no-restricted-syntax common.mustCall(function() {}, /foo/); }, /^TypeError: Invalid exact value: \/foo\/$/); assert.throws(function() { + // eslint-disable-next-line no-restricted-syntax common.mustCallAtLeast(function() {}, /foo/); }, /^TypeError: Invalid minimum value: \/foo\/$/); diff --git a/test/parallel/test-domain-multi.js b/test/parallel/test-domain-multi.js index 072f8e86bb077c..4a30dfeec0449e 100644 --- a/test/parallel/test-domain-multi.js +++ b/test/parallel/test-domain-multi.js @@ -73,5 +73,5 @@ const server = http.createServer((req, res) => { res.pipe(process.stdout); }); - c.on('error', common.mustCall((er) => { })); + c.on('error', common.mustCall()); }); diff --git a/test/parallel/test-fs-watchfile-bigint.js b/test/parallel/test-fs-watchfile-bigint.js index 569c7ad6f57fe4..0f462947a7799d 100644 --- a/test/parallel/test-fs-watchfile-bigint.js +++ b/test/parallel/test-fs-watchfile-bigint.js @@ -66,4 +66,4 @@ const watcher = // 'stop' should only be emitted once - stopping a stopped watcher should // not trigger a 'stop' event. -watcher.on('stop', common.mustCall(function onStop() {})); +watcher.on('stop', common.mustCall()); diff --git a/test/parallel/test-fs-watchfile.js b/test/parallel/test-fs-watchfile.js index 4e5af9d77bb15a..8d1241bae8f1c2 100644 --- a/test/parallel/test-fs-watchfile.js +++ b/test/parallel/test-fs-watchfile.js @@ -80,7 +80,7 @@ const watcher = // 'stop' should only be emitted once - stopping a stopped watcher should // not trigger a 'stop' event. -watcher.on('stop', common.mustCall(function onStop() {})); +watcher.on('stop', common.mustCall()); // Watch events should callback with a filename on supported systems. // Omitting AIX. It works but not reliably. diff --git a/test/parallel/test-http2-socket-proxy-handler-for-has.js b/test/parallel/test-http2-socket-proxy-handler-for-has.js index ccc63149ff1b12..a8dfbfe07a24e5 100644 --- a/test/parallel/test-http2-socket-proxy-handler-for-has.js +++ b/test/parallel/test-http2-socket-proxy-handler-for-has.js @@ -29,8 +29,7 @@ server.listen(common.mustCall(() => { const req = client.request({}); req.on('response', common.mustCall((headers, flags) => { console.log(headers); - server.close(common.mustCall(() => { - })); + server.close(common.mustCall()); })); req.on('end', common.mustCall(() => { client.close(); diff --git a/test/parallel/test-https-max-header-size-per-stream.js b/test/parallel/test-https-max-header-size-per-stream.js index f7117e16fb43f6..796af5e6e08793 100644 --- a/test/parallel/test-https-max-header-size-per-stream.js +++ b/test/parallel/test-https-max-header-size-per-stream.js @@ -98,7 +98,7 @@ const certFixture = { // clientError may be emitted multiple times when header is larger than // maxHeaderSize. - server.on('clientError', common.mustCallAtLeast(() => {}, 1)); + server.on('clientError', common.mustCallAtLeast(1)); server.listen(0, common.mustCall(() => { const client = tls.connect({ diff --git a/test/parallel/test-spawn-cmd-named-pipe.js b/test/parallel/test-spawn-cmd-named-pipe.js index 30d0ec2c263fcb..4e7ad185a5401c 100644 --- a/test/parallel/test-spawn-cmd-named-pipe.js +++ b/test/parallel/test-spawn-cmd-named-pipe.js @@ -17,8 +17,7 @@ if (!process.argv[2]) { const stdoutPipeName = `\\\\.\\pipe\\${pipeNamePrefix}.stdout`; const stdinPipeServer = net.createServer(function(c) { - c.on('end', common.mustCall(function() { - })); + c.on('end', common.mustCall()); c.end('hello'); }); stdinPipeServer.listen(stdinPipeName); diff --git a/test/parallel/test-stream-pipeline-with-empty-string.js b/test/parallel/test-stream-pipeline-with-empty-string.js index 3f5ee799c53386..5df1ff9edf9103 100644 --- a/test/parallel/test-stream-pipeline-with-empty-string.js +++ b/test/parallel/test-stream-pipeline-with-empty-string.js @@ -11,7 +11,7 @@ async function runTest() { await pipeline( '', new PassThrough({ objectMode: true }), - common.mustCall(() => { }) + common.mustCall(), ); } diff --git a/test/parallel/test-tls-client-reject.js b/test/parallel/test-tls-client-reject.js index ea10ef6da20834..68922e3690eac0 100644 --- a/test/parallel/test-tls-client-reject.js +++ b/test/parallel/test-tls-client-reject.js @@ -59,8 +59,7 @@ function unauthorized() { })); socket.on('end', () => rejectUnauthorized()); })); - socket.once('session', common.mustCall(() => { - })); + socket.once('session', common.mustCall()); socket.on('error', common.mustNotCall()); socket.end('ok'); } diff --git a/test/parallel/test-tls-client-resume.js b/test/parallel/test-tls-client-resume.js index 0f5c9caa7c3f8f..b9d7fd828b5380 100644 --- a/test/parallel/test-tls-client-resume.js +++ b/test/parallel/test-tls-client-resume.js @@ -61,8 +61,7 @@ server.listen(0, common.mustCall(function() { reconnect(); })); - client1.on('data', common.mustCall((d) => { - })); + client1.on('data', common.mustCall()); client1.once('session', common.mustCall((session) => { console.log('session1'); diff --git a/test/parallel/test-tls-disable-renegotiation.js b/test/parallel/test-tls-disable-renegotiation.js index 3de7c79cf04025..f91868c6345d71 100644 --- a/test/parallel/test-tls-disable-renegotiation.js +++ b/test/parallel/test-tls-disable-renegotiation.js @@ -88,9 +88,7 @@ server.listen(0, common.mustCall(() => { })); })); assert.strictEqual(ok, true); - client.on('secureConnect', common.mustCall(() => { - })); - client.on('secure', common.mustCall(() => { - })); + client.on('secureConnect', common.mustCall()); + client.on('secure', common.mustCall()); })); })); diff --git a/test/parallel/test-tls-getprotocol.js b/test/parallel/test-tls-getprotocol.js index 02c683c71c8775..d45287d671d8af 100644 --- a/test/parallel/test-tls-getprotocol.js +++ b/test/parallel/test-tls-getprotocol.js @@ -23,9 +23,8 @@ const serverConfig = { cert: fixtures.readKey('agent2-cert.pem') }; -const server = tls.createServer(serverConfig, common.mustCall(function() { - -}, clientConfigs.length)).listen(0, common.localhostIPv4, function() { +const server = tls.createServer(serverConfig, common.mustCall(clientConfigs.length)) +.listen(0, common.localhostIPv4, function() { let connected = 0; clientConfigs.forEach(function(v) { tls.connect({ diff --git a/test/parallel/test-tls-ocsp-callback.js b/test/parallel/test-tls-ocsp-callback.js index d374ebdf63fb2c..04a60a0890c506 100644 --- a/test/parallel/test-tls-ocsp-callback.js +++ b/test/parallel/test-tls-ocsp-callback.js @@ -87,7 +87,7 @@ function test(testOptions, cb) { requestOCSP: testOptions.ocsp, secureOptions: testOptions.ocsp ? 0 : SSL_OP_NO_TICKET, rejectUnauthorized: false - }, common.mustCall(() => { }, requestCount)); + }, common.mustCall(requestCount)); client.on('OCSPResponse', common.mustCall((resp) => { if (testOptions.response) { diff --git a/test/parallel/test-x509-escaping.js b/test/parallel/test-x509-escaping.js index c31a6d21351dc9..170103fd9c973d 100644 --- a/test/parallel/test-x509-escaping.js +++ b/test/parallel/test-x509-escaping.js @@ -499,8 +499,6 @@ const { hasOpenSSL3 } = common; tls.connect(port, { ca: cert, servername, - }, common.mustCall(() => { - // Do nothing, the server will close the connection. - })); + }, common.mustCall()); })); }