test: remove unnecessary noop function args to mustCall()

RefsL https://github.com/nodejs/node/pull/45027

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Antoine du Hamel 2022-10-20 08:13:32 -05:00 committed by GitHub
parent 806ea92e70
commit 2c1b9f506a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 32 additions and 38 deletions

View File

@ -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

View File

@ -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.

View File

@ -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();

View File

@ -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');

View File

@ -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();

View File

@ -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();

View File

@ -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*/);
}),

View File

@ -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();

View File

@ -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) {

View File

@ -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) {

View File

@ -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\/$/);

View File

@ -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());
});

View File

@ -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());

View File

@ -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.

View File

@ -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();

View File

@ -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({

View File

@ -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);

View File

@ -11,7 +11,7 @@ async function runTest() {
await pipeline(
'',
new PassThrough({ objectMode: true }),
common.mustCall(() => { })
common.mustCall(),
);
}

View File

@ -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');
}

View File

@ -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');

View File

@ -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());
}));
}));

View File

@ -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({

View File

@ -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) {

View File

@ -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());
}));
}