From 1b8da297e3d3ff4a0fadb1b05ae3379e7c341638 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Mon, 13 Sep 2021 02:31:08 -0700 Subject: [PATCH] Fix Flipper lints #2 Summary: Per title. Reviewed By: timur-valiev Differential Revision: D30843077 fbshipit-source-id: 1a3f4757518610b8caf41c62af7e27723d0de8d6 --- .../src/dispatcher/__tests__/plugins.node.tsx | 3 ++- desktop/app/src/dispatcher/application.tsx | 2 ++ desktop/app/src/dispatcher/flipperServer.tsx | 1 + desktop/app/src/dispatcher/index.tsx | 2 ++ desktop/app/src/dispatcher/pluginDownloads.tsx | 8 +++----- desktop/app/src/dispatcher/pluginManager.tsx | 16 ++++++++-------- desktop/app/src/dispatcher/reactNative.tsx | 2 ++ desktop/app/src/dispatcher/tracking.tsx | 2 ++ 8 files changed, 22 insertions(+), 14 deletions(-) diff --git a/desktop/app/src/dispatcher/__tests__/plugins.node.tsx b/desktop/app/src/dispatcher/__tests__/plugins.node.tsx index 04a9f435e..61b5e5ffa 100644 --- a/desktop/app/src/dispatcher/__tests__/plugins.node.tsx +++ b/desktop/app/src/dispatcher/__tests__/plugins.node.tsx @@ -18,8 +18,9 @@ import dispatcher, { } from '../plugins'; import {BundledPluginDetails, InstalledPluginDetails} from 'flipper-plugin-lib'; import path from 'path'; +// Allowed in a test. +// eslint-disable-next-line flipper/no-electron-remote-imports import {remote} from 'electron'; -import {FlipperPlugin} from '../../plugin'; import {createRootReducer, State} from '../../reducers/index'; import {getInstance} from '../../fb-stubs/Logger'; import configureStore from 'redux-mock-store'; diff --git a/desktop/app/src/dispatcher/application.tsx b/desktop/app/src/dispatcher/application.tsx index 058a1e52a..2ed20d7bb 100644 --- a/desktop/app/src/dispatcher/application.tsx +++ b/desktop/app/src/dispatcher/application.tsx @@ -7,6 +7,8 @@ * @format */ +// Fine for app startup. +// eslint-disable-next-line flipper/no-electron-remote-imports import {remote, ipcRenderer, IpcRendererEvent} from 'electron'; import {Store} from '../reducers/index'; import {Logger} from '../fb-interfaces/Logger'; diff --git a/desktop/app/src/dispatcher/flipperServer.tsx b/desktop/app/src/dispatcher/flipperServer.tsx index 7e4a01fdf..f40654b4d 100644 --- a/desktop/app/src/dispatcher/flipperServer.tsx +++ b/desktop/app/src/dispatcher/flipperServer.tsx @@ -155,6 +155,7 @@ export async function handleClientConnected(store: Store, client: Client) { payload: client, }); + // eslint-disable-next-line node/no-sync const device = client.deviceSync; if (device) { store.dispatch(selectDevice(device)); diff --git a/desktop/app/src/dispatcher/index.tsx b/desktop/app/src/dispatcher/index.tsx index 340f98040..a23b3a195 100644 --- a/desktop/app/src/dispatcher/index.tsx +++ b/desktop/app/src/dispatcher/index.tsx @@ -7,6 +7,8 @@ * @format */ +// Used responsibly. +// eslint-disable-next-line flipper/no-electron-remote-imports import {remote} from 'electron'; import flipperServer from './flipperServer'; import application from './application'; diff --git a/desktop/app/src/dispatcher/pluginDownloads.tsx b/desktop/app/src/dispatcher/pluginDownloads.tsx index 6bb7f0acc..e4ae55e3e 100644 --- a/desktop/app/src/dispatcher/pluginDownloads.tsx +++ b/desktop/app/src/dispatcher/pluginDownloads.tsx @@ -86,10 +86,8 @@ async function handlePluginDownload( const tmpFile = path.join(tmpDir, `${name}-${version}.tgz`); let installedPlugin: InstalledPluginDetails | undefined; try { - const cancellationSource = axios.CancelToken.source(); - dispatch( - pluginDownloadStarted({plugin, cancel: cancellationSource.cancel}), - ); + const cancelationSource = axios.CancelToken.source(); + dispatch(pluginDownloadStarted({plugin, cancel: cancelationSource.cancel})); if (await fs.pathExists(installationDir)) { console.log( `Using existing files instead of downloading plugin "${title}" v${version} from "${downloadUrl}" to "${installationDir}"`, @@ -100,7 +98,7 @@ async function handlePluginDownload( let percentCompleted = 0; const response = await axios.get(plugin.downloadUrl, { adapter: axiosHttpAdapter, - cancelToken: cancellationSource.token, + cancelToken: cancelationSource.token, responseType: 'stream', headers: { 'Sec-Fetch-Site': 'none', diff --git a/desktop/app/src/dispatcher/pluginManager.tsx b/desktop/app/src/dispatcher/pluginManager.tsx index 264080acf..5cc34574a 100644 --- a/desktop/app/src/dispatcher/pluginManager.tsx +++ b/desktop/app/src/dispatcher/pluginManager.tsx @@ -51,13 +51,11 @@ import {getPluginKey} from '../utils/pluginKey'; const maxInstalledPluginVersionsToKeep = 2; -function refreshInstalledPlugins(store: Store) { - removePlugins(store.getState().plugins.uninstalledPluginNames.values()) - .then(() => - cleanupOldInstalledPluginVersions(maxInstalledPluginVersionsToKeep), - ) - .then(() => getInstalledPlugins()) - .then((plugins) => store.dispatch(registerInstalledPlugins(plugins))); +async function refreshInstalledPlugins(store: Store) { + await removePlugins(store.getState().plugins.uninstalledPluginNames.values()); + await cleanupOldInstalledPluginVersions(maxInstalledPluginVersionsToKeep); + const plugins = await getInstalledPlugins(); + return store.dispatch(registerInstalledPlugins(plugins)); } export default ( @@ -70,7 +68,9 @@ export default ( // This needn't happen immediately and is (light) I/O work. if (window.requestIdleCallback) { window.requestIdleCallback(() => { - refreshInstalledPlugins(store); + refreshInstalledPlugins(store).catch((err) => + console.error('Failed to refresh installed plugins:', err), + ); }); } diff --git a/desktop/app/src/dispatcher/reactNative.tsx b/desktop/app/src/dispatcher/reactNative.tsx index c1194eb93..c6223936a 100644 --- a/desktop/app/src/dispatcher/reactNative.tsx +++ b/desktop/app/src/dispatcher/reactNative.tsx @@ -7,6 +7,8 @@ * @format */ +// Used to register a shortcut. Don't have an alternative for that. +// eslint-disable-next-line flipper/no-electron-remote-imports import {remote} from 'electron'; import MetroDevice from '../server/devices/metro/MetroDevice'; import {Store} from '../reducers'; diff --git a/desktop/app/src/dispatcher/tracking.tsx b/desktop/app/src/dispatcher/tracking.tsx index 645e6d1fd..a5568a0db 100644 --- a/desktop/app/src/dispatcher/tracking.tsx +++ b/desktop/app/src/dispatcher/tracking.tsx @@ -7,6 +7,8 @@ * @format */ +// Used for PID tracking. +// eslint-disable-next-line flipper/no-electron-remote-imports import {ipcRenderer, remote} from 'electron'; import {performance} from 'perf_hooks'; import {EventEmitter} from 'events';