Skip to content

Commit

Permalink
Fix @typescript-eslint/no-unsafe-return errors
Browse files Browse the repository at this point in the history
  • Loading branch information
LabhanshAgrawal committed Apr 7, 2021
1 parent c347ce8 commit e266dd0
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 16 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
1 change: 1 addition & 0 deletions app/config/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const _extract = (script?: vm.Script): Record<string, any> => {
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;
};

Expand Down
8 changes: 6 additions & 2 deletions app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -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')) {
Expand Down
11 changes: 7 additions & 4 deletions app/plugins.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -100,7 +101,7 @@ function updatePlugins({force = false} = {}) {
updating = true;
syncPackageJSON();
const id_ = id;
install((err: any) => {
install((err) => {
updating = false;

if (err) {
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions app/plugins/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 6 additions & 2 deletions app/ui/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions app/utils/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}, {});
};
2 changes: 2 additions & 0 deletions cli/api.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
3 changes: 2 additions & 1 deletion cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}) => {
Expand Down
3 changes: 2 additions & 1 deletion lib/components/term.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ export default class Term extends React.PureComponent<TermProps> {
}
Term.reportRenderer(props.uid, useWebGL ? 'WebGL' : 'Canvas');

const shallActivateWebLink = (event: Record<string, any> | undefined) => {
const shallActivateWebLink = (event: Record<string, any> | undefined): boolean => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return event && (!props.webLinksActivationKey || event[`${props.webLinksActivationKey}Key`]);
};

Expand Down
1 change: 1 addition & 0 deletions lib/utils/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 2 additions & 0 deletions lib/utils/object.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>) {
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/plugins.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 2 additions & 1 deletion test/unit/cli-api.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit e266dd0

Please sign in to comment.