From f1ca3174aa504cec284c6b828c0f299401beef3d Mon Sep 17 00:00:00 2001 From: Stephen Cresswell <229672+cressie176@users.noreply.github.com> Date: Sat, 6 Sep 2025 09:37:42 +0100 Subject: [PATCH] Enable noUselessCatch lint rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Configure noUselessCatch rule to error in biome.json to prevent useless catch blocks that only rethrow errors - Remove useless catch blocks from example files (examples/receive_generator.js and examples/send_generators.js) - Update CHANGELOG.md with the new lint rule 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- CHANGELOG.md | 1 + biome.json | 2 +- examples/receive_generator.js | 22 +++++++++------------- examples/send_generators.js | 2 -- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1f09e65..91fdfdb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Ensure no variable redeclarations exist to prevent shadowing issues - Replace global isFinite with Number.isFinite for safer numeric validation - Enable useArrowFunction lint rule to prefer arrow functions for cleaner syntax +- Enable noUselessCatch lint rule to prevent useless catch blocks that only rethrow errors ## v0.10.9 - Add support for IPv6 urls diff --git a/biome.json b/biome.json index 14f11ddc..035d28b1 100644 --- a/biome.json +++ b/biome.json @@ -13,7 +13,7 @@ "rules": { "complexity": { "noCommaOperator": "off", - "noUselessCatch": "off", + "noUselessCatch": "error", "useArrowFunction": "error", "useOptionalChain": "off", "noArguments": "off", diff --git a/examples/receive_generator.js b/examples/receive_generator.js index 73da1392..9f88970f 100644 --- a/examples/receive_generator.js +++ b/examples/receive_generator.js @@ -10,19 +10,15 @@ co(function* () { } }; const conn = yield amqp.connect('amqp://localhost'); - try { - // create a message to consume - const q = 'hello'; - const msg = 'Hello World!'; - const channel = yield conn.createChannel(); - yield channel.assertQueue(q); - channel.sendToQueue(q, Buffer.from(msg)); - console.log(" [x] Sent '%s'", msg); - // consume the message - yield channel.consume(q, myConsumer, {noAck: true}); - } catch (e) { - throw e; - } + // create a message to consume + const q = 'hello'; + const msg = 'Hello World!'; + const channel = yield conn.createChannel(); + yield channel.assertQueue(q); + channel.sendToQueue(q, Buffer.from(msg)); + console.log(" [x] Sent '%s'", msg); + // consume the message + yield channel.consume(q, myConsumer, {noAck: true}); }).catch((err) => { console.warn('Error:', err); }); diff --git a/examples/send_generators.js b/examples/send_generators.js index 7f97d321..353265e1 100755 --- a/examples/send_generators.js +++ b/examples/send_generators.js @@ -27,8 +27,6 @@ co(function* () { console.log(" [x] Sent '%s'", msg); channel.close(); - } catch (e) { - throw e; } finally { conn.close(); }