Upgrading flow and fixing lint errors

Summary:
Upgrading to flow 0.91, fixing a bunch of `$FloxFixMe`s that were introduced by upgrading to 0.86.
Also fixing some linting issues.

Reviewed By: priteshrnandgaonkar

Differential Revision: D13900794

fbshipit-source-id: 5d0a1b62371f3b5d34b909bae0876583acb6f977
This commit is contained in:
Pascal Hartig
2019-02-01 06:42:40 -08:00
committed by Facebook Github Bot
parent 88cc299811
commit 09a93cd9e6
30 changed files with 477 additions and 338 deletions

View File

@@ -29,14 +29,18 @@ import type {ActiveSheet} from './reducers/application.js';
const version = remote.app.getVersion();
type Props = {
type OwnProps = {|
logger: Logger,
bugReporter: BugReporter,
|};
type Props = {|
...OwnProps,
leftSidebarVisible: boolean,
selectedDevice: ?BaseDevice,
error: ?string,
activeSheet: ActiveSheet,
};
|};
export class App extends React.Component<Props> {
componentDidMount() {
@@ -88,11 +92,8 @@ export class App extends React.Component<Props> {
);
}
}
/* $FlowFixMe(>=0.86.0) This
* comment suppresses an error found when Flow v0.86 was
* deployed. To see the error, delete this comment and
* run Flow. */
export default connect(
export default connect<Props, OwnProps, _, _, _, _>(
({
application: {leftSidebarVisible, activeSheet},
connections: {selectedDevice, error},

View File

@@ -98,24 +98,28 @@ export default class Notifications extends FlipperDevicePlugin<{}> {
}
}
type Props = {|
type OwnProps = {|
...SearchableProps,
onClear: () => void,
selectedID: ?string,
logger: Logger,
|};
type Props = {|
...OwnProps,
activeNotifications: Array<PluginNotification>,
invalidatedNotifications: Array<PluginNotification>,
blacklistedPlugins: Array<string>,
blacklistedCategories: Array<string>,
devicePlugins: Map<string, Class<FlipperDevicePlugin<>>>,
clientPlugins: Map<string, Class<FlipperPlugin<>>>,
onClear: () => void,
updatePluginBlacklist: (blacklist: Array<string>) => mixed,
updateCategoryBlacklist: (blacklist: Array<string>) => mixed,
selectPlugin: ({
selectPlugin: (payload: {|
selectedPlugin: ?string,
selectedApp: ?string,
deepLinkPayload?: ?string,
}) => mixed,
selectedID: ?string,
logger: Logger,
deepLinkPayload: ?string,
|}) => mixed,
|};
type State = {|
@@ -322,11 +326,7 @@ class NotificationsTable extends Component<Props, State> {
}
}
/* $FlowFixMe(>=0.86.0) This
* comment suppresses an error found when Flow v0.86 was
* deployed. To see the error, delete this comment and
* run Flow. */
const ConnectedNotificationsTable = connect(
const ConnectedNotificationsTable = connect<Props, OwnProps, _, _, _, _>(
({
notifications: {
activeNotifications,
@@ -343,6 +343,7 @@ const ConnectedNotificationsTable = connect(
devicePlugins,
clientPlugins,
}),
// $FlowFixMe
{
updatePluginBlacklist,
updateCategoryBlacklist,
@@ -453,11 +454,11 @@ type ItemProps = {
onHideCategory?: () => mixed,
isSelected?: boolean,
inactive?: boolean,
selectPlugin?: ({
selectPlugin?: (payload: {|
selectedPlugin: ?string,
selectedApp: ?string,
deepLinkPayload?: ?string,
}) => mixed,
deepLinkPayload: ?string,
|}) => mixed,
logger?: Logger,
plugin: ?Class<FlipperBasePlugin<>>,
};

View File

@@ -38,8 +38,19 @@ const SidebarContainer = styled(FlexRow)({
overflow: 'scroll',
});
type Props = {
/*
pluginState: pluginStates[pluginKey],
activePlugin,
target,
deepLinkPayload,
pluginKey,
*/
type OwnProps = {|
logger: LogManager,
|};
type Props = {|
...OwnProps,
pluginState: Object,
activePlugin: ?Class<FlipperPlugin<> | FlipperDevicePlugin<>>,
target: Client | BaseDevice | null,
@@ -55,7 +66,7 @@ type Props = {
pluginKey: string,
state: Object,
}) => void,
};
|};
class PluginContainer extends PureComponent<Props> {
plugin: ?FlipperPlugin<> | FlipperDevicePlugin<>;
@@ -132,11 +143,7 @@ class PluginContainer extends PureComponent<Props> {
}
}
/* $FlowFixMe(>=0.86.0) This
* comment suppresses an error found when Flow v0.86 was
* deployed. To see the error, delete this comment and
* run Flow. */
export default connect(
export default connect<Props, OwnProps, _, _, _, _>(
({
application: {rightSidebarVisible, rightSidebarAvailable},
connections: {
@@ -182,6 +189,7 @@ export default connect(
pluginKey,
};
},
// $FlowFixMe
{
setPluginState,
selectPlugin,

View File

@@ -7,7 +7,6 @@
import {
FlexRow,
Text,
colors,
LoadingIndicator,
Glyph,

View File

@@ -11,12 +11,17 @@ import Sidebar from '../ui/components/Sidebar';
import {connect} from 'react-redux';
import {toggleRightSidebarAvailable} from '../reducers/application.js';
type Props = {
type OwnProps = {|
children: any,
width?: number,
minWidth?: number,
|};
type Props = {
...OwnProps,
rightSidebarVisible: boolean,
rightSidebarAvailable: boolean,
toggleRightSidebarAvailable: (visible?: boolean) => any,
width?: number,
};
class DetailSidebar extends React.Component<Props> {
@@ -42,7 +47,10 @@ class DetailSidebar extends React.Component<Props> {
this.props.rightSidebarVisible &&
domNode &&
ReactDOM.createPortal(
<Sidebar width={this.props.width || 300} position="right">
<Sidebar
minWidth={this.props.minWidth}
width={this.props.width || 300}
position="right">
{this.props.children}
</Sidebar>,
domNode,
@@ -51,11 +59,7 @@ class DetailSidebar extends React.Component<Props> {
}
}
/* $FlowFixMe(>=0.86.0) This
* comment suppresses an error found when Flow v0.86 was
* deployed. To see the error, delete this comment and
* run Flow. */
export default connect(
export default connect<Props, OwnProps, _, _, _, _>(
({application: {rightSidebarVisible, rightSidebarAvailable}}) => ({
rightSidebarVisible,
rightSidebarAvailable,

View File

@@ -28,22 +28,22 @@ const DropdownButton = styled(Button)({
fontSize: 11,
});
// Remove this if the flow fixme at the bottom is addressed (or has already been removed).
/* eslint-disable prettier/prettier */
class DevicesButton extends Component<Props> {
launchEmulator = (name: string) => {
// On Linux, you must run the emulator from the directory it's in because
// reasons ...
whichPromise('emulator').then(emulatorPath => {
const child = spawn(emulatorPath, [`@${name}`], {
detached: true,
cwd: dirname(emulatorPath),
});
child.stderr.on('data', data => {
console.error(`Android emulator error: ${data}`);
});
child.on('error', console.error);
}).catch(console.error);
whichPromise('emulator')
.then(emulatorPath => {
const child = spawn(emulatorPath, [`@${name}`], {
detached: true,
cwd: dirname(emulatorPath),
});
child.stderr.on('data', data => {
console.error(`Android emulator error: ${data}`);
});
child.on('error', console.error);
})
.catch(console.error);
this.props.preferDevice(name);
};
@@ -109,10 +109,8 @@ class DevicesButton extends Component<Props> {
</DropdownButton>
);
}
} /* $FlowFixMe(>=0.86.0) This comment suppresses an error found when Flow v0.86
* was deployed. To see the error, delete this comment and run Flow.
*/
export default connect(
}
export default connect<Props, {||}, _, _, _, _>(
({connections: {devices, androidEmulators, selectedDevice}}) => ({
devices,
androidEmulators,

View File

@@ -10,6 +10,7 @@ import type BaseDevice from '../devices/BaseDevice.js';
import type Client from '../Client.js';
import type {UninitializedClient} from '../UninitializedClient.js';
import type {PluginNotification} from '../reducers/notifications';
import type {ActiveSheet} from '../reducers/application';
import {
PureComponent,
@@ -190,11 +191,11 @@ type MainSidebarProps = {|
selectedApp: ?string,
selectedDevice: ?BaseDevice,
windowIsFocused: boolean,
selectPlugin: (payload: {
selectPlugin: (payload: {|
selectedPlugin: ?string,
selectedApp: ?string,
deepLinkPayload: ?string,
}) => void,
|}) => void,
clients: Array<Client>,
uninitializedClients: Array<{
client: UninitializedClient,
@@ -204,7 +205,7 @@ type MainSidebarProps = {|
numNotifications: number,
devicePlugins: Map<string, Class<FlipperDevicePlugin<>>>,
clientPlugins: Map<string, Class<FlipperPlugin<>>>,
setActiveSheet: (activeSheet: ?string) => any,
setActiveSheet: (activeSheet: ActiveSheet) => void,
|};
class MainSidebar extends PureComponent<MainSidebarProps> {
@@ -348,11 +349,7 @@ class MainSidebar extends PureComponent<MainSidebarProps> {
}
}
/* $FlowFixMe(>=0.86.0) This
* comment suppresses an error found when Flow v0.86 was
* deployed. To see the error, delete this comment and
* run Flow. */
export default connect(
export default connect<MainSidebarProps, {||}, _, _, _, _>(
({
application: {windowIsFocused},
connections: {

View File

@@ -8,6 +8,7 @@
import type {FlipperDevicePlugin, FlipperPlugin} from '../plugin';
import type {PluginDefinition} from '../dispatcher/plugins';
import type Client from '../Client';
import type {TableBodyRow} from '../ui/components/table/types';
import {Component, Fragment} from 'react';
import {connect} from 'react-redux';
@@ -20,7 +21,6 @@ import {
colors,
Link,
} from 'flipper';
import {remote} from 'electron';
const Container = styled(FlexColumn)({
padding: 10,
@@ -118,7 +118,7 @@ class PluginDebugger extends Component<Props> {
GKname: ?string,
GKpassing: ?boolean,
pluginPath: ?string,
) {
): TableBodyRow {
return {
key: name.toLowerCase(),
columns: {
@@ -165,8 +165,8 @@ class PluginDebugger extends Component<Props> {
.join(', ');
}
getRows() {
let rows = [];
getRows(): Array<TableBodyRow> {
let rows: Array<TableBodyRow> = [];
// bundled plugins are loaded from the defaultPlugins directory within
// Flipper's package.

View File

@@ -302,10 +302,8 @@ class ScreenCaptureButtons extends Component<Props, State> {
}
}
/* $FlowFixMe(>=0.86.0) This
* comment suppresses an error found when Flow v0.86 was
* deployed. To see the error, delete this comment and
* run Flow. */
export default connect(({connections: {selectedDevice}}) => ({
selectedDevice,
}))(ScreenCaptureButtons);
export default connect<Props, {||}, _, _, _, _>(
({connections: {selectedDevice}}) => ({
selectedDevice,
}),
)(ScreenCaptureButtons);

View File

@@ -35,10 +35,14 @@ const DialogContainer = styled('div')(({state}) => ({
boxShadow: '0 5px 13px rgba(0, 0, 0, 0.2)',
}));
type OwnProps = {|
children: (onHide: () => mixed) => any,
|};
type Props = {|
...OwnProps,
activeSheet: ActiveSheet,
onHideSheet: () => void,
children: (onHide: () => mixed) => any,
|};
type State = {|
@@ -105,11 +109,8 @@ class Sheet extends Component<Props, State> {
);
}
}
/* $FlowFixMe(>=0.86.0) This
* comment suppresses an error found when Flow v0.86 was
* deployed. To see the error, delete this comment and
* run Flow. */
export default connect(
export default connect<Props, OwnProps, _, _, _, _>(
({application: {activeSheet}}) => ({
activeSheet,
}),

View File

@@ -51,7 +51,12 @@ const AppTitleBar = styled(FlexRow)(({focused}) => ({
zIndex: 4,
}));
type OwnProps = {|
version: string,
|};
type Props = {|
...OwnProps,
windowIsFocused: boolean,
leftSidebarVisible: boolean,
rightSidebarVisible: boolean,
@@ -59,7 +64,6 @@ type Props = {|
toggleLeftSidebarVisible: (visible?: boolean) => void,
toggleRightSidebarVisible: (visible?: boolean) => void,
setActiveSheet: (sheet: ActiveSheet) => void,
version: string,
|};
const VersionText = styled(Text)({
@@ -114,23 +118,19 @@ class TitleBar extends Component<Props> {
}
}
/* $FlowFixMe(>=0.86.0) This comment suppresses an error found when Flow v0.86
* was deployed. To see the error, delete this comment and run Flow. */
export default connect(
export default connect<Props, OwnProps, _, _, _, _>(
({
application: {
windowIsFocused,
leftSidebarVisible,
rightSidebarVisible,
rightSidebarAvailable,
pluginManagerVisible,
},
}) => ({
windowIsFocused,
leftSidebarVisible,
rightSidebarVisible,
rightSidebarAvailable,
pluginManagerVisible,
}),
{
setActiveSheet,

View File

@@ -58,7 +58,6 @@ type State = {|
* the client in an unknown state.
*/
export function createTablePlugin<T: RowData>(props: Props<T>) {
// $FlowFixMe persistedStateReducer is fine to accept payload of type T, because it is of type RowData
return class extends FlipperPlugin<State, *, PersistedState<T>> {
static keyboardActions = ['clear', 'createPaste'];

View File

@@ -6,7 +6,6 @@
*/
import type {DeviceType, DeviceShell} from './BaseDevice.js';
import type {Store} from '../reducers/index';
import {Priority} from 'adbkit-logcat-fb';
import child_process from 'child_process';
@@ -69,7 +68,7 @@ export default class AndroidDevice extends BaseDevice {
return ['date', 'pid', 'tid', 'tag', 'message', 'type', 'time'];
}
reverse(ports: [number]): Promise<void> {
reverse(ports: [number, number]): Promise<void> {
return Promise.all(
ports.map(port =>
this.adb.reverse(this.serial, `tcp:${port}`, `tcp:${port}`),

View File

@@ -7,6 +7,7 @@
export type LogTypes = 'error' | 'warn' | 'info' | 'debug';
export type TrackType = 'duration' | 'usage' | 'performance' | 'success-rate';
import type {Store} from '../reducers/index';
import ScribeLogger from './ScribeLogger';
var instance: ?LogManager = null;

View File

@@ -5,6 +5,8 @@
* @format
*/
import type {TableBodyRow} from 'flipper';
import {
PureComponent,
FlexColumn,
@@ -129,11 +131,7 @@ export default class LogWatcher extends PureComponent<Props, State> {
this.props.onChange(newCounters);
};
buildRows = () => {
/* $FlowFixMe(>=0.86.0) This
* comment suppresses an error found when Flow v0.86 was
* deployed. To see the error, delete this comment and
* run Flow. */
buildRows = (): Array<TableBodyRow> => {
return this.props.counters.map(({label, count, notify}, i) => ({
columns: {
expression: {

View File

@@ -104,7 +104,7 @@ export default class extends FlipperPlugin<SharedPreferencesState> {
const change = event.change;
const entry = state.sharedPreferences[change.preferences];
if (entry == null) {
return;
return state;
}
if (change.deleted) {
delete entry.preferences[change.name];

View File

@@ -37,7 +37,14 @@ import type {
} from './plugins.js';
import type {Store as ReduxStore} from 'redux';
// $FlowFixMe introduced when removing $Subtype/$Supertype
type Actions =
| ApplicationAction
| DevicesAction
| PluginStatesAction
| NotificationsAction
| PluginsAction
| {|type: 'INIT'|};
export type Store = ReduxStore<
{|
application: ApplicationState,
@@ -46,19 +53,10 @@ export type Store = ReduxStore<
notifications: NotificationsState,
plugins: PluginsState,
|},
| ApplicationAction
| DevicesAction
| PluginStatesAction
| NotificationsAction
| PluginsAction
| {|type: 'INIT'|},
Actions,
>;
/* $FlowFixMe(>=0.86.0) This
* comment suppresses an error found when Flow v0.86 was
* deployed. To see the error, delete this comment and
* run Flow. */
export default combineReducers({
export default combineReducers<_, Actions>({
application,
connections: persistReducer(
{

View File

@@ -81,7 +81,7 @@ type Props = {|
client: PluginClient,
realClient: Client,
logger: Logger,
extensions?: Array<any>,
extensions?: Array<Function>,
|};
type State = {|
@@ -118,12 +118,8 @@ export class InspectorSidebar extends Component<Props, State> {
return null;
}
const sections =
const sections: Array<any> =
(extensions &&
/* $FlowFixMe(>=0.86.0) This
* comment suppresses an error found when Flow v0.86 was
* deployed. To see the error, delete this comment and
* run Flow. */
extensions.map(ext =>
ext(
this.props.client,

View File

@@ -156,9 +156,7 @@ class ManagedTable extends React.Component<
shouldScrollToBottom: Boolean(this.props.stickyBottom),
};
tableRef: {
current: null | List,
} = React.createRef();
tableRef = React.createRef<List>();
scrollRef: {
current: null | HTMLDivElement,

View File

@@ -8,8 +8,6 @@
import LogManager from '../fb-stubs/Logger';
import {RecurringError} from './errors';
import {promisify} from 'util';
import child_process from 'child_process';
const exec = promisify(child_process.exec);
const fs = require('fs');
const adb = require('adbkit-fb');
import {

View File

@@ -14,10 +14,10 @@ import {getInstance} from '../fb-stubs/Logger';
Use this variant to report failures in core platform (Flipper) code.
*/
export function reportPlatformFailures(
promise: Promise<*>,
export function reportPlatformFailures<T>(
promise: Promise<T>,
name: string,
): Promise<*> {
): Promise<T> {
return promise.then(
fulfilledValue => {
getInstance().track('success-rate', name, 1);
@@ -37,11 +37,11 @@ export function reportPlatformFailures(
Use this variant to report failures in plugin code.
*/
export function reportPluginFailures(
promise: Promise<*>,
export function reportPluginFailures<T>(
promise: Promise<T>,
name: string,
plugin: string,
): Promise<*> {
): Promise<T> {
return promise.then(
fulfilledValue => {
getInstance().track('success-rate', name, 1, plugin);