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

@@ -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'