Skip to content

Commit 226a86c

Browse files
committed
tools: enable no-unused-expressions lint rule
Fixes: #36246 PR-URL: #36248 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 52cbe89 commit 226a86c

Some content is hidden

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

52 files changed

+91
-93
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ module.exports = {
239239
'no-unreachable': 'error',
240240
'no-unsafe-finally': 'error',
241241
'no-unsafe-negation': 'error',
242+
'no-unused-expressions': ['error', { allowShortCircuit: true }],
242243
'no-unused-labels': 'error',
243244
'no-unused-vars': ['error', { args: 'none', caughtErrors: 'all' }],
244245
'no-use-before-define': ['error', {

benchmark/_benchmark_progress.js

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class BenchmarkProgress {
3939
this.completedConfig = 0;
4040
// Total number of configurations for the current file
4141
this.scheduledConfig = 0;
42-
this.interval; // Updates the elapsed time.
4342
}
4443

4544
startQueue(index) {

benchmark/es/destructuring-bench.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function runSwapManual(n) {
1212
let x, y, r;
1313
bench.start();
1414
for (let i = 0; i < n; i++) {
15-
x = 1, y = 2;
15+
x = 1;
16+
y = 2;
1617
r = x;
1718
x = y;
1819
y = r;
@@ -26,7 +27,8 @@ function runSwapDestructured(n) {
2627
let x, y;
2728
bench.start();
2829
for (let i = 0; i < n; i++) {
29-
x = 1, y = 2;
30+
x = 1;
31+
y = 2;
3032
[x, y] = [y, x];
3133
assert.strictEqual(x, 2);
3234
assert.strictEqual(y, 1);

benchmark/perf_hooks/bench-eventlooputil.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function main({ method, n }) {
3333
function benchIdleTime(n) {
3434
bench.start();
3535
for (let i = 0; i < n; i++)
36-
nodeTiming.idleTime;
36+
nodeTiming.idleTime; // eslint-disable-line no-unused-expressions
3737
bench.end(n);
3838
}
3939

benchmark/process/bench-env.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function main({ n, operation }) {
1313
case 'get':
1414
bench.start();
1515
for (let i = 0; i < n; i++) {
16-
process.env.PATH;
16+
process.env.PATH; // eslint-disable-line no-unused-expressions
1717
}
1818
bench.end(n);
1919
break;
@@ -42,7 +42,7 @@ function main({ n, operation }) {
4242
case 'query':
4343
bench.start();
4444
for (let i = 0; i < n; i++) {
45-
'PATH' in process.env;
45+
'PATH' in process.env; // eslint-disable-line no-unused-expressions
4646
}
4747
bench.end(n);
4848
break;

benchmark/string_decoder/string-decoder-create.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ const bench = common.createBenchmark(main, {
1212
function main({ encoding, n }) {
1313
bench.start();
1414
for (let i = 0; i < n; ++i) {
15-
const sd = new StringDecoder(encoding);
16-
!!sd.encoding;
15+
new StringDecoder(encoding);
1716
}
1817
bench.end(n);
1918
}

doc/.eslintrc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ rules:
44
# ease some restrictions in doc examples
55
no-restricted-properties: off
66
no-undef: off
7+
no-unused-expressions: off
78
no-unused-vars: off
89
symbol-description: off
910

lib/internal/assert/assertion_error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ class AssertionError extends Error {
455455
}
456456
ErrorCaptureStackTrace(this, stackStartFn || stackStartFunction);
457457
// Create error message including the error code in the name.
458-
this.stack;
458+
this.stack; // eslint-disable-line no-unused-expressions
459459
// Reset the name.
460460
this.name = 'AssertionError';
461461
}

lib/internal/buffer.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -951,18 +951,18 @@ function writeFloatBackwards(val, offset = 0) {
951951
class FastBuffer extends Uint8Array {}
952952

953953
function addBufferPrototypeMethods(proto) {
954-
proto.readBigUInt64LE = readBigUInt64LE,
955-
proto.readBigUInt64BE = readBigUInt64BE,
956-
proto.readBigUint64LE = readBigUInt64LE,
957-
proto.readBigUint64BE = readBigUInt64BE,
958-
proto.readBigInt64LE = readBigInt64LE,
959-
proto.readBigInt64BE = readBigInt64BE,
960-
proto.writeBigUInt64LE = writeBigUInt64LE,
961-
proto.writeBigUInt64BE = writeBigUInt64BE,
962-
proto.writeBigUint64LE = writeBigUInt64LE,
963-
proto.writeBigUint64BE = writeBigUInt64BE,
964-
proto.writeBigInt64LE = writeBigInt64LE,
965-
proto.writeBigInt64BE = writeBigInt64BE,
954+
proto.readBigUInt64LE = readBigUInt64LE;
955+
proto.readBigUInt64BE = readBigUInt64BE;
956+
proto.readBigUint64LE = readBigUInt64LE;
957+
proto.readBigUint64BE = readBigUInt64BE;
958+
proto.readBigInt64LE = readBigInt64LE;
959+
proto.readBigInt64BE = readBigInt64BE;
960+
proto.writeBigUInt64LE = writeBigUInt64LE;
961+
proto.writeBigUInt64BE = writeBigUInt64BE;
962+
proto.writeBigUint64LE = writeBigUInt64LE;
963+
proto.writeBigUint64BE = writeBigUInt64BE;
964+
proto.writeBigInt64LE = writeBigInt64LE;
965+
proto.writeBigInt64BE = writeBigInt64BE;
966966

967967
proto.readUIntLE = readUIntLE;
968968
proto.readUInt32LE = readUInt32LE;

lib/internal/errors.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ function addCodeToName(err, name, code) {
328328
err.name = `${name} [${code}]`;
329329
// Access the stack to generate the error message including the error code
330330
// from the name.
331-
err.stack;
331+
err.stack; // eslint-disable-line no-unused-expressions
332332
// Reset the name to the actual name.
333333
if (name === 'SystemError') {
334334
ObjectDefineProperty(err, 'name', {
@@ -1399,11 +1399,11 @@ E('ERR_TLS_CERT_ALTNAME_INVALID', function(reason, host, cert) {
13991399
}, Error);
14001400
E('ERR_TLS_DH_PARAM_SIZE', 'DH parameter size %s is less than 2048', Error);
14011401
E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout', Error);
1402-
E('ERR_TLS_INVALID_CONTEXT', '%s must be a SecureContext', TypeError),
1403-
E('ERR_TLS_INVALID_STATE', 'TLS socket connection must be securely established',
1404-
Error),
1402+
E('ERR_TLS_INVALID_CONTEXT', '%s must be a SecureContext', TypeError);
14051403
E('ERR_TLS_INVALID_PROTOCOL_VERSION',
14061404
'%j is not a valid %s TLS protocol version', TypeError);
1405+
E('ERR_TLS_INVALID_STATE', 'TLS socket connection must be securely established',
1406+
Error);
14071407
E('ERR_TLS_PROTOCOL_VERSION_CONFLICT',
14081408
'TLS protocol version %j conflicts with secureProtocol %j', TypeError);
14091409
E('ERR_TLS_RENEGOTIATION_DISABLED',

lib/internal/streams/destroy.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function destroy(err, cb) {
1616

1717
if (err) {
1818
// Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
19-
err.stack;
19+
err.stack; // eslint-disable-line no-unused-expressions
2020

2121
if (w && !w.errored) {
2222
w.errored = err;
@@ -39,7 +39,7 @@ function destroy(err, cb) {
3939
this._destroy(err || null, (err) => {
4040
if (err) {
4141
// Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
42-
err.stack;
42+
err.stack; // eslint-disable-line no-unused-expressions
4343

4444
if (w && !w.errored) {
4545
w.errored = err;
@@ -153,7 +153,7 @@ function errorOrDestroy(stream, err, sync) {
153153
stream.destroy(err);
154154
else if (err) {
155155
// Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
156-
err.stack;
156+
err.stack; // eslint-disable-line no-unused-expressions
157157

158158
if (w && !w.errored) {
159159
w.errored = err;

lib/internal/streams/writable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ function onwrite(stream, er) {
408408

409409
if (er) {
410410
// Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364
411-
er.stack;
411+
er.stack; // eslint-disable-line no-unused-expressions
412412

413413
if (!state.errored) {
414414
state.errored = er;

test/common/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ function getCallSite(top) {
423423
const err = new Error();
424424
Error.captureStackTrace(err, top);
425425
// With the V8 Error API, the stack is not formatted until it is accessed
426-
err.stack;
426+
err.stack; // eslint-disable-line no-unused-expressions
427427
Error.prepareStackTrace = originalStackFormatter;
428428
return err.stack;
429429
}

test/js-native-api/test_general/testEnvCleanup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if (process.argv[2] === 'child') {
3030
// Make sure that only the latest attached version of a re-wrapped item's
3131
// finalizer gets called at env cleanup.
3232
module.exports['first wrap'] =
33-
test_general.envCleanupWrap({}, finalizerMessages['first wrap']),
33+
test_general.envCleanupWrap({}, finalizerMessages['first wrap']);
3434
test_general.removeWrap(module.exports['first wrap']);
3535
test_general.envCleanupWrap(module.exports['first wrap'],
3636
finalizerMessages['second wrap']);

test/message/nexttick_throw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ process.nextTick(function() {
2626
process.nextTick(function() {
2727
process.nextTick(function() {
2828
process.nextTick(function() {
29-
// eslint-disable-next-line no-undef
29+
// eslint-disable-next-line no-undef,no-unused-expressions
3030
undefined_reference_error_maker;
3131
});
3232
});

test/message/timeout_throw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
require('../common');
2424

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

test/parallel/test-accessor-properties.js

+3-2
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;
20+
UDP.prototype.fd; // eslint-disable-line no-unused-expressions
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];
29+
TTY.prototype[property]; // eslint-disable-line no-unused-expressions
3030
}, TypeError, `Missing expected TypeError for TTY.prototype.${property}`);
3131

3232
// Should not throw for Object.getOwnPropertyDescriptor
@@ -42,6 +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
4546
crypto.SecureContext.prototype._external;
4647
}, TypeError);
4748

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

+1-1
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;
34+
array.buffer; // eslint-disable-line no-unused-expressions
3535
assert(arrayBufferViewHasBuffer(array));
3636
}
3737
}

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

+1-1
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;
17+
new Error().stack; // eslint-disable-line no-unused-expressions

test/parallel/test-buffer-fakes.js

+1-1
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;
17+
+Buffer.prototype; // eslint-disable-line no-unused-expressions
1818
}, TypeError);
1919

2020
assert.throws(function() {

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

+1-1
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;
30+
process.stdin; // eslint-disable-line no-unused-expressions
3131
return;
3232
}
3333

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

+1-1
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];
34+
sock[propName]; // eslint-disable-line no-unused-expressions
3535
},
3636
() => {
3737
// Test property setter

test/parallel/test-disable-proto-throw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { Worker, isMainThread } = require('worker_threads');
1010
assert(Object.prototype.hasOwnProperty('__proto__'));
1111

1212
assert.throws(() => {
13-
// eslint-disable-next-line no-proto
13+
// eslint-disable-next-line no-proto,no-unused-expressions
1414
({}).__proto__;
1515
}, {
1616
code: 'ERR_PROTO_ACCESS'

test/parallel/test-error-prepare-stack-trace.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const assert = require('assert');
1313
try {
1414
throw new Error('foo');
1515
} catch (err) {
16-
err.stack;
16+
err.stack; // eslint-disable-line no-unused-expressions
1717
}
1818
assert(prepareCalled);
1919
}

test/parallel/test-fs-promises-file-handle-read.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ let useConf = false;
7272
.then(validateLargeRead)
7373
.then(common.mustCall());
7474
}
75-
});
75+
})().then(common.mustCall());

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function getFileName() {
1818
const allocateEmptyBuffers = (combinedLength) => {
1919
const bufferArr = [];
2020
// Allocate two buffers, each half the size of exptectedBuff
21-
bufferArr[0] = Buffer.alloc(Math.floor(combinedLength / 2)),
21+
bufferArr[0] = Buffer.alloc(Math.floor(combinedLength / 2));
2222
bufferArr[1] = Buffer.alloc(combinedLength - bufferArr[0].length);
2323

2424
return bufferArr;

test/parallel/test-fs-readv-sync.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fs.writeFileSync(filename, exptectedBuff);
1919
const allocateEmptyBuffers = (combinedLength) => {
2020
const bufferArr = [];
2121
// Allocate two buffers, each half the size of exptectedBuff
22-
bufferArr[0] = Buffer.alloc(Math.floor(combinedLength / 2)),
22+
bufferArr[0] = Buffer.alloc(Math.floor(combinedLength / 2));
2323
bufferArr[1] = Buffer.alloc(combinedLength - bufferArr[0].length);
2424

2525
return bufferArr;

test/parallel/test-fs-readv.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const exptectedBuff = Buffer.from(expected);
1717
const allocateEmptyBuffers = (combinedLength) => {
1818
const bufferArr = [];
1919
// Allocate two buffers, each half the size of exptectedBuff
20-
bufferArr[0] = Buffer.alloc(Math.floor(combinedLength / 2)),
20+
bufferArr[0] = Buffer.alloc(Math.floor(combinedLength / 2));
2121
bufferArr[1] = Buffer.alloc(combinedLength - bufferArr[0].length);
2222

2323
return bufferArr;

test/parallel/test-http-outgoing-internal-headernames-getter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ common.expectWarning('DeprecationWarning', warn, 'DEP0066');
99
{
1010
// Tests for _headerNames get method
1111
const outgoingMessage = new OutgoingMessage();
12-
outgoingMessage._headerNames;
12+
outgoingMessage._headerNames; // eslint-disable-line no-unused-expressions
1313
}

test/parallel/test-http-outgoing-internal-headers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ common.expectWarning('DeprecationWarning', warn, 'DEP0066');
1313
// Tests for _headers get method
1414
const outgoingMessage = new OutgoingMessage();
1515
outgoingMessage.getHeaders = common.mustCall();
16-
outgoingMessage._headers;
16+
outgoingMessage._headers; // eslint-disable-line no-unused-expressions
1717
}
1818

1919
{

test/parallel/test-http-same-map.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ onresponse.responses = [];
3939

4040
function allSame(list) {
4141
assert(list.length >= 2);
42-
// Use |elt| in no-op position to pacify eslint.
43-
for (const elt of list) elt, eval('%DebugPrint(elt)');
44-
for (const elt of list) elt, assert(eval('%HaveSameMap(list[0], elt)'));
42+
// eslint-disable-next-line no-unused-vars
43+
for (const elt of list) eval('%DebugPrint(elt)');
44+
// eslint-disable-next-line no-unused-vars
45+
for (const elt of list) assert(eval('%HaveSameMap(list[0], elt)'));
4546
}
4647

4748
process.on('exit', () => {

test/parallel/test-http2-unbound-socket-proxy.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ server.listen(0, common.mustCall(() => {
2626
// informative error.
2727
setImmediate(common.mustCall(() => {
2828
assert.throws(() => {
29-
socket.example;
29+
socket.example; // eslint-disable-line no-unused-expressions
3030
}, {
3131
code: 'ERR_HTTP2_SOCKET_UNBOUND'
3232
});
@@ -36,6 +36,7 @@ server.listen(0, common.mustCall(() => {
3636
code: 'ERR_HTTP2_SOCKET_UNBOUND'
3737
});
3838
assert.throws(() => {
39+
// eslint-disable-next-line no-unused-expressions
3940
socket instanceof net.Socket;
4041
}, {
4142
code: 'ERR_HTTP2_SOCKET_UNBOUND'

test/parallel/test-inspector-tracing-domain.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function post(message, data) {
3030
function generateTrace() {
3131
return new Promise((resolve) => setTimeout(() => {
3232
for (let i = 0; i < 1000000; i++) {
33-
'test' + i;
33+
'test' + i; // eslint-disable-line no-unused-expressions
3434
}
3535
resolve();
3636
}, 1));

0 commit comments

Comments
 (0)