Skip to content

Commit 18ac07d

Browse files
committed
lint: 0 warnings left
1 parent 61a0ff3 commit 18ac07d

32 files changed

+668
-1022
lines changed

.eslintignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ coverage
66
src/WABinary/index.ts
77
WAProto
88
WASignalGroup
9-
Example/test.ts
9+
Example/Example.ts
1010
docs

.eslintrc.json

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "@adiwajshing",
2+
"extends": "@whiskeysockets",
33
"parserOptions": {
44
"sourceType": "module",
55
"project": "./tsconfig.json"
@@ -21,13 +21,7 @@
2121
"@typescript-eslint/no-unnecessary-type-assertion": [
2222
"warn"
2323
],
24-
"no-restricted-syntax": [
25-
"warn",
26-
{
27-
"selector": "TSEnumDeclaration",
28-
"message": "Don't declare enums, use literals instead"
29-
}
30-
],
24+
"no-restricted-syntax": "off",
3125
"keyword-spacing": [
3226
"warn"
3327
]

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
3535
"example": "node --inspect -r ts-node/register Example/example.ts",
3636
"gen:protobuf": "sh WAProto/GenerateStatics.sh",
37-
"lint": "eslint src --ext .js,.ts,.jsx,.tsx",
38-
"lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
37+
"lint": "eslint src --ext .js,.ts",
38+
"lint:fix": "yarn lint --fix",
3939
"prepack": "tsc",
4040
"prepare": "tsc",
4141
"release": "release-it",
@@ -44,6 +44,7 @@
4444
"dependencies": {
4545
"@adiwajshing/keyed-db": "^0.2.4",
4646
"@hapi/boom": "^9.1.3",
47+
"@whiskeysockets/eslint-config": "github:whiskeysockets/eslint-config",
4748
"async-lock": "^1.4.1",
4849
"audio-decode": "^2.1.3",
4950
"axios": "^1.6.0",
@@ -60,7 +61,6 @@
6061
"ws": "^8.13.0"
6162
},
6263
"devDependencies": {
63-
"@adiwajshing/eslint-config": "github:adiwajshing/eslint-config",
6464
"@types/got": "^9.6.11",
6565
"@types/jest": "^27.5.1",
6666
"@types/node": "^16.0.0",

src/Defaults/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ export const KEY_BUNDLE_TYPE = Buffer.from([5])
2020
export const NOISE_WA_HEADER = Buffer.from(
2121
[ 87, 65, 6, DICT_VERSION ]
2222
) // last is "DICT_VERSION"
23-
export const PROTOCOL_VERSION = [5, 2]
24-
export const MOBILE_NOISE_HEADER = Buffer.concat([Buffer.from('WA'), Buffer.from(PROTOCOL_VERSION)])
2523
/** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
2624
export const URL_REGEX = /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/
2725

src/Socket/chats.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -999,15 +999,13 @@ export const makeChatsSocket = (config: SocketConfig) => {
999999
)
10001000
}
10011001

1002-
if(receivedPendingNotifications) {
1003-
// if we don't have the app state key
1002+
if(receivedPendingNotifications && // if we don't have the app state key
10041003
// we keep buffering events until we finally have
10051004
// the key and can sync the messages
10061005
// todo scrutinize
1007-
if(!authState.creds?.myAppStateKeyId) {
1008-
ev.buffer()
1009-
needToFlushWithAppStateSync = true
1010-
}
1006+
!authState.creds?.myAppStateKeyId) {
1007+
ev.buffer()
1008+
needToFlushWithAppStateSync = true
10111009
}
10121010
})
10131011

src/Socket/messages-recv.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
342342

343343
break
344344
case 'membership_approval_mode':
345-
const approvalMode: any = getBinaryNodeChild(child, 'group_join')
345+
const approvalMode = getBinaryNodeChild(child, 'group_join')
346346
if(approvalMode) {
347347
msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE
348348
msg.messageStubParameters = [ approvalMode.attrs.state ]
@@ -574,8 +574,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
574574

575575
logger.debug({ participant, sendToAll }, 'forced new session for retry recp')
576576

577-
for(let i = 0; i < msgs.length;i++) {
578-
const msg = msgs[i]
577+
for(const [i, msg] of msgs.entries()) {
579578
if(msg) {
580579
updateSendMessageAgainCount(ids[i], participant)
581580
const msgRelayOpts: MessageRelayOptions = { messageId: ids[i] }
@@ -761,10 +760,8 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
761760
msg.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, response]
762761
}
763762

764-
if(msg.message?.protocolMessage?.type === proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER) {
765-
if(node.attrs.sender_pn) {
766-
ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn })
767-
}
763+
if(msg.message?.protocolMessage?.type === proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER && node.attrs.sender_pn) {
764+
ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn })
768765
}
769766

770767
try {
@@ -851,7 +848,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
851848
return sendPeerDataOperationMessage(pdoMessage)
852849
}
853850

854-
const requestPlaceholderResend = async(messageKey: WAMessageKey): Promise<'RESOLVED'| string | undefined> => {
851+
const requestPlaceholderResend = async(messageKey: WAMessageKey): Promise<string | undefined> => {
855852
if(!authState.creds.me?.id) {
856853
throw new Boom('Not authenticated')
857854
}

src/Socket/messages-send.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
280280
}
281281
}
282282

283-
const meJid = jidNormalizedUser(authState.creds.me.id)!
283+
const meJid = jidNormalizedUser(authState.creds.me.id)
284284

285285
const msgId = await relayMessage(meJid, protocolMessage, {
286286
additionalAttributes: {

src/Socket/socket.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const makeSocket = (config: SocketConfig) => {
7676
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'))
7777
}
7878

79-
const ws = config.socket ? config.socket : new WebSocketClient(url, config)
79+
const ws = new WebSocketClient(url, config)
8080

8181
ws.connect()
8282

@@ -327,11 +327,12 @@ export const makeSocket = (config: SocketConfig) => {
327327
const l1 = frame.attrs || {}
328328
const l2 = Array.isArray(frame.content) ? frame.content[0]?.tag : ''
329329

330-
Object.keys(l1).forEach(key => {
330+
for(const key of Object.keys(l1)) {
331331
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered
332332
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered
333333
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered
334-
})
334+
}
335+
335336
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered
336337
anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered
337338

src/Store/make-in-memory-store.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,14 @@ export default (config: BaileysInMemoryStoreConfig) => {
225225
const list = assertMessageList(jid)
226226
list.upsert(msg, 'append')
227227

228-
if(type === 'notify') {
229-
if(!chats.get(jid)) {
230-
ev.emit('chats.upsert', [
231-
{
232-
id: jid,
233-
conversationTimestamp: toNumber(msg.messageTimestamp),
234-
unreadCount: 1
235-
}
236-
])
237-
}
228+
if(type === 'notify' && !chats.get(jid)) {
229+
ev.emit('chats.upsert', [
230+
{
231+
id: jid,
232+
conversationTimestamp: toNumber(msg.messageTimestamp),
233+
unreadCount: 1
234+
}
235+
])
238236
}
239237
}
240238

src/Store/make-ordered-dictionary.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ function makeOrderedDictionary<T>(idGetter: (item: T) => string) {
6161
},
6262
clear: () => {
6363
array.splice(0, array.length)
64-
Object.keys(dict).forEach(key => {
64+
for(const key of Object.keys(dict)) {
6565
delete dict[key]
66-
})
66+
}
6767
},
6868
filter: (contain: (item: T) => boolean) => {
6969
let i = 0

src/Types/Contact.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export interface Contact {
1515
* null => if the profile picture has not been set (default profile picture)
1616
* any other string => url of the profile picture
1717
*/
18-
imgUrl?: string | null | 'changed'
18+
imgUrl?: string | null
1919
status?: string
2020
}

src/Types/Message.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export type WAGenericMediaMessage = proto.Message.IVideoMessage | proto.Message.
2323
export import WAMessageStubType = proto.WebMessageInfo.StubType
2424
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
2525
export import WAMessageStatus = proto.WebMessageInfo.Status
26-
export type WAMediaUpload = Buffer | { url: URL | string } | { stream: Readable }
26+
export type WAMediaPayloadURL = { url: URL | string }
27+
export type WAMediaPayloadStream = { stream: Readable }
28+
export type WAMediaUpload = Buffer | WAMediaPayloadStream | WAMediaPayloadURL
2729
/** Set of message types that are supported by the library */
2830
export type MessageType = keyof proto.Message
2931

src/Types/Socket.ts

-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,4 @@ export type SocketConfig = {
125125
cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>
126126

127127
makeSignalRepository: (auth: SignalAuthState) => SignalRepository
128-
129-
/** Socket passthrough */
130-
socket?: any
131128
}

src/Utils/auth-utils.ts

+2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export const addTransactionCapability = (
160160
let tries = maxCommitRetries
161161
while(tries) {
162162
tries -= 1
163+
//eslint-disable-next-line max-depth
163164
try {
164165
await state.set(mutations)
165166
logger.trace({ dbQueriesInTransaction }, 'committed transaction')
@@ -207,6 +208,7 @@ export const initAuthCreds = (): AuthenticationCreds => {
207208
accountSettings: {
208209
unarchiveChats: false
209210
},
211+
registered: false,
210212
pairingCode: undefined,
211213
lastPropHash: undefined,
212214
routingInfo: undefined,

src/Utils/baileys-event-stream.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const captureEventStream = (ev: BaileysEventEmitter, filename: string) =>
3535
* @param filename filename containing event data
3636
* @param delayIntervalMs delay between each event emit
3737
*/
38-
export const readAndEmitEventStream = (filename: string, delayIntervalMs: number = 0) => {
38+
export const readAndEmitEventStream = (filename: string, delayIntervalMs = 0) => {
3939
const ev = new EventEmitter() as BaileysEventEmitter
4040

4141
const fireEvents = async() => {

0 commit comments

Comments
 (0)