From 040b39f076d8169fc51c14282b95d2a1b4ec57a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 24 Nov 2020 14:11:20 +0100 Subject: [PATCH] tools: enable no-unused-expressions lint rule Fixes: https://github.com/nodejs/node/issues/36246 PR-URL: https://github.com/nodejs/node/pull/36248 Reviewed-By: Antoine du Hamel Reviewed-By: Colin Ihrig Reviewed-By: Joyee Cheung Reviewed-By: Luigi Pinca Reviewed-By: Yongsheng Zhang Reviewed-By: Rich Trott Reviewed-By: James M Snell --- .eslintrc.js | 1 + benchmark/_benchmark_progress.js | 1 - benchmark/es/destructuring-bench.js | 6 +++-- benchmark/perf_hooks/bench-eventlooputil.js | 2 +- benchmark/process/bench-env.js | 4 ++-- .../string_decoder/string-decoder-create.js | 3 +-- doc/.eslintrc.yaml | 1 + lib/internal/assert/assertion_error.js | 2 +- lib/internal/buffer.js | 24 +++++++++---------- lib/internal/errors.js | 8 +++---- lib/internal/streams/destroy.js | 6 ++--- lib/internal/streams/writable.js | 2 +- test/common/index.js | 2 +- .../test_general/testEnvCleanup.js | 2 +- test/message/nexttick_throw.js | 2 +- test/message/timeout_throw.js | 2 +- test/parallel/test-accessor-properties.js | 5 ++-- .../test-buffer-backing-arraybuffer.js | 2 +- ...st-buffer-constructor-deprecation-error.js | 2 +- test/parallel/test-buffer-fakes.js | 2 +- test/parallel/test-child-process-stdin-ipc.js | 2 +- test/parallel/test-dgram-deprecation-error.js | 2 +- test/parallel/test-disable-proto-throw.js | 2 +- .../test-error-prepare-stack-trace.js | 2 +- test/parallel/test-fs-readv-promises.js | 2 +- test/parallel/test-fs-readv-sync.js | 2 +- test/parallel/test-fs-readv.js | 2 +- ...tp-outgoing-internal-headernames-getter.js | 2 +- .../test-http-outgoing-internal-headers.js | 2 +- test/parallel/test-http-same-map.js | 7 +++--- .../test-http2-unbound-socket-proxy.js | 3 ++- .../parallel/test-inspector-tracing-domain.js | 2 +- ...spector-vm-global-accessors-sideeffects.js | 3 +-- .../test-internal-iterable-weak-map.js | 2 +- test/parallel/test-net-after-close.js | 2 ++ test/parallel/test-net-during-close.js | 2 ++ .../test-process-env-windows-error-reset.js | 4 ++-- test/parallel/test-repl-options.js | 2 +- test/parallel/test-repl-tab-complete.js | 2 +- test/parallel/test-source-map-api.js | 1 + test/parallel/test-stdin-hang.js | 2 +- test/parallel/test-stdio-closed.js | 2 ++ test/parallel/test-stdio-pipe-access.js | 2 +- .../parallel/test-stream-pipeline-uncaught.js | 4 +--- test/parallel/test-stream-pipeline.js | 10 ++------ .../test-stream-readable-async-iterators.js | 19 +++++---------- test/parallel/test-tls-external-accessor.js | 4 ++-- test/parallel/test-trace-events-bootstrap.js | 2 +- .../parallel/test-trace-events-environment.js | 2 ++ test/parallel/test-vm-module-errors.js | 6 ++--- .../test-worker-unsupported-things.js | 2 +- 51 files changed, 90 insertions(+), 92 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 7f37fc19d5a543..edb2b6c1ee3419 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -234,6 +234,7 @@ module.exports = { 'no-unreachable': 'error', 'no-unsafe-finally': 'error', 'no-unsafe-negation': 'error', + 'no-unused-expressions': ['error', { allowShortCircuit: true }], 'no-unused-labels': 'error', 'no-unused-vars': ['error', { args: 'none', caughtErrors: 'all' }], 'no-use-before-define': ['error', { diff --git a/benchmark/_benchmark_progress.js b/benchmark/_benchmark_progress.js index 1b7ac738f6de0d..6c925f34e68202 100644 --- a/benchmark/_benchmark_progress.js +++ b/benchmark/_benchmark_progress.js @@ -39,7 +39,6 @@ class BenchmarkProgress { this.completedConfig = 0; // Total number of configurations for the current file this.scheduledConfig = 0; - this.interval; // Updates the elapsed time. } startQueue(index) { diff --git a/benchmark/es/destructuring-bench.js b/benchmark/es/destructuring-bench.js index c07c0383da91ac..d412b82757f083 100644 --- a/benchmark/es/destructuring-bench.js +++ b/benchmark/es/destructuring-bench.js @@ -12,7 +12,8 @@ function runSwapManual(n) { let x, y, r; bench.start(); for (let i = 0; i < n; i++) { - x = 1, y = 2; + x = 1; + y = 2; r = x; x = y; y = r; @@ -26,7 +27,8 @@ function runSwapDestructured(n) { let x, y; bench.start(); for (let i = 0; i < n; i++) { - x = 1, y = 2; + x = 1; + y = 2; [x, y] = [y, x]; assert.strictEqual(x, 2); assert.strictEqual(y, 1); diff --git a/benchmark/perf_hooks/bench-eventlooputil.js b/benchmark/perf_hooks/bench-eventlooputil.js index 984b2b66aecbcf..1fd452afa91300 100644 --- a/benchmark/perf_hooks/bench-eventlooputil.js +++ b/benchmark/perf_hooks/bench-eventlooputil.js @@ -33,7 +33,7 @@ function main({ method, n }) { function benchIdleTime(n) { bench.start(); for (let i = 0; i < n; i++) - nodeTiming.idleTime; + nodeTiming.idleTime; // eslint-disable-line no-unused-expressions bench.end(n); } diff --git a/benchmark/process/bench-env.js b/benchmark/process/bench-env.js index 5df521cc958389..e96c1d02507214 100644 --- a/benchmark/process/bench-env.js +++ b/benchmark/process/bench-env.js @@ -13,7 +13,7 @@ function main({ n, operation }) { case 'get': bench.start(); for (let i = 0; i < n; i++) { - process.env.PATH; + process.env.PATH; // eslint-disable-line no-unused-expressions } bench.end(n); break; @@ -42,7 +42,7 @@ function main({ n, operation }) { case 'query': bench.start(); for (let i = 0; i < n; i++) { - 'PATH' in process.env; + 'PATH' in process.env; // eslint-disable-line no-unused-expressions } bench.end(n); break; diff --git a/benchmark/string_decoder/string-decoder-create.js b/benchmark/string_decoder/string-decoder-create.js index f7fa5e0246b860..641e562fdeab3d 100644 --- a/benchmark/string_decoder/string-decoder-create.js +++ b/benchmark/string_decoder/string-decoder-create.js @@ -12,8 +12,7 @@ const bench = common.createBenchmark(main, { function main({ encoding, n }) { bench.start(); for (let i = 0; i < n; ++i) { - const sd = new StringDecoder(encoding); - !!sd.encoding; + new StringDecoder(encoding); } bench.end(n); } diff --git a/doc/.eslintrc.yaml b/doc/.eslintrc.yaml index 49c4f4f64736c7..8e01bea6abd8a7 100644 --- a/doc/.eslintrc.yaml +++ b/doc/.eslintrc.yaml @@ -4,6 +4,7 @@ rules: # ease some restrictions in doc examples no-restricted-properties: off no-undef: off + no-unused-expressions: off no-unused-vars: off symbol-description: off diff --git a/lib/internal/assert/assertion_error.js b/lib/internal/assert/assertion_error.js index c13a9d1ca1c3d8..e9e9a101970509 100644 --- a/lib/internal/assert/assertion_error.js +++ b/lib/internal/assert/assertion_error.js @@ -455,7 +455,7 @@ class AssertionError extends Error { } ErrorCaptureStackTrace(this, stackStartFn || stackStartFunction); // Create error message including the error code in the name. - this.stack; + this.stack; // eslint-disable-line no-unused-expressions // Reset the name. this.name = 'AssertionError'; } diff --git a/lib/internal/buffer.js b/lib/internal/buffer.js index 9eb722e2634deb..60f6cab093135d 100644 --- a/lib/internal/buffer.js +++ b/lib/internal/buffer.js @@ -952,18 +952,18 @@ function writeFloatBackwards(val, offset = 0) { class FastBuffer extends Uint8Array {} function addBufferPrototypeMethods(proto) { - proto.readBigUInt64LE = readBigUInt64LE, - proto.readBigUInt64BE = readBigUInt64BE, - proto.readBigUint64LE = readBigUInt64LE, - proto.readBigUint64BE = readBigUInt64BE, - proto.readBigInt64LE = readBigInt64LE, - proto.readBigInt64BE = readBigInt64BE, - proto.writeBigUInt64LE = writeBigUInt64LE, - proto.writeBigUInt64BE = writeBigUInt64BE, - proto.writeBigUint64LE = writeBigUInt64LE, - proto.writeBigUint64BE = writeBigUInt64BE, - proto.writeBigInt64LE = writeBigInt64LE, - proto.writeBigInt64BE = writeBigInt64BE, + proto.readBigUInt64LE = readBigUInt64LE; + proto.readBigUInt64BE = readBigUInt64BE; + proto.readBigUint64LE = readBigUInt64LE; + proto.readBigUint64BE = readBigUInt64BE; + proto.readBigInt64LE = readBigInt64LE; + proto.readBigInt64BE = readBigInt64BE; + proto.writeBigUInt64LE = writeBigUInt64LE; + proto.writeBigUInt64BE = writeBigUInt64BE; + proto.writeBigUint64LE = writeBigUInt64LE; + proto.writeBigUint64BE = writeBigUInt64BE; + proto.writeBigInt64LE = writeBigInt64LE; + proto.writeBigInt64BE = writeBigInt64BE; proto.readUIntLE = readUIntLE; proto.readUInt32LE = readUInt32LE; diff --git a/lib/internal/errors.js b/lib/internal/errors.js index d608ca42a09b75..8a7e744c5fe667 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -332,7 +332,7 @@ function addCodeToName(err, name, code) { err.name = `${name} [${code}]`; // Access the stack to generate the error message including the error code // from the name. - err.stack; + err.stack; // eslint-disable-line no-unused-expressions // Reset the name to the actual name. if (name === 'SystemError') { ObjectDefineProperty(err, 'name', { @@ -1411,11 +1411,11 @@ E('ERR_TLS_CERT_ALTNAME_INVALID', function(reason, host, cert) { }, Error); E('ERR_TLS_DH_PARAM_SIZE', 'DH parameter size %s is less than 2048', Error); E('ERR_TLS_HANDSHAKE_TIMEOUT', 'TLS handshake timeout', Error); -E('ERR_TLS_INVALID_CONTEXT', '%s must be a SecureContext', TypeError), -E('ERR_TLS_INVALID_STATE', 'TLS socket connection must be securely established', - Error), +E('ERR_TLS_INVALID_CONTEXT', '%s must be a SecureContext', TypeError); E('ERR_TLS_INVALID_PROTOCOL_VERSION', '%j is not a valid %s TLS protocol version', TypeError); +E('ERR_TLS_INVALID_STATE', 'TLS socket connection must be securely established', + Error); E('ERR_TLS_PROTOCOL_VERSION_CONFLICT', 'TLS protocol version %j conflicts with secureProtocol %j', TypeError); E('ERR_TLS_RENEGOTIATION_DISABLED', diff --git a/lib/internal/streams/destroy.js b/lib/internal/streams/destroy.js index 7477ec97379ff9..ff1bea5a415577 100644 --- a/lib/internal/streams/destroy.js +++ b/lib/internal/streams/destroy.js @@ -11,7 +11,7 @@ const kConstruct = Symbol('kConstruct'); function checkError(err, w, r) { if (err) { // Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364 - err.stack; + err.stack; // eslint-disable-line no-unused-expressions if (w && !w.errored) { w.errored = err; @@ -118,7 +118,7 @@ function _destroy(self, err, cb) { function(err) { const r = self._readableState; const w = self._writableState; - err.stack; + err.stack; // eslint-disable-line no-unused-expressions called = true; @@ -237,7 +237,7 @@ function errorOrDestroy(stream, err, sync) { stream.destroy(err); else if (err) { // Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364 - err.stack; + err.stack; // eslint-disable-line no-unused-expressions if (w && !w.errored) { w.errored = err; diff --git a/lib/internal/streams/writable.js b/lib/internal/streams/writable.js index 104a3c43452931..f76f3eb60777c8 100644 --- a/lib/internal/streams/writable.js +++ b/lib/internal/streams/writable.js @@ -438,7 +438,7 @@ function onwrite(stream, er) { if (er) { // Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364 - er.stack; + er.stack; // eslint-disable-line no-unused-expressions if (!state.errored) { state.errored = er; diff --git a/test/common/index.js b/test/common/index.js index 4ec68cf5857a9f..0952f5de52fa3f 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -424,7 +424,7 @@ function getCallSite(top) { const err = new Error(); Error.captureStackTrace(err, top); // With the V8 Error API, the stack is not formatted until it is accessed - err.stack; + err.stack; // eslint-disable-line no-unused-expressions Error.prepareStackTrace = originalStackFormatter; return err.stack; } diff --git a/test/js-native-api/test_general/testEnvCleanup.js b/test/js-native-api/test_general/testEnvCleanup.js index 8d567bef4518ce..99b47a3e62560f 100644 --- a/test/js-native-api/test_general/testEnvCleanup.js +++ b/test/js-native-api/test_general/testEnvCleanup.js @@ -30,7 +30,7 @@ if (process.argv[2] === 'child') { // Make sure that only the latest attached version of a re-wrapped item's // finalizer gets called at env cleanup. module.exports['first wrap'] = - test_general.envCleanupWrap({}, finalizerMessages['first wrap']), + test_general.envCleanupWrap({}, finalizerMessages['first wrap']); test_general.removeWrap(module.exports['first wrap']); test_general.envCleanupWrap(module.exports['first wrap'], finalizerMessages['second wrap']); diff --git a/test/message/nexttick_throw.js b/test/message/nexttick_throw.js index a3369e0d102924..d7e51b411eda64 100644 --- a/test/message/nexttick_throw.js +++ b/test/message/nexttick_throw.js @@ -26,7 +26,7 @@ process.nextTick(function() { process.nextTick(function() { process.nextTick(function() { process.nextTick(function() { - // eslint-disable-next-line no-undef + // eslint-disable-next-line no-undef,no-unused-expressions undefined_reference_error_maker; }); }); diff --git a/test/message/timeout_throw.js b/test/message/timeout_throw.js index 6ae705369786c4..9bcbd85b5036e2 100644 --- a/test/message/timeout_throw.js +++ b/test/message/timeout_throw.js @@ -23,6 +23,6 @@ require('../common'); setTimeout(function() { - // eslint-disable-next-line no-undef + // eslint-disable-next-line no-undef,no-unused-expressions undefined_reference_error_maker; }, 1); diff --git a/test/parallel/test-accessor-properties.js b/test/parallel/test-accessor-properties.js index a84889d617b4ad..ae7919ea318c09 100644 --- a/test/parallel/test-accessor-properties.js +++ b/test/parallel/test-accessor-properties.js @@ -17,7 +17,7 @@ const UDP = internalBinding('udp_wrap').UDP; { // Should throw instead of raise assertions assert.throws(() => { - UDP.prototype.fd; + UDP.prototype.fd; // eslint-disable-line no-unused-expressions }, TypeError); const StreamWrapProto = Object.getPrototypeOf(TTY.prototype); @@ -26,7 +26,7 @@ const UDP = internalBinding('udp_wrap').UDP; properties.forEach((property) => { // Should throw instead of raise assertions assert.throws(() => { - TTY.prototype[property]; + TTY.prototype[property]; // eslint-disable-line no-unused-expressions }, TypeError, `Missing expected TypeError for TTY.prototype.${property}`); // Should not throw for Object.getOwnPropertyDescriptor @@ -42,6 +42,7 @@ const UDP = internalBinding('udp_wrap').UDP; const crypto = internalBinding('crypto'); assert.throws(() => { + // eslint-disable-next-line no-unused-expressions crypto.SecureContext.prototype._external; }, TypeError); diff --git a/test/parallel/test-buffer-backing-arraybuffer.js b/test/parallel/test-buffer-backing-arraybuffer.js index e7e15c079e6332..75dcd60068d5ab 100644 --- a/test/parallel/test-buffer-backing-arraybuffer.js +++ b/test/parallel/test-buffer-backing-arraybuffer.js @@ -31,7 +31,7 @@ for (const { length, expectOnHeap } of tests) { `for ${array.constructor.name}, length = ${length}`); // Consistency check: Accessing .buffer should create it. - array.buffer; + array.buffer; // eslint-disable-line no-unused-expressions assert(arrayBufferViewHasBuffer(array)); } } diff --git a/test/parallel/test-buffer-constructor-deprecation-error.js b/test/parallel/test-buffer-constructor-deprecation-error.js index 46535e103b33ee..6628bd490a2ff3 100644 --- a/test/parallel/test-buffer-constructor-deprecation-error.js +++ b/test/parallel/test-buffer-constructor-deprecation-error.js @@ -14,4 +14,4 @@ process.on('warning', common.mustCall()); Error.prepareStackTrace = (err, trace) => new Buffer(10); -new Error().stack; +new Error().stack; // eslint-disable-line no-unused-expressions diff --git a/test/parallel/test-buffer-fakes.js b/test/parallel/test-buffer-fakes.js index d126d39aa95263..da78fe0895e6bb 100644 --- a/test/parallel/test-buffer-fakes.js +++ b/test/parallel/test-buffer-fakes.js @@ -14,7 +14,7 @@ assert.throws(function() { }, TypeError); assert.throws(function() { - +Buffer.prototype; + +Buffer.prototype; // eslint-disable-line no-unused-expressions }, TypeError); assert.throws(function() { diff --git a/test/parallel/test-child-process-stdin-ipc.js b/test/parallel/test-child-process-stdin-ipc.js index b162ced916096d..945960b99b72cc 100644 --- a/test/parallel/test-child-process-stdin-ipc.js +++ b/test/parallel/test-child-process-stdin-ipc.js @@ -27,7 +27,7 @@ const spawn = require('child_process').spawn; if (process.argv[2] === 'child') { // Just reference stdin, it should start it - process.stdin; + process.stdin; // eslint-disable-line no-unused-expressions return; } diff --git a/test/parallel/test-dgram-deprecation-error.js b/test/parallel/test-dgram-deprecation-error.js index d244940b64d793..37664a5720c96f 100644 --- a/test/parallel/test-dgram-deprecation-error.js +++ b/test/parallel/test-dgram-deprecation-error.js @@ -31,7 +31,7 @@ const propertyCases = propertiesToTest.map((propName) => { `Socket.prototype.${propName} is deprecated`, 'DEP0112' ); - sock[propName]; + sock[propName]; // eslint-disable-line no-unused-expressions }, () => { // Test property setter diff --git a/test/parallel/test-disable-proto-throw.js b/test/parallel/test-disable-proto-throw.js index e7a1f679765235..a39cfef0d8bd43 100644 --- a/test/parallel/test-disable-proto-throw.js +++ b/test/parallel/test-disable-proto-throw.js @@ -10,7 +10,7 @@ const { Worker, isMainThread } = require('worker_threads'); assert(Object.prototype.hasOwnProperty('__proto__')); assert.throws(() => { - // eslint-disable-next-line no-proto + // eslint-disable-next-line no-proto,no-unused-expressions ({}).__proto__; }, { code: 'ERR_PROTO_ACCESS' diff --git a/test/parallel/test-error-prepare-stack-trace.js b/test/parallel/test-error-prepare-stack-trace.js index 2ace9c8d71491d..28ecdd25f50135 100644 --- a/test/parallel/test-error-prepare-stack-trace.js +++ b/test/parallel/test-error-prepare-stack-trace.js @@ -13,7 +13,7 @@ const assert = require('assert'); try { throw new Error('foo'); } catch (err) { - err.stack; + err.stack; // eslint-disable-line no-unused-expressions } assert(prepareCalled); } diff --git a/test/parallel/test-fs-readv-promises.js b/test/parallel/test-fs-readv-promises.js index 1132417c9e27c4..1d12126e557683 100644 --- a/test/parallel/test-fs-readv-promises.js +++ b/test/parallel/test-fs-readv-promises.js @@ -18,7 +18,7 @@ function getFileName() { const allocateEmptyBuffers = (combinedLength) => { const bufferArr = []; // Allocate two buffers, each half the size of exptectedBuff - bufferArr[0] = Buffer.alloc(Math.floor(combinedLength / 2)), + bufferArr[0] = Buffer.alloc(Math.floor(combinedLength / 2)); bufferArr[1] = Buffer.alloc(combinedLength - bufferArr[0].length); return bufferArr; diff --git a/test/parallel/test-fs-readv-sync.js b/test/parallel/test-fs-readv-sync.js index 92aa2fb6816752..9da39824d7f583 100644 --- a/test/parallel/test-fs-readv-sync.js +++ b/test/parallel/test-fs-readv-sync.js @@ -19,7 +19,7 @@ fs.writeFileSync(filename, exptectedBuff); const allocateEmptyBuffers = (combinedLength) => { const bufferArr = []; // Allocate two buffers, each half the size of exptectedBuff - bufferArr[0] = Buffer.alloc(Math.floor(combinedLength / 2)), + bufferArr[0] = Buffer.alloc(Math.floor(combinedLength / 2)); bufferArr[1] = Buffer.alloc(combinedLength - bufferArr[0].length); return bufferArr; diff --git a/test/parallel/test-fs-readv.js b/test/parallel/test-fs-readv.js index 8cffdb29c02060..2ca79b302c636f 100644 --- a/test/parallel/test-fs-readv.js +++ b/test/parallel/test-fs-readv.js @@ -17,7 +17,7 @@ const exptectedBuff = Buffer.from(expected); const allocateEmptyBuffers = (combinedLength) => { const bufferArr = []; // Allocate two buffers, each half the size of exptectedBuff - bufferArr[0] = Buffer.alloc(Math.floor(combinedLength / 2)), + bufferArr[0] = Buffer.alloc(Math.floor(combinedLength / 2)); bufferArr[1] = Buffer.alloc(combinedLength - bufferArr[0].length); return bufferArr; diff --git a/test/parallel/test-http-outgoing-internal-headernames-getter.js b/test/parallel/test-http-outgoing-internal-headernames-getter.js index c3caffff1f8a42..4a56a1301050b5 100644 --- a/test/parallel/test-http-outgoing-internal-headernames-getter.js +++ b/test/parallel/test-http-outgoing-internal-headernames-getter.js @@ -9,5 +9,5 @@ common.expectWarning('DeprecationWarning', warn, 'DEP0066'); { // Tests for _headerNames get method const outgoingMessage = new OutgoingMessage(); - outgoingMessage._headerNames; + outgoingMessage._headerNames; // eslint-disable-line no-unused-expressions } diff --git a/test/parallel/test-http-outgoing-internal-headers.js b/test/parallel/test-http-outgoing-internal-headers.js index b9e7aed165b68d..7bd97bcb530955 100644 --- a/test/parallel/test-http-outgoing-internal-headers.js +++ b/test/parallel/test-http-outgoing-internal-headers.js @@ -13,7 +13,7 @@ common.expectWarning('DeprecationWarning', warn, 'DEP0066'); // Tests for _headers get method const outgoingMessage = new OutgoingMessage(); outgoingMessage.getHeaders = common.mustCall(); - outgoingMessage._headers; + outgoingMessage._headers; // eslint-disable-line no-unused-expressions } { diff --git a/test/parallel/test-http-same-map.js b/test/parallel/test-http-same-map.js index 0adb73222de184..3d8d325ad7b0d1 100644 --- a/test/parallel/test-http-same-map.js +++ b/test/parallel/test-http-same-map.js @@ -39,9 +39,10 @@ onresponse.responses = []; function allSame(list) { assert(list.length >= 2); - // Use |elt| in no-op position to pacify eslint. - for (const elt of list) elt, eval('%DebugPrint(elt)'); - for (const elt of list) elt, assert(eval('%HaveSameMap(list[0], elt)')); + // eslint-disable-next-line no-unused-vars + for (const elt of list) eval('%DebugPrint(elt)'); + // eslint-disable-next-line no-unused-vars + for (const elt of list) assert(eval('%HaveSameMap(list[0], elt)')); } process.on('exit', () => { diff --git a/test/parallel/test-http2-unbound-socket-proxy.js b/test/parallel/test-http2-unbound-socket-proxy.js index a5505c8509dca3..74ca0169446afb 100644 --- a/test/parallel/test-http2-unbound-socket-proxy.js +++ b/test/parallel/test-http2-unbound-socket-proxy.js @@ -26,7 +26,7 @@ server.listen(0, common.mustCall(() => { // informative error. setImmediate(common.mustCall(() => { assert.throws(() => { - socket.example; + socket.example; // eslint-disable-line no-unused-expressions }, { code: 'ERR_HTTP2_SOCKET_UNBOUND' }); @@ -36,6 +36,7 @@ server.listen(0, common.mustCall(() => { code: 'ERR_HTTP2_SOCKET_UNBOUND' }); assert.throws(() => { + // eslint-disable-next-line no-unused-expressions socket instanceof net.Socket; }, { code: 'ERR_HTTP2_SOCKET_UNBOUND' diff --git a/test/parallel/test-inspector-tracing-domain.js b/test/parallel/test-inspector-tracing-domain.js index 152df1491553f1..164fbe1cd86b67 100644 --- a/test/parallel/test-inspector-tracing-domain.js +++ b/test/parallel/test-inspector-tracing-domain.js @@ -30,7 +30,7 @@ function post(message, data) { function generateTrace() { return new Promise((resolve) => setTimeout(() => { for (let i = 0; i < 1000000; i++) { - 'test' + i; + 'test' + i; // eslint-disable-line no-unused-expressions } resolve(); }, 1)); diff --git a/test/parallel/test-inspector-vm-global-accessors-sideeffects.js b/test/parallel/test-inspector-vm-global-accessors-sideeffects.js index 33545e14c7ae2b..b07ce182232fba 100644 --- a/test/parallel/test-inspector-vm-global-accessors-sideeffects.js +++ b/test/parallel/test-inspector-vm-global-accessors-sideeffects.js @@ -19,8 +19,7 @@ session.post('Runtime.evaluate', { expression: 'a', throwOnSideEffect: true, contextId: 2 // context's id -}, common.mustCall((error, res) => { - assert.ifError(error), +}, common.mustSucceed((res) => { assert.deepStrictEqual(res, { result: { type: 'number', diff --git a/test/parallel/test-internal-iterable-weak-map.js b/test/parallel/test-internal-iterable-weak-map.js index 04636c20903a2e..e0282c9081ee33 100644 --- a/test/parallel/test-internal-iterable-weak-map.js +++ b/test/parallel/test-internal-iterable-weak-map.js @@ -18,7 +18,7 @@ const { IterableWeakMap } = require('internal/util/iterable_weak_map'); wm.set(_cache.moduleC, 'goodbye'); delete _cache.moduleB; setImmediate(() => { - _cache; + _cache; // eslint-disable-line no-unused-expressions globalThis.gc(); const values = [...wm]; deepStrictEqual(values, ['hello', 'goodbye']); diff --git a/test/parallel/test-net-after-close.js b/test/parallel/test-net-after-close.js index 7d49780d001d6e..413e8f75992de9 100644 --- a/test/parallel/test-net-after-close.js +++ b/test/parallel/test-net-after-close.js @@ -32,6 +32,7 @@ const server = net.createServer(common.mustCall((s) => { server.listen(0, common.mustCall(() => { const c = net.createConnection(server.address().port); c.on('close', common.mustCall(() => { + /* eslint-disable no-unused-expressions */ console.error('connection closed'); assert.strictEqual(c._handle, null); // Calling functions / accessing properties of a closed socket should not @@ -45,5 +46,6 @@ server.listen(0, common.mustCall(() => { c.remoteAddress; c.remotePort; server.close(); + /* eslint-enable no-unused-expressions */ })); })); diff --git a/test/parallel/test-net-during-close.js b/test/parallel/test-net-during-close.js index 7bceb64041f2cc..3670ed9c273920 100644 --- a/test/parallel/test-net-during-close.js +++ b/test/parallel/test-net-during-close.js @@ -28,6 +28,7 @@ const server = net.createServer(function(socket) { }); server.listen(0, common.mustCall(function() { + /* eslint-disable no-unused-expressions */ const client = net.createConnection(this.address().port); server.close(); // Server connection event has not yet fired client is still attempting to @@ -37,4 +38,5 @@ server.listen(0, common.mustCall(function() { client.remotePort; // Exit now, do not wait for the client error event. process.exit(0); + /* eslint-enable no-unused-expressions */ })); diff --git a/test/parallel/test-process-env-windows-error-reset.js b/test/parallel/test-process-env-windows-error-reset.js index 59e5f287d82346..881da06d2926d3 100644 --- a/test/parallel/test-process-env-windows-error-reset.js +++ b/test/parallel/test-process-env-windows-error-reset.js @@ -7,7 +7,7 @@ const assert = require('assert'); { process.env.FOO = ''; - process.env.NONEXISTENT_ENV_VAR; + process.env.NONEXISTENT_ENV_VAR; // eslint-disable-line no-unused-expressions const foo = process.env.FOO; assert.strictEqual(foo, ''); @@ -15,7 +15,7 @@ const assert = require('assert'); { process.env.FOO = ''; - process.env.NONEXISTENT_ENV_VAR; + process.env.NONEXISTENT_ENV_VAR; // eslint-disable-line no-unused-expressions const hasFoo = 'FOO' in process.env; assert.strictEqual(hasFoo, true); diff --git a/test/parallel/test-repl-options.js b/test/parallel/test-repl-options.js index 94d849712b3e84..953255319cf9eb 100644 --- a/test/parallel/test-repl-options.js +++ b/test/parallel/test-repl-options.js @@ -29,7 +29,7 @@ const repl = require('repl'); const cp = require('child_process'); assert.strictEqual(repl.repl, undefined); -repl._builtinLibs; +repl._builtinLibs; // eslint-disable-line no-unused-expressions common.expectWarning({ DeprecationWarning: { diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js index 6f5cbe2becd5f7..cc3dce1093fe4e 100644 --- a/test/parallel/test-repl-tab-complete.js +++ b/test/parallel/test-repl-tab-complete.js @@ -532,7 +532,7 @@ testMe.complete('obj.', common.mustCall((error, data) => { // check Buffer.prototype.length not crashing. // Refs: https://github.com/nodejs/node/pull/11961 -putIn.run['.clear']; +putIn.run(['.clear']); testMe.complete('Buffer.prototype.', common.mustCall()); const testNonGlobal = repl.start({ diff --git a/test/parallel/test-source-map-api.js b/test/parallel/test-source-map-api.js index 9bebc4c6c9ccae..b8ff59e365e2e9 100644 --- a/test/parallel/test-source-map-api.js +++ b/test/parallel/test-source-map-api.js @@ -54,6 +54,7 @@ const { readFileSync } = require('fs'); // Require a file that throws an exception, and has a source map. require('../fixtures/source-map/typescript-throw.js'); } catch (err) { + // eslint-disable-next-line no-unused-expressions err.stack; // Force prepareStackTrace() to be called. } assert(callSite); diff --git a/test/parallel/test-stdin-hang.js b/test/parallel/test-stdin-hang.js index 23c686320d3299..887f31fdb75adf 100644 --- a/test/parallel/test-stdin-hang.js +++ b/test/parallel/test-stdin-hang.js @@ -27,6 +27,6 @@ require('../common'); // If it does, then the test-runner will nuke it. // invoke the getter. -process.stdin; +process.stdin; // eslint-disable-line no-unused-expressions console.error('Should exit normally now.'); diff --git a/test/parallel/test-stdio-closed.js b/test/parallel/test-stdio-closed.js index c21bbc2eac12b7..cc9f1e86ccbf6c 100644 --- a/test/parallel/test-stdio-closed.js +++ b/test/parallel/test-stdio-closed.js @@ -7,10 +7,12 @@ const fixtures = require('../common/fixtures'); if (common.isWindows) { if (process.argv[2] === 'child') { + /* eslint-disable no-unused-expressions */ process.stdin; process.stdout; process.stderr; return; + /* eslint-enable no-unused-expressions */ } const python = process.env.PYTHON || 'python'; const script = fixtures.path('spawn_closed_stdio.py'); diff --git a/test/parallel/test-stdio-pipe-access.js b/test/parallel/test-stdio-pipe-access.js index e8f8131d1f19e8..6093e60b8b10a5 100644 --- a/test/parallel/test-stdio-pipe-access.js +++ b/test/parallel/test-stdio-pipe-access.js @@ -32,6 +32,6 @@ switch (who) { process.stderr ] }); break; case 'bottom': - process.stdin; + process.stdin; // eslint-disable-line no-unused-expressions break; } diff --git a/test/parallel/test-stream-pipeline-uncaught.js b/test/parallel/test-stream-pipeline-uncaught.js index 35b67c4ff0afb8..bfac4f1fee8d0b 100644 --- a/test/parallel/test-stream-pipeline-uncaught.js +++ b/test/parallel/test-stream-pipeline-uncaught.js @@ -16,9 +16,7 @@ process.on('uncaughtException', common.mustCall((err) => { const s = new PassThrough(); s.end('data'); pipeline(s, async function(source) { - for await (const chunk of source) { - chunk; - } + for await (const chunk of source) {} // eslint-disable-line no-unused-vars }, common.mustSucceed(() => { throw new Error('error'); })); diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index 5b12531f92e7a4..f4801ece268a5b 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -628,9 +628,7 @@ const net = require('net'); await Promise.resolve(); yield 'hello'; }, async function*(source) { - for await (const chunk of source) { - chunk; - } + for await (const chunk of source) {} }, common.mustCall((err) => { assert.strictEqual(err, undefined); })); @@ -646,9 +644,7 @@ const net = require('net'); await Promise.resolve(); throw new Error('kaboom'); }, async function*(source) { - for await (const chunk of source) { - chunk; - } + for await (const chunk of source) {} }, common.mustCall((err) => { assert.strictEqual(err.message, 'kaboom'); })); @@ -704,7 +700,6 @@ const net = require('net'); yield 'world'; }, s, async function(source) { for await (const chunk of source) { - chunk; throw new Error('kaboom'); } }, common.mustCall((err, val) => { @@ -719,7 +714,6 @@ const net = require('net'); return ['hello', 'world']; }, s, async function*(source) { for await (const chunk of source) { - chunk; throw new Error('kaboom'); } }, common.mustCall((err) => { diff --git a/test/parallel/test-stream-readable-async-iterators.js b/test/parallel/test-stream-readable-async-iterators.js index 788ed8a8e2e0e0..7c457fdc3da24b 100644 --- a/test/parallel/test-stream-readable-async-iterators.js +++ b/test/parallel/test-stream-readable-async-iterators.js @@ -62,8 +62,7 @@ async function tests() { }); await (async () => { - for await (const d of readable) { - d; + for await (const d of readable) { // eslint-disable-line no-unused-vars return; } })(); @@ -595,9 +594,7 @@ async function tests() { } }); - for await (const chunk of r) { - chunk; - } + for await (const chunk of r) {} // eslint-disable-line no-unused-vars assert.strictEqual(r.destroyed, false); } @@ -612,8 +609,7 @@ async function tests() { } }); - for await (const chunk of r) { - chunk; + for await (const chunk of r) { // eslint-disable-line no-unused-vars break; } assert.strictEqual(r.destroyed, true); @@ -631,9 +627,7 @@ async function tests() { assert.strictEqual(r.destroyed, false); }); - for await (const chunk of r) { - chunk; - } + for await (const chunk of r) {} // eslint-disable-line no-unused-vars assert.strictEqual(r.destroyed, true); } @@ -717,9 +711,8 @@ async function tests() { let _err; try { - for await (const chunk of res) { - chunk; - } + // eslint-disable-next-line no-unused-vars + for await (const chunk of res) {} } catch (err) { _err = err; } diff --git a/test/parallel/test-tls-external-accessor.js b/test/parallel/test-tls-external-accessor.js index 33d371923a600c..07d79ef64a5167 100644 --- a/test/parallel/test-tls-external-accessor.js +++ b/test/parallel/test-tls-external-accessor.js @@ -12,11 +12,11 @@ const tls = require('tls'); const pctx = tls.createSecureContext().context; const cctx = Object.create(pctx); assert.throws(() => cctx._external, TypeError); - pctx._external; + pctx._external; // eslint-disable-line no-unused-expressions } { const pctx = tls.createSecurePair().credentials.context; const cctx = Object.create(pctx); assert.throws(() => cctx._external, TypeError); - pctx._external; + pctx._external; // eslint-disable-line no-unused-expressions } diff --git a/test/parallel/test-trace-events-bootstrap.js b/test/parallel/test-trace-events-bootstrap.js index 7251a9824dc951..634ee7ece0294f 100644 --- a/test/parallel/test-trace-events-bootstrap.js +++ b/test/parallel/test-trace-events-bootstrap.js @@ -16,7 +16,7 @@ const names = [ ]; if (process.argv[2] === 'child') { - 1 + 1; + 1 + 1; // eslint-disable-line no-unused-expressions } else { tmpdir.refresh(); diff --git a/test/parallel/test-trace-events-environment.js b/test/parallel/test-trace-events-environment.js index 14900dfc96ff46..75714283fb1335 100644 --- a/test/parallel/test-trace-events-environment.js +++ b/test/parallel/test-trace-events-environment.js @@ -21,12 +21,14 @@ const names = new Set([ ]); if (process.argv[2] === 'child') { + /* eslint-disable no-unused-expressions */ // This is just so that the child has something to do. 1 + 1; // These ensure that the RunTimers, CheckImmediate, and // RunAndClearNativeImmediates appear in the list. setImmediate(() => { 1 + 1; }); setTimeout(() => { 1 + 1; }, 1); + /* eslint-enable no-unused-expressions */ } else { tmpdir.refresh(); diff --git a/test/parallel/test-vm-module-errors.js b/test/parallel/test-vm-module-errors.js index 2e9697ff4123f7..942e2f370dfff8 100644 --- a/test/parallel/test-vm-module-errors.js +++ b/test/parallel/test-vm-module-errors.js @@ -86,7 +86,7 @@ async function checkModuleState() { assert.throws(() => { const m = new SourceTextModule(''); - m.error; + m.error; // eslint-disable-line no-unused-expressions }, { code: 'ERR_VM_MODULE_STATUS', message: 'Module status must be errored' @@ -95,7 +95,7 @@ async function checkModuleState() { await assert.rejects(async () => { const m = await createEmptyLinkedModule(); await m.evaluate(); - m.error; + m.error; // eslint-disable-line no-unused-expressions }, { code: 'ERR_VM_MODULE_STATUS', message: 'Module status must be errored' @@ -103,7 +103,7 @@ async function checkModuleState() { assert.throws(() => { const m = new SourceTextModule(''); - m.namespace; + m.namespace; // eslint-disable-line no-unused-expressions }, { code: 'ERR_VM_MODULE_STATUS', message: 'Module status must not be unlinked or linking' diff --git a/test/parallel/test-worker-unsupported-things.js b/test/parallel/test-worker-unsupported-things.js index cc9eec4af67760..a9f434eeaf55bb 100644 --- a/test/parallel/test-worker-unsupported-things.js +++ b/test/parallel/test-worker-unsupported-things.js @@ -40,7 +40,7 @@ if (!process.env.HAS_STARTED_WORKER) { ['channel', 'connected'].forEach((fn) => { assert.throws(() => { - process[fn]; + process[fn]; // eslint-disable-line no-unused-expressions }, { code: 'ERR_WORKER_UNSUPPORTED_OPERATION' }); });