Upgrade eslint (#291)

This commit is contained in:
Philip Peterson 2026-05-06 13:48:06 -07:00 committed by GitHub
parent c8b1770039
commit 90941470fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 16212 additions and 1296 deletions

View file

@ -96,7 +96,14 @@
"@typescript-eslint/ban-types": "off",
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"],
"@typescript-eslint/no-unused-vars": ["error", {"caughtErrorsIgnorePattern": "^_"}],
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/only-throw-error": "off",
"@typescript-eslint/prefer-promise-reject-errors": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/consistent-type-imports": [ "error", { "disallowTypeAnnotations": false } ],

View file

@ -10,7 +10,7 @@ import {cfgPath, cfgDir} from './config/paths';
import notify from './notify';
import {getColorMap} from './utils/colors';
const watchers: Function[] = [];
const watchers: (() => unknown)[] = [];
let cfg: parsedConfig = {} as any;
let _watcher: chokidar.FSWatcher;
@ -69,7 +69,7 @@ const _watch = () => {
});
};
export const subscribe = (fn: Function) => {
export const subscribe = (fn: () => unknown) => {
watchers.push(fn);
return () => {
watchers.splice(watchers.indexOf(fn), 1);

View file

@ -42,7 +42,7 @@ const _importConf = () => {
let userCfg: rawConfig;
try {
userCfg = JSON.parse(readFileSync(cfgPath, 'utf8'));
} catch (err) {
} catch (_err) {
notify("Couldn't parse config file. Using default config instead.");
userCfg = JSON.parse(defaultCfgRaw);
}

View file

@ -43,7 +43,7 @@ if (isDev) {
cfgPath = devCfg;
cfgDir = devDir;
console.log('using config file:', cfgPath);
} catch (err) {
} catch (_err) {
// ignore
}
}

View file

@ -3,7 +3,6 @@ import {cfgPath} from './config/paths';
// Print diagnostic information for a few arguments instead of running Hyper.
if (['--help', '-v', '--version'].includes(process.argv[1])) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const {version} = require('./package');
console.log(`Hyper version ${version}`);
console.log('Hyper does not accept any command line arguments. Please modify the config file instead.');

View file

@ -70,7 +70,7 @@ export const createMenu = (
.map((z) => z.trim())
.join('\n'),
buttons: [],
icon: icon as any
icon: icon
});
};
const menu = [

View file

@ -1,6 +1,6 @@
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-call */
import {exec, execFile} from 'child_process';
import {writeFileSync} from 'fs';
import {resolve, basename} from 'path';
@ -14,7 +14,6 @@ import Config from 'electron-store';
import ms from 'ms';
import ReactDom from 'react-dom';
import type {IpcMainWithCommands} from '../typings/common';
import type {configOptions} from '../typings/config';
import * as config from './config';
@ -42,7 +41,7 @@ function getId(plugins_: any) {
return JSON.stringify(plugins_);
}
const watchers: Function[] = [];
const watchers: (() => unknown)[] = [];
// we listen on configuration updates to trigger
// plugin installation
@ -62,7 +61,6 @@ config.subscribe(() => {
// so plugins can `require` them without needing their own version
// https://github.com/vercel/hyper/issues/619
function patchModuleLoad() {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Module = require('module');
const originalLoad = Module._load;
Module._load = function _load(modulePath: string) {
@ -135,7 +133,7 @@ function updatePlugins({force = false} = {}) {
// notify watchers
watchers.forEach((fn) => {
fn(err, {force});
fn();
});
if (force || changed) {
@ -155,10 +153,9 @@ function getPluginVersions() {
return paths_.map((path_) => {
let version: string | null = null;
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
version = require(resolve(path_, 'package.json')).version;
//eslint-disable-next-line no-empty
} catch (err) {}
} catch (_err) {}
return [basename(path_), version];
});
}
@ -220,7 +217,7 @@ function syncPackageJSON() {
const file = resolve(path, 'package.json');
try {
writeFileSync(file, JSON.stringify(pkg, null, 2));
} catch (err) {
} catch (_err) {
alert(`An error occurred writing to ${file}`);
}
}
@ -252,7 +249,7 @@ function toDependencies(plugins_: {plugins: string[]}) {
return obj;
}
export const subscribe = (fn: Function) => {
export const subscribe = (fn: () => unknown) => {
watchers.push(fn);
return () => {
watchers.splice(watchers.indexOf(fn), 1);
@ -299,9 +296,8 @@ function requirePlugins(): any[] {
// populate the name for internal errors here
mod._name = basename(path_);
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
mod._version = require(resolve(path_, 'package.json')).version;
} catch (err) {
} catch (_err) {
console.warn(`No package.json found in ${path_}`);
}
console.log(`[plugins] loaded: ${mod._name} (${mod._version})`);
@ -469,7 +465,7 @@ export const decorateSessionClass = <T>(Session: T): T => {
export {toDependencies as _toDependencies};
const ipcMain = _ipcMain as IpcMainWithCommands;
const ipcMain = _ipcMain;
ipcMain.handle('child_process.exec', (event, command, options) => {
return promisify(exec)(command, options);

View file

@ -20,9 +20,8 @@ const createNodePtyError = () =>
let spawn: typeof npSpawn;
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
spawn = require('node-pty').spawn;
} catch (err) {
} catch (_err) {
throw createNodePtyError();
}

View file

@ -136,7 +136,7 @@ export function newWindow(
const profile = extraOptionsFiltered.profile || profileName;
const activeSession = extraOptionsFiltered.activeUid ? sessions.get(extraOptionsFiltered.activeUid) : undefined;
let cwd = '';
if (cfg.preserveCWD !== false && activeSession && activeSession.profile === profile) {
if (cfg.preserveCWD !== false && activeSession?.profile === profile) {
const activePID = activeSession.pty?.pid;
if (activePID !== undefined) {
try {
@ -346,12 +346,10 @@ export function newWindow(
// load plugins
load();
const pluginsUnsubscribe = app.plugins.subscribe((err: any) => {
if (!err) {
load();
window.webContents.send('plugins change');
updateBackgroundColor();
}
const pluginsUnsubscribe = app.plugins.subscribe(() => {
load();
window.webContents.send('plugins change');
updateBackgroundColor();
});
// Keep track of focus time of every window, to figure out

View file

@ -20,9 +20,10 @@ type AutoUpdaterEvent =
| 'update-available'
| 'update-not-available';
interface AutoUpdater extends OriginalAutoUpdater {
on(event: AutoUpdaterEvent, listener: Function): this;
removeListener(event: AutoUpdaterEvent, listener: Function): this;
interface AutoUpdater extends Omit<OriginalAutoUpdater, 'on' | 'removeListener'> {
on(event: AutoUpdaterEvent, listener: (...args: any[]) => void): this;
removeListener(event: AutoUpdaterEvent, listener: (...args: any[]) => void): this;
}
const {platform} = process;
@ -60,7 +61,7 @@ const buildFeedUrl = (canary: boolean, currentVersion: string) => {
const isCanary = (updateChannel: string) => updateChannel === 'canary';
async function init() {
autoUpdater.on('error', (err) => {
autoUpdater.on('error', (err: Error) => {
console.error('Error fetching updates', `${err.message} (${err.stack})`);
});

View file

@ -80,7 +80,6 @@ const addBinToUserPath = () => {
}
return new Promise<void>((resolve, reject) => {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Registry = require('native-reg') as typeof NativeReg;
const envKey = Registry.openKey(Registry.HKCU, 'Environment', Registry.Access.ALL_ACCESS)!;
@ -131,7 +130,7 @@ const addBinToUserPath = () => {
const logNotify = (withNotification: boolean, title: string, body: string, details?: {error?: any}) => {
console.log(title, body, details);
withNotification && notify(title, body, details);
if (withNotification) notify(title, body, details);
};
export const installCLI = async (withNotification: boolean) => {

View file

@ -245,9 +245,8 @@ 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) {

View file

@ -15,7 +15,7 @@ export const getRegisteredKeys = async () => {
return Object.keys(keymaps).reduce((result: Record<string, string>, actionName) => {
const commandKeys = keymaps[actionName];
commandKeys.forEach((shortcut) => {
commandKeys.forEach((shortcut: string) => {
result[shortcut] = actionName;
});
return result;

View file

@ -43,7 +43,6 @@ const Hyper = forwardRef<HTMLDivElement, HyperProps>((props, ref) => {
const attachKeyListeners = async () => {
if (!mousetrap.current) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
mousetrap.current = new (Mousetrap as any)(window, true);
mousetrap.current!.stopCallback = () => {
// All events should be intercepted even if focus is in an input/textarea
@ -62,7 +61,7 @@ const Hyper = forwardRef<HTMLDivElement, HyperProps>((props, ref) => {
// We should tell xterm to ignore this event.
(e as any).catched = true;
props.execCommand(command, getCommandHandler(command), e);
shouldPreventDefault(command) && e.preventDefault();
if (shouldPreventDefault(command)) e.preventDefault();
},
'keydown'
);

View file

@ -6,14 +6,15 @@ import terms from '../terms';
// the only side effect we perform from middleware
// is to write to the react term instance directly
// to avoid a performance hit
const writeMiddleware: Middleware<{}, HyperState, Dispatch<HyperActions>> = () => (next) => (action: HyperActions) => {
if (action.type === 'SESSION_PTY_DATA') {
const term = terms[action.uid];
if (term) {
term.term.write(action.data);
const writeMiddleware: Middleware<object, HyperState, Dispatch<HyperActions>> =
() => (next) => (action: HyperActions) => {
if (action.type === 'SESSION_PTY_DATA') {
const term = terms[action.uid];
if (term) {
term.term.write(action.data);
}
}
}
next(action);
};
next(action);
};
export default writeMiddleware;

View file

@ -9,10 +9,9 @@ import type {HyperActions, HyperState} from '../../typings/hyper';
* defer or add to existing side effects at will
* as the result of an action being triggered.
*/
const effectsMiddleware: Middleware<{}, HyperState, Dispatch<HyperActions>> = () => (next) => (action) => {
const effectsMiddleware: Middleware<object, HyperState, Dispatch<HyperActions>> = () => (next) => (action) => {
const ret = next(action);
if (action.effect) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
action.effect();
delete action.effect;
}

View file

@ -1,5 +1,3 @@
import {ipcRenderer as _ipc} from 'electron';
import type {IpcRendererWithCommands} from '../../typings/common';
export const ipcRenderer = _ipc as IpcRendererWithCommands;
export const ipcRenderer = _ipc;

View file

@ -80,7 +80,6 @@ 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});
@ -103,13 +102,13 @@ function getDecorated<P extends Record<string, any>>(
modules.forEach((mod: any) => {
const method = 'decorate' + name;
const fn: Function & {_pluginName: string} = mod[method];
const fn: ((...args: unknown[]) => unknown) & {_pluginName: string} = mod[method];
if (fn) {
let class__;
try {
class__ = fn(class_, {React, PureComponent, Notification, notify});
class__ = fn(class_, {React, PureComponent, Notification, notify}) as React.ComponentClass<P>;
class__.displayName = `${fn._pluginName}(${name})`;
} catch (err) {
notify(
@ -168,10 +167,11 @@ export function decorate<P extends Record<string, any>>(
// patching Module._load
// so plugins can `require` them without needing their own version
// https://github.com/vercel/hyper/issues/619
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Module = require('module') as typeof import('module') & {_load: Function};
const Module = require('module') as typeof import('module') & {_load: (...args: unknown[]) => unknown};
const originalLoad = Module._load;
Module._load = function _load(path: string) {
Module._load = function _load(...args: unknown[]) {
const path = args[0] as string;
// PLEASE NOTE: Code changes here, also need to be changed in
// app/plugins.js
switch (path) {
@ -195,8 +195,7 @@ Module._load = function _load(path: string) {
case 'child_process':
return process.platform === 'darwin' ? IPCChildProcess : ChildProcess;
default:
// eslint-disable-next-line prefer-rest-params
return originalLoad.apply(this, arguments);
return originalLoad.apply(this, args);
}
};
@ -207,7 +206,6 @@ const clearModulesCache = () => {
// trigger unload hooks
modules.forEach((mod) => {
if (mod.onRendererUnload) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
mod.onRendererUnload(window);
}
});
@ -227,7 +225,7 @@ const getPluginVersion = (path: string): string | null => {
let version: string | null = null;
try {
version = window.require(pathModule.resolve(path, 'package.json')).version as string;
} catch (err) {
} catch (_err) {
console.warn(`No package.json found in ${path}`);
}
return version;
@ -381,7 +379,6 @@ const loadModules = () => {
}
if (mod.onRendererWindow) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
mod.onRendererWindow(window);
}
console.log(`[renderer:plugins] loaded: ${pluginName} (${pluginVersion})`);
@ -423,7 +420,6 @@ 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.`, {
@ -466,7 +462,7 @@ export function getTabProps<T extends Assignable<TabProps, T>>(tab: any, parentP
// connects + decorates a class
// plugins can override mapToState, dispatchToProps
// and the class gets decorated (proxied)
export function connect<stateProps extends {}, dispatchProps>(
export function connect<stateProps extends object, dispatchProps>(
stateFn: (state: HyperState) => stateProps,
dispatchFn: (dispatch: HyperDispatch) => dispatchProps,
c: null | undefined,
@ -483,7 +479,6 @@ export function connect<stateProps extends {}, dispatchProps>(
let ret_;
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
ret_ = fn(state, ret);
} catch (err) {
notify(
@ -509,7 +504,6 @@ export function connect<stateProps extends {}, dispatchProps>(
let ret_;
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
ret_ = fn(dispatch, ret);
} catch (err) {
notify(
@ -545,14 +539,12 @@ 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.`, {
@ -586,7 +578,7 @@ export function decorateSessionsReducer(fn: ISessionReducer) {
}
// redux middleware generator
export const middleware: Middleware<{}, HyperState, Dispatch<HyperActions>> = (store) => (next) => (action) => {
export const middleware: Middleware<object, HyperState, Dispatch<HyperActions>> = (store) => (next) => (action) => {
const nextMiddleware = (remaining: Middleware[]) => (action_: any) =>
remaining.length ? remaining[0](store)(nextMiddleware(remaining.slice(1)))(action_) : next(action_);
nextMiddleware(middlewares)(action);

15007
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -56,7 +56,7 @@
"got": "12.4.1",
"json-loader": "0.5.7",
"lodash": "4.17.21",
"mousetrap": "chabou/mousetrap#useCapture",
"mousetrap": "https://github.com/chabou/mousetrap.git#useCapture",
"ms": "2.1.3",
"open": "8.4.2",
"ora": "9.4.0",
@ -106,8 +106,8 @@
"@types/seamless-immutable": "7.1.19",
"@types/styled-jsx": "2.2.9",
"@types/uuid": "10.0.0",
"@typescript-eslint/eslint-plugin": "7.0.0",
"@typescript-eslint/parser": "6.21.0",
"@typescript-eslint/eslint-plugin": "^8.59.2",
"@typescript-eslint/parser": "^8.59.2",
"ava": "https://github.com/quine-global/ava#ad77c3bc92de51a3436c1be1acbb3da594e3251e",
"babel-loader": "10.1.1",
"concurrently": "9.1.0",

View file

@ -1,6 +1,6 @@
/* 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';
import proxyquireLib from 'proxyquire';

View file

@ -1,5 +1,3 @@
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable @typescript-eslint/no-unsafe-call */
import test from 'ava';
import proxyquireLib from 'proxyquire';

2
typings/hyper.d.ts vendored
View file

@ -256,7 +256,7 @@ export type NotificationProps = {
backgroundColor: string;
color?: string;
dismissAfter?: number;
onDismiss: Function;
onDismiss: () => void;
text?: string | null;
userDismissable?: boolean | null;
userDismissColor?: string;

2364
yarn.lock

File diff suppressed because it is too large Load diff