Skip to content

Commit c694dae

Browse files
Trottruyadorno
authored andcommitted
test: enable no-empty ESLint rule
PR-URL: #41831 Refs: https://eslint.org/docs/rules/no-empty Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 6c82276 commit c694dae

File tree

46 files changed

+206
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+206
-132
lines changed

test/.eslintrc.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ env:
55
es6: true
66

77
rules:
8+
multiline-comment-style: ["error", "separate-lines"]
9+
no-empty: error
810
no-var: error
911
prefer-const: error
1012
symbol-description: off
11-
multiline-comment-style: ["error", "separate-lines"]
1213

1314
no-restricted-syntax:
1415
# Config copied from .eslintrc.js

test/addons/uv-handle-leak/test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ try {
1616
const { isMainThread } = require('worker_threads');
1717
if (!isMainThread)
1818
common.skip('Cannot run test in environment with clean-exit policy');
19-
} catch {}
19+
} catch {
20+
// Continue regardless of error.
21+
}
2022

2123
binding.leakHandle();
2224
binding.leakHandle(0);

test/common/inspector-helper.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@ class NodeInstance extends EventEmitter {
365365
['--expose-internals'],
366366
`${scriptContents}\nprocess._rawDebug('started');`, undefined);
367367
const msg = 'Timed out waiting for process to start';
368-
while (await fires(instance.nextStderrString(), msg, TIMEOUT) !==
369-
'started') {}
368+
while (await fires(instance.nextStderrString(), msg, TIMEOUT) !== 'started');
370369
process._debugProcess(instance._process.pid);
371370
return instance;
372371
}

test/common/report.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ function validateContent(report, fields = []) {
4646
} catch (err) {
4747
try {
4848
err.stack += util.format('\n------\nFailing Report:\n%O', report);
49-
} catch {}
49+
} catch {
50+
// Continue regardless of error.
51+
}
5052
throw err;
5153
}
5254
}

test/internet/test-dgram-broadcast-multi-process.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ if (process.argv[2] !== 'child') {
184184
const buf = messages[i++];
185185

186186
if (!buf) {
187-
try { sendSocket.close(); } catch {}
187+
try { sendSocket.close(); } catch {
188+
// Continue regardless of error.
189+
}
188190
return;
189191
}
190192

test/internet/test-dgram-multicast-multi-process.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ if (process.argv[2] !== 'child') {
170170
const buf = messages[i++];
171171

172172
if (!buf) {
173-
try { sendSocket.close(); } catch {}
173+
try { sendSocket.close(); } catch {
174+
// Continue regardless of error.
175+
}
174176
return;
175177
}
176178

test/internet/test-dgram-multicast-ssm-multi-process.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ if (process.argv[2] !== 'child') {
164164
const buf = messages[i++];
165165

166166
if (!buf) {
167-
try { sendSocket.close(); } catch {}
167+
try { sendSocket.close(); } catch {
168+
// Continue regardless of error.
169+
}
168170
return;
169171
}
170172

test/internet/test-dgram-multicast-ssmv6-multi-process.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ if (process.argv[2] !== 'child') {
164164
const buf = messages[i++];
165165

166166
if (!buf) {
167-
try { sendSocket.close(); } catch {}
167+
try { sendSocket.close(); } catch {
168+
// Continue regardless of error.
169+
}
168170
return;
169171
}
170172

test/message/vm_dont_display_runtime_error.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ try {
3030
filename: 'test.vm',
3131
displayErrors: false
3232
});
33-
} catch {}
33+
} catch {
34+
// Continue regardless of error.
35+
}
3436

3537
console.error('middle');
3638

test/message/vm_dont_display_syntax_error.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ try {
3030
filename: 'test.vm',
3131
displayErrors: false
3232
});
33-
} catch {}
33+
} catch {
34+
// Continue regardless of error.
35+
}
3436

3537
console.error('middle');
3638

test/node-api/test_fatal/test_threads.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ const test_fatal = require(`./build/${common.buildType}/test_fatal`);
88
// that crashes the process.
99
if (process.argv[2] === 'child') {
1010
test_fatal.TestThread();
11-
// Busy loop to allow the work thread to abort.
12-
while (true) {}
11+
while (true) {
12+
// Busy loop to allow the work thread to abort.
13+
}
1314
}
1415

1516
const p = child_process.spawnSync(

test/node-api/test_fatal/test_threads_report.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if (common.buildType === 'Debug')
1616
if (process.argv[2] === 'child') {
1717
test_fatal.TestThread();
1818
// Busy loop to allow the work thread to abort.
19-
while (true) {}
19+
while (true);
2020
}
2121

2222
tmpdir.refresh();

test/parallel/test-async-hooks-run-in-async-scope-caught-exception.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ const { AsyncResource } = require('async_hooks');
55

66
try {
77
new AsyncResource('foo').runInAsyncScope(() => { throw new Error('bar'); });
8-
} catch {}
8+
} catch {
9+
// Continue regardless of error.
10+
}
911
// Should abort (fail the case) if async id is not matching.

test/parallel/test-cluster-kill-infinite-loop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ if (cluster.isPrimary) {
1717
assert.strictEqual(signal, 'SIGTERM');
1818
}));
1919
} else {
20-
while (true) {}
20+
while (true);
2121
}

test/parallel/test-domain-with-abort-on-uncaught-exception.js

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ if (process.argv[2] === 'child') {
4949
try {
5050
throw new Error(domainErrHandlerExMessage);
5151
} catch {
52+
// Continue regardless of error.
5253
}
5354
} else {
5455
throw new Error(domainErrHandlerExMessage);

test/parallel/test-file-write-stream2.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ process.on('exit', function() {
5656
function removeTestFile() {
5757
try {
5858
fs.unlinkSync(filepath);
59-
} catch {}
59+
} catch {
60+
// Continue regardless of error.
61+
}
6062
}
6163

6264

test/parallel/test-fs-access.js

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ if (!common.isWindows && process.getuid() === 0) {
6060
process.setuid('nobody');
6161
hasWriteAccessForReadonlyFile = false;
6262
} catch {
63+
// Continue regardless of error.
6364
}
6465
}
6566

test/parallel/test-fs-promises-watch.js

+26-14
Original file line numberDiff line numberDiff line change
@@ -75,42 +75,54 @@ for (const testCase of kCases) {
7575
}
7676

7777
assert.rejects(
78-
// eslint-disable-next-line no-unused-vars
79-
async () => { for await (const _ of watch(1)) {} },
78+
async () => {
79+
// eslint-disable-next-line no-unused-vars, no-empty
80+
for await (const _ of watch(1)) { }
81+
},
8082
{ code: 'ERR_INVALID_ARG_TYPE' });
8183

8284
assert.rejects(
83-
// eslint-disable-next-line no-unused-vars
84-
async () => { for await (const _ of watch(__filename, 1)) {} },
85+
async () => {
86+
// eslint-disable-next-line no-unused-vars, no-empty
87+
for await (const _ of watch(__filename, 1)) { }
88+
},
8589
{ code: 'ERR_INVALID_ARG_TYPE' });
8690

8791
assert.rejects(
88-
// eslint-disable-next-line no-unused-vars
89-
async () => { for await (const _ of watch('', { persistent: 1 })) {} },
92+
async () => {
93+
// eslint-disable-next-line no-unused-vars, no-empty
94+
for await (const _ of watch('', { persistent: 1 })) { }
95+
},
9096
{ code: 'ERR_INVALID_ARG_TYPE' });
9197

9298
assert.rejects(
93-
// eslint-disable-next-line no-unused-vars
94-
async () => { for await (const _ of watch('', { recursive: 1 })) {} },
99+
async () => {
100+
// eslint-disable-next-line no-unused-vars, no-empty
101+
for await (const _ of watch('', { recursive: 1 })) { }
102+
},
95103
{ code: 'ERR_INVALID_ARG_TYPE' });
96104

97105
assert.rejects(
98-
// eslint-disable-next-line no-unused-vars
99-
async () => { for await (const _ of watch('', { encoding: 1 })) {} },
106+
async () => {
107+
// eslint-disable-next-line no-unused-vars, no-empty
108+
for await (const _ of watch('', { encoding: 1 })) { }
109+
},
100110
{ code: 'ERR_INVALID_ARG_VALUE' });
101111

102112
assert.rejects(
103-
// eslint-disable-next-line no-unused-vars
104-
async () => { for await (const _ of watch('', { signal: 1 })) {} },
113+
async () => {
114+
// eslint-disable-next-line no-unused-vars, no-empty
115+
for await (const _ of watch('', { signal: 1 })) { }
116+
},
105117
{ code: 'ERR_INVALID_ARG_TYPE' });
106118

107119
(async () => {
108120
const ac = new AbortController();
109121
const { signal } = ac;
110122
setImmediate(() => ac.abort());
111123
try {
112-
// eslint-disable-next-line no-unused-vars
113-
for await (const _ of watch(__filename, { signal })) {}
124+
// eslint-disable-next-line no-unused-vars, no-empty
125+
for await (const _ of watch(__filename, { signal })) { }
114126
} catch (err) {
115127
assert.strictEqual(err.name, 'AbortError');
116128
}

test/parallel/test-fs-realpath.js

+42-14
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ function test_simple_relative_symlink(realpath, realpathSync, callback) {
108108
[
109109
[entry, `../${path.basename(tmpDir)}/cycles/root.js`],
110110
].forEach(function(t) {
111-
try { fs.unlinkSync(t[0]); } catch {}
111+
try { fs.unlinkSync(t[0]); } catch {
112+
// Continue regardless of error.
113+
}
112114
console.log('fs.symlinkSync(%j, %j, %j)', t[1], t[0], 'file');
113115
fs.symlinkSync(t[1], t[0], 'file');
114116
unlink.push(t[0]);
@@ -134,7 +136,9 @@ function test_simple_absolute_symlink(realpath, realpathSync, callback) {
134136
[
135137
[entry, expected],
136138
].forEach(function(t) {
137-
try { fs.unlinkSync(t[0]); } catch {}
139+
try { fs.unlinkSync(t[0]); } catch {
140+
// Continue regardless of error.
141+
}
138142
console.error('fs.symlinkSync(%j, %j, %j)', t[1], t[0], type);
139143
fs.symlinkSync(t[1], t[0], type);
140144
unlink.push(t[0]);
@@ -159,13 +163,17 @@ function test_deep_relative_file_symlink(realpath, realpathSync, callback) {
159163
expected);
160164
const linkPath1 = path.join(targetsAbsDir,
161165
'nested-index', 'one', 'symlink1.js');
162-
try { fs.unlinkSync(linkPath1); } catch {}
166+
try { fs.unlinkSync(linkPath1); } catch {
167+
// Continue regardless of error.
168+
}
163169
fs.symlinkSync(linkData1, linkPath1, 'file');
164170

165171
const linkData2 = '../one/symlink1.js';
166172
const entry = path.join(targetsAbsDir,
167173
'nested-index', 'two', 'symlink1-b.js');
168-
try { fs.unlinkSync(entry); } catch {}
174+
try { fs.unlinkSync(entry); } catch {
175+
// Continue regardless of error.
176+
}
169177
fs.symlinkSync(linkData2, entry, 'file');
170178
unlink.push(linkPath1);
171179
unlink.push(entry);
@@ -186,13 +194,17 @@ function test_deep_relative_dir_symlink(realpath, realpathSync, callback) {
186194
const path1b = path.join(targetsAbsDir, 'nested-index', 'one');
187195
const linkPath1b = path.join(path1b, 'symlink1-dir');
188196
const linkData1b = path.relative(path1b, expected);
189-
try { fs.unlinkSync(linkPath1b); } catch {}
197+
try { fs.unlinkSync(linkPath1b); } catch {
198+
// Continue regardless of error.
199+
}
190200
fs.symlinkSync(linkData1b, linkPath1b, 'dir');
191201

192202
const linkData2b = '../one/symlink1-dir';
193203
const entry = path.join(targetsAbsDir,
194204
'nested-index', 'two', 'symlink12-dir');
195-
try { fs.unlinkSync(entry); } catch {}
205+
try { fs.unlinkSync(entry); } catch {
206+
// Continue regardless of error.
207+
}
196208
fs.symlinkSync(linkData2b, entry, 'dir');
197209
unlink.push(linkPath1b);
198210
unlink.push(entry);
@@ -216,7 +228,9 @@ function test_cyclic_link_protection(realpath, realpathSync, callback) {
216228
[path.join(tmpDir, '/cycles/realpath-3b'), '../cycles/realpath-3c'],
217229
[path.join(tmpDir, '/cycles/realpath-3c'), '../cycles/realpath-3a'],
218230
].forEach(function(t) {
219-
try { fs.unlinkSync(t[0]); } catch {}
231+
try { fs.unlinkSync(t[0]); } catch {
232+
// Continue regardless of error.
233+
}
220234
fs.symlinkSync(t[1], t[0], 'dir');
221235
unlink.push(t[0]);
222236
});
@@ -243,7 +257,9 @@ function test_cyclic_link_overprotection(realpath, realpathSync, callback) {
243257
const link = `${folder}/cycles`;
244258
let testPath = cycles;
245259
testPath += '/folder/cycles'.repeat(10);
246-
try { fs.unlinkSync(link); } catch {}
260+
try { fs.unlinkSync(link); } catch {
261+
// Continue regardless of error.
262+
}
247263
fs.symlinkSync(cycles, link, 'dir');
248264
unlink.push(link);
249265
assertEqualPath(realpathSync(testPath), path.resolve(expected));
@@ -271,7 +287,9 @@ function test_relative_input_cwd(realpath, realpathSync, callback) {
271287
].forEach(function(t) {
272288
const fn = t[0];
273289
console.error('fn=%j', fn);
274-
try { fs.unlinkSync(fn); } catch {}
290+
try { fs.unlinkSync(fn); } catch {
291+
// Continue regardless of error.
292+
}
275293
const b = path.basename(t[1]);
276294
const type = (b === 'root.js' ? 'file' : 'dir');
277295
console.log('fs.symlinkSync(%j, %j, %j)', t[1], fn, type);
@@ -309,8 +327,12 @@ function test_deep_symlink_mix(realpath, realpathSync, callback) {
309327
// $tmpDir/targets/cycles/root.js (hard)
310328

311329
const entry = tmp('node-test-realpath-f1');
312-
try { fs.unlinkSync(tmp('node-test-realpath-d2/foo')); } catch {}
313-
try { fs.rmdirSync(tmp('node-test-realpath-d2')); } catch {}
330+
try { fs.unlinkSync(tmp('node-test-realpath-d2/foo')); } catch {
331+
// Continue regardless of error.
332+
}
333+
try { fs.rmdirSync(tmp('node-test-realpath-d2')); } catch {
334+
// Continue regardless of error.
335+
}
314336
fs.mkdirSync(tmp('node-test-realpath-d2'), 0o700);
315337
try {
316338
[
@@ -325,7 +347,9 @@ function test_deep_symlink_mix(realpath, realpathSync, callback) {
325347
[`${targetsAbsDir}/nested-index/two/realpath-c`,
326348
`${tmpDir}/cycles/root.js`],
327349
].forEach(function(t) {
328-
try { fs.unlinkSync(t[0]); } catch {}
350+
try { fs.unlinkSync(t[0]); } catch {
351+
// Continue regardless of error.
352+
}
329353
fs.symlinkSync(t[1], t[0]);
330354
unlink.push(t[0]);
331355
});
@@ -479,14 +503,18 @@ function test_abs_with_kids(realpath, realpathSync, cb) {
479503
['/a/b/c/x.txt',
480504
'/a/link',
481505
].forEach(function(file) {
482-
try { fs.unlinkSync(root + file); } catch {}
506+
try { fs.unlinkSync(root + file); } catch {
507+
// Continue regardless of error.
508+
}
483509
});
484510
['/a/b/c',
485511
'/a/b',
486512
'/a',
487513
'',
488514
].forEach(function(folder) {
489-
try { fs.rmdirSync(root + folder); } catch {}
515+
try { fs.rmdirSync(root + folder); } catch {
516+
// Continue regardless of error.
517+
}
490518
});
491519
}
492520

test/parallel/test-global.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ builtinModules.forEach((moduleName) => {
3636
// This could throw for e.g., crypto if the binary is not compiled
3737
// accordingly.
3838
require(moduleName);
39-
} catch {}
39+
} catch {
40+
// Continue regardless of error.
41+
}
4042
}
4143
});
4244

0 commit comments

Comments
 (0)