Skip to content

Commit

Permalink
test: enable no-empty ESLint rule
Browse files Browse the repository at this point in the history
PR-URL: #41831
Backport-PR-URL: #42160
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>
  • Loading branch information
Trott authored and danielleadams committed Mar 8, 2022
1 parent 96cfaba commit c78168f
Show file tree
Hide file tree
Showing 44 changed files with 204 additions and 132 deletions.
3 changes: 2 additions & 1 deletion test/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ env:
es6: true

rules:
multiline-comment-style: ["error", "separate-lines"]
no-empty: error
no-var: error
prefer-const: error
symbol-description: off
multiline-comment-style: ["error", "separate-lines"]

no-restricted-syntax:
# Config copied from .eslintrc.js
Expand Down
4 changes: 3 additions & 1 deletion test/addons/uv-handle-leak/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ try {
const { isMainThread } = require('worker_threads');
if (!isMainThread)
common.skip('Cannot run test in environment with clean-exit policy');
} catch {}
} catch {
// Continue regardless of error.
}

binding.leakHandle();
binding.leakHandle(0);
Expand Down
3 changes: 1 addition & 2 deletions test/common/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ class NodeInstance extends EventEmitter {
['--expose-internals'],
`${scriptContents}\nprocess._rawDebug('started');`, undefined);
const msg = 'Timed out waiting for process to start';
while (await fires(instance.nextStderrString(), msg, TIMEOUT) !==
'started') {}
while (await fires(instance.nextStderrString(), msg, TIMEOUT) !== 'started');
process._debugProcess(instance._process.pid);
return instance;
}
Expand Down
4 changes: 3 additions & 1 deletion test/common/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ function validateContent(report, fields = []) {
} catch (err) {
try {
err.stack += util.format('\n------\nFailing Report:\n%O', report);
} catch {}
} catch {
// Continue regardless of error.
}
throw err;
}
}
Expand Down
4 changes: 3 additions & 1 deletion test/internet/test-dgram-broadcast-multi-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ if (process.argv[2] !== 'child') {
const buf = messages[i++];

if (!buf) {
try { sendSocket.close(); } catch {}
try { sendSocket.close(); } catch {
// Continue regardless of error.
}
return;
}

Expand Down
4 changes: 3 additions & 1 deletion test/internet/test-dgram-multicast-multi-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ if (process.argv[2] !== 'child') {
const buf = messages[i++];

if (!buf) {
try { sendSocket.close(); } catch {}
try { sendSocket.close(); } catch {
// Continue regardless of error.
}
return;
}

Expand Down
4 changes: 3 additions & 1 deletion test/internet/test-dgram-multicast-ssm-multi-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ if (process.argv[2] !== 'child') {
const buf = messages[i++];

if (!buf) {
try { sendSocket.close(); } catch {}
try { sendSocket.close(); } catch {
// Continue regardless of error.
}
return;
}

Expand Down
4 changes: 3 additions & 1 deletion test/internet/test-dgram-multicast-ssmv6-multi-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ if (process.argv[2] !== 'child') {
const buf = messages[i++];

if (!buf) {
try { sendSocket.close(); } catch {}
try { sendSocket.close(); } catch {
// Continue regardless of error.
}
return;
}

Expand Down
4 changes: 3 additions & 1 deletion test/message/vm_dont_display_runtime_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ try {
filename: 'test.vm',
displayErrors: false
});
} catch {}
} catch {
// Continue regardless of error.
}

console.error('middle');

Expand Down
4 changes: 3 additions & 1 deletion test/message/vm_dont_display_syntax_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ try {
filename: 'test.vm',
displayErrors: false
});
} catch {}
} catch {
// Continue regardless of error.
}

console.error('middle');

Expand Down
5 changes: 3 additions & 2 deletions test/node-api/test_fatal/test_threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const test_fatal = require(`./build/${common.buildType}/test_fatal`);
// that crashes the process.
if (process.argv[2] === 'child') {
test_fatal.TestThread();
// Busy loop to allow the work thread to abort.
while (true) {}
while (true) {
// Busy loop to allow the work thread to abort.
}
}

const p = child_process.spawnSync(
Expand Down
2 changes: 1 addition & 1 deletion test/node-api/test_fatal/test_threads_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (common.buildType === 'Debug')
if (process.argv[2] === 'child') {
test_fatal.TestThread();
// Busy loop to allow the work thread to abort.
while (true) {}
while (true);
}

tmpdir.refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ const { AsyncResource } = require('async_hooks');

try {
new AsyncResource('foo').runInAsyncScope(() => { throw new Error('bar'); });
} catch {}
} catch {
// Continue regardless of error.
}
// Should abort (fail the case) if async id is not matching.
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-kill-infinite-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ if (cluster.isPrimary) {
assert.strictEqual(signal, 'SIGTERM');
}));
} else {
while (true) {}
while (true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ if (process.argv[2] === 'child') {
try {
throw new Error(domainErrHandlerExMessage);
} catch {
// Continue regardless of error.
}
} else {
throw new Error(domainErrHandlerExMessage);
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-file-write-stream2.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ process.on('exit', function() {
function removeTestFile() {
try {
fs.unlinkSync(filepath);
} catch {}
} catch {
// Continue regardless of error.
}
}


Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-fs-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ if (!common.isWindows && process.getuid() === 0) {
process.setuid('nobody');
hasWriteAccessForReadonlyFile = false;
} catch {
// Continue regardless of error.
}
}

Expand Down
40 changes: 26 additions & 14 deletions test/parallel/test-fs-promises-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,42 +75,54 @@ for (const testCase of kCases) {
}

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

assert.rejects(
// eslint-disable-next-line no-unused-vars
async () => { for await (const _ of watch(__filename, 1)) {} },
async () => {
// eslint-disable-next-line no-unused-vars, no-empty
for await (const _ of watch(__filename, 1)) { }
},
{ code: 'ERR_INVALID_ARG_TYPE' });

assert.rejects(
// eslint-disable-next-line no-unused-vars
async () => { for await (const _ of watch('', { persistent: 1 })) {} },
async () => {
// eslint-disable-next-line no-unused-vars, no-empty
for await (const _ of watch('', { persistent: 1 })) { }
},
{ code: 'ERR_INVALID_ARG_TYPE' });

assert.rejects(
// eslint-disable-next-line no-unused-vars
async () => { for await (const _ of watch('', { recursive: 1 })) {} },
async () => {
// eslint-disable-next-line no-unused-vars, no-empty
for await (const _ of watch('', { recursive: 1 })) { }
},
{ code: 'ERR_INVALID_ARG_TYPE' });

assert.rejects(
// eslint-disable-next-line no-unused-vars
async () => { for await (const _ of watch('', { encoding: 1 })) {} },
async () => {
// eslint-disable-next-line no-unused-vars, no-empty
for await (const _ of watch('', { encoding: 1 })) { }
},
{ code: 'ERR_INVALID_ARG_VALUE' });

assert.rejects(
// eslint-disable-next-line no-unused-vars
async () => { for await (const _ of watch('', { signal: 1 })) {} },
async () => {
// eslint-disable-next-line no-unused-vars, no-empty
for await (const _ of watch('', { signal: 1 })) { }
},
{ code: 'ERR_INVALID_ARG_TYPE' });

(async () => {
const ac = new AbortController();
const { signal } = ac;
setImmediate(() => ac.abort());
try {
// eslint-disable-next-line no-unused-vars
for await (const _ of watch(__filename, { signal })) {}
// eslint-disable-next-line no-unused-vars, no-empty
for await (const _ of watch(__filename, { signal })) { }
} catch (err) {
assert.strictEqual(err.name, 'AbortError');
}
Expand Down
56 changes: 42 additions & 14 deletions test/parallel/test-fs-realpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ function test_simple_relative_symlink(realpath, realpathSync, callback) {
[
[entry, `../${path.basename(tmpDir)}/cycles/root.js`],
].forEach(function(t) {
try { fs.unlinkSync(t[0]); } catch {}
try { fs.unlinkSync(t[0]); } catch {
// Continue regardless of error.
}
console.log('fs.symlinkSync(%j, %j, %j)', t[1], t[0], 'file');
fs.symlinkSync(t[1], t[0], 'file');
unlink.push(t[0]);
Expand All @@ -134,7 +136,9 @@ function test_simple_absolute_symlink(realpath, realpathSync, callback) {
[
[entry, expected],
].forEach(function(t) {
try { fs.unlinkSync(t[0]); } catch {}
try { fs.unlinkSync(t[0]); } catch {
// Continue regardless of error.
}
console.error('fs.symlinkSync(%j, %j, %j)', t[1], t[0], type);
fs.symlinkSync(t[1], t[0], type);
unlink.push(t[0]);
Expand All @@ -159,13 +163,17 @@ function test_deep_relative_file_symlink(realpath, realpathSync, callback) {
expected);
const linkPath1 = path.join(targetsAbsDir,
'nested-index', 'one', 'symlink1.js');
try { fs.unlinkSync(linkPath1); } catch {}
try { fs.unlinkSync(linkPath1); } catch {
// Continue regardless of error.
}
fs.symlinkSync(linkData1, linkPath1, 'file');

const linkData2 = '../one/symlink1.js';
const entry = path.join(targetsAbsDir,
'nested-index', 'two', 'symlink1-b.js');
try { fs.unlinkSync(entry); } catch {}
try { fs.unlinkSync(entry); } catch {
// Continue regardless of error.
}
fs.symlinkSync(linkData2, entry, 'file');
unlink.push(linkPath1);
unlink.push(entry);
Expand All @@ -186,13 +194,17 @@ function test_deep_relative_dir_symlink(realpath, realpathSync, callback) {
const path1b = path.join(targetsAbsDir, 'nested-index', 'one');
const linkPath1b = path.join(path1b, 'symlink1-dir');
const linkData1b = path.relative(path1b, expected);
try { fs.unlinkSync(linkPath1b); } catch {}
try { fs.unlinkSync(linkPath1b); } catch {
// Continue regardless of error.
}
fs.symlinkSync(linkData1b, linkPath1b, 'dir');

const linkData2b = '../one/symlink1-dir';
const entry = path.join(targetsAbsDir,
'nested-index', 'two', 'symlink12-dir');
try { fs.unlinkSync(entry); } catch {}
try { fs.unlinkSync(entry); } catch {
// Continue regardless of error.
}
fs.symlinkSync(linkData2b, entry, 'dir');
unlink.push(linkPath1b);
unlink.push(entry);
Expand All @@ -216,7 +228,9 @@ function test_cyclic_link_protection(realpath, realpathSync, callback) {
[path.join(tmpDir, '/cycles/realpath-3b'), '../cycles/realpath-3c'],
[path.join(tmpDir, '/cycles/realpath-3c'), '../cycles/realpath-3a'],
].forEach(function(t) {
try { fs.unlinkSync(t[0]); } catch {}
try { fs.unlinkSync(t[0]); } catch {
// Continue regardless of error.
}
fs.symlinkSync(t[1], t[0], 'dir');
unlink.push(t[0]);
});
Expand All @@ -243,7 +257,9 @@ function test_cyclic_link_overprotection(realpath, realpathSync, callback) {
const link = `${folder}/cycles`;
let testPath = cycles;
testPath += '/folder/cycles'.repeat(10);
try { fs.unlinkSync(link); } catch {}
try { fs.unlinkSync(link); } catch {
// Continue regardless of error.
}
fs.symlinkSync(cycles, link, 'dir');
unlink.push(link);
assertEqualPath(realpathSync(testPath), path.resolve(expected));
Expand Down Expand Up @@ -271,7 +287,9 @@ function test_relative_input_cwd(realpath, realpathSync, callback) {
].forEach(function(t) {
const fn = t[0];
console.error('fn=%j', fn);
try { fs.unlinkSync(fn); } catch {}
try { fs.unlinkSync(fn); } catch {
// Continue regardless of error.
}
const b = path.basename(t[1]);
const type = (b === 'root.js' ? 'file' : 'dir');
console.log('fs.symlinkSync(%j, %j, %j)', t[1], fn, type);
Expand Down Expand Up @@ -309,8 +327,12 @@ function test_deep_symlink_mix(realpath, realpathSync, callback) {
// $tmpDir/targets/cycles/root.js (hard)

const entry = tmp('node-test-realpath-f1');
try { fs.unlinkSync(tmp('node-test-realpath-d2/foo')); } catch {}
try { fs.rmdirSync(tmp('node-test-realpath-d2')); } catch {}
try { fs.unlinkSync(tmp('node-test-realpath-d2/foo')); } catch {
// Continue regardless of error.
}
try { fs.rmdirSync(tmp('node-test-realpath-d2')); } catch {
// Continue regardless of error.
}
fs.mkdirSync(tmp('node-test-realpath-d2'), 0o700);
try {
[
Expand All @@ -325,7 +347,9 @@ function test_deep_symlink_mix(realpath, realpathSync, callback) {
[`${targetsAbsDir}/nested-index/two/realpath-c`,
`${tmpDir}/cycles/root.js`],
].forEach(function(t) {
try { fs.unlinkSync(t[0]); } catch {}
try { fs.unlinkSync(t[0]); } catch {
// Continue regardless of error.
}
fs.symlinkSync(t[1], t[0]);
unlink.push(t[0]);
});
Expand Down Expand Up @@ -479,14 +503,18 @@ function test_abs_with_kids(realpath, realpathSync, cb) {
['/a/b/c/x.txt',
'/a/link',
].forEach(function(file) {
try { fs.unlinkSync(root + file); } catch {}
try { fs.unlinkSync(root + file); } catch {
// Continue regardless of error.
}
});
['/a/b/c',
'/a/b',
'/a',
'',
].forEach(function(folder) {
try { fs.rmdirSync(root + folder); } catch {}
try { fs.rmdirSync(root + folder); } catch {
// Continue regardless of error.
}
});
}

Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ builtinModules.forEach((moduleName) => {
// This could throw for e.g., crypto if the binary is not compiled
// accordingly.
require(moduleName);
} catch {}
} catch {
// Continue regardless of error.
}
}
});

Expand Down
Loading

0 comments on commit c78168f

Please sign in to comment.