Skip to content
Merged
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
15 changes: 5 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,23 @@ module.exports = {
rules: {
'global-require': 'off',
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-unused-vars': 'off',
'no-unused-vars': ['error', { args: 'none' }],
'no-underscore-dangle': 'off',
'no-param-reassign': 'off',
'no-restricted-syntax': 'off',
camelcase: 'off',
'default-case': 'off',
'consistent-return': 'off',
'import/order': 'off',
'max-classes-per-file': 'off',
'no-plusplus': 'off',
'guard-for-in': 'off',
'no-bitwise': 'off',
'class-methods-use-this': 'off',
'no-continue': 'off',
'prefer-destructuring': 'off',
'no-use-before-define': 'off',
// Typescript rules
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ args: 'none' }
],
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/no-use-before-define': 'off',
Expand Down
2 changes: 1 addition & 1 deletion src/bin/mqtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import publish from './pub'
import subscribe from './sub'

// eslint-disable-next-line @typescript-eslint/no-var-requires
const version = require('../../package.json').version
const { version } = require('../../package.json')

const helpMe = help({
dir: path.join(__dirname, '../../', 'help'),
Expand Down
2 changes: 1 addition & 1 deletion src/bin/pub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import help from 'help-me'

import minimist, { type ParsedArgs } from 'minimist'
import split2 from 'split2'
import { connect } from '../mqtt'
import { type IClientOptions, type IClientPublishOptions } from 'src/lib/client'
import { pipeline } from 'stream'
import { connect } from '../mqtt'

const helpMe = help({
dir: path.join(__dirname, '../../', 'help'),
Expand Down
2 changes: 1 addition & 1 deletion src/bin/sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import path from 'path'
import fs from 'fs'
import minimist from 'minimist'
import help from 'help-me'
import { connect } from '../mqtt'
import { type IClientOptions } from 'src/lib/client'
import { connect } from '../mqtt'

const helpMe = help({
dir: path.join(__dirname, '../../', 'help'),
Expand Down
16 changes: 8 additions & 8 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Module dependencies
*/
import TopicAliasRecv from './topic-alias-recv'
import mqttPacket, {
type IAuthPacket,
IConnackPacket,
Expand All @@ -15,17 +14,18 @@ import mqttPacket, {
type ISubackPacket,
type IConnectPacket,
} from 'mqtt-packet'
import DefaultMessageIdProvider, {
type IMessageIdProvider,
} from './default-message-id-provider'
import { type DuplexOptions, Writable } from 'readable-stream'
import clone from 'rfdc/default'
import * as validations from './validations'
import _debug from 'debug'
import Store, { type IStore } from './store'
import handlePacket from './handlers'
import type { ClientOptions } from 'ws'
import { type ClientRequestArgs } from 'http'
import * as validations from './validations'
import Store, { type IStore } from './store'
import handlePacket from './handlers'
import DefaultMessageIdProvider, {
type IMessageIdProvider,
} from './default-message-id-provider'
import TopicAliasRecv from './topic-alias-recv'
import {
type DoneCallback,
type ErrorWithReasonCode,
Expand Down Expand Up @@ -1157,7 +1157,7 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
}
opts = { ...defaultOpts, ...opts } as IClientSubscribeOptions

const properties = opts.properties
const { properties } = opts

const subs: ISubscriptionRequest[] = []

Expand Down
5 changes: 3 additions & 2 deletions src/lib/connect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ function parseAuthOptions(opts: IClientOptions) {
if (opts.auth) {
matches = opts.auth.match(/^(.+):(.+)$/)
if (matches) {
opts.username = matches[1]
opts.password = matches[2]
const [, username, password] = matches
opts.username = username
opts.password = password
} else {
opts.username = opts.auth
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/connect/socks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Duplex } from 'stream'
import { SocksClient, type SocksProxy } from 'socks'
import * as dns from 'dns'
import { type SocksProxyType } from 'socks/typings/common/constants'
import { type IStream } from '../shared'
import { promisify } from 'util'
import { type Socket } from 'net'
import assert from 'assert'
import { type IStream } from '../shared'

const debug = _debug('mqttjs:socks')

Expand Down
3 changes: 1 addition & 2 deletions src/lib/connect/tcp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { type StreamBuilder } from '../shared'

import net from 'net'
import _debug from 'debug'
import { type StreamBuilder } from '../shared'
import openSocks from './socks'

const debug = _debug('mqttjs:tcp')
Expand Down
2 changes: 1 addition & 1 deletion src/lib/connect/ws.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type StreamBuilder } from '../shared'
import { Buffer } from 'buffer'
import Ws, { type ClientOptions } from 'ws'
import _debug from 'debug'
import { type DuplexOptions, Transform } from 'readable-stream'
import { type StreamBuilder } from '../shared'
import isBrowser from '../is-browser'
import { type IClientOptions } from '../client'
import type MqttClient from '../client'
Expand Down
3 changes: 1 addition & 2 deletions src/lib/connect/wx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { type StreamBuilder } from '../shared'

import { Buffer } from 'buffer'
import { Transform } from 'readable-stream'
import { type StreamBuilder } from '../shared'
import { type IClientOptions } from '../client'
import type MqttClient from '../client'
import { BufferedDuplex } from '../BufferedDuplex'
Expand Down
2 changes: 1 addition & 1 deletion src/lib/get-timer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import isBrowser, { isWebWorker, isReactNativeBrowser } from './is-browser'
import { clearInterval as clearI, setInterval as setI } from 'worker-timers'
import isBrowser, { isWebWorker, isReactNativeBrowser } from './is-browser'
import type { TimerVariant } from './shared'

// dont directly assign globals to class props otherwise this throws in web workers: Uncaught TypeError: Illegal invocation
Expand Down
2 changes: 1 addition & 1 deletion src/lib/handlers/connack.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type IConnackPacket } from 'mqtt-packet'
import { ReasonCodes } from './ack'
import TopicAliasSend from '../topic-alias-send'
import { ErrorWithReasonCode, type PacketHandler } from '../shared'
import { type IConnackPacket } from 'mqtt-packet'

const handleConnack: PacketHandler = (client, packet: IConnackPacket) => {
client.log('_handleConnack')
Expand Down
18 changes: 9 additions & 9 deletions test/node/abstract_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import { assert } from 'chai'
import sinon from 'sinon'
import fs from 'fs'
import levelStore from 'mqtt-level-store'
import {
type IPublishPacket,
type IPubrelPacket,
type ISubackPacket,
type QoS,
} from 'mqtt-packet'
import { type DoneCallback, ErrorWithReasonCode } from 'src/lib/shared'
import { fail } from 'assert'
import { describe, it, beforeEach, afterEach, after } from 'node:test'
import Store from '../../src/lib/store'
import serverBuilderFn from './server_helpers_for_client_tests'
import handlePubrel from '../../src/lib/handlers/pubrel'
Expand All @@ -18,15 +27,6 @@ import mqtt, {
type ISubscriptionMap,
type ISubscriptionRequest,
} from '../../src'
import {
type IPublishPacket,
type IPubrelPacket,
type ISubackPacket,
type QoS,
} from 'mqtt-packet'
import { type DoneCallback, ErrorWithReasonCode } from 'src/lib/shared'
import { fail } from 'assert'
import { describe, it, beforeEach, afterEach, after } from 'node:test'

/**
* These tests try to be consistent with names for servers (brokers) and clients,
Expand Down
2 changes: 1 addition & 1 deletion test/node/abstract_store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type IPublishPacket, type IPubrelPacket } from 'mqtt-packet'
import { type IStore } from '../../src'
import 'should'
import { it, beforeEach, afterEach } from 'node:test'
import { type IStore } from '../../src'

export default function abstractStoreTest(
build: (cb: (err?: Error, store?: IStore) => void) => void,
Expand Down
8 changes: 4 additions & 4 deletions test/node/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useFakeTimers } from 'sinon'
import mqtt from '../../src'
import { assert } from 'chai'
import { fork } from 'child_process'
import path from 'path'
Expand All @@ -9,13 +8,14 @@ import mqttPacket from 'mqtt-packet'
import { Duplex } from 'readable-stream'
import Connection from 'mqtt-connection'
import util from 'util'
import _debug from 'debug'
import { type IClientOptions } from 'src/lib/client'
import { describe, it, after } from 'node:test'
import getPorts from './helpers/port_list'
import serverBuilder from './server_helpers_for_client_tests'
import _debug from 'debug'
import { MqttServer } from './server'
import abstractClientTests from './abstract_client'
import { type IClientOptions } from 'src/lib/client'
import { describe, it, after } from 'node:test'
import mqtt from '../../src'

// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkgJson = require('../../package.json')
Expand Down
2 changes: 1 addition & 1 deletion test/node/client_mqtt5.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { assert } from 'chai'
import { after, describe, it } from 'node:test'
import abstractClientTests from './abstract_client'
import { MqttServer } from './server'
import serverBuilder from './server_helpers_for_client_tests'
import getPorts from './helpers/port_list'
import mqtt, { type ErrorWithReasonCode } from '../../src'
import { after, describe, it } from 'node:test'

const ports = getPorts(1)

Expand Down
2 changes: 1 addition & 1 deletion test/node/keepaliveManager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { afterEach, beforeEach, describe, it } from 'node:test'
import KeepaliveManager from '../../src/lib/KeepaliveManager'
import { assert } from 'chai'
import { useFakeTimers, spy, stub } from 'sinon'
import { type MqttClient } from 'src'
import KeepaliveManager from '../../src/lib/KeepaliveManager'

function mockedClient(keepalive: number) {
return {
Expand Down
2 changes: 1 addition & 1 deletion test/node/message-id-provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert } from 'chai'
import { DefaultMessageIdProvider, UniqueMessageIdProvider } from '../../src'
import { describe, it } from 'node:test'
import { DefaultMessageIdProvider, UniqueMessageIdProvider } from '../../src'

describe('message id provider', () => {
describe('default', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/node/mqtt.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import path from 'path'
import mqtt, { type IClientOptions } from '../../src'
import { describe, it } from 'node:test'
import mqtt, { type IClientOptions } from '../../src'
import 'should'

describe('mqtt', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/node/mqtt_store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Store } from '../../src'
import { describe, it } from 'node:test'
import { Store } from '../../src'
import 'should'

describe('store in lib/connect/index.js (webpack entry point)', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/node/secure_client.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from 'path'
import fs from 'fs'
import { assert } from 'chai'
import { describe, it, after } from 'node:test'
import mqtt from '../../src'
import abstractClientTests from './abstract_client'
import { MqttSecureServer, type MqttServerListener } from './server'
import { assert } from 'chai'
import 'should'
import { describe, it, after } from 'node:test'
import getPorts from './helpers/port_list'

const ports = getPorts(5)
Expand Down
2 changes: 1 addition & 1 deletion test/node/server_helpers_for_client_tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { MqttServer, MqttSecureServer, type MqttServerListener } from './server'
import _debug from 'debug'

import path from 'path'
Expand All @@ -8,6 +7,7 @@ import http from 'http'
import WebSocket from 'ws'
import MQTTConnection from 'mqtt-connection'
import { type Server } from 'net'
import { MqttServer, MqttSecureServer, type MqttServerListener } from './server'

const KEY = path.join(__dirname, 'helpers', 'tls-key.pem')
const CERT = path.join(__dirname, 'helpers', 'tls-cert.pem')
Expand Down
2 changes: 1 addition & 1 deletion test/node/store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe } from 'node:test'
import Store from '../../src/lib/store'
import abstractTest from './abstract_store'
import { describe } from 'node:test'

describe('in-memory store', () => {
abstractTest(function test(done) {
Expand Down
2 changes: 1 addition & 1 deletion test/node/unique_message_id_provider_client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, after } from 'node:test'
import abstractClientTests from './abstract_client'
import serverBuilder from './server_helpers_for_client_tests'
import { UniqueMessageIdProvider, type IClientOptions } from '../../src'
import getPorts from './helpers/port_list'
import { describe, after } from 'node:test'

const ports = getPorts(3)

Expand Down
2 changes: 1 addition & 1 deletion test/node/websocket_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import http from 'http'
import WebSocket from 'ws'
import MQTTConnection from 'mqtt-connection'
import assert from 'assert'
import { after, describe, it } from 'node:test'
import abstractClientTests from './abstract_client'
import getPorts from './helpers/port_list'
import { MqttServerNoWait } from './server'
import mqtt, { type IClientOptions } from '../../src'
import { after, describe, it } from 'node:test'

const ports = getPorts(4)

Expand Down