Skip to content

Commit

Permalink
Fix @typescript-eslint/no-unsafe-call errors
Browse files Browse the repository at this point in the history
  • Loading branch information
LabhanshAgrawal committed Apr 7, 2021
1 parent 9b0a57d commit c347ce8
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 20 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"],
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/restrict-template-expressions": "off"
Expand Down
2 changes: 1 addition & 1 deletion app/config/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {rawConfig} from '../../lib/config';

let defaultConfig: rawConfig;

const _write = (path: string, data: any) => {
const _write = (path: string, data: string) => {
// This method will take text formatted as Unix line endings and transform it
// to text formatted with DOS line endings. We do this because the default
// text editor on Windows (notepad) doesn't Deal with LF files. Still. In 2017.
Expand Down
2 changes: 2 additions & 0 deletions app/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-call */
import {app, dialog, BrowserWindow, App} from 'electron';
import {resolve, basename} from 'path';
import {writeFileSync} from 'fs';
Expand Down
6 changes: 3 additions & 3 deletions app/ui/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function newWindow(
window.uid = classOpts.uid;

const rpc = createRPC(window);
const sessions = new Map();
const sessions = new Map<string, Session>();

const updateBackgroundColor = () => {
const cfg_ = app.plugins.getDecoratedConfig();
Expand Down Expand Up @@ -187,11 +187,11 @@ export function newWindow(
session.resize({cols, rows});
}
});
rpc.on('data', ({uid, data, escaped}) => {
rpc.on('data', ({uid, data, escaped}: {uid: string; data: string; escaped: boolean}) => {
const session = sessions.get(uid);
if (session) {
if (escaped) {
const escapedData = session.shell.endsWith('cmd.exe')
const escapedData = session.shell?.endsWith('cmd.exe')
? `"${data}"` // This is how cmd.exe does it
: `'${data.replace(/'/g, `'\\''`)}'`; // Inside a single-quoted string nothing is interpreted

Expand Down
2 changes: 2 additions & 0 deletions cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ const main = (argv: string[]) => {
const child = spawn(process.execPath, args_, options);

if (flags.verbose) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
child.stdout?.on('data', (data) => console.log(data.toString('utf8')));
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
child.stderr?.on('data', (data) => console.error(data.toString('utf8')));
}
if (flags.verbose) {
Expand Down
4 changes: 1 addition & 3 deletions lib/actions/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ import {
import {setActiveGroup} from './term-groups';
import parseUrl from 'parse-url';
import {HyperState, HyperDispatch, HyperActions} from '../hyper';
import {Stats} from 'fs';

const {stat} = window.require('fs');
import {stat, Stats} from 'fs';

export function openContextMenu(uid: string, selection: any) {
return (dispatch: HyperDispatch, getState: () => HyperState) => {
Expand Down
2 changes: 2 additions & 0 deletions lib/components/split-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class SplitPane extends React.PureComponent<SplitPaneProps, {drag
};

handleDragStart = (ev: any) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
ev.preventDefault();
this.setState({dragging: true});
window.addEventListener('mousemove', this.onDrag);
Expand All @@ -65,6 +66,7 @@ export default class SplitPane extends React.PureComponent<SplitPaneProps, {drag

this.dragTarget = ev.target;
this.dragPanePosition = this.dragTarget.getBoundingClientRect()[this.d2];
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
this.panesSize = ev.target.parentNode.getBoundingClientRect()[this.d1];
this.setupPanes(ev);
};
Expand Down
3 changes: 2 additions & 1 deletion lib/components/term.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,14 @@ export default class Term extends React.PureComponent<TermProps> {

// intercepting paste event for any necessary processing of
// clipboard data, if result is falsy, paste event continues
onWindowPaste = (e: any) => {
onWindowPaste = (e: Event) => {
if (!this.props.isTermActive) return;

const processed = processClipboard();
if (processed) {
e.preventDefault();
e.stopPropagation();
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
(this.term as any)._core.handler(processed);
}
};
Expand Down
5 changes: 3 additions & 2 deletions lib/containers/hyper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Hyper extends React.PureComponent<HyperProps> {

attachKeyListeners() {
if (!this.mousetrap) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
this.mousetrap = new (Mousetrap as any)(window, true);
this.mousetrap.stopCallback = () => {
// All events should be intercepted even if focus is in an input/textarea
Expand All @@ -65,10 +66,10 @@ class Hyper extends React.PureComponent<HyperProps> {
Object.keys(keys).forEach((commandKeys) => {
this.mousetrap.bind(
commandKeys,
(e: any) => {
(e) => {
const command = keys[commandKeys];
// We should tell to xterm that it should ignore this event.
e.catched = true;
(e as any).catched = true;
this.props.execCommand(command, getCommandHandler(command), e);
shouldPreventDefault(command) && e.preventDefault();
},
Expand Down
4 changes: 2 additions & 2 deletions lib/reducers/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,12 @@ const reducer = (state = initial, action: HyperActions) => {

case SESSION_PTY_EXIT:
state_ = state
.updateIn(['openAt'], (times: ImmutableType<any>) => {
.updateIn(['openAt'], (times: ImmutableType<Record<string, number>>) => {
const times_ = times.asMutable();
delete times_[action.uid];
return times_;
})
.updateIn(['activityMarkers'], (markers: ImmutableType<any>) => {
.updateIn(['activityMarkers'], (markers: ImmutableType<Record<string, boolean>>) => {
const markers_ = markers.asMutable();
delete markers_[action.uid];
return markers_;
Expand Down
1 change: 1 addition & 0 deletions lib/utils/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {Middleware} from 'redux';
const effectsMiddleware: Middleware = () => (next) => (action) => {
const ret = next(action);
if (action.effect) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
action.effect();
delete action.effect;
}
Expand Down
22 changes: 15 additions & 7 deletions lib/utils/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {ObjectTypedKeys} from './object';
const plugins = remote.require('./plugins') as typeof import('../../app/plugins');

// `require`d modules
let modules: any;
let modules: hyperPlugin[];

// cache of decorated components
let decorated: Record<string, React.ComponentClass<any>> = {};
Expand Down Expand Up @@ -74,6 +74,7 @@ function exposeDecorated<P extends Record<string, any>>(
onRef = (decorated_: any) => {
if (this.props.onDecorated) {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
this.props.onDecorated(decorated_);
} catch (e) {
notify('Plugin error', `Error occurred. Check Developer Tools for details`, {error: e});
Expand All @@ -93,7 +94,7 @@ function getDecorated<P>(parent: React.ComponentType<P>, name: string): React.Co

modules.forEach((mod: any) => {
const method = 'decorate' + name;
const fn = mod[method];
const fn: Function & {_pluginName: string} = mod[method];

if (fn) {
let class__;
Expand Down Expand Up @@ -190,8 +191,9 @@ const clearModulesCache = () => {
const {path, localPath} = plugins.getBasePaths();

// trigger unload hooks
modules.forEach((mod: any) => {
modules.forEach((mod) => {
if (mod.onRendererUnload) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
mod.onRendererUnload(window);
}
});
Expand Down Expand Up @@ -255,16 +257,16 @@ const loadModules = () => {
const loadedPlugins = plugins.getLoadedPluginVersions().map((plugin: any) => plugin.name);
modules = paths.plugins
.concat(paths.localPlugins)
.filter((plugin: any) => loadedPlugins.indexOf(basename(plugin)) !== -1)
.map((path: any) => {
.filter((plugin) => loadedPlugins.indexOf(basename(plugin)) !== -1)
.map((path) => {
let mod: hyperPlugin;
const pluginName = getPluginName(path);
const pluginVersion = getPluginVersion(path);

// window.require allows us to ensure this doesn't get
// in the way of our build
try {
mod = window.require(path) as any;
mod = window.require(path);
} catch (err) {
notify(
'Plugin load error',
Expand Down Expand Up @@ -358,13 +360,14 @@ const loadModules = () => {
}

if (mod.onRendererWindow) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
mod.onRendererWindow(window);
}
console.log(`Plugin ${pluginName} (${pluginVersion}) loaded.`);

return mod;
})
.filter((mod: any) => Boolean(mod));
.filter((mod): mod is hyperPlugin => Boolean(mod));

const deprecatedPlugins = plugins.getDeprecatedConfig();
Object.keys(deprecatedPlugins).forEach((name) => {
Expand Down Expand Up @@ -398,6 +401,7 @@ function getProps(name: keyof typeof propsDecorators, props: any, ...fnArgs: any
}

try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
ret_ = fn(...fnArgs, props_);
} catch (err) {
notify('Plugin error', `${fn._pluginName}: Error occurred in \`${name}\`. Check Developer Tools for details.`, {
Expand Down Expand Up @@ -454,6 +458,7 @@ export function connect<stateProps, dispatchProps>(
let ret_;

try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
ret_ = fn(state, ret);
} catch (err) {
notify(
Expand All @@ -479,6 +484,7 @@ export function connect<stateProps, dispatchProps>(
let ret_;

try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
ret_ = fn(dispatch, ret);
} catch (err) {
notify(
Expand Down Expand Up @@ -514,12 +520,14 @@ const decorateReducer: {
} = <T extends keyof typeof reducersDecorators>(name: T, fn: any) => {
const reducers = reducersDecorators[name];
return (state: any, action: any) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
let state_ = fn(state, action);

reducers.forEach((pluginReducer: any) => {
let state__;

try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
state__ = pluginReducer(state_, action);
} catch (err) {
notify('Plugin error', `${fn._pluginName}: Error occurred in \`${name}\`. Check Developer Tools for details.`, {
Expand Down
2 changes: 2 additions & 0 deletions test/unit/cli-api.test.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-call */
import test from 'ava';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const proxyquire = require('proxyquire').noCallThru();
Expand Down
2 changes: 2 additions & 0 deletions test/unit/window-utils.test.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-call */
import test from 'ava';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const proxyquire = require('proxyquire').noCallThru();
Expand Down
2 changes: 2 additions & 0 deletions webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const config: webpack.Configuration[] = [
]
},
plugins: [
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
new Copy({
patterns: [
{
Expand Down Expand Up @@ -98,6 +99,7 @@ const config: webpack.Configuration[] = [
NODE_ENV: JSON.stringify(nodeEnv)
}
}),
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
new Copy({
patterns: [
{
Expand Down

0 comments on commit c347ce8

Please sign in to comment.