Skip to content
Permalink
Browse files
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>
  • Loading branch information
targos committed Jun 11, 2021
1 parent 52cbe89 commit 226a86c3b57fb88388590cebf17b9714ba2905e9
Showing with 91 additions and 93 deletions.
  1. +1 −0 .eslintrc.js
  2. +0 −1 benchmark/_benchmark_progress.js
  3. +4 −2 benchmark/es/destructuring-bench.js
  4. +1 −1 benchmark/perf_hooks/bench-eventlooputil.js
  5. +2 −2 benchmark/process/bench-env.js
  6. +1 −2 benchmark/string_decoder/string-decoder-create.js
  7. +1 −0 doc/.eslintrc.yaml
  8. +1 −1 lib/internal/assert/assertion_error.js
  9. +12 −12 lib/internal/buffer.js
  10. +4 −4 lib/internal/errors.js
  11. +3 −3 lib/internal/streams/destroy.js
  12. +1 −1 lib/internal/streams/writable.js
  13. +1 −1 test/common/index.js
  14. +1 −1 test/js-native-api/test_general/testEnvCleanup.js
  15. +1 −1 test/message/nexttick_throw.js
  16. +1 −1 test/message/timeout_throw.js
  17. +3 −2 test/parallel/test-accessor-properties.js
  18. +1 −1 test/parallel/test-buffer-backing-arraybuffer.js
  19. +1 −1 test/parallel/test-buffer-constructor-deprecation-error.js
  20. +1 −1 test/parallel/test-buffer-fakes.js
  21. +1 −1 test/parallel/test-child-process-stdin-ipc.js
  22. +1 −1 test/parallel/test-dgram-deprecation-error.js
  23. +1 −1 test/parallel/test-disable-proto-throw.js
  24. +1 −1 test/parallel/test-error-prepare-stack-trace.js
  25. +1 −1 test/parallel/test-fs-promises-file-handle-read.js
  26. +1 −1 test/parallel/test-fs-readv-promises.js
  27. +1 −1 test/parallel/test-fs-readv-sync.js
  28. +1 −1 test/parallel/test-fs-readv.js
  29. +1 −1 test/parallel/test-http-outgoing-internal-headernames-getter.js
  30. +1 −1 test/parallel/test-http-outgoing-internal-headers.js
  31. +4 −3 test/parallel/test-http-same-map.js
  32. +2 −1 test/parallel/test-http2-unbound-socket-proxy.js
  33. +1 −1 test/parallel/test-inspector-tracing-domain.js
  34. +1 −2 test/parallel/test-inspector-vm-global-accessors-sideeffects.js
  35. +1 −1 test/parallel/test-internal-iterable-weak-map.js
  36. +2 −0 test/parallel/test-net-after-close.js
  37. +2 −0 test/parallel/test-net-during-close.js
  38. +2 −2 test/parallel/test-process-env-windows-error-reset.js
  39. +1 −1 test/parallel/test-repl-options.js
  40. +1 −1 test/parallel/test-repl-tab-complete.js
  41. +1 −0 test/parallel/test-source-map-api.js
  42. +1 −1 test/parallel/test-stdin-hang.js
  43. +2 −0 test/parallel/test-stdio-closed.js
  44. +1 −1 test/parallel/test-stdio-pipe-access.js
  45. +1 −3 test/parallel/test-stream-pipeline-uncaught.js
  46. +2 −8 test/parallel/test-stream-pipeline.js
  47. +6 −13 test/parallel/test-stream-readable-async-iterators.js
  48. +2 −2 test/parallel/test-tls-external-accessor.js
  49. +1 −1 test/parallel/test-trace-events-bootstrap.js
  50. +2 −0 test/parallel/test-trace-events-environment.js
  51. +3 −3 test/parallel/test-vm-module-errors.js
  52. +1 −1 test/parallel/test-worker-unsupported-things.js
@@ -239,6 +239,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', {
@@ -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) {
@@ -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);
@@ -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);
}

@@ -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;
@@ -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);
}
@@ -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

@@ -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';
}
@@ -951,18 +951,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;
@@ -328,7 +328,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', {
@@ -1399,11 +1399,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',
@@ -16,7 +16,7 @@ function destroy(err, cb) {

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;
@@ -39,7 +39,7 @@ function destroy(err, cb) {
this._destroy(err || null, (err) => {
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;
@@ -153,7 +153,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;
@@ -408,7 +408,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;
@@ -423,7 +423,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;
}
@@ -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']);
@@ -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;
});
});
@@ -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);
@@ -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);

@@ -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));
}
}
@@ -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
@@ -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() {
@@ -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;
}

@@ -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
@@ -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'
@@ -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);
}
@@ -72,4 +72,4 @@ let useConf = false;
.then(validateLargeRead)
.then(common.mustCall());
}
});
})().then(common.mustCall());
@@ -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;
@@ -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;
@@ -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;
@@ -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
}
@@ -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
}

{
@@ -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', () => {
@@ -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'
@@ -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));

0 comments on commit 226a86c

Please sign in to comment.