Skip to content

Commit 94b6fd1

Browse files
committed
test: use void to indicate "useless" expressions
Instead of disabling the `no-unused-expressions` ESLint rule, mark intentional "useless" expressions with `void`. Refs: https://eslint.org/docs/rules/no-unused-expressions#options
1 parent de9be2a commit 94b6fd1

30 files changed

+48
-65
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ module.exports = {
257257
'no-useless-concat': 'error',
258258
'no-useless-constructor': 'error',
259259
'no-useless-return': 'error',
260-
'no-void': 'error',
260+
'no-void': ['error', { allowAsStatement: true }],
261261
'no-whitespace-before-property': 'error',
262262
'object-curly-newline': 'error',
263263
'object-curly-spacing': ['error', 'always'],

test/common/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ function getCallSite(top) {
475475
const err = new Error();
476476
Error.captureStackTrace(err, top);
477477
// With the V8 Error API, the stack is not formatted until it is accessed
478-
err.stack; // eslint-disable-line no-unused-expressions
478+
void err.stack;
479479
Error.prepareStackTrace = originalStackFormatter;
480480
return err.stack;
481481
}

test/message/nexttick_throw.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ process.nextTick(function() {
2626
process.nextTick(function() {
2727
process.nextTick(function() {
2828
process.nextTick(function() {
29-
// eslint-disable-next-line no-undef,no-unused-expressions
30-
undefined_reference_error_maker;
29+
void undefined_reference_error_maker;
3130
});
3231
});
3332
});

test/message/timeout_throw.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@
2323
require('../common');
2424

2525
setTimeout(function() {
26-
// eslint-disable-next-line no-undef,no-unused-expressions
27-
undefined_reference_error_maker;
26+
void undefined_reference_error_maker;
2827
}, 1);

test/parallel/test-accessor-properties.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const UDP = internalBinding('udp_wrap').UDP;
1717
{
1818
// Should throw instead of raise assertions
1919
assert.throws(() => {
20-
UDP.prototype.fd; // eslint-disable-line no-unused-expressions
20+
void UDP.prototype.fd;
2121
}, TypeError);
2222

2323
const StreamWrapProto = Object.getPrototypeOf(TTY.prototype);
@@ -26,7 +26,7 @@ const UDP = internalBinding('udp_wrap').UDP;
2626
properties.forEach((property) => {
2727
// Should throw instead of raise assertions
2828
assert.throws(() => {
29-
TTY.prototype[property]; // eslint-disable-line no-unused-expressions
29+
void TTY.prototype[property];
3030
}, TypeError, `Missing expected TypeError for TTY.prototype.${property}`);
3131

3232
// Should not throw for Object.getOwnPropertyDescriptor
@@ -42,8 +42,7 @@ const UDP = internalBinding('udp_wrap').UDP;
4242
const crypto = internalBinding('crypto');
4343

4444
assert.throws(() => {
45-
// eslint-disable-next-line no-unused-expressions
46-
crypto.SecureContext.prototype._external;
45+
void crypto.SecureContext.prototype._external;
4746
}, TypeError);
4847

4948
assert.strictEqual(

test/parallel/test-buffer-backing-arraybuffer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ for (const { length, expectOnHeap } of tests) {
3131
`for ${array.constructor.name}, length = ${length}`);
3232

3333
// Consistency check: Accessing .buffer should create it.
34-
array.buffer; // eslint-disable-line no-unused-expressions
34+
void array.buffer;
3535
assert(arrayBufferViewHasBuffer(array));
3636
}
3737
}

test/parallel/test-buffer-constructor-deprecation-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ process.on('warning', common.mustCall());
1414

1515
Error.prepareStackTrace = (err, trace) => new Buffer(10);
1616

17-
new Error().stack; // eslint-disable-line no-unused-expressions
17+
void new Error().stack;

test/parallel/test-buffer-fakes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ assert.throws(function() {
1414
}, TypeError);
1515

1616
assert.throws(function() {
17-
+Buffer.prototype; // eslint-disable-line no-unused-expressions
17+
void +Buffer.prototype;
1818
}, TypeError);
1919

2020
assert.throws(function() {

test/parallel/test-child-process-stdin-ipc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const spawn = require('child_process').spawn;
2727

2828
if (process.argv[2] === 'child') {
2929
// Just reference stdin, it should start it
30-
process.stdin; // eslint-disable-line no-unused-expressions
30+
void process.stdin;
3131
return;
3232
}
3333

test/parallel/test-dgram-deprecation-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const propertyCases = propertiesToTest.map((propName) => {
3131
`Socket.prototype.${propName} is deprecated`,
3232
'DEP0112'
3333
);
34-
sock[propName]; // eslint-disable-line no-unused-expressions
34+
void sock[propName];
3535
},
3636
() => {
3737
// Test property setter

0 commit comments

Comments
 (0)