From c4a296f59b3fba4be6df09b73e61981302b6cd13 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 2 Feb 2022 21:28:06 -0800 Subject: [PATCH] benchmark: enable no-empty ESLint rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/41831 Backport-PR-URL: https://github.com/nodejs/node/pull/42160 Refs: https://eslint.org/docs/rules/no-empty Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen Reviewed-By: Antoine du Hamel --- benchmark/.eslintrc.yaml | 1 + benchmark/es/foreach-bench.js | 2 +- benchmark/fs/bench-statSync-failure.js | 1 + benchmark/fs/read-stream-throughput.js | 12 ++++++++++-- benchmark/fs/readfile-partitioned.js | 12 ++++++++++-- benchmark/fs/readfile-promises.js | 12 ++++++++++-- benchmark/fs/readfile.js | 12 ++++++++++-- benchmark/fs/write-stream-throughput.js | 12 ++++++++++-- benchmark/fs/writefile-promises.js | 6 +++++- benchmark/misc/punycode.js | 4 +++- benchmark/net/net-c2s-cork.js | 2 +- 11 files changed, 62 insertions(+), 14 deletions(-) diff --git a/benchmark/.eslintrc.yaml b/benchmark/.eslintrc.yaml index 6871299adece7b..d7c59654fbe46d 100644 --- a/benchmark/.eslintrc.yaml +++ b/benchmark/.eslintrc.yaml @@ -5,5 +5,6 @@ env: es6: true rules: + no-empty: error no-var: error prefer-arrow-callback: error diff --git a/benchmark/es/foreach-bench.js b/benchmark/es/foreach-bench.js index 6992a1a5749438..86bd8dff4c0a2c 100644 --- a/benchmark/es/foreach-bench.js +++ b/benchmark/es/foreach-bench.js @@ -22,7 +22,7 @@ function useFor(n, items, count) { function useForOf(n, items) { bench.start(); for (let i = 0; i < n; i++) { - // eslint-disable-next-line no-unused-vars + // eslint-disable-next-line no-unused-vars, no-empty for (const item of items) {} } bench.end(n); diff --git a/benchmark/fs/bench-statSync-failure.js b/benchmark/fs/bench-statSync-failure.js index 82cb24c09f4af2..dd69259eacd07e 100644 --- a/benchmark/fs/bench-statSync-failure.js +++ b/benchmark/fs/bench-statSync-failure.js @@ -21,6 +21,7 @@ function main({ n, statSyncType }) { try { fs.statSync(arg); } catch { + // Continue regardless of error. } } } diff --git a/benchmark/fs/read-stream-throughput.js b/benchmark/fs/read-stream-throughput.js index 5984317ff91743..d4a0a798409a12 100644 --- a/benchmark/fs/read-stream-throughput.js +++ b/benchmark/fs/read-stream-throughput.js @@ -50,7 +50,11 @@ function main(conf) { buf.fill('x'); } - try { fs.unlinkSync(filename); } catch {} + try { + fs.unlinkSync(filename); + } catch { + // Continue regardless of error. + } const ws = fs.createWriteStream(filename); ws.on('close', runTest.bind(null, filesize, highWaterMark, encoding, n)); ws.on('drain', write); @@ -81,7 +85,11 @@ function runTest(filesize, highWaterMark, encoding, n) { }); rs.on('end', () => { - try { fs.unlinkSync(filename); } catch {} + try { + fs.unlinkSync(filename); + } catch { + // Continue regardless of error. + } // MB/sec bench.end(bytes / (1024 * 1024)); }); diff --git a/benchmark/fs/readfile-partitioned.js b/benchmark/fs/readfile-partitioned.js index 51700cfd649dfd..fac331ec38ba82 100644 --- a/benchmark/fs/readfile-partitioned.js +++ b/benchmark/fs/readfile-partitioned.js @@ -23,7 +23,11 @@ const bench = common.createBenchmark(main, { }); function main({ len, dur, concurrent }) { - try { fs.unlinkSync(filename); } catch {} + try { + fs.unlinkSync(filename); + } catch { + // Continue regardless of error. + } let data = Buffer.alloc(len, 'x'); fs.writeFileSync(filename, data); data = null; @@ -38,7 +42,11 @@ function main({ len, dur, concurrent }) { const totalOps = reads + zips; benchEnded = true; bench.end(totalOps); - try { fs.unlinkSync(filename); } catch {} + try { + fs.unlinkSync(filename); + } catch { + // Continue regardless of error. + } }, dur * 1000); function read() { diff --git a/benchmark/fs/readfile-promises.js b/benchmark/fs/readfile-promises.js index 28633c3f06427b..5cfa5b4cc02465 100644 --- a/benchmark/fs/readfile-promises.js +++ b/benchmark/fs/readfile-promises.js @@ -20,7 +20,11 @@ const bench = common.createBenchmark(main, { }); function main({ len, duration, concurrent }) { - try { fs.unlinkSync(filename); } catch { } + try { + fs.unlinkSync(filename); + } catch { + // Continue regardless of error. + } let data = Buffer.alloc(len, 'x'); fs.writeFileSync(filename, data); data = null; @@ -31,7 +35,11 @@ function main({ len, duration, concurrent }) { setTimeout(() => { benchEnded = true; bench.end(writes); - try { fs.unlinkSync(filename); } catch { } + try { + fs.unlinkSync(filename); + } catch { + // Continue regardless of error. + } process.exit(0); }, duration * 1000); diff --git a/benchmark/fs/readfile.js b/benchmark/fs/readfile.js index 3f996e02ede876..e27fe08f43ca86 100644 --- a/benchmark/fs/readfile.js +++ b/benchmark/fs/readfile.js @@ -20,7 +20,11 @@ const bench = common.createBenchmark(main, { }); function main({ len, duration, concurrent }) { - try { fs.unlinkSync(filename); } catch {} + try { + fs.unlinkSync(filename); + } catch { + // Continue regardless of error. + } let data = Buffer.alloc(len, 'x'); fs.writeFileSync(filename, data); data = null; @@ -31,7 +35,11 @@ function main({ len, duration, concurrent }) { setTimeout(() => { benchEnded = true; bench.end(reads); - try { fs.unlinkSync(filename); } catch {} + try { + fs.unlinkSync(filename); + } catch { + // Continue regardless of error. + } process.exit(0); }, duration * 1000); diff --git a/benchmark/fs/write-stream-throughput.js b/benchmark/fs/write-stream-throughput.js index 44a3bb23b041d1..88d3bce06d114e 100644 --- a/benchmark/fs/write-stream-throughput.js +++ b/benchmark/fs/write-stream-throughput.js @@ -36,7 +36,11 @@ function main({ dur, encodingType, size }) { throw new Error(`invalid encodingType: ${encodingType}`); } - try { fs.unlinkSync(filename); } catch {} + try { + fs.unlinkSync(filename); + } catch { + // Continue regardless of error. + } let started = false; let ended = false; @@ -48,7 +52,11 @@ function main({ dur, encodingType, size }) { f.on('finish', () => { ended = true; const written = fs.statSync(filename).size / 1024; - try { fs.unlinkSync(filename); } catch {} + try { + fs.unlinkSync(filename); + } catch { + // Continue regardless of error. + } bench.end(written / 1024); }); diff --git a/benchmark/fs/writefile-promises.js b/benchmark/fs/writefile-promises.js index 2ba25184ff3132..8b3cd528bac5c9 100644 --- a/benchmark/fs/writefile-promises.js +++ b/benchmark/fs/writefile-promises.js @@ -46,7 +46,11 @@ function main({ encodingType, duration, concurrent, size }) { benchEnded = true; bench.end(writes); for (let i = 0; i < filesWritten; i++) { - try { fs.unlinkSync(`${filename}-${i}`); } catch { } + try { + fs.unlinkSync(`${filename}-${i}`); + } catch { + // Continue regardless of error. + } } process.exit(0); }, duration * 1000); diff --git a/benchmark/misc/punycode.js b/benchmark/misc/punycode.js index 9c674b5deefb8c..d0ee938ebd39a3 100644 --- a/benchmark/misc/punycode.js +++ b/benchmark/misc/punycode.js @@ -4,7 +4,9 @@ const common = require('../common.js'); let icu; try { icu = common.binding('icu'); -} catch {} +} catch { + // Continue regardless of error. +} const punycode = require('punycode'); const bench = common.createBenchmark(main, { diff --git a/benchmark/net/net-c2s-cork.js b/benchmark/net/net-c2s-cork.js index 1493cae68d0069..9a1129218531f1 100644 --- a/benchmark/net/net-c2s-cork.js +++ b/benchmark/net/net-c2s-cork.js @@ -55,7 +55,7 @@ function main({ dur, len, type }) { function send() { socket.cork(); - while (socket.write(chunk, encoding)) {} + while (socket.write(chunk, encoding)); socket.uncork(); } });