chore: add stronger lint rules

This commit is contained in:
Adhiraj Singh
2022-08-18 10:37:40 +05:30
parent 8d6e00eab6
commit c5917364ba
10 changed files with 101 additions and 103 deletions

View File

@@ -81,7 +81,6 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
const generateKeysForAuth = async(ref: string, ttl?: number) => {
curveKeys = Curve.generateKeyPair()
const publicKey = Buffer.from(curveKeys.public).toString('base64')
let qrGens = 0
const qrLoop = ttl => {
const qr = [ref, publicKey, authInfo.clientID].join(',')
@@ -111,7 +110,6 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
}
}
qrGens += 1
qrLoop(ttl)
}, ttl || 20_000) // default is 20s, on the off-chance ttl is not present
}

View File

@@ -103,7 +103,7 @@ const makeGroupsSocket = (config: LegacySocketConfig) => {
return meta
}
socketEvents.on('CB:Chat,cmd:action', (json: BinaryNode) => {
socketEvents.on('CB:Chat,cmd:action', () => {
/*const data = json[1].data
if (data) {
const emitGroupParticipantsUpdate = (action: WAParticipantAction) => this.emitParticipantsUpdate

View File

@@ -266,9 +266,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
attrs: {
v: '2',
type,
// do not send extra params
// causes retries to fail for some reason now
// ...extraAttrs || {}
...extraAttrs || {}
},
content: ciphertext
}]
@@ -302,7 +300,6 @@ export const makeMessagesSocket = (config: SocketConfig) => {
const binaryNodeContent: BinaryNode[] = []
const devices: JidWithDevice[] = []
const extraParticipantNodeAttrs: BinaryNode['attrs'] = { }
if(participant) {
// when the retry request is not for a group
// only send to the specific device that asked for a retry
@@ -311,8 +308,6 @@ export const makeMessagesSocket = (config: SocketConfig) => {
additionalAttributes = { ...additionalAttributes, device_fanout: 'false' }
}
extraParticipantNodeAttrs.count = participant.count.toString()
const { user, device } = jidDecode(participant.jid)!
devices.push({ user, device })
}
@@ -376,7 +371,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
await assertSessions(senderKeyJids, false)
const result = await createParticipantNodes(senderKeyJids, encSenderKeyMsg, extraParticipantNodeAttrs)
const result = await createParticipantNodes(senderKeyJids, encSenderKeyMsg)
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity
participants.push(...result.nodes)
@@ -428,8 +423,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 },
{ nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }
] = await Promise.all([
createParticipantNodes(meJids, encodedMeMsg, extraParticipantNodeAttrs),
createParticipantNodes(otherJids, encodedMsg, extraParticipantNodeAttrs)
createParticipantNodes(meJids, encodedMeMsg),
createParticipantNodes(otherJids, encodedMsg)
])
participants.push(...meNodes)
participants.push(...otherNodes)

View File

@@ -16,7 +16,9 @@ export type WATextMessage = proto.Message.IExtendedTextMessage
export type WAContextInfo = proto.IContextInfo
export type WALocationMessage = proto.Message.ILocationMessage
export type WAGenericMediaMessage = proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage
// eslint-disable-next-line no-unused-vars
export import WAMessageStubType = proto.WebMessageInfo.StubType
// eslint-disable-next-line no-unused-vars
export import WAMessageStatus = proto.WebMessageInfo.Status
export type WAMediaUpload = Buffer | { url: URL | string } | { stream: Readable }
/** Set of message types that are supported by the library */

View File

@@ -206,7 +206,7 @@ export const printQRIfNecessaryListener = (ev: CommonBaileysEventEmitter<any>, l
ev.on('connection.update', async({ qr }) => {
if(qr) {
const QR = await import('qrcode-terminal')
.catch(err => {
.catch(() => {
logger.error('QR code terminal not added as dependency')
})
QR?.generate(qr, { small: true })

View File

@@ -561,8 +561,6 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger }: C
}
}
const GCM_AUTH_TAG_LENGTH: number | undefined = 128 >> 3
const getMediaRetryKey = (mediaKey: Buffer | Uint8Array) => {
return hkdf(mediaKey, 32, { info: 'WhatsApp Media Retry Notification' })
}

View File

@@ -101,7 +101,7 @@ export const signalStorage = ({ creds, keys }: SignalAuthState) => ({
}
},
removePreKey: (id: number) => keys.set({ 'pre-key': { [id]: null } }),
loadSignedPreKey: (keyId: number) => {
loadSignedPreKey: () => {
const key = creds.signedPreKey
return {
privKey: Buffer.from(key.keyPair.private),

View File

@@ -170,7 +170,6 @@ export const encodeBinaryNode = (
}
const writeString = (str: string) => {
// console.log('before write of ', str, ' ', Buffer.from(buffer).toString('hex'))
const tokenIndex = TOKEN_MAP[str]
if(tokenIndex) {
if(typeof tokenIndex.dict === 'number') {
@@ -207,7 +206,7 @@ export const encodeBinaryNode = (
typeof attrs[k] !== 'undefined' && attrs[k] !== null
))
writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' && content !== null ? 1 : 0))
writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0))
writeString(tag)
for(const key of validAttributes) {
@@ -225,11 +224,9 @@ export const encodeBinaryNode = (
} else if(Array.isArray(content)) {
writeListStart(content.length)
for(const item of content) {
if(item) {
encodeBinaryNode(item, opts, buffer)
}
encodeBinaryNode(item, opts, buffer)
}
} else if(typeof content === 'undefined' || content === null) {
} else if(typeof content === 'undefined') {
// do nothing
} else {
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`)

View File

@@ -45,11 +45,11 @@ export const areJidsSameUser = (jid1: string | undefined, jid2: string | undefin
jidDecode(jid1)?.user === jidDecode(jid2)?.user
)
/** is the jid a user */
export const isJidUser = (jid: string) => (jid?.endsWith('@s.whatsapp.net'))
export const isJidUser = (jid: string | undefined) => (jid?.endsWith('@s.whatsapp.net'))
/** is the jid a broadcast */
export const isJidBroadcast = (jid: string) => (jid?.endsWith('@broadcast'))
export const isJidBroadcast = (jid: string | undefined) => (jid?.endsWith('@broadcast'))
/** is the jid a group */
export const isJidGroup = (jid: string) => (jid?.endsWith('@g.us'))
export const isJidGroup = (jid: string | undefined) => (jid?.endsWith('@g.us'))
/** is the jid the status broadcast */
export const isJidStatusBroadcast = (jid: string) => jid === 'status@broadcast'