From 0e776c9152407d8ef83ece45629cdff8b751fb0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gonza=CC=81lez=20Garci=CC=81a?= Date: Fri, 8 Sep 2023 14:09:09 +0200 Subject: [PATCH] fix linting problems --- src/lib/client.ts | 9 +++-- test/abstract_client.ts | 75 ++++++++++++++++++++++++----------------- test/client_mqtt5.ts | 11 +++--- 3 files changed, 58 insertions(+), 37 deletions(-) diff --git a/src/lib/client.ts b/src/lib/client.ts index cecbbfdd7..27b9b2b6d 100644 --- a/src/lib/client.ts +++ b/src/lib/client.ts @@ -977,7 +977,10 @@ export default class MqttClient extends TypedEventEmitter + public publishAsync( + topic: string, + message: string | Buffer, + ): Promise public publishAsync( topic: string, message: string | Buffer, @@ -1347,7 +1350,9 @@ export default class MqttClient extends TypedEventEmitter + public unsubscribeAsync( + topic: string | string[], + ): Promise public unsubscribeAsync( topic: string | string[], opts?: IClientSubscribeOptions, diff --git a/test/abstract_client.ts b/test/abstract_client.ts index d549e16df..5d0325a90 100644 --- a/test/abstract_client.ts +++ b/test/abstract_client.ts @@ -372,7 +372,7 @@ export default function abstractTest(server, config) { it('should emit connect', function _test(done) { const client = connect() client.once('connect', (packet: mqtt.IConnackPacket) => { - assert.equal(packet.cmd, "connack") + assert.equal(packet.cmd, 'connack') client.end(true, (err) => done(err)) }) client.once('error', done) @@ -1135,19 +1135,24 @@ export default function abstractTest(server, config) { }) client.once('connect', () => { - client.publish('a', 'b', pubOpts, (err, packet?: mqtt.Packet) => { - assert.exists(packet) - if (version === 5) { - assert.strictEqual(err.code, pubackReasonCode) - } else { - assert.ifError(err) - } - setImmediate(() => { - client.end(() => { - server2.close(done) + client.publish( + 'a', + 'b', + pubOpts, + (err, packet?: mqtt.Packet) => { + assert.exists(packet) + if (version === 5) { + assert.strictEqual(err.code, pubackReasonCode) + } else { + assert.ifError(err) + } + setImmediate(() => { + client.end(() => { + server2.close(done) + }) }) - }) - }) + }, + ) }) }) }) @@ -1204,19 +1209,24 @@ export default function abstractTest(server, config) { }) client.once('connect', () => { - client.publish('a', 'b', pubOpts, (err, packet?: mqtt.Packet) => { - assert.exists(packet) - if (version === 5) { - assert.strictEqual(err.code, pubrecReasonCode) - } else { - assert.ifError(err) - } - setImmediate(() => { - client.end(true, () => { - server2.close(done) + client.publish( + 'a', + 'b', + pubOpts, + (err, packet?: mqtt.Packet) => { + assert.exists(packet) + if (version === 5) { + assert.strictEqual(err.code, pubrecReasonCode) + } else { + assert.ifError(err) + } + setImmediate(() => { + client.end(true, () => { + server2.close(done) + }) }) - }) - }) + }, + ) }) }) }) @@ -2381,12 +2391,15 @@ export default function abstractTest(server, config) { // client.subscribe(testPacket.topic) - client.once('message', (topic, message, packet: mqtt.IPublishPacket) => { - assert.strictEqual(topic, testPacket.topic) - assert.strictEqual(message.toString(), testPacket.payload) - assert.strictEqual(packet.cmd, 'publish') - client.end(true, done) - }) + client.once( + 'message', + (topic, message, packet: mqtt.IPublishPacket) => { + assert.strictEqual(topic, testPacket.topic) + assert.strictEqual(message.toString(), testPacket.payload) + assert.strictEqual(packet.cmd, 'publish') + client.end(true, done) + }, + ) server.once('client', (serverClient) => { serverClient.on('subscribe', () => { diff --git a/test/client_mqtt5.ts b/test/client_mqtt5.ts index 639b88021..d17c48266 100644 --- a/test/client_mqtt5.ts +++ b/test/client_mqtt5.ts @@ -1048,10 +1048,13 @@ describe('MQTT 5.0', () => { } const client = mqtt.connect(opts) - client.once('disconnect', (disconnectPacket: mqtt.IDisconnectPacket) => { - assert.strictEqual(disconnectPacket.reasonCode, 128) - client.end(true, (err) => done(err)) - }) + client.once( + 'disconnect', + (disconnectPacket: mqtt.IDisconnectPacket) => { + assert.strictEqual(disconnectPacket.reasonCode, 128) + client.end(true, (err) => done(err)) + }, + ) }) it('pubrec handling custom reason code', function test(done) {