From 3a78d4e6e44b740790cfb68b0400dc1cca88af50 Mon Sep 17 00:00:00 2001 From: Stephen Cresswell <229672+cressie176@users.noreply.github.com> Date: Sat, 6 Sep 2025 10:08:58 +0100 Subject: [PATCH] Enable useSingleVarDeclarator lint rule to enforce separate variable declarations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Split comma-separated variable declarations into individual statements for consistency. This improves code readability by making each variable declaration explicit and clear. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- CHANGELOG.md | 1 + biome.json | 3 +++ examples/tutorials/callback_api/rpc_server.js | 4 ++-- examples/tutorials/rpc_server.js | 4 ++-- lib/bitset.js | 4 ++-- lib/channel.js | 4 ++-- lib/codec.js | 14 ++++++++------ lib/connect.js | 10 ++++++---- lib/frame.js | 10 +++++----- test/channel.js | 6 +++--- test/channel_api.js | 16 ++++++++-------- test/codec.js | 6 +++--- test/connect.js | 18 +++++++++--------- test/connection.js | 6 +++--- test/frame.js | 4 ++-- test/util.js | 4 ++-- 16 files changed, 61 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8115166e..42f3495d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Remove redundant 'use strict' directives as modules are automatically in strict mode - Refactor assignment-in-expression patterns to improve code clarity and readability - Replace comma operators with individual statements for clearer, more readable code +- Split comma-separated variable declarations into individual statements for consistency - Replace Object.prototype.hasOwnProperty() with safer Object.hasOwn() method - Enforce strict equality checks (=== and !==) instead of loose equality (== and !=) - Replace global isNaN with Number.isNaN for safer type checking diff --git a/biome.json b/biome.json index e47e68f8..8908255d 100644 --- a/biome.json +++ b/biome.json @@ -26,6 +26,9 @@ "noGlobalIsFinite": "error", "noPrototypeBuiltins": "error", "noVar": "error" + }, + "style": { + "useSingleVarDeclarator": "error" } } }, diff --git a/examples/tutorials/callback_api/rpc_server.js b/examples/tutorials/callback_api/rpc_server.js index 02920528..28f0fa17 100755 --- a/examples/tutorials/callback_api/rpc_server.js +++ b/examples/tutorials/callback_api/rpc_server.js @@ -42,8 +42,8 @@ amqp.connect((err, connection) => { function fib(n) { // Do it the ridiculous, but not most ridiculous, way. For better, // see http://nayuki.eigenstate.org/page/fast-fibonacci-algorithms - let a = 0, - b = 1; + let a = 0; + let b = 1; for (let i = 0; i < n; i++) { const c = a + b; a = b; diff --git a/examples/tutorials/rpc_server.js b/examples/tutorials/rpc_server.js index c3526058..f2eb10cd 100755 --- a/examples/tutorials/rpc_server.js +++ b/examples/tutorials/rpc_server.js @@ -36,8 +36,8 @@ const queue = 'rpc_queue'; function fib(n) { // Do it the ridiculous, but not most ridiculous, way. For better, // see http://nayuki.eigenstate.org/page/fast-fibonacci-algorithms - let a = 0, - b = 1; + let a = 0; + let b = 1; for (let i = 0; i < n; i++) { const c = a + b; a = b; diff --git a/lib/bitset.js b/lib/bitset.js index 63b5d4cf..f1a5a425 100644 --- a/lib/bitset.js +++ b/lib/bitset.js @@ -112,8 +112,8 @@ function trailingZeros(i) { // since bit ops are not necessarily the quick way to do things in // JS. if (i === 0) return 32; - let y, - n = 31; + let y; + let n = 31; y = i << 16; if (y !== 0) { n = n - 16; diff --git a/lib/channel.js b/lib/channel.js index 573e11ee..810cd3c9 100644 --- a/lib/channel.js +++ b/lib/channel.js @@ -370,8 +370,8 @@ function acceptDeliveryOrReturn(f) { // Move to the state of waiting for message frames (headers, then // one or more content frames) function acceptMessage(continuation) { - let totalSize = 0, - remaining = 0; + let totalSize = 0; + let remaining = 0; let buffers = null; const message = { diff --git a/lib/codec.js b/lib/codec.js index 2c1c2f8a..20aabfee 100644 --- a/lib/codec.js +++ b/lib/codec.js @@ -48,8 +48,8 @@ function encodeArray(buffer, val, offset) { function encodeFieldValue(buffer, value, offset) { const start = offset; - let type = typeof value, - val = value; + let type = typeof value; + let val = value; // A trapdoor for specifying a type, e.g., timestamp if (value && type === 'object' && Object.hasOwn(value, '!')) { val = value.value; @@ -206,10 +206,12 @@ function encodeFieldValue(buffer, value, offset) { // Assume we're given a slice of the buffer that contains just the // fields. function decodeFields(slice) { - let fields = {}, - offset = 0, - size = slice.length; - let len, key, val; + const fields = {}; + let offset = 0; + const size = slice.length; + let len; + let key; + let val; function decodeFieldValue() { const tag = String.fromCharCode(slice[offset]); diff --git a/lib/connect.js b/lib/connect.js index 76613705..cf45946c 100644 --- a/lib/connect.js +++ b/lib/connect.js @@ -68,8 +68,8 @@ function openFrames(vhost, query, credentials, extraClientProperties) { // Decide on credentials based on what we're supplied. function credentialsFromUrl(parts) { - let user = 'guest', - passwd = 'guest'; + let user = 'guest'; + let passwd = 'guest'; if (parts.username !== '' || parts.password !== '') { user = parts.username ? unescape(parts.username) : ''; passwd = parts.password ? unescape(parts.password) : ''; @@ -93,14 +93,16 @@ function connect(url, socketOptions, openCallback) { const extraClientProperties = sockopts.clientProperties || {}; - let protocol, fields; + let protocol; + let fields; if (typeof url === 'object') { protocol = `${url.protocol || 'amqp'}:`; sockopts.host = url.hostname; sockopts.servername = sockopts.servername || url.hostname; sockopts.port = url.port || (protocol === 'amqp:' ? 5672 : 5671); - let user, pass; + let user; + let pass; // Only default if both are missing, to have the same behaviour as // the stringly URL. if (url.username === undefined && url.password === undefined) { diff --git a/lib/frame.js b/lib/frame.js index 5749c48c..7306399b 100644 --- a/lib/frame.js +++ b/lib/frame.js @@ -20,11 +20,11 @@ module.exports.PROTOCOL_HEADER = `AMQP${String.fromCharCode(0, 0, 9, 1)}`; */ // framing constants -const FRAME_METHOD = constants.FRAME_METHOD, - FRAME_HEARTBEAT = constants.FRAME_HEARTBEAT, - FRAME_HEADER = constants.FRAME_HEADER, - FRAME_BODY = constants.FRAME_BODY, - FRAME_END = constants.FRAME_END; +const FRAME_METHOD = constants.FRAME_METHOD; +const FRAME_HEARTBEAT = constants.FRAME_HEARTBEAT; +const FRAME_HEADER = constants.FRAME_HEADER; +const FRAME_BODY = constants.FRAME_BODY; +const FRAME_END = constants.FRAME_END; // expected byte sizes for frame parts const TYPE_BYTES = 1; diff --git a/test/channel.js b/test/channel.js index 1470bf05..777dab02 100644 --- a/test/channel.js +++ b/test/channel.js @@ -3,9 +3,9 @@ const promisify = require('node:util').promisify; const Channel = require('../lib/channel').Channel; const Connection = require('../lib/connection').Connection; const util = require('./util'); -const succeed = util.succeed, - fail = util.fail, - latch = util.latch; +const succeed = util.succeed; +const fail = util.fail; +const latch = util.latch; const completes = util.completes; const defs = require('../lib/defs'); const conn_handshake = require('./connection').connection_handshake; diff --git a/test/channel_api.js b/test/channel_api.js index 7dc1e89d..e29e8ec2 100644 --- a/test/channel_api.js +++ b/test/channel_api.js @@ -1,8 +1,8 @@ const assert = require('node:assert'); const api = require('../channel_api'); const util = require('./util'); -const succeed = util.succeed, - fail = util.fail; +const succeed = util.succeed; +const fail = util.fail; const schedule = util.schedule; const randomString = util.randomString; const promisify = require('node:util').promisify; @@ -273,11 +273,11 @@ suite('binding, consuming', () => { // To some extent this is now just testing semantics of the server, // but we can at least try out a few settings, and consume. chtest('consume via exchange-exchange binding', (ch) => { - const ex1 = 'test.ex-ex-binding1', - ex2 = 'test.ex-ex-binding2'; + const ex1 = 'test.ex-ex-binding1'; + const ex2 = 'test.ex-ex-binding2'; const q = 'test.ex-ex-binding-q'; - const rk = 'test.routing.key', - msg = randomString(); + const rk = 'test.routing.key'; + const msg = randomString(); return Promise.all([ ch.assertExchange(ex1, 'direct', EX_OPTS), ch.assertExchange(ex2, 'fanout', {durable: false, internal: true}), @@ -396,8 +396,8 @@ suite('binding, consuming', () => { // ack, by default, removes a single message from the queue chtest('ack', (ch) => { const q = 'test.ack'; - const msg1 = randomString(), - msg2 = randomString(); + const msg1 = randomString(); + const msg2 = randomString(); return Promise.all([ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)]) .then(() => { diff --git a/test/codec.js b/test/codec.js index 19ee541a..0586236e 100644 --- a/test/codec.js +++ b/test/codec.js @@ -79,9 +79,9 @@ function bufferToArray(b) { suite('Implicit encodings', () => { testCases.forEach((tc) => { - const name = tc[0], - val = tc[1], - expect = tc[2]; + const name = tc[0]; + const val = tc[1]; + const expect = tc[2]; test(name, () => { const buffer = Buffer.alloc(1000); const size = codec.encodeTable(buffer, val, 0); diff --git a/test/connect.js b/test/connect.js index 537549b9..73fd04bb 100644 --- a/test/connect.js +++ b/test/connect.js @@ -4,11 +4,11 @@ const defs = require('../lib/defs'); const assert = require('node:assert'); const util = require('./util'); const net = require('node:net'); -const fail = util.fail, - succeed = util.succeed, - latch = util.latch, - kCallback = util.kCallback, - succeedIfAttributeEquals = util.succeedIfAttributeEquals; +const fail = util.fail; +const succeed = util.succeed; +const latch = util.latch; +const kCallback = util.kCallback; +const succeedIfAttributeEquals = util.succeedIfAttributeEquals; const format = require('node:util').format; const URL = process.env.URL || 'amqp://localhost'; @@ -107,8 +107,8 @@ suite('Connect API', () => { test('using plain credentials', (done) => { const url = require('node:url'); const parts = url.parse(URL, true); - let u = 'guest', - p = 'guest'; + let u = 'guest'; + let p = 'guest'; if (parts.auth) { const auth = parts.auth.split(':'); u = auth[0]; @@ -120,8 +120,8 @@ suite('Connect API', () => { test('using amqplain credentials', (done) => { const url = require('node:url'); const parts = url.parse(URL, true); - let u = 'guest', - p = 'guest'; + let u = 'guest'; + let p = 'guest'; if (parts.auth) { const auth = parts.auth.split(':'); u = auth[0]; diff --git a/test/connection.js b/test/connection.js index e5611a5a..b34f771b 100644 --- a/test/connection.js +++ b/test/connection.js @@ -4,9 +4,9 @@ const Connection = require('../lib/connection').Connection; const HEARTBEAT = require('../lib/frame').HEARTBEAT; const HB_BUF = require('../lib/frame').HEARTBEAT_BUF; const util = require('./util'); -const succeed = util.succeed, - fail = util.fail, - latch = util.latch; +const succeed = util.succeed; +const fail = util.fail; +const latch = util.latch; const completes = util.completes; const kCallback = util.kCallback; diff --git a/test/frame.js b/test/frame.js index 58af4afc..5243d646 100644 --- a/test/frame.js +++ b/test/frame.js @@ -109,8 +109,8 @@ suite('Parsing', () => { const bufs = []; const input = inputs(); const frames = new Frames(input); - let i = 0, - ex; + let i = 0; + let ex; frames.accept = (f) => { // A minor hack to make sure we get the assertion exception; // otherwise, it's just a test that we reached the line diff --git a/test/util.js b/test/util.js index 731bec43..1b32fa41 100644 --- a/test/util.js +++ b/test/util.js @@ -166,8 +166,8 @@ function versionGreaterThan(actual, spec) { const version = actual.split('.').map(int); const desired = spec.split('.').map(int); for (let i = 0; i < desired.length; i++) { - const a = version[i], - b = desired[i]; + const a = version[i]; + const b = desired[i]; if (a !== b) return a > b; } return false;