Skip to content

Commit 1acb5cd

Browse files
Trottdanielleadams
authored andcommitted
benchmark: enable no-empty ESLint rule
PR-URL: nodejs#41831 Backport-PR-URL: nodejs#42160 Refs: https://eslint.org/docs/rules/no-empty Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 63a865c commit 1acb5cd

11 files changed

+62
-14
lines changed

benchmark/.eslintrc.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ env:
55
es6: true
66

77
rules:
8+
no-empty: error
89
no-var: error
910
prefer-arrow-callback: error

benchmark/es/foreach-bench.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function useFor(n, items, count) {
2222
function useForOf(n, items) {
2323
bench.start();
2424
for (let i = 0; i < n; i++) {
25-
// eslint-disable-next-line no-unused-vars
25+
// eslint-disable-next-line no-unused-vars, no-empty
2626
for (const item of items) {}
2727
}
2828
bench.end(n);

benchmark/fs/bench-statSync-failure.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function main({ n, statSyncType }) {
2121
try {
2222
fs.statSync(arg);
2323
} catch {
24+
// Continue regardless of error.
2425
}
2526
}
2627
}

benchmark/fs/read-stream-throughput.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ function main(conf) {
5050
buf.fill('x');
5151
}
5252

53-
try { fs.unlinkSync(filename); } catch {}
53+
try {
54+
fs.unlinkSync(filename);
55+
} catch {
56+
// Continue regardless of error.
57+
}
5458
const ws = fs.createWriteStream(filename);
5559
ws.on('close', runTest.bind(null, filesize, highWaterMark, encoding, n));
5660
ws.on('drain', write);
@@ -81,7 +85,11 @@ function runTest(filesize, highWaterMark, encoding, n) {
8185
});
8286

8387
rs.on('end', () => {
84-
try { fs.unlinkSync(filename); } catch {}
88+
try {
89+
fs.unlinkSync(filename);
90+
} catch {
91+
// Continue regardless of error.
92+
}
8593
// MB/sec
8694
bench.end(bytes / (1024 * 1024));
8795
});

benchmark/fs/readfile-partitioned.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ const bench = common.createBenchmark(main, {
2323
});
2424

2525
function main({ len, dur, concurrent }) {
26-
try { fs.unlinkSync(filename); } catch {}
26+
try {
27+
fs.unlinkSync(filename);
28+
} catch {
29+
// Continue regardless of error.
30+
}
2731
let data = Buffer.alloc(len, 'x');
2832
fs.writeFileSync(filename, data);
2933
data = null;
@@ -38,7 +42,11 @@ function main({ len, dur, concurrent }) {
3842
const totalOps = reads + zips;
3943
benchEnded = true;
4044
bench.end(totalOps);
41-
try { fs.unlinkSync(filename); } catch {}
45+
try {
46+
fs.unlinkSync(filename);
47+
} catch {
48+
// Continue regardless of error.
49+
}
4250
}, dur * 1000);
4351

4452
function read() {

benchmark/fs/readfile-promises.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ const bench = common.createBenchmark(main, {
2020
});
2121

2222
function main({ len, duration, concurrent }) {
23-
try { fs.unlinkSync(filename); } catch { }
23+
try {
24+
fs.unlinkSync(filename);
25+
} catch {
26+
// Continue regardless of error.
27+
}
2428
let data = Buffer.alloc(len, 'x');
2529
fs.writeFileSync(filename, data);
2630
data = null;
@@ -31,7 +35,11 @@ function main({ len, duration, concurrent }) {
3135
setTimeout(() => {
3236
benchEnded = true;
3337
bench.end(writes);
34-
try { fs.unlinkSync(filename); } catch { }
38+
try {
39+
fs.unlinkSync(filename);
40+
} catch {
41+
// Continue regardless of error.
42+
}
3543
process.exit(0);
3644
}, duration * 1000);
3745

benchmark/fs/readfile.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ const bench = common.createBenchmark(main, {
2020
});
2121

2222
function main({ len, duration, concurrent }) {
23-
try { fs.unlinkSync(filename); } catch {}
23+
try {
24+
fs.unlinkSync(filename);
25+
} catch {
26+
// Continue regardless of error.
27+
}
2428
let data = Buffer.alloc(len, 'x');
2529
fs.writeFileSync(filename, data);
2630
data = null;
@@ -31,7 +35,11 @@ function main({ len, duration, concurrent }) {
3135
setTimeout(() => {
3236
benchEnded = true;
3337
bench.end(reads);
34-
try { fs.unlinkSync(filename); } catch {}
38+
try {
39+
fs.unlinkSync(filename);
40+
} catch {
41+
// Continue regardless of error.
42+
}
3543
process.exit(0);
3644
}, duration * 1000);
3745

benchmark/fs/write-stream-throughput.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ function main({ dur, encodingType, size }) {
3636
throw new Error(`invalid encodingType: ${encodingType}`);
3737
}
3838

39-
try { fs.unlinkSync(filename); } catch {}
39+
try {
40+
fs.unlinkSync(filename);
41+
} catch {
42+
// Continue regardless of error.
43+
}
4044

4145
let started = false;
4246
let ended = false;
@@ -48,7 +52,11 @@ function main({ dur, encodingType, size }) {
4852
f.on('finish', () => {
4953
ended = true;
5054
const written = fs.statSync(filename).size / 1024;
51-
try { fs.unlinkSync(filename); } catch {}
55+
try {
56+
fs.unlinkSync(filename);
57+
} catch {
58+
// Continue regardless of error.
59+
}
5260
bench.end(written / 1024);
5361
});
5462

benchmark/fs/writefile-promises.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ function main({ encodingType, duration, concurrent, size }) {
4646
benchEnded = true;
4747
bench.end(writes);
4848
for (let i = 0; i < filesWritten; i++) {
49-
try { fs.unlinkSync(`${filename}-${i}`); } catch { }
49+
try {
50+
fs.unlinkSync(`${filename}-${i}`);
51+
} catch {
52+
// Continue regardless of error.
53+
}
5054
}
5155
process.exit(0);
5256
}, duration * 1000);

benchmark/misc/punycode.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ const common = require('../common.js');
44
let icu;
55
try {
66
icu = common.binding('icu');
7-
} catch {}
7+
} catch {
8+
// Continue regardless of error.
9+
}
810
const punycode = require('punycode');
911

1012
const bench = common.createBenchmark(main, {

benchmark/net/net-c2s-cork.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function main({ dur, len, type }) {
5555

5656
function send() {
5757
socket.cork();
58-
while (socket.write(chunk, encoding)) {}
58+
while (socket.write(chunk, encoding));
5959
socket.uncork();
6060
}
6161
});

0 commit comments

Comments
 (0)