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

@ -31,10 +31,5 @@ webpack.config.ts
# Temporarily ignored during TSLint transition
# JIRA: DESKTOP-304
ts/shims/**
ts/sql/**
ts/storybook/**
ts/styleguide/**
ts/test/**
ts/textsecure/**
ts/updater/**

View File

@ -139,7 +139,7 @@ module.exports = {
rules,
},
{
files: ['**/*.stories.tsx', 'ts/build/**'],
files: ['**/*.stories.tsx', 'ts/build/**', 'ts/test/**'],
rules: {
...rules,
'import/no-extraneous-dependencies': 'off',

View File

@ -444,6 +444,32 @@ Signal Desktop makes use of the following open source projects.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
## dashdash
# This is the MIT license
Copyright (c) 2013 Trent Mick. All rights reserved.
Copyright (c) 2013 Joyent Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
## draft-js
BSD License

View File

@ -0,0 +1 @@
export function stringToArrayBuffer(string: string): ArrayBuffer;

View File

@ -76,6 +76,7 @@
"config": "1.28.1",
"copy-text-to-clipboard": "2.1.0",
"curve25519-n": "https://github.com/scottnonnenberg-signal/node-curve25519.git#3e94f60bc54b2426476520d8d1a0aa835c25f5cc",
"dashdash": "1.14.1",
"draft-js": "0.10.5",
"emoji-datasource": "5.0.1",
"emoji-datasource-apple": "5.0.1",
@ -163,6 +164,7 @@
"@types/chai": "4.1.2",
"@types/classnames": "2.2.3",
"@types/config": "0.0.34",
"@types/dashdash": "1.14.0",
"@types/draft-js": "0.10.32",
"@types/filesize": "3.6.0",
"@types/fs-extra": "5.0.5",
@ -213,7 +215,6 @@
"core-js": "2.4.1",
"cross-env": "5.2.0",
"css-loader": "3.2.0",
"dashdash": "1.14.1",
"electron": "8.3.4",
"electron-builder": "22.3.6",
"electron-mocha": "8.1.1",

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;

View File

@ -190,8 +190,12 @@
"ts/protobuf/**",
"ts/scripts/**",
"ts/services/**",
"ts/shims/**",
"ts/state/**",
"ts/storybook/**",
"ts/test/**",
"ts/types/**",
"ts/updater/**",
"ts/util/**"
]
}

View File

@ -2124,6 +2124,11 @@
dependencies:
"@types/node" "*"
"@types/dashdash@1.14.0":
version "1.14.0"
resolved "https://registry.yarnpkg.com/@types/dashdash/-/dashdash-1.14.0.tgz#bfa457c2688497cf0e6695dbd522c67a9232833f"
integrity sha512-dBnfu9H6TVawx85FGmVEs5lYFXNwUVxn3Nqu5FHhCAi4aPvZR35W4FEMK3ljlpM2vHPGgEnCZGARF59/QGTNJw==
"@types/debug@^4.1.4", "@types/debug@^4.1.5":
version "4.1.5"
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.5.tgz#b14efa8852b7768d898906613c23f688713e02cd"