Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove unnecessary noop function args to mustCall() #45047

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/async-hooks/test-http-agent-handle-reuse-parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions test/async-hooks/test-http-agent-handle-reuse-serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions test/known_issues/test-http-path-contains-unicode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-async-hooks-http-agent-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-async-hooks-http-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-cluster-fork-windowsHide.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*/);
}),
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-ipc-throw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-worker-kill-signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-worker-kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\/$/);

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-domain-multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
2 changes: 1 addition & 1 deletion test/parallel/test-fs-watchfile-bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
2 changes: 1 addition & 1 deletion test/parallel/test-fs-watchfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-http2-socket-proxy-handler-for-has.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-https-max-header-size-per-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-spawn-cmd-named-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-pipeline-with-empty-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function runTest() {
await pipeline(
'',
new PassThrough({ objectMode: true }),
common.mustCall(() => { })
common.mustCall(),
);
}

Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-tls-client-reject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-tls-client-resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 2 additions & 4 deletions test/parallel/test-tls-disable-renegotiation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}));
}));
5 changes: 2 additions & 3 deletions test/parallel/test-tls-getprotocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-ocsp-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-x509-escaping.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}));
}