From e266dd00f22ea03d8744e17d372c26a5edd0f8ee Mon Sep 17 00:00:00 2001 From: Labhansh Agrawal Date: Mon, 29 Mar 2021 01:43:49 +0530 Subject: [PATCH] Fix @typescript-eslint/no-unsafe-return errors --- .eslintrc.json | 1 - app/config.ts | 4 +++- app/config/init.ts | 1 + app/index.ts | 8 ++++++-- app/plugins.ts | 11 +++++++---- app/plugins/install.ts | 6 +++--- app/ui/window.ts | 8 ++++++-- app/utils/colors.ts | 2 ++ cli/api.ts | 2 ++ cli/index.ts | 3 ++- lib/components/term.tsx | 3 ++- lib/utils/effects.ts | 1 + lib/utils/object.ts | 2 ++ lib/utils/plugins.ts | 2 ++ test/unit/cli-api.test.ts | 3 ++- 15 files changed, 41 insertions(+), 16 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 8df0b80a..02af8b96 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -106,7 +106,6 @@ "@typescript-eslint/no-shadow": ["error"], "@typescript-eslint/no-unsafe-assignment": "off", "@typescript-eslint/no-unsafe-member-access": "off", - "@typescript-eslint/no-unsafe-return": "off", "@typescript-eslint/restrict-template-expressions": "off" } } diff --git a/app/config.ts b/app/config.ts index c64f306f..949e1d0e 100644 --- a/app/config.ts +++ b/app/config.ts @@ -44,7 +44,9 @@ const _watch = () => { setTimeout(() => { cfg = _import(); notify('Configuration updated', 'Hyper configuration reloaded!'); - watchers.forEach((fn) => fn()); + watchers.forEach((fn) => { + fn(); + }); checkDeprecatedConfig(); }, 100); }; diff --git a/app/config/init.ts b/app/config/init.ts index 1a80fcf7..39a62b51 100644 --- a/app/config/init.ts +++ b/app/config/init.ts @@ -9,6 +9,7 @@ const _extract = (script?: vm.Script): Record => { if (!module.exports) { throw new Error('Error reading configuration: `module.exports` not set'); } + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return module.exports; }; diff --git a/app/index.ts b/app/index.ts index e60f20f7..94d8fa7b 100644 --- a/app/index.ts +++ b/app/index.ts @@ -205,7 +205,9 @@ app.on('ready', () => app.on('open-file', (event, path) => { const lastWindow = app.getLastFocusedWindow(); - const callback = (win: BrowserWindow) => win.rpc.emit('open file', {path}); + const callback = (win: BrowserWindow) => { + win.rpc.emit('open file', {path}); + }; if (lastWindow) { callback(lastWindow); } else if (!lastWindow && {}.hasOwnProperty.call(app, 'createWindow')) { @@ -219,7 +221,9 @@ app.on('open-file', (event, path) => { app.on('open-url', (event, sshUrl) => { const lastWindow = app.getLastFocusedWindow(); - const callback = (win: BrowserWindow) => win.rpc.emit('open ssh', sshUrl); + const callback = (win: BrowserWindow) => { + win.rpc.emit('open ssh', sshUrl); + }; if (lastWindow) { callback(lastWindow); } else if (!lastWindow && {}.hasOwnProperty.call(app, 'createWindow')) { diff --git a/app/plugins.ts b/app/plugins.ts index 9bd99872..012c83c4 100644 --- a/app/plugins.ts +++ b/app/plugins.ts @@ -1,4 +1,5 @@ -// eslint-disable-next-line eslint-comments/disable-enable-pair +/* eslint-disable eslint-comments/disable-enable-pair */ +/* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-unsafe-call */ import {app, dialog, BrowserWindow, App} from 'electron'; import {resolve, basename} from 'path'; @@ -100,7 +101,7 @@ function updatePlugins({force = false} = {}) { updating = true; syncPackageJSON(); const id_ = id; - install((err: any) => { + install((err) => { updating = false; if (err) { @@ -125,7 +126,9 @@ function updatePlugins({force = false} = {}) { cache.set('hyper.plugin-versions', pluginVersions); // notify watchers - watchers.forEach((fn) => fn(err, {force})); + watchers.forEach((fn) => { + fn(err, {force}); + }); if (force || changed) { if (changed) { @@ -142,7 +145,7 @@ function updatePlugins({force = false} = {}) { function getPluginVersions() { const paths_ = paths.plugins.concat(paths.localPlugins); return paths_.map((path_) => { - let version = null; + let version: string | null = null; try { // eslint-disable-next-line @typescript-eslint/no-var-requires version = require(resolve(path_, 'package.json')).version; diff --git a/app/plugins/install.ts b/app/plugins/install.ts index b0b68162..61fec231 100644 --- a/app/plugins/install.ts +++ b/app/plugins/install.ts @@ -3,9 +3,9 @@ import queue from 'queue'; import ms from 'ms'; import {yarn, plugs} from '../config/paths'; -export const install = (fn: Function) => { +export const install = (fn: (err: string | null) => void) => { const spawnQueue = queue({concurrency: 1}); - function yarnFn(args: string[], cb: Function) { + function yarnFn(args: string[], cb: (err: string | null) => void) { const env = { NODE_ENV: 'production', ELECTRON_RUN_AS_NODE: 'true' @@ -38,7 +38,7 @@ export const install = (fn: Function) => { spawnQueue.start(); } - yarnFn(['install', '--no-emoji', '--no-lockfile', '--cache-folder', plugs.cache], (err: any) => { + yarnFn(['install', '--no-emoji', '--no-lockfile', '--cache-folder', plugs.cache], (err) => { if (err) { return fn(err); } diff --git a/app/ui/window.ts b/app/ui/window.ts index 9ad25ed0..2f001460 100644 --- a/app/ui/window.ts +++ b/app/ui/window.ts @@ -98,7 +98,9 @@ export function newWindow( // If no callback is passed to createWindow, // a new session will be created by default. if (!fn) { - fn = (win: BrowserWindow) => win.rpc.emit('termgroup add req', {}); + fn = (win: BrowserWindow) => { + win.rpc.emit('termgroup add req', {}); + }; } // app.windowCallback is the createWindow callback @@ -219,7 +221,9 @@ export function newWindow( // is maximized on Windows results in unmaximize, without hitting any // app buttons for (const ev of ['maximize', 'unmaximize', 'minimize', 'restore'] as any) { - window.on(ev, () => rpc.emit('windowGeometry change', {})); + window.on(ev, () => { + rpc.emit('windowGeometry change', {}); + }); } window.on('move', () => { const position = window.getPosition(); diff --git a/app/utils/colors.ts b/app/utils/colors.ts index 9ca3e0d1..04a92397 100644 --- a/app/utils/colors.ts +++ b/app/utils/colors.ts @@ -25,10 +25,12 @@ export const getColorMap: { if (!Array.isArray(colors)) { return colors; } + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return colors.reduce((result, color, index) => { if (index < colorList.length) { result[colorList[index]] = color; } + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return result; }, {}); }; diff --git a/cli/api.ts b/cli/api.ts index d9af2533..37c32f20 100644 --- a/cli/api.ts +++ b/cli/api.ts @@ -1,3 +1,5 @@ +// eslint-disable-next-line eslint-comments/disable-enable-pair +/* eslint-disable @typescript-eslint/no-unsafe-return */ import fs from 'fs'; import os from 'os'; import got from 'got'; diff --git a/cli/index.ts b/cli/index.ts index c3c62661..99bbaa86 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -84,8 +84,9 @@ const lsRemote = (pattern?: string) => { const URL = `https://api.npms.io/v2/search?q=${ (pattern && `${pattern}+`) || '' }keywords:hyper-plugin,hyper-theme&size=250`; + type npmResult = {package: {name: string; description: string}}; return got(URL) - .then((response) => JSON.parse(response.body).results as any[]) + .then((response) => JSON.parse(response.body).results as npmResult[]) .then((entries) => entries.map((entry) => entry.package)) .then((entries) => entries.map(({name, description}) => { diff --git a/lib/components/term.tsx b/lib/components/term.tsx index 1feca829..b80f9d0f 100644 --- a/lib/components/term.tsx +++ b/lib/components/term.tsx @@ -148,7 +148,8 @@ export default class Term extends React.PureComponent { } Term.reportRenderer(props.uid, useWebGL ? 'WebGL' : 'Canvas'); - const shallActivateWebLink = (event: Record | undefined) => { + const shallActivateWebLink = (event: Record | undefined): boolean => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return event && (!props.webLinksActivationKey || event[`${props.webLinksActivationKey}Key`]); }; diff --git a/lib/utils/effects.ts b/lib/utils/effects.ts index acfefbb1..4ccdb7b1 100644 --- a/lib/utils/effects.ts +++ b/lib/utils/effects.ts @@ -14,6 +14,7 @@ const effectsMiddleware: Middleware = () => (next) => (action) => { action.effect(); delete action.effect; } + // eslint-disable-next-line @typescript-eslint/no-unsafe-return return ret; }; export default effectsMiddleware; diff --git a/lib/utils/object.ts b/lib/utils/object.ts index 831a451c..50633d8b 100644 --- a/lib/utils/object.ts +++ b/lib/utils/object.ts @@ -1,3 +1,5 @@ +// eslint-disable-next-line eslint-comments/disable-enable-pair +/* eslint-disable @typescript-eslint/no-unsafe-return */ const valsCache = new WeakMap(); export function values(imm: Record) { diff --git a/lib/utils/plugins.ts b/lib/utils/plugins.ts index d44461c2..6e37f786 100644 --- a/lib/utils/plugins.ts +++ b/lib/utils/plugins.ts @@ -1,3 +1,5 @@ +// eslint-disable-next-line eslint-comments/disable-enable-pair +/* eslint-disable @typescript-eslint/no-unsafe-return */ import {remote} from 'electron'; // TODO: Should be updates to new async API https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31 diff --git a/test/unit/cli-api.test.ts b/test/unit/cli-api.test.ts index a9c9b252..8fd5cd26 100644 --- a/test/unit/cli-api.test.ts +++ b/test/unit/cli-api.test.ts @@ -1,4 +1,5 @@ -// eslint-disable-next-line eslint-comments/disable-enable-pair +/* eslint-disable eslint-comments/disable-enable-pair */ +/* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-unsafe-call */ import test from 'ava'; // eslint-disable-next-line @typescript-eslint/no-var-requires