Skip to content

Commit

Permalink
Suppress missing annotations in xplat/js
Browse files Browse the repository at this point in the history
Summary: Add annotations to function parameters required for Flow's Local Type Inference project. This codemod prepares the codebase to match Flow's new typechecking algorithm. The new algorithm will make Flow more reliable and predictable.

Reviewed By: bradzacher

Differential Revision: D37388949

fbshipit-source-id: cdcbc98035ce9b6994842005ea46df42de54f9b8
  • Loading branch information
pieterv authored and facebook-github-bot committed Jun 23, 2022
1 parent e549227 commit 66c6a75
Show file tree
Hide file tree
Showing 37 changed files with 118 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Libraries/Alert/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class Alert {
config.buttonPositive = buttonPositive.text || defaultPositiveText;
}

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by
* Flow's LTI update could not be added via codemod */
const onAction = (action, buttonKey) => {
if (action === constants.buttonClicked) {
if (buttonKey === constants.buttonNeutral) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ class DrawerLayoutAndroid extends React.Component<Props, State> {
);
}

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
_onDrawerSlide = event => {
if (this.props.onDrawerSlide) {
this.props.onDrawerSlide(event);
Expand All @@ -253,6 +255,8 @@ class DrawerLayoutAndroid extends React.Component<Props, State> {
}
};

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
_onDrawerStateChanged = event => {
if (this.props.onDrawerStateChanged) {
this.props.onDrawerStateChanged(
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Components/Pressable/Pressable.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ type Props = $ReadOnly<{|
* Component used to build display components that should respond to whether the
* component is currently pressed or not.
*/
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function Pressable(props: Props, forwardedRef): React.Node {
const {
accessible,
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,8 @@ const styles = StyleSheet.create({
},
});

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function Wrapper(props, ref: (mixed => mixed) | {current: mixed, ...}) {
return <ScrollView {...props} scrollViewRef={ref} />;
}
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Components/ScrollView/ScrollViewStickyHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class ScrollViewStickyHeader extends React.Component<Props, State> {
}
};

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
_setComponentRef = ref => {
this._ref = ref;
};
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Components/Touchable/PooledClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const fourArgumentPooler = function (a1: any, a2: any, a3: any, a4: any) {
}
};

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
const standardReleaser = function (instance) {
const Klass = this; // eslint-disable-line consistent-this
invariant(
Expand Down
8 changes: 6 additions & 2 deletions Libraries/Components/Touchable/TouchableNativeFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,15 @@ class TouchableNativeFeedback extends React.Component<Props, State> {

const getBackgroundProp =
Platform.OS === 'android'
? (background, useForeground: boolean) =>
? /* $FlowFixMe[missing-local-annot] The type annotation(s) required by
* Flow's LTI update could not be added via codemod */
(background, useForeground: boolean) =>
useForeground && TouchableNativeFeedback.canUseNativeForeground()
? {nativeForegroundAndroid: background}
: {nativeBackgroundAndroid: background}
: (background, useForeground: boolean) => null;
: /* $FlowFixMe[missing-local-annot] The type annotation(s) required by
* Flow's LTI update could not be added via codemod */
(background, useForeground: boolean) => null;

TouchableNativeFeedback.displayName = 'TouchableNativeFeedback';

Expand Down
2 changes: 2 additions & 0 deletions Libraries/Core/ExceptionsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ function handleException(e: mixed, isFatal: boolean) {
}
}

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function reactConsoleErrorHandler(...args) {
// bubble up to any original handlers
console._errorOriginal(...args);
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Core/setUpBatchedBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ if (global.RN$Bridgeless === true && global.RN$registerCallableModule) {
| $TEMPORARY$string<'RCTNativeAppEventEmitter'>
| $TEMPORARY$string<'SamplingProfiler'>
| $TEMPORARY$string<'Systrace'>,
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by
* Flow's LTI update could not be added via codemod */
factory,
) => BatchedBridge.registerLazyCallableModule(moduleName, factory);
}
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Image/Image.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ export type ImageComponentStatics = $ReadOnly<{|
*
* See https://reactnative.dev/docs/image
*/
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
const BaseImage = (props: ImagePropsType, forwardedRef) => {
let source = resolveAssetSource(props.source);
const defaultSource = resolveAssetSource(props.defaultSource);
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Image/Image.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export type ImageComponentStatics = $ReadOnly<{|
*
* See https://reactnative.dev/docs/image
*/
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
const BaseImage = (props: ImagePropsType, forwardedRef) => {
const source = resolveAssetSource(props.source) || {
uri: undefined,
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Lists/SectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ export default class SectionList<
}

_wrapperListRef: ?React.ElementRef<typeof VirtualizedSectionList>;
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
_captureRef = ref => {
this._wrapperListRef = ref;
};
Expand Down
4 changes: 4 additions & 0 deletions Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,8 @@ class VirtualizedList extends React.PureComponent<Props, State> {
_updateCellsToRenderBatcher: Batchinator;
_viewabilityTuples: Array<ViewabilityHelperCallbackTuple> = [];

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
_captureScrollRef = ref => {
this._scrollRef = ref;
};
Expand All @@ -1253,6 +1255,8 @@ class VirtualizedList extends React.PureComponent<Props, State> {
);
}

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
_defaultRenderScrollComponent = props => {
const onRefresh = props.onRefresh;
if (this._isNestedWithSameOrientation()) {
Expand Down
2 changes: 2 additions & 0 deletions Libraries/LogBox/LogBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ if (__DEV__) {
}
};

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
const registerError = (...args): void => {
// Let errors within LogBox itself fall through.
if (LogBoxData.isLogBoxErrorMessage(args[0])) {
Expand Down
2 changes: 2 additions & 0 deletions Libraries/LogBox/UI/AnsiHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export default function Ansi({
}
});

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
const getText = (content, key) => {
if (key === 1) {
// Remove the vertical bar after line numbers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ StaticViewConfigValidator: Invalid static view config for 'RCTView'.

function expectSVCToNotMatchNVC(
name: string,
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
nativeViewConfig,
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
staticViewConfig,
message: string,
) {
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Pressability/__tests__/Pressability-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ function getMock<TArguments: $ReadOnlyArray<mixed>, TReturn>(
return (fn: $FlowFixMe);
}

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
const createMockPressability = overrides => {
const config = {
cancelable: null,
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Storage/AsyncStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ function convertErrors(

declare function convertError(void | null): null;
declare function convertError({message: string, key?: string}): Error;
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function convertError(error) {
if (!error) {
return null;
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Utilities/__tests__/useMergeRefs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {act, create} from 'react-test-renderer';
/**
* TestView provide a component execution environment to test hooks.
*/
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function TestView({name, refs}) {
const mergeRef = useMergeRefs(...refs);
return <View ref={mergeRef} testID={name} />;
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ function deepFreezeAndThrowOnMutationInDev<T: {...} | Array<mixed>>(
return object;
}

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function throwOnImmutableMutation(key: empty, value) {
throw Error(
'You attempted to set the key `' +
Expand Down
2 changes: 2 additions & 0 deletions ReactAndroid/src/androidTest/js/UIManagerTestModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ class UpdatePositionInListTestApp extends React.Component<
active: false,
};

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
constructor(...args) {
super(...args);
flushUpdatePositionInList = () => this.setState({active: true});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import type {
} from '../../../CodegenSchema.js';

function getPropertyType(
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
name,
optional: boolean,
typeAnnotation: $FlowFixMe,
Expand Down Expand Up @@ -151,6 +153,8 @@ function findEventArgumentsAndType(
}
}
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function buildPropertiesForEvent(property): NamedShape<EventTypeAnnotation> {
const name = property.key.name;
const optional =
Expand All @@ -163,6 +167,8 @@ function buildPropertiesForEvent(property): NamedShape<EventTypeAnnotation> {
return getPropertyType(name, optional, typeAnnotation);
}
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function getEventArgument(argumentProps, name: $FlowFixMe) {
return {
type: 'ObjectTypeAnnotation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const {getExtendsProps, removeKnownExtends} = require('./extends');
const {getCommandOptions, getOptions} = require('./options');
const {getPropProperties, getProps} = require('./props');

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function findComponentConfig(ast) {
const foundConfigs = [];

Expand Down Expand Up @@ -123,6 +125,8 @@ function findComponentConfig(ast) {
}

function getCommandProperties(
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
commandTypeName,
types: TypeDeclarationMap,
commandOptions: ?CommandOptions,
Expand Down Expand Up @@ -175,6 +179,8 @@ function getCommandProperties(
}

// $FlowFixMe[signature-verification-failure] there's no flowtype for AST
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function buildComponentSchema(ast): ComponentSchemaBuilderConfig {
const {
componentName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ import type {
} from '../../../CodegenSchema.js';

function getPropertyType(
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
name,
optional: boolean,
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
typeAnnotation,
): NamedShape<EventTypeAnnotation> {
const type =
Expand Down Expand Up @@ -169,6 +173,8 @@ function findEventArgumentsAndType(
}
}
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function buildPropertiesForEvent(property): NamedShape<EventTypeAnnotation> {
const name = property.key.name;
const optional = property.optional || false;
Expand All @@ -177,6 +183,8 @@ function buildPropertiesForEvent(property): NamedShape<EventTypeAnnotation> {
return getPropertyType(name, optional, typeAnnotation);
}
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function getEventArgument(argumentProps, name: $FlowFixMe) {
return {
type: 'ObjectTypeAnnotation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const {getExtendsProps, removeKnownExtends} = require('./extends');
const {getCommandOptions, getOptions} = require('./options');
const {getPropProperties, getProps} = require('./props');

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function findComponentConfig(ast) {
const foundConfigs = [];

Expand Down Expand Up @@ -123,6 +125,8 @@ function findComponentConfig(ast) {
}

function getCommandProperties(
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
commandTypeName,
types: TypeDeclarationMap,
commandOptions: ?CommandOptions,
Expand Down Expand Up @@ -176,6 +180,8 @@ function getCommandProperties(
}

// $FlowFixMe[signature-verification-failure] TODO(T108222691): Use flow-types for @babel/parser
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function buildComponentSchema(ast): ComponentSchemaBuilderConfig {
const {
componentName,
Expand Down
4 changes: 4 additions & 0 deletions packages/rn-tester/js/components/RNTesterModuleList.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const {

import {RNTesterThemeContext} from './RNTesterTheme';

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
const ExampleModuleRow = ({
onShowUnderlay,
onHideUnderlay,
Expand Down Expand Up @@ -123,6 +125,8 @@ const RNTesterModuleList: React$AbstractComponent<any, void> = React.memo(
(!category || example.category === category) &&
(!Platform.isTV || example.supportsTVOS);

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by
* Flow's LTI update could not be added via codemod */
const renderListItem = ({item, section, separators}) => {
return (
<ExampleModuleRow
Expand Down
2 changes: 2 additions & 0 deletions packages/rn-tester/js/components/RNTesterNavbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const BookmarkTab = ({
</View>
);

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
const NavbarButton = ({
testID,
theme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ class AnExApp extends React.Component<any, any> {
} else {
let onLayout = null;
if (!this.state.restLayouts[idx]) {
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by
* Flow's LTI update could not be added via codemod */
onLayout = function (index, e) {
const layout = e.nativeEvent.layout;
this.setState(state => {
Expand Down
4 changes: 4 additions & 0 deletions packages/rn-tester/js/examples/FlatList/FlatList-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class FlatListExample extends React.PureComponent<Props, State> {
isRTL: IS_RTL,
};

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
_onChangeFilterText = filterText => {
this.setState({filterText});
};
Expand Down Expand Up @@ -297,6 +299,8 @@ class FlatListExample extends React.PureComponent<Props, State> {
/* $FlowFixMe[invalid-computed-prop] (>=0.111.0 site=react_native_fb)
* This comment suppresses an error found when Flow v0.111 was deployed.
* To see the error, delete this comment and run Flow. */
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by
* Flow's LTI update could not be added via codemod */
[flatListPropKey]: ({item, separators}) => {
return (
<ItemComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class MultiColumnExample extends React.PureComponent<
numColumns: 2,
virtualized: true,
};
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
_onChangeFilterText = filterText => {
this.setState(() => ({filterText}));
};
Expand Down
Loading

0 comments on commit 66c6a75

Please sign in to comment.