Migrate to eslint

This commit is contained in:
Chris Svenningsen 2020-09-16 12:31:05 -07:00 committed by Josh Perez
parent 0fe7e30398
commit b4e9c278d3
27 changed files with 104 additions and 71 deletions

View file

@ -1,18 +1,21 @@
export function getSearchResultsProps(attributes: any) {
// @ts-ignore
// Matching Whisper.Message API
// eslint-disable-next-line max-len
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
export function getSearchResultsProps(attributes: any): any {
const model = new window.Whisper.Message(attributes);
return model.getPropsForSearchResult();
}
export function getBubbleProps(attributes: any) {
// @ts-ignore
// Matching Whisper.Message API
// eslint-disable-next-line max-len
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
export function getBubbleProps(attributes: any): any {
const model = new window.Whisper.Message(attributes);
return model.getPropsForBubble();
}
export function showSettings() {
// @ts-ignore
export function showSettings(): void {
window.showSettings();
}

View file

@ -1,9 +1,9 @@
import { ipcRenderer } from 'electron';
export function bounceAppIconStart(isCritical = false) {
export function bounceAppIconStart(isCritical = false): void {
ipcRenderer.send('bounce-app-icon-start', isCritical);
}
export function bounceAppIconStop() {
export function bounceAppIconStop(): void {
ipcRenderer.send('bounce-app-icon-stop');
}

View file

@ -1,3 +1,6 @@
export function trigger(name: string, param1?: any, param2?: any) {
// Matching Whisper.events.trigger API
// eslint-disable-next-line max-len
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
export function trigger(name: string, param1?: any, param2?: any): void {
window.Whisper.events.trigger(name, param1, param2);
}

View file

@ -1,4 +1,4 @@
export function getSocketStatus() {
export function getSocketStatus(): number {
const { getSocketStatus: getMessageReceiverStatus } = window;
return getMessageReceiverStatus();

View file

@ -1,7 +1,10 @@
export function put(key: string, value: any) {
// Matching window.storage.put API
// eslint-disable-next-line max-len
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
export function put(key: string, value: any): void {
window.storage.put(key, value);
}
export async function remove(key: string) {
export async function remove(key: string): Promise<void> {
await window.storage.remove(key);
}

View file

@ -2,7 +2,7 @@ export function sendStickerPackSync(
packId: string,
packKey: string,
installed: boolean
) {
): void {
const { ConversationController, textsecure, log } = window;
const ourNumber = textsecure.storage.user.getNumber();
const { wrap, sendOptions } = ConversationController.prepareForSend(

View file

@ -1,9 +1,9 @@
import { ipcRenderer } from 'electron';
export function startUpdate() {
export function startUpdate(): void {
ipcRenderer.send('start-update');
}
export function ackRender() {
export function ackRender(): void {
ipcRenderer.send('show-update-dialog-ack');
}

View file

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore
import gif from '../../fixtures/giphy-GVNvOUpeYmI7e.gif';
// @ts-ignore

View file

@ -3,7 +3,6 @@ import { assert } from 'chai';
import * as Attachment from '../../types/Attachment';
import * as MIME from '../../types/MIME';
import { SignalService } from '../../protobuf';
// @ts-ignore
import { stringToArrayBuffer } from '../../../js/modules/string_to_array_buffer';
describe('Attachment', () => {

View file

@ -2,7 +2,7 @@ import os from 'os';
import Sinon from 'sinon';
import { assert } from 'chai';
import * as Settings from '../../../ts/types/Settings';
import * as Settings from '../../types/Settings';
describe('Settings', () => {
let sandbox: Sinon.SinonSandbox;

View file

@ -1,10 +1,9 @@
import { assert } from 'chai';
import * as Message from '../../../../ts/types/message/initializeAttachmentMetadata';
import { IncomingMessage } from '../../../../ts/types/Message';
import { SignalService } from '../../../../ts/protobuf';
import * as MIME from '../../../../ts/types/MIME';
// @ts-ignore
import * as Message from '../../../types/message/initializeAttachmentMetadata';
import { IncomingMessage } from '../../../types/Message';
import { SignalService } from '../../../protobuf';
import * as MIME from '../../../types/MIME';
import { stringToArrayBuffer } from '../../../../js/modules/string_to_array_buffer';
describe('Message', () => {

View file

@ -1,3 +1,4 @@
/* eslint-disable no-console */
import {
createWriteStream,
statSync,
@ -6,9 +7,7 @@ import {
import { join, normalize } from 'path';
import { tmpdir } from 'os';
// @ts-ignore
import { createParser } from 'dashdash';
// @ts-ignore
import { createParser, ParserConfiguration } from 'dashdash';
import ProxyAgent from 'proxy-agent';
import { FAILSAFE_SCHEMA, safeLoad } from 'js-yaml';
import { gt } from 'semver';
@ -24,7 +23,6 @@ import { getTempPath } from '../../app/attachments';
import { Dialogs } from '../types/Dialogs';
import { getUserAgent } from '../util/getUserAgent';
// @ts-ignore
import * as packageJson from '../../package.json';
import { getSignatureFileName } from './signature';
import { isPathInside } from '../util/isPathInside';
@ -70,7 +68,7 @@ export async function checkForUpdates(
return null;
}
export function validatePath(basePath: string, targetPath: string) {
export function validatePath(basePath: string, targetPath: string): void {
const normalized = normalize(targetPath);
if (!isPathInside(normalized, basePath)) {
@ -252,9 +250,9 @@ export function getUpdatesFileName(): string {
if (platform === 'darwin') {
return `${prefix}-mac.yml`;
} else {
return `${prefix}.yml`;
}
return `${prefix}.yml`;
}
const hasBeta = /beta/i;
@ -268,29 +266,27 @@ function isVersionNewer(newVersion: string): boolean {
return gt(newVersion, version);
}
export function getVersion(yaml: string): string | undefined {
export function getVersion(yaml: string): string | null {
const info = parseYaml(yaml);
if (info && info.version) {
return info.version;
}
return;
return info && info.version;
}
const validFile = /^[A-Za-z0-9\.\-]+$/;
export function isUpdateFileNameValid(name: string) {
const validFile = /^[A-Za-z0-9.-]+$/;
export function isUpdateFileNameValid(name: string): boolean {
return validFile.test(name);
}
export function getUpdateFileName(yaml: string) {
// Reliant on third party parser that returns any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getUpdateFileName(yaml: string): any {
const info = parseYaml(yaml);
if (!info || !info.path) {
throw new Error('getUpdateFileName: No path present in YAML file');
}
const path = info.path;
const { path } = info;
if (!isUpdateFileNameValid(path)) {
throw new Error(
`getUpdateFileName: Path '${path}' contains invalid characters`
@ -300,6 +296,8 @@ export function getUpdateFileName(yaml: string) {
return path;
}
// Reliant on third party parser that returns any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function parseYaml(yaml: string): any {
return safeLoad(yaml, { schema: FAILSAFE_SCHEMA, json: true });
}
@ -336,7 +334,7 @@ function getBaseTempDir() {
return app ? getTempPath(app.getPath('userData')) : tmpdir();
}
export async function createTempDir() {
export async function createTempDir(): Promise<string> {
const baseTempDir = getBaseTempDir();
const uniqueName = getGuid();
const targetDir = join(baseTempDir, uniqueName);
@ -345,7 +343,7 @@ export async function createTempDir() {
return targetDir;
}
export async function deleteTempDir(targetDir: string) {
export async function deleteTempDir(targetDir: string): Promise<void> {
const pathInfo = statSync(targetDir);
if (!pathInfo.isDirectory()) {
throw new Error(
@ -363,22 +361,21 @@ export async function deleteTempDir(targetDir: string) {
await rimrafPromise(targetDir);
}
export function getPrintableError(error: Error) {
export function getPrintableError(error: Error): Error | string {
return error && error.stack ? error.stack : error;
}
export function getCliOptions<T>(options: any): T {
export function getCliOptions<T>(options: ParserConfiguration['options']): T {
const parser = createParser({ options });
const cliOptions = parser.parse(process.argv);
if (cliOptions.help) {
const help = parser.help().trimRight();
// tslint:disable-next-line:no-console
console.log(help);
process.exit(0);
}
return cliOptions;
return (cliOptions as unknown) as T;
}
export function setUpdateListener(performUpdateCallback: () => void): void {

View file

@ -5,7 +5,7 @@ import {
verifySignature,
} from 'curve25519-n';
export function keyPair() {
export function keyPair(): Record<string, Buffer> {
const privateKey = randomBytes(32);
const { pubKey, privKey } = generateKeyPair(privateKey);

View file

@ -1,9 +1,8 @@
/* eslint-disable no-console */
import { getCliOptions, getPrintableError } from './common';
import { keyPair } from './curve';
import { writeHexToPath } from './signature';
/* tslint:disable:no-console */
const OPTIONS = [
{
names: ['help', 'h'],

View file

@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { join, resolve } from 'path';
import { readdir as readdirCallback } from 'fs';
@ -5,14 +6,10 @@ import pify from 'pify';
import { getCliOptions, getPrintableError } from './common';
import { writeSignature } from './signature';
// @ts-ignore
import * as packageJson from '../../package.json';
const readdir = pify(readdirCallback);
/* tslint:disable:no-console */
const OPTIONS = [
{
names: ['help', 'h'],

View file

@ -12,7 +12,7 @@ export async function start(
getMainWindow: () => BrowserWindow,
locale?: LocaleType,
logger?: LoggerType
) {
): Promise<void> {
const { platform } = process;
if (initialized) {

View file

@ -33,7 +33,7 @@ export async function start(
getMainWindow: () => BrowserWindow,
locale: LocaleType,
logger: LoggerType
) {
): Promise<void> {
logger.info('macos/start: starting checks...');
loggerForQuitHandler = logger;
@ -214,8 +214,6 @@ async function handToAutoUpdate(
autoUpdater.checkForUpdates();
} catch (error) {
reject(error);
return;
}
});
});
@ -296,7 +294,6 @@ function write404(
function getServerUrl(server: Server) {
const address = server.address() as AddressInfo;
// tslint:disable-next-line:no-http-string
return `http://127.0.0.1:${address.port}`;
}
function generateFileUrl(): string {

View file

@ -17,7 +17,7 @@ export async function generateSignature(
updatePackagePath: string,
version: string,
privateKeyPath: string
) {
): Promise<Buffer> {
const privateKey = await loadHexFromPath(privateKeyPath);
const message = await generateMessage(updatePackagePath, version);
@ -52,7 +52,7 @@ export async function writeSignature(
updatePackagePath: string,
version: string,
privateKeyPath: string
) {
): Promise<void> {
const signaturePath = getSignaturePath(updatePackagePath);
const signature = await generateSignature(
updatePackagePath,
@ -79,7 +79,7 @@ export async function _getFileHash(updatePackagePath: string): Promise<Buffer> {
});
}
export function getSignatureFileName(fileName: string) {
export function getSignatureFileName(fileName: string): string {
return `${fileName}.sig`;
}
@ -105,6 +105,9 @@ export async function loadHexFromPath(target: string): Promise<Buffer> {
return hexToBinary(hexString);
}
export async function writeHexToPath(target: string, data: Buffer) {
export async function writeHexToPath(
target: string,
data: Buffer
): Promise<void> {
await writeFile(target, binaryToHex(data));
}

View file

@ -38,7 +38,7 @@ export async function start(
getMainWindow: () => BrowserWindow,
locale: LocaleType,
logger: LoggerType
) {
): Promise<void> {
logger.info('windows/start: starting checks...');
loggerForQuitHandler = logger;
@ -163,7 +163,7 @@ async function install(filePath: string, logger: LoggerType): Promise<void> {
const args = ['--updated'];
const options = {
detached: true,
stdio: 'ignore' as 'ignore', // TypeScript considers this a plain string without help
stdio: 'ignore' as const, // TypeScript considers this a plain string without help
};
try {
@ -209,7 +209,6 @@ async function spawn(
emitter.on('error', reject);
emitter.unref();
// tslint:disable-next-line no-string-based-set-timeout
setTimeout(resolve, 200);
});
}

1
ts/window.d.ts vendored
View file

@ -72,6 +72,7 @@ declare global {
reduxActions: ReduxActions;
restart: () => void;
showWindow: () => void;
showSettings: () => void;
setBadgeCount: (count: number) => void;
storage: {
put: (key: string, value: any) => void;