Skip to content

Commit

Permalink
Lint against floating promises
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbl committed Jun 24, 2024
1 parent 9095a3b commit c980008
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 49 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ module.exports = {
'no-empty': 'off',
'no-inner-declarations': 'off',
// customized
'import/no-unresolved': 'error',
'react/jsx-boolean-value': ['error', 'always'],
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-unused-vars': [
'warn',
{
Expand All @@ -31,6 +30,8 @@ module.exports = {
caughtErrorsIgnorePattern: '^_.*$',
},
],
'import/no-unresolved': 'error',
'react/jsx-boolean-value': ['error', 'always'],
},
plugins: [
'@typescript-eslint',
Expand Down
8 changes: 5 additions & 3 deletions src/main/RequestAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ export async function initRequestAPI(): Promise<void> {

const onData = (buffer: Buffer) => {
// IPC has trouble with Buffer so send it as number[]
BroadcastAPI.send(id, 'data', [...buffer.values()]);
BroadcastAPI.send(id, 'data', [...buffer.values()]).catch(
console.error,
);
};

const onSuccess = () => {
BroadcastAPI.send(id, 'success');
BroadcastAPI.send(id, 'success').catch(console.error);
};

const onFailure = (error: Error) => {
BroadcastAPI.send(id, 'error', error);
BroadcastAPI.send(id, 'error', error).catch(console.error);
};

const request = net.request(url);
Expand Down
8 changes: 4 additions & 4 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const createWindow = async () => {
// Open urls in the user's browser
mainWindow.webContents.on('new-window', (event, url) => {
event.preventDefault();
shell.openExternal(url);
shell.openExternal(url).catch(console.error);
});

console.log('[main] Initializing IPC...');
Expand Down Expand Up @@ -137,7 +137,7 @@ const createWindow = async () => {
app.quit();
}

mainWindow.loadURL(resolveHtmlPath('index.html'));
await mainWindow.loadURL(resolveHtmlPath('index.html'));
};

app.on('window-all-closed', () => {
Expand All @@ -153,11 +153,11 @@ initPreferences();
app
.whenReady()
.then(() => {
createWindow();
createWindow().catch(console.error);
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) createWindow();
if (mainWindow === null) createWindow().catch(console.error);
});
})
.catch(console.log);
4 changes: 2 additions & 2 deletions src/main/worker/BridgeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ const config = JSON.parse(D2RMM.getConfigJSON());
'installationProgress',
i,
runtime.modsToInstall.length,
);
).catch(console.error);
runtime.mod = runtime.modsToInstall[i];
let code: string = '';
let sourceMap: string = '';
Expand Down Expand Up @@ -1105,7 +1105,7 @@ const config = JSON.parse(D2RMM.getConfigJSON());
'installationProgress',
runtime.modsToInstall.length,
runtime.modsToInstall.length,
);
).catch(console.error);

if (!runtime.options.isPreExtractedData) {
await BridgeAPI.closeStorage();
Expand Down
40 changes: 21 additions & 19 deletions src/main/worker/NetworkFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,27 @@ export async function fetch<T extends Destination>(
}
reject();
};
RequestAPI.createRequest(sourceUrl).then((id) => {
const listener = async (event: unknown, payload: unknown) => {
switch (event as 'data' | 'success' | 'error') {
case 'data':
onData(payload as number[]);
break;
case 'success':
BroadcastAPI.removeEventListener(id, listener);
onSuccess();
break;
case 'error':
BroadcastAPI.removeEventListener(id, listener);
onFailure();
break;
}
};
BroadcastAPI.addEventListener(id, listener);
RequestAPI.sendRequest(id);
});
RequestAPI.createRequest(sourceUrl)
.then((id) => {
const listener = async (event: unknown, payload: unknown) => {
switch (event as 'data' | 'success' | 'error') {
case 'data':
onData(payload as number[]);
break;
case 'success':
BroadcastAPI.removeEventListener(id, listener);
onSuccess();
break;
case 'error':
BroadcastAPI.removeEventListener(id, listener);
onFailure();
break;
}
};
BroadcastAPI.addEventListener(id, listener);
RequestAPI.sendRequest(id).catch(console.error);
})
.catch(console.error);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/worker/UpdaterAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export async function installUpdate(update: Update): Promise<void> {
});

child.unref();
AppInfoAPI.quit();
await AppInfoAPI.quit();
}

async function cleanupUpdate(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/ModListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function ModListItem({

const onOpenWebsite = useCallback((): void => {
if (mod.info.website != null) {
ShellAPI.openExternal(mod.info.website);
ShellAPI.openExternal(mod.info.website).catch(console.error);
}
}, [mod]);

Expand Down
26 changes: 14 additions & 12 deletions src/renderer/ModManagerLogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,20 @@ export default function ModManagerSettings(_props: Props): JSX.Element {
);

const onCopy = useCallback((): void => {
navigator.clipboard.writeText(
// always copy all logs, including the filtered ones
// because people will forget to enable debug level
logs
.map((log) => [
new Date(log.timestamp).toISOString(),
log.level,
...log.data.map(prettyPrintData),
])
.map((log) => log.join(','))
.join('\n'),
);
navigator.clipboard
.writeText(
// always copy all logs, including the filtered ones
// because people will forget to enable debug level
logs
.map((log) => [
new Date(log.timestamp).toISOString(),
log.level,
...log.data.map(prettyPrintData),
])
.map((log) => log.join(','))
.join('\n'),
)
.catch(console.error);
onCloseExportMenu();
}, [logs, onCloseExportMenu]);

Expand Down
6 changes: 3 additions & 3 deletions src/renderer/ModsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function ModsContextProvider({
const [mods, setMods] = useState<Mod[]>([]);

useEffect(() => {
getMods().then(setMods);
getMods().then(setMods).catch(console.error);
}, []);

const setModConfig = useCallback(
Expand All @@ -129,7 +129,7 @@ export function ModsContextProvider({
prevMods.map((mod) => {
if (mod.id === id) {
const config = getConfig(mod.config);
BridgeAPI.writeModConfig(id, config);
BridgeAPI.writeModConfig(id, config).catch(console.error);
return { ...mod, config };
}
return mod;
Expand All @@ -141,7 +141,7 @@ export function ModsContextProvider({

const refreshMods = useCallback((): void => {
// manually refresh mods
getMods().then(setMods);
getMods().then(setMods).catch(console.error);
}, [getMods]);

const [installedMods, setInstalledMods] = useSavedState(
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/RunGameButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function RunGameButton(_props: Props): JSX.Element {
const command = useMemo(() => ['D2R.exe'].concat(args).join(' '), [args]);

const onRunGame = useCallback(() => {
BridgeAPI.execute(`${gamePath}\\D2R.exe`, args);
BridgeAPI.execute(`${gamePath}\\D2R.exe`, args).catch(console.error);
}, [args, gamePath]);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/UpdaterDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function UpdaterDialog() {

const onInstall = useCallback(() => {
if (update != null) {
UpdaterAPI.installUpdate(update);
UpdaterAPI.installUpdate(update).catch(console.error);
}
setIsUpdateIgnored(true);
}, [update]);
Expand Down

0 comments on commit c980008

Please sign in to comment.