Migrate textsecure to eslint

Co-authored-by: Chris Svenningsen <chris@carbonfive.com>
This commit is contained in:
Sidney Keese 2020-09-24 14:53:21 -07:00 committed by Josh Perez
parent b5df9b4067
commit 7b6d8f55d6
24 changed files with 706 additions and 299 deletions

View file

@ -1,4 +1,11 @@
import { w3cwebsocket as WebSocket } from 'websocket';
/* eslint-disable no-param-reassign */
/* eslint-disable more/no-then */
/* eslint-disable no-bitwise */
/* eslint-disable guard-for-in */
/* eslint-disable no-restricted-syntax */
/* eslint-disable no-nested-ternary */
/* eslint-disable @typescript-eslint/no-explicit-any */
import fetch, { Response } from 'node-fetch';
import ProxyAgent from 'proxy-agent';
import { Agent } from 'https';
@ -11,12 +18,14 @@ import {
zipObject,
} from 'lodash';
import { createVerify } from 'crypto';
import { Long } from '../window.d';
import { pki } from 'node-forge';
import is from '@sindresorhus/is';
import PQueue from 'p-queue';
import { v4 as getGuid } from 'uuid';
import { Long } from '../window.d';
import { getUserAgent } from '../util/getUserAgent';
import { isPackIdValid, redactPackId } from '../../js/modules/stickers';
import MessageSender from './SendMessage';
import {
arrayBufferToBase64,
base64ToArrayBuffer,
@ -30,11 +39,6 @@ import {
getRandomValue,
splitUuids,
} from '../Crypto';
import { getUserAgent } from '../util/getUserAgent';
import PQueue from 'p-queue';
import { v4 as getGuid } from 'uuid';
import {
AvatarUploadAttributesClass,
GroupChangeClass,
@ -44,6 +48,9 @@ import {
StorageServiceCredentials,
} from '../textsecure.d';
import { WebSocket } from './WebSocket';
import MessageSender from './SendMessage';
type SgxConstantsType = {
SGX_FLAGS_INITTED: Long;
SGX_FLAGS_DEBUG: Long;
@ -81,8 +88,6 @@ function getSgxConstants() {
return sgxConstantCache;
}
// tslint:disable no-bitwise
function _btoa(str: any) {
let buffer;
@ -142,24 +147,27 @@ function _getStringable(thing: any) {
function _ensureStringed(thing: any): any {
if (_getStringable(thing)) {
return _getString(thing);
} else if (thing instanceof Array) {
}
if (thing instanceof Array) {
const res = [];
for (let i = 0; i < thing.length; i += 1) {
res[i] = _ensureStringed(thing[i]);
}
return res;
} else if (thing === Object(thing)) {
}
if (thing === Object(thing)) {
const res: any = {};
// tslint:disable-next-line forin no-for-in
for (const key in thing) {
res[key] = _ensureStringed(thing[key]);
}
return res;
} else if (thing === null) {
}
if (thing === null) {
return null;
} else if (thing === undefined) {
}
if (thing === undefined) {
return undefined;
}
throw new Error(`unsure of how to jsonify object of type ${typeof thing}`);
@ -185,7 +193,6 @@ function _base64ToBytes(sBase64: string, nBlocksSize?: number) {
for (let nInIdx = 0; nInIdx < nInLen; nInIdx += 1) {
nMod4 = nInIdx & 3;
// tslint:disable-next-line binary-expression-operand-order
nUint24 |= _b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << (18 - 6 * nMod4);
if (nMod4 === 3 || nInLen - nInIdx === 1) {
for (
@ -219,7 +226,6 @@ function _createRedactor(
function _validateResponse(response: any, schema: any) {
try {
// tslint:disable-next-line forin no-for-in
for (const i in schema) {
switch (schema[i]) {
case 'object':
@ -327,12 +333,10 @@ type ArrayBufferWithDetailsType = {
response: Response;
};
// tslint:disable-next-line max-func-body-length
async function _promiseAjax(
providedUrl: string | null,
options: PromiseAjaxOptionsType
): Promise<any> {
// tslint:disable-next-line max-func-body-length
return new Promise((resolve, reject) => {
const url = providedUrl || `${options.host}/${options.path}`;
@ -376,8 +380,6 @@ async function _promiseAjax(
} as HeaderListType,
redirect: options.redirect,
agent,
// We patched node-fetch to add the ca param; its type definitions don't have it
// @ts-ignore
ca: options.certificateAuthority,
timeout,
};
@ -414,7 +416,6 @@ async function _promiseAjax(
}
fetch(url, fetchOptions)
// tslint:disable-next-line max-func-body-length
.then(async response => {
// Build expired!
if (response.status === 499) {
@ -439,16 +440,13 @@ async function _promiseAjax(
resultPromise = response.textConverted();
}
// tslint:disable-next-line max-func-body-length
return resultPromise.then(result => {
if (
options.responseType === 'arraybuffer' ||
options.responseType === 'arraybufferwithdetails'
) {
// tslint:disable-next-line no-parameter-reassignment
result = result.buffer.slice(
result.byteOffset,
// tslint:disable-next-line: restrict-plus-operands
result.byteOffset + result.byteLength
);
}
@ -539,8 +537,6 @@ async function _promiseAjax(
options.stack
)
);
return;
});
})
.catch(e => {
@ -757,7 +753,7 @@ export type WebAPIType = {
) => Promise<any>;
getProvisioningSocket: () => WebSocket;
getSenderCertificate: (withUuid?: boolean) => Promise<any>;
getSticker: (packId: string, stickerId: string) => Promise<any>;
getSticker: (packId: string, stickerId: number) => Promise<any>;
getStickerPackManifest: (packId: string) => Promise<StickerPackManifestType>;
getStorageCredentials: MessageSender['getStorageCredentials'];
getStorageManifest: MessageSender['getStorageManifest'];
@ -852,7 +848,6 @@ export type ProxiedRequestOptionsType = {
};
// We first set up the data that won't change during this session of the app
// tslint:disable-next-line max-func-body-length
export function initialize({
url,
storageUrl,
@ -911,7 +906,6 @@ export function initialize({
// Then we connect to the server with user-specific information. This is the only API
// exposed to the browser context, ensuring that it can't connect to arbitrary
// locations.
// tslint:disable-next-line max-func-body-length
function connect({
username: initialUsername,
password: initialPassword,
@ -1263,7 +1257,7 @@ export function initialize({
'gv2-3': true,
},
fetchesMessages: true,
name: deviceName ? deviceName : undefined,
name: deviceName || undefined,
registrationId,
supportsSms: false,
unidentifiedAccessKey: accessKey
@ -1551,7 +1545,7 @@ export function initialize({
);
}
async function getSticker(packId: string, stickerId: string) {
async function getSticker(packId: string, stickerId: number) {
if (!isPackIdValid(packId)) {
throw new Error('getSticker: pack ID was invalid');
}
@ -2031,7 +2025,6 @@ export function initialize({
window.log.info('opening message socket', url);
const fixedScheme = url
.replace('https://', 'wss://')
// tslint:disable-next-line no-http-string
.replace('http://', 'ws://');
const login = encodeURIComponent(username);
const pass = encodeURIComponent(password);
@ -2047,7 +2040,6 @@ export function initialize({
window.log.info('opening provisioning socket', url);
const fixedScheme = url
.replace('https://', 'wss://')
// tslint:disable-next-line no-http-string
.replace('http://', 'ws://');
const clientVersion = encodeURIComponent(version);
@ -2247,7 +2239,6 @@ export function initialize({
}
}
// tslint:disable-next-line max-func-body-length
async function putRemoteAttestation(auth: {
username: string;
password: string;