Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
irahopkinson committed Mar 13, 2023
1 parent 4e788ff commit fbb3ba9
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 86 deletions.
14 changes: 12 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ module.exports = {

// #region Our rules

// This is already a Typescript rule, so we don't need it to be reported twice
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': 'error',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'comma-dangle': ['error', 'always-multiline'],
indent: 'off',
'jsx-a11y/label-has-associated-control': [
Expand All @@ -35,13 +41,17 @@ module.exports = {

// #endregion
},
globals: {
globalThis: 'readonly',
},
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
project: './tsconfig.json',
tsconfigRootDir: __dirname,
createDefaultProgram: true,
},
plugins: ['@typescript-eslint'],
settings: {
'import/resolver': {
// See https://github.com/benmosher/eslint-plugin-import/issues/1396#issuecomment-575727774 for line below
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@
"@types/terser-webpack-plugin": "^5.0.4",
"@types/webpack-bundle-analyzer": "^4.6.0",
"@types/ws": "^8.5.4",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.54.1",
"browserslist-config-erb": "^0.0.3",
"chalk": "^4.1.2",
"concurrently": "^7.6.0",
Expand Down
24 changes: 12 additions & 12 deletions src/extension-host/services/ExtensionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ import Module from 'module';
import papi from '@shared/services/papi';
import logger from '@shared/util/logger';

/** Whether this service has finished setting up */
let isInitialized = false;

/** Promise that resolves when this service is finished initializing */
let initializePromise: Promise<void> | undefined;

/** Extensions that are available to us */
let availableExtensions: ExtensionInfo[];

/** Map of extension name to extension that is currently active and running */
const activeExtensions = new Map<string, ActiveExtension>();

/** Information about an extension provided by the extension developer */
type ExtensionManifest = Readonly<{
name: string;
Expand All @@ -48,6 +36,18 @@ type ActiveExtension = {
deactivator: UnsubscriberAsync;
};

/** Whether this service has finished setting up */
let isInitialized = false;

/** Promise that resolves when this service is finished initializing */
let initializePromise: Promise<void> | undefined;

/** Extensions that are available to us */
let availableExtensions: ExtensionInfo[];

/** Map of extension name to extension that is currently active and running */
const activeExtensions = new Map<string, ActiveExtension>();

/** Get information for all the extensions present */
const getExtensions = async (): Promise<ExtensionInfo[]> => {
const extensionFolders = (await readDir('resources://extensions'))[
Expand Down
13 changes: 9 additions & 4 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
* `./src/main.js` using webpack. This gives us some performance wins.
*/
import path from 'path';
import { app, BrowserWindow, shell, ipcMain } from 'electron';
import {
app,
BrowserWindow,
shell,
ipcMain,
IpcMainInvokeEvent,
} from 'electron';
import { autoUpdater } from 'electron-updater';
import windowStateKeeper from 'electron-window-state';
import '@main/globalThis';
Expand Down Expand Up @@ -154,7 +160,7 @@ app.on('will-quit', () => {
/** Map from ipc channel to handler function. Use with ipcRenderer.invoke */
const ipcHandlers: {
[ipcChannel: string]: (
event: Electron.IpcMainInvokeEvent,
event: IpcMainInvokeEvent,
// We don't know the exact parameter types since ipc handlers can be anything
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...args: any[]
Expand Down Expand Up @@ -215,8 +221,7 @@ const commandHandlers: { [commandName: string]: CommandHandler } = {
Object.entries(ipcHandlers).forEach(([ipcHandle, handler]) => {
NetworkService.registerRequestHandler(
ipcHandle,
async (...args: unknown[]) =>
handler({} as Electron.IpcMainInvokeEvent, ...args),
async (...args: unknown[]) => handler({} as IpcMainInvokeEvent, ...args),
);
});
Object.entries(commandHandlers).forEach(([commandName, handler]) => {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/docking/ErrorTab.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TabInfo } from '@shared/data/WebviewTypes';

const ErrorTab = ({ errorMessage }: { errorMessage: string }) => {
function ErrorTab({ errorMessage }: { errorMessage: string }) {
return (
<>
<div>
Expand All @@ -10,7 +10,7 @@ const ErrorTab = ({ errorMessage }: { errorMessage: string }) => {
<div>Message: {errorMessage}</div>
</>
);
};
}

/**
* Creates a new error message tab with the specified error message
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/docking/ParanextDockLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const groups: {
},
};

const ParanextDockLayout = () => {
function ParanextDockLayout() {
return (
<DockLayout
groups={groups}
Expand All @@ -86,6 +86,6 @@ const ParanextDockLayout = () => {
style={{ position: 'absolute', left: 3, top: 3, right: 3, bottom: 3 }}
/>
);
};
}

export default ParanextDockLayout;
4 changes: 2 additions & 2 deletions src/renderer/components/docking/ParanextPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import './ParanextPanel.css';
* Used for possible styling on every panel in Paranext
* @param children The children of the panel (usually supplied from an extension)
*/
const ParanextPanel = ({ children }: { children: ReactNode }) => {
function ParanextPanel({ children }: { children: ReactNode }) {
return <div className="paranextPanel">{children}</div>;
};
}

export default ParanextPanel;
4 changes: 2 additions & 2 deletions src/renderer/components/docking/ParanextTabTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import logger from '@shared/util/logger';
* Custom tab title for all tabs in Paranext
* @param text The text to show on the tab title
*/
const ParanextTabTitle = ({ text }: { text: string }) => {
function ParanextTabTitle({ text }: { text: string }) {
const toggleDropdown = () => {
logger.log('Pretend a menu was shown!');
};
Expand All @@ -21,6 +21,6 @@ const ParanextTabTitle = ({ text }: { text: string }) => {
<span>{text}</span>
</div>
);
};
}

export default ParanextTabTitle;
4 changes: 2 additions & 2 deletions src/renderer/testing/HelloPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import icon from '@assets/icon.png';
import { TabInfo } from '@shared/data/WebviewTypes';

const HelloPanel = () => {
function HelloPanel() {
return (
<div
style={{
Expand All @@ -17,7 +17,7 @@ const HelloPanel = () => {
</div>
</div>
);
};
}

const createHelloPanel = (): TabInfo => {
return {
Expand Down
8 changes: 5 additions & 3 deletions src/renderer/testing/TestButtonsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const executeMany = async <T,>(fn: () => Promise<T>) => {
}
};

const TestButtonsPanel = () => {
function TestButtonsPanel() {
const [promiseReturn, setPromiseReturn] = useState('Click a button.');
const updatePromiseReturn = useCallback(
(state: unknown) =>
Expand All @@ -122,7 +122,9 @@ const TestButtonsPanel = () => {

const [resourcesPath] = usePromise(
useCallback(async () => {
await new Promise<void>((resolve) => setTimeout(() => resolve(), 5000));
await new Promise<void>((resolve) => {
setTimeout(() => resolve(), 5000);
});
return getResourcesPath();
}, []),
'retrieving',
Expand Down Expand Up @@ -379,7 +381,7 @@ const TestButtonsPanel = () => {
))}
</>
);
};
}

const createButtonsPanel = (): TabInfo => {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/testing/TestPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export type TabData = {
content: string;
};

const TestPanel = ({ content }: { content: string }) => {
function TestPanel({ content }: { content: string }) {
return <div>{content}</div>;
};
}

const createTabPanel = (tabInfo: SavedTabInfo): TabInfo => {
if (!tabInfo.data) throw Error('Tab creation data is missing');
Expand Down
17 changes: 8 additions & 9 deletions src/shared/globalThis.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
/* eslint-disable vars-on-top */
/* eslint-disable no-var */

/** Type of Paranext process */
// eslint-disable-next-line import/prefer-default-export
export enum ProcessType {
Main = 'main',
Renderer = 'renderer',
ExtensionHost = 'extension-host',
}

/**
* Variables that are defined in global scope. These must be defined in main.ts (main), index.ts (renderer), and extension-host.ts (extension host)
*/

declare global {
/** Type of process this is. Helps with running specific code based on which process you're in */
var processType: ProcessType;
Expand All @@ -13,11 +20,3 @@ declare global {
/** Path to the app's resources directory. This is a string representation of the resources uri on frontend */
var resourcesPath: string;
}

/** Type of Paranext process */
// eslint-disable-next-line import/prefer-default-export
export enum ProcessType {
Main = 'main',
Renderer = 'renderer',
ExtensionHost = 'extension-host',
}
72 changes: 33 additions & 39 deletions src/shared/services/NetworkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ComplexRequest,
ComplexResponse,
createSafeRegisterFn,
RequestHandlerType,
UnsubPromiseAsync,
UnsubscriberAsync,
} from '@shared/util/PapiUtil';
Expand All @@ -21,39 +22,6 @@ import * as ConnectionService from '@shared/services/ConnectionService';
import { isClient, isRenderer, isServer } from '@shared/util/InternalUtil';
import logger from '@shared/util/logger';

/** Whether this service has finished setting up */
let isInitialized = false;

/** Promise that resolves when this service is finished initializing */
let initializePromise: Promise<void> | undefined;

/** Map of requestType to registered handler for that request or (on server) information about which connection to send the request */
const requestRegistrations = new Map<string, RequestRegistration>();

/** Request handler that is a local function and can be handled locally */
type LocalRequestRegistration<TParam, TReturn> = {
registrationType: 'local';
requestType: string;
handlerType: RequestHandlerType;
handler:
| RoutedRequestHandler<TParam, TReturn>
| RoutedRequestHandler<TParam[], TReturn>;
};

/** Request handler that is not on this network service and must be requested on the network. Server-only as clients will all just send to the server */
type RemoteRequestRegistration = {
registrationType: 'remote';
requestType: string;
clientId: number;
};

/** Information about the request handler and how to run it */
// Any is probably fine because we likely never know or care about the args or return
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type RequestRegistration<TParam = any, TReturn = any> =
| LocalRequestRegistration<TParam, TReturn>
| RemoteRequestRegistration;

/**
* Args handler function for a request. Called when a request is handled.
* The function should accept the spread of the contents array of the request as its parameters.
Expand Down Expand Up @@ -100,12 +68,38 @@ type RoutedRequestHandler<TParam = any, TReturn = any> =
| ContentsRequestHandler<TParam, TReturn>
| ComplexRequestHandler<TParam, TReturn>;

/** Type of request handler - indicates what type of parameters and what return type the handler has */
enum RequestHandlerType {
Args = 'args',
Contents = 'contents',
Complex = 'complex',
}
/** Request handler that is a local function and can be handled locally */
type LocalRequestRegistration<TParam, TReturn> = {
registrationType: 'local';
requestType: string;
handlerType: RequestHandlerType;
handler:
| RoutedRequestHandler<TParam, TReturn>
| RoutedRequestHandler<TParam[], TReturn>;
};

/** Request handler that is not on this network service and must be requested on the network. Server-only as clients will all just send to the server */
type RemoteRequestRegistration = {
registrationType: 'remote';
requestType: string;
clientId: number;
};

/** Information about the request handler and how to run it */
// Any is probably fine because we likely never know or care about the args or return
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type RequestRegistration<TParam = any, TReturn = any> =
| LocalRequestRegistration<TParam, TReturn>
| RemoteRequestRegistration;

/** Whether this service has finished setting up */
let isInitialized = false;

/** Promise that resolves when this service is finished initializing */
let initializePromise: Promise<void> | undefined;

/** Map of requestType to registered handler for that request or (on server) information about which connection to send the request */
const requestRegistrations = new Map<string, RequestRegistration>();

// #region Private unsafe functions (do not call manually outside of initialization)

Expand Down
2 changes: 1 addition & 1 deletion src/shared/util/PapiUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export type RequestType = {
/**
* Create a request message requestType string from a category and a directive
* @param category the general category of request
* @param directive specific idenitifer for this type of request
* @param directive specific identifier for this type of request
* @returns full requestType for use in network calls
*/
export const serializeRequestType = (
Expand Down
1 change: 1 addition & 0 deletions src/shared/util/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function isString(o: unknown): o is string {
* @param valueSelector function to run on each item to get the value it should have in the group (like map function). If not provided, uses the item itself
* @returns map of keys to groups of values corresponding to each item
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function groupBy<T, K, V>(
items: T[],
keySelector: (item: T) => K,
Expand Down

0 comments on commit fbb3ba9

Please sign in to comment.