Skip to content

Commit f5d4cd3

Browse files
authored
tools: allow unused variables named only with underscores
And enforces that underscore-only variables stayed unused. Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #67883 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
1 parent ccf9d2d commit f5d4cd3

75 files changed

Lines changed: 63 additions & 192 deletions

File tree

Some content is hidden

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

‎benchmark/es/foreach-bench.js‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ function useFor(n, items, count) {
1212
bench.start();
1313
for (let i = 0; i < n; i++) {
1414
for (let j = 0; j < count; j++) {
15-
// eslint-disable-next-line no-unused-vars
16-
const item = items[j];
15+
const _ = items[j];
1716
}
1817
}
1918
bench.end(n);
@@ -22,8 +21,8 @@ function useFor(n, items, count) {
2221
function useForOf(n, items) {
2322
bench.start();
2423
for (let i = 0; i < n; i++) {
25-
// eslint-disable-next-line no-unused-vars, no-empty
26-
for (const item of items) {}
24+
// eslint-disable-next-line no-empty
25+
for (const _ of items) {}
2726
}
2827
bench.end(n);
2928
}
@@ -32,8 +31,7 @@ function useForIn(n, items) {
3231
bench.start();
3332
for (let i = 0; i < n; i++) {
3433
for (const j in items) {
35-
// eslint-disable-next-line no-unused-vars
36-
const item = items[j];
34+
const _ = items[j];
3735
}
3836
}
3937
bench.end(n);

‎benchmark/fs/bench-opendir.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ async function main({ n, dir, mode, bufferSize }) {
2020
for (let i = 0; i < n; i++) {
2121
if (mode === 'async') {
2222
const dir = await fs.promises.opendir(fullPath, { bufferSize });
23-
// eslint-disable-next-line no-unused-vars
24-
for await (const entry of dir)
23+
for await (const _ of dir)
2524
counter++;
2625
} else if (mode === 'callback') {
2726
const dir = await fs.promises.opendir(fullPath, { bufferSize });

‎benchmark/readline/readline-iterable.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ async function main({ n, type }) {
7474

7575
const readlineIterable = type === 'old' ? oldWay.call(iterable) : iterable;
7676

77-
// eslint-disable-next-line no-unused-vars
7877
for await (const _ of readlineIterable) {
7978
lineCount++;
8079
}

‎benchmark/streams/iter-throughput-broadcast.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ function benchIter(chunk, numConsumers, datasize, n, totalOps) {
114114

115115
// No-op consumer: drain all batches without collecting
116116
async function drain(source) {
117-
// eslint-disable-next-line no-unused-vars
118117
for await (const _ of source) { /* drain */ }
119118
}
120119

‎benchmark/test_runner/run-single-test-file.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ async function runBenchmark({ numberOfTestFiles, isolation }) {
4747
concurrency: false, // We don't want to run tests concurrently
4848
});
4949

50-
// eslint-disable-next-line no-unused-vars
5150
for await (const _ of stream);
5251

5352
return numberOfTestFiles;

‎eslint.config.mjs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,14 @@ export default [
242242
'no-undef': ['error', { typeof: true }],
243243
'no-undef-init': 'error',
244244
'no-unused-expressions': ['error', { allowShortCircuit: true }],
245-
'no-unused-vars': ['error', { args: 'none', caughtErrors: 'all' }],
245+
'no-unused-vars': ['error', {
246+
args: 'none',
247+
caughtErrors: 'all',
248+
varsIgnorePattern: '^_+$',
249+
caughtErrorsIgnorePattern: '^_+$',
250+
destructuredArrayIgnorePattern: '^_+$',
251+
reportUsedIgnorePattern: true,
252+
}],
246253
'no-use-before-define': ['error', {
247254
classes: true,
248255
functions: false,

‎lib/diagnostics_channel.js‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ class ActiveChannel {
208208
}
209209

210210
runStores(data, fn, thisArg, ...args) {
211-
// eslint-disable-next-line no-unused-vars
212-
using scope = this.withStoreScope(data);
211+
using _ = this.withStoreScope(data);
213212
return ReflectApply(fn, thisArg, args);
214213
}
215214
}
@@ -406,8 +405,7 @@ class BoundedChannel {
406405

407406
run(context, fn, thisArg, ...args) {
408407
context ??= {};
409-
// eslint-disable-next-line no-unused-vars
410-
using scope = this.withScope(context);
408+
using _ = this.withScope(context);
411409
return ReflectApply(fn, thisArg, args);
412410
}
413411
}
@@ -535,8 +533,7 @@ class TracingChannel {
535533

536534
const { error } = this;
537535

538-
// eslint-disable-next-line no-unused-vars
539-
using scope = this.#callWindow.withScope(context);
536+
using _ = this.#callWindow.withScope(context);
540537
try {
541538
const result = ReflectApply(fn, thisArg, args);
542539
context.result = result;
@@ -568,8 +565,7 @@ class TracingChannel {
568565
context.error = err;
569566
error.publish(context);
570567
// Use continuation window for asyncStart/asyncEnd
571-
// eslint-disable-next-line no-unused-vars
572-
using scope = continuationWindow.withScope(context);
568+
using _ = continuationWindow.withScope(context);
573569
// TODO: Is there a way to have asyncEnd _after_ the continuation?
574570
}
575571

@@ -581,14 +577,12 @@ class TracingChannel {
581577
function onResolve(result) {
582578
context.result = result;
583579
// Use continuation window for asyncStart/asyncEnd
584-
// eslint-disable-next-line no-unused-vars
585-
using scope = continuationWindow.withScope(context);
580+
using _ = continuationWindow.withScope(context);
586581
// TODO: Is there a way to have asyncEnd _after_ the continuation?
587582
return result;
588583
}
589584

590-
// eslint-disable-next-line no-unused-vars
591-
using scope = this.#callWindow.withScope(context);
585+
using _ = this.#callWindow.withScope(context);
592586
try {
593587
const result = ReflectApply(fn, thisArg, args);
594588
// If the return value is not a thenable, return it directly with a warning.
@@ -637,17 +631,15 @@ class TracingChannel {
637631
}
638632

639633
// Use continuation window for asyncStart/asyncEnd around callback
640-
// eslint-disable-next-line no-unused-vars
641-
using scope = continuationWindow.withScope(context);
634+
using _ = continuationWindow.withScope(context);
642635
return ReflectApply(callback, this, arguments);
643636
}
644637

645638
const callback = ArrayPrototypeAt(args, position);
646639
validateFunction(callback, 'callback');
647640
ArrayPrototypeSplice(args, position, 1, wrappedCallback);
648641

649-
// eslint-disable-next-line no-unused-vars
650-
using scope = this.#callWindow.withScope(context);
642+
using _ = this.#callWindow.withScope(context);
651643
try {
652644
return ReflectApply(fn, thisArg, args);
653645
} catch (err) {

‎lib/internal/streams/operators.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ async function forEach(fn, options) {
220220
await fn(value, options);
221221
return kEmpty;
222222
}
223-
// eslint-disable-next-line no-unused-vars
224-
for await (const unused of map.call(this, forEachFn, options));
223+
for await (const _ of map.call(this, forEachFn, options));
225224
}
226225

227226
function filter(fn, options) {

‎lib/internal/test_runner/mock/mock_timers.js‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,7 @@ class MockTimers {
409409
}
410410

411411
// Prototype is read-only, and non assignable through Object.defineProperties
412-
// eslint-disable-next-line no-unused-vars -- used to get the prototype out of the object
413-
const { prototype, ...dateProps } = ObjectGetOwnPropertyDescriptors(NativeDateConstructor);
412+
const { prototype: _, ...dateProps } = ObjectGetOwnPropertyDescriptors(NativeDateConstructor);
414413

415414
// Binds all the properties of Date to the MockDate function
416415
ObjectDefineProperties(
@@ -478,8 +477,7 @@ class MockTimers {
478477
options);
479478

480479
try {
481-
// eslint-disable-next-line no-unused-vars
482-
for await (const event of eventIt) {
480+
for await (const _ of eventIt) {
483481
yield result;
484482
}
485483
} finally {

‎test/parallel/test-blob-file-backed.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ writeFileSync(testfile5, '');
5757
stream = blob.stream();
5858

5959
const read = async () => {
60-
// eslint-disable-next-line no-unused-vars, no-empty
60+
// eslint-disable-next-line no-empty
6161
for await (const _ of stream) {}
6262
};
6363

@@ -98,7 +98,6 @@ writeFileSync(testfile5, '');
9898
const blob = await openAsBlob(testfile3);
9999
const stream = blob.stream();
100100
const read = async () => {
101-
// eslint-disable-next-line no-unused-vars
102101
for await (const _ of stream) {
103102
writeFileSync(testfile3, data + 'abc');
104103
}

0 commit comments

Comments
 (0)