Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Enforce const usage for variables that are never reassigned
- Add node: protocol prefix to Node.js builtin module imports for clarity
- Use modern exponentiation operator (**) instead of Math.pow()
- Replace string concatenation with modern template literals

## v0.10.9
- Add support for IPv6 urls
Expand Down
30 changes: 15 additions & 15 deletions bin/generate-defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ for (let i = 0, len = defs.classes.length; i < len; i++) {
for (let j = 0, num = clazz.methods.length; j < num; j++) {
const method = clazz.methods[j];
const name = methodName(clazz, method);
const info = 'methodInfo' + name;
const info = `methodInfo${name}`;

methods[name] = {
id: methodId(clazz, method),
Expand All @@ -80,8 +80,8 @@ for (let i = 0, len = defs.classes.length; i < len; i++) {
clazz: clazz.name,
args: method['arguments'].map(argument),
isReply: method.answer,
encoder: 'encode' + name,
decoder: 'decode' + name,
encoder: `encode${name}`,
decoder: `decode${name}`,
info: info,
};
}
Expand All @@ -91,9 +91,9 @@ for (let i = 0, len = defs.classes.length; i < len; i++) {
propertieses[name] = {
id: clazz.id,
name: name,
encoder: 'encode' + name,
decoder: 'decode' + name,
info: 'propertiesInfo' + name,
encoder: `encode${name}`,
decoder: `decode${name}`,
info: `propertiesInfo${name}`,
args: props.map(argument),
};
}
Expand Down Expand Up @@ -203,7 +203,7 @@ function methodId(clazz, method) {
}

function propertiesName(clazz) {
return initial(clazz.name) + 'Properties';
return `${initial(clazz.name)}Properties`;
}

function valTypeTest(arg) {
Expand Down Expand Up @@ -298,11 +298,11 @@ function assignTable(a) {
}

function tableVar(a) {
return a.name + '_encoded';
return `${a.name}_encoded`;
}

function stringLenVar(a) {
return a.name + '_len';
return `${a.name}_len`;
}

function assignStringLen(a) {
Expand Down Expand Up @@ -438,7 +438,7 @@ function encoderFn(method) {
println('offset += %s.copy(buffer, offset);', tableVar(a));
break;
default:
throw new Error('Unexpected argument type: ' + a.type);
throw new Error(`Unexpected argument type: ${a.type}`);
}
}

Expand Down Expand Up @@ -473,7 +473,7 @@ function decoderFn(method) {

for (let i = 0, num = args.length; i < num; i++) {
const a = args[i];
const field = "fields['" + a.name + "']";
const field = `fields['${a.name}']`;

// Flush any collected bits before doing a new field
if (a.type != 'bit' && bitsInARow > 0) {
Expand Down Expand Up @@ -520,7 +520,7 @@ function decoderFn(method) {
println('offset += len;');
break;
default:
throw new TypeError('Unexpected type in argument list: ' + a.type);
throw new TypeError(`Unexpected type in argument list: ${a.type}`);
}
println('%s = val;', field);
}
Expand Down Expand Up @@ -661,7 +661,7 @@ function encodePropsFn(props) {
println('offset += %s.copy(buffer, offset);', tableVar(p));
break;
default:
throw new Error('Unexpected argument type: ' + p.type);
throw new Error(`Unexpected argument type: ${p.type}`);
}
}
println('}'); // != undefined
Expand All @@ -688,7 +688,7 @@ function decodePropsFn(props) {

for (let i = 0, num = args.length; i < num; i++) {
const p = argument(args[i]);
const field = "fields['" + p.name + "']";
const field = `fields['${p.name}']`;

println('if (flags & %d) {', flagAt(i));
if (p.type === 'bit') {
Expand Down Expand Up @@ -724,7 +724,7 @@ function decodePropsFn(props) {
println('offset += len;');
break;
default:
throw new TypeError('Unexpected type in argument list: ' + p.type);
throw new TypeError(`Unexpected type in argument list: ${p.type}`);
}
println('%s = val;', field);
}
Expand Down
3 changes: 0 additions & 3 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
"noArguments": "off",
"useLiteralKeys": "off"
},
"style": {
"useTemplate": "off"
},
"suspicious": {
"noRedundantUseStrict": "off",
"noAssignInExpressions": "off",
Expand Down
2 changes: 1 addition & 1 deletion lib/callback_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class Channel extends BaseChannel {
cb(null, m);
});
} else {
cb(new Error('Unexpected response to BasicGet: ' + inspect(f)));
cb(new Error(`Unexpected response to BasicGet: ${inspect(f)}`));
}
}
});
Expand Down
6 changes: 3 additions & 3 deletions lib/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class Channel extends EventEmitter {
methodId: 0,
classId: 0,
});
const s = stackCapture('closeBecause called: ' + reason);
const s = stackCapture(`closeBecause called: ${reason}`);
this.toClosing(s, k);
}

Expand Down Expand Up @@ -296,7 +296,7 @@ class Channel extends EventEmitter {
this.reply = null;
reply(f);
}
const emsg = 'Channel closed by server: ' + closeMsg(f);
const emsg = `Channel closed by server: ${closeMsg(f)}`;
this.sendImmediately(defs.ChannelCloseOk, {});

const error = new Error(emsg);
Expand Down Expand Up @@ -459,7 +459,7 @@ class BaseChannel extends Channel {
return consumer(message);
} else {
// %%% Surely a race here
throw new Error('Unknown consumer: ' + consumerTag);
throw new Error(`Unknown consumer: ${consumerTag}`);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/codec.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ function encodeFieldValue(buffer, value, offset) {
offset++;
buffer.writeUInt32BE(val.digits, offset);
offset += 4;
} else throw new TypeError("Decimal value must be {'places': 0..255, 'digits': uint32}, " + 'got ' + JSON.stringify(val));
} else throw new TypeError(`Decimal value must be {'places': 0..255, 'digits': uint32}, got ${JSON.stringify(val)}`);
break;
default:
throw new TypeError('Unknown type to encode: ' + type);
throw new TypeError(`Unknown type to encode: ${type}`);
}
return offset - start;
}
Expand Down Expand Up @@ -352,7 +352,7 @@ function decodeFields(slice) {
offset += len;
break;
default:
throw new TypeError('Unexpected type tag "' + tag + '"');
throw new TypeError(`Unexpected type tag "${tag}"`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function connect(url, socketOptions, openCallback) {

let protocol, fields;
if (typeof url === 'object') {
protocol = (url.protocol || 'amqp') + ':';
protocol = `${url.protocol || 'amqp'}:`;
sockopts.host = url.hostname;
sockopts.servername = sockopts.servername || url.hostname;
sockopts.port = url.port || (protocol === 'amqp:' ? 5672 : 5671);
Expand Down Expand Up @@ -167,7 +167,7 @@ function connect(url, socketOptions, openCallback) {
} else if (protocol === 'amqps:') {
sock = require('node:tls').connect(sockopts, onConnect);
} else {
throw new Error('Expected amqp: or amqps: as the protocol; got ' + protocol);
throw new Error(`Expected amqp: or amqps: as the protocol; got ${protocol}`);
}

if (timeout) {
Expand Down
2 changes: 1 addition & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class Connection extends EventEmitter {
methodId: 0,
classId: 0,
});
const s = stackCapture('closeBecause called: ' + reason);
const s = stackCapture(`closeBecause called: ${reason}`);
this.toClosing(s, k);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function trimStack(stack, num) {
function IllegalOperationError(msg, stack) {
const tmp = new Error();
this.message = msg;
this.stack = this.toString() + '\n' + trimStack(tmp.stack, 2);
this.stack = `${this.toString()}\n${trimStack(tmp.stack, 2)}`;
this.stackAtStateChange = stack;
}
inherits(IllegalOperationError, Error);
Expand All @@ -16,7 +16,7 @@ IllegalOperationError.prototype.name = 'IllegalOperationError';

function stackCapture(reason) {
const e = new Error();
return 'Stack capture: ' + reason + '\n' + trimStack(e.stack, 2);
return `Stack capture: ${reason}\n${trimStack(e.stack, 2)}`;
}

module.exports.IllegalOperationError = IllegalOperationError;
Expand Down
2 changes: 1 addition & 1 deletion lib/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ module.exports.inspect = function (frame, showFields) {
return format('<Content channel:%d size:%d>', frame.channel, frame.size);
} else {
const info = defs.info(frame.id);
return format('<%s channel:%d%s>', info.name, frame.channel, showFields ? ' ' + JSON.stringify(frame.fields, undefined, 2) : '');
return format('<%s channel:%d%s>', info.name, frame.channel, showFields ? ` ${JSON.stringify(frame.fields, undefined, 2)}` : '');
}
};
4 changes: 2 additions & 2 deletions lib/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const defs = require('./defs');
const constants = defs.constants;
const decode = defs.decode;

module.exports.PROTOCOL_HEADER = 'AMQP' + String.fromCharCode(0, 0, 9, 1);
module.exports.PROTOCOL_HEADER = `AMQP${String.fromCharCode(0, 0, 9, 1)}`;

/*
Frame format:
Expand Down Expand Up @@ -162,7 +162,7 @@ module.exports.decodeFrame = (frame) => {
case FRAME_HEARTBEAT:
return HEARTBEAT;
default:
throw new Error('Unknown frame type ' + frame.type);
throw new Error(`Unknown frame type ${frame.type}`);
}
};

Expand Down
8 changes: 4 additions & 4 deletions test/callback_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function twice(done) {
// Adapt 'done' to a callback that's expected to fail
function failCallback(done) {
return function (err, _) {
if (err == null) done(new Error('Expected failure, got ' + val));
if (err == null) done(new Error(`Expected failure, got ${val}`));
else done();
};
}
Expand Down Expand Up @@ -199,7 +199,7 @@ suite('sending messages', function () {
q.queue,
function (m) {
if (m.content.toString() == msg) done();
else done(new Error("message content doesn't match:" + msg + ' =/= ' + m.content.toString()));
else done(new Error(`message content doesn't match:${msg} =/= ${m.content.toString()}`));
},
{noAck: true, exclusive: true},
);
Expand All @@ -217,7 +217,7 @@ suite('sending messages', function () {
if (m.content.toString() == msg) {
ch.ack(m);
done();
} else done(new Error("message content doesn't match:" + msg + ' =/= ' + m.content.toString()));
} else done(new Error(`message content doesn't match:${msg} =/= ${m.content.toString()}`));
},
{noAck: false, exclusive: true},
);
Expand All @@ -236,7 +236,7 @@ suite('sending messages', function () {
if (e != null) return done(e);
else if (!m) return done(new Error('Empty (false) not expected'));
else if (m.content.toString() == msg) return done();
else return done(new Error('Messages do not match: ' + msg + ' =/= ' + m.content.toString()));
else return done(new Error(`Messages do not match: ${msg} =/= ${m.content.toString()}`));
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ suite('channel machinery', function () {

function confirmTest(variety, Method) {
return test(
'confirm ' + variety,
`confirm ${variety}`,
channelTest(
function (ch, done) {
ch.on(variety, function (f) {
Expand Down
6 changes: 3 additions & 3 deletions test/channel_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ suite('assert, check, delete', function () {
});

chtest("fail on checking a queue that's not there", function (ch) {
return expectFail(ch.checkQueue('test.random-' + randomString()));
return expectFail(ch.checkQueue(`test.random-${randomString()}`));
});

chtest("fail on checking an exchange that's not there", function (ch) {
return expectFail(ch.checkExchange('test.random-' + randomString()));
return expectFail(ch.checkExchange(`test.random-${randomString()}`));
});

chtest('fail on reasserting exchange with different type', function (ch) {
Expand Down Expand Up @@ -587,7 +587,7 @@ suite('confirms', function () {

return Promise.all(cs).then(function () {
if (multipleRainbows) return true;
else if (num > 500) throw new Error("Couldn't provoke the server" + ' into multi-acking with ' + num + ' messages; giving up');
else if (num > 500) throw new Error(`Couldn't provoke the server into multi-acking with ${num} messages; giving up`);
else {
//console.warn("Failed with " + num + "; trying " + num * 2);
return prod(num * 2);
Expand Down
8 changes: 4 additions & 4 deletions test/codec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ suite('Roundtrip values', function () {
amqp.FieldArray,
amqp.FieldTable,
].forEach(function (T) {
test(T.toString() + ' roundtrip', roundtrips(T).asTest());
test(`${T.toString()} roundtrip`, roundtrips(T).asTest());
});
});

Expand Down Expand Up @@ -208,7 +208,7 @@ function assertEqualModuloDefaults(original, decodedFields) {
}
} catch (assertionErr) {
const methodOrProps = defs.info(original.id).name;
assertionErr.message += ' (frame ' + methodOrProps + ' field ' + arg.name + ')';
assertionErr.message += ` (frame ${methodOrProps} field ${arg.name})`;
throw assertionErr;
}
}
Expand Down Expand Up @@ -242,12 +242,12 @@ function roundtripProperties(Properties) {

suite('Roundtrip methods', function () {
amqp.methods.forEach(function (Method) {
test(Method.toString() + ' roundtrip', roundtripMethod(Method).asTest());
test(`${Method.toString()} roundtrip`, roundtripMethod(Method).asTest());
});
});

suite('Roundtrip properties', function () {
amqp.properties.forEach(function (Properties) {
test(Properties.toString() + ' roundtrip', roundtripProperties(Properties).asTest());
test(`${Properties.toString()} roundtrip`, roundtripProperties(Properties).asTest());
});
});
4 changes: 2 additions & 2 deletions test/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ suite('Errors on connect', function () {
server = net
.createServer(function (socket) {
socket.once('data', function (protocolHeader) {
assert.deepStrictEqual(protocolHeader, Buffer.from('AMQP' + String.fromCharCode(0, 0, 9, 1)));
assert.deepStrictEqual(protocolHeader, Buffer.from(`AMQP${String.fromCharCode(0, 0, 9, 1)}`));
util.runServer(socket, function (send, wait) {
send(defs.ConnectionStart, {
versionMajor: 0,
Expand All @@ -200,7 +200,7 @@ suite('Errors on connect', function () {
})
.listen(0);

connect('amqp://localhost:' + server.address().port, {}, function (err) {
connect(`amqp://localhost:${server.address().port}`, {}, function (err) {
if (!err) bothDone(new Error('Expected authentication error'));
bothDone();
});
Expand Down
2 changes: 1 addition & 1 deletion test/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function connectionTest(client, server) {

// NB only not a race here because the writes are synchronous
const protocolHeader = pair.server.read(8);
assert.deepEqual(Buffer.from('AMQP' + String.fromCharCode(0, 0, 9, 1)), protocolHeader);
assert.deepEqual(Buffer.from(`AMQP${String.fromCharCode(0, 0, 9, 1)}`), protocolHeader);

util.runServer(pair.server, function (send, wait) {
server(send, wait, bothDone, pair.server);
Expand Down
2 changes: 1 addition & 1 deletion test/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ const domainProps = [

suite('Domains', function () {
domainProps.forEach(function (p) {
test(p[0] + ' domain', forAll(p[0]).satisfy(p[1]).asTest({times: 500}));
test(`${p[0]} domain`, forAll(p[0]).satisfy(p[1]).asTest({times: 500}));
});
});

Expand Down
Loading