From cecacbc3ac995e9037e1f87fd3c796e4938dd1a3 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Wed, 6 May 2020 18:08:55 -0700 Subject: [PATCH] Add eslint-plugin-flowtype --- .eslintrc | 30 +++++------------ package.json | 1 + packages/benchmarks/src/app/ReportCard.js | 2 ++ packages/benchmarks/src/impl.js | 2 ++ .../FlatList/examples/MultiColumn.js | 2 +- .../FlatList/examples/SingleColumn.js | 2 ++ .../components/FlatList/examples/shared.js | 2 ++ .../TextInput/examples/OnSelectionChange.js | 4 +++ .../src/exports/Image/index.js | 21 ++---------- .../src/exports/Image/types.js | 32 +++++++++++++++++-- yarn.lock | 7 ++++ 11 files changed, 62 insertions(+), 43 deletions(-) diff --git a/.eslintrc b/.eslintrc index 874dbebd..e0c37712 100644 --- a/.eslintrc +++ b/.eslintrc @@ -17,41 +17,23 @@ "sourceType": "module" }, "extends": [ + "plugin:flowtype/recommended", "prettier", "prettier/react" ], "plugins": [ + "flowtype", "promise", "react", "react-hooks" ], "env": { + "browser": true, "es6": true, "node": true }, "globals": { - "document": false, - "navigator": false, - "window": false, - // Flow global types, - "$Diff": false, - "$ElementType": false, - "$Enum": false, - "$PropertyType": false, - "$ReadOnly": false, - "$ReadOnlyArray": false, - "CSSStyleSheet": false, - "HTMLElement": false, - "HTMLInputElement": false, - "ReactClass": false, - "ReactComponent": false, - "ReactElement": false, - "ReactPropsChainableTypeChecker": false, - "ReactPropsCheckType": false, - "ReactPropTypes": false, - "ResizeObserver": false, - "SyntheticEvent": false, - "TimeoutID": false, + }, "rules": { "camelcase": 0, @@ -141,6 +123,10 @@ "valid-typeof": 2, "yoda": [2, "never"], + // flow + "flowtype/generic-spacing": 0, + "flowtype/space-after-type-colon": 0, + // promise "promise/param-names": 2, diff --git a/package.json b/package.json index ce2f3f6c..54a75f0a 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "del-cli": "^3.0.0", "eslint": "^6.5.1", "eslint-config-prettier": "^6.4.0", + "eslint-plugin-flowtype": "^4.7.0", "eslint-plugin-promise": "^4.2.1", "eslint-plugin-react": "^7.16.0", "eslint-plugin-react-hooks": "^2.3.0", diff --git a/packages/benchmarks/src/app/ReportCard.js b/packages/benchmarks/src/app/ReportCard.js index bd261eca..cff98596 100644 --- a/packages/benchmarks/src/app/ReportCard.js +++ b/packages/benchmarks/src/app/ReportCard.js @@ -1,3 +1,5 @@ +/* @noflow */ + import Text from './Text'; import { StyleSheet, View } from 'react-native'; import React, { Fragment } from 'react'; diff --git a/packages/benchmarks/src/impl.js b/packages/benchmarks/src/impl.js index 76a6c9f4..36f367f0 100644 --- a/packages/benchmarks/src/impl.js +++ b/packages/benchmarks/src/impl.js @@ -1,3 +1,5 @@ +/* @noflow */ + import { type Component } from 'react'; import packageJson from '../package.json'; diff --git a/packages/docs/src/components/FlatList/examples/MultiColumn.js b/packages/docs/src/components/FlatList/examples/MultiColumn.js index 3caeb9f2..94f52ea1 100644 --- a/packages/docs/src/components/FlatList/examples/MultiColumn.js +++ b/packages/docs/src/components/FlatList/examples/MultiColumn.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @providesModule MultiColumnExample + * @noflow */ 'use strict'; diff --git a/packages/docs/src/components/FlatList/examples/SingleColumn.js b/packages/docs/src/components/FlatList/examples/SingleColumn.js index 73c45239..0a31deea 100644 --- a/packages/docs/src/components/FlatList/examples/SingleColumn.js +++ b/packages/docs/src/components/FlatList/examples/SingleColumn.js @@ -3,6 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @noflow */ 'use strict'; diff --git a/packages/docs/src/components/FlatList/examples/shared.js b/packages/docs/src/components/FlatList/examples/shared.js index 5b8c142d..eb6a30be 100644 --- a/packages/docs/src/components/FlatList/examples/shared.js +++ b/packages/docs/src/components/FlatList/examples/shared.js @@ -3,6 +3,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @noflow */ 'use strict'; diff --git a/packages/docs/src/components/TextInput/examples/OnSelectionChange.js b/packages/docs/src/components/TextInput/examples/OnSelectionChange.js index 07b9c2d4..82b4bbd1 100644 --- a/packages/docs/src/components/TextInput/examples/OnSelectionChange.js +++ b/packages/docs/src/components/TextInput/examples/OnSelectionChange.js @@ -1,3 +1,7 @@ +/** + * @noflow + */ + import React from 'react'; import { styles } from '../helpers'; import { Text, TextInput, View } from 'react-native'; diff --git a/packages/react-native-web/src/exports/Image/index.js b/packages/react-native-web/src/exports/Image/index.js index d6c0ae0f..75fe13d3 100644 --- a/packages/react-native-web/src/exports/Image/index.js +++ b/packages/react-native-web/src/exports/Image/index.js @@ -8,8 +8,7 @@ * @flow */ -import type { ViewProps } from '../View'; -import type { ResizeMode, Source, Style } from './types'; +import type { ImageProps } from './types'; import createElement from '../createElement'; import css from '../StyleSheet/css'; @@ -22,21 +21,7 @@ import TextAncestorContext from '../Text/TextAncestorContext'; import View from '../View'; import React, { forwardRef, useContext, useEffect, useRef, useState } from 'react'; -export type ImageProps = { - ...ViewProps, - blurRadius?: number, - defaultSource?: Source, - draggable?: boolean, - onError?: (e: any) => void, - onLayout?: (e: any) => void, - onLoad?: (e: any) => void, - onLoadEnd?: (e: any) => void, - onLoadStart?: (e: any) => void, - onProgress?: (e: any) => void, - resizeMode?: ResizeMode, - source: Source, - style?: Style -}; +export type { ImageProps }; const ERRORED = 'ERRORED'; const LOADED = 'LOADED'; @@ -108,7 +93,7 @@ function resolveAssetDimensions(source) { if (typeof source === 'number') { const { height, width } = getAssetByID(source); return { height, width }; - } else if (source != null && typeof source === 'object') { + } else if (source != null && !Array.isArray(source) && typeof source === 'object') { const { height, width } = source; return { height, width }; } diff --git a/packages/react-native-web/src/exports/Image/types.js b/packages/react-native-web/src/exports/Image/types.js index 8d4c507b..b80a2160 100644 --- a/packages/react-native-web/src/exports/Image/types.js +++ b/packages/react-native-web/src/exports/Image/types.js @@ -1,4 +1,16 @@ -import type { ColorValue } from '../../types'; +/** + * Copyright (c) Nicolas Gallagher. + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + */ + +import type { ColorValue, GenericStyleProp } from '../../types'; +import type { ViewProps } from '../View/types'; + import type { AnimationStyles, BorderStyles, @@ -69,7 +81,7 @@ export type ResizeMode = 'center' | 'contain' | 'cover' | 'none' | 'repeat' | 's export type Source = number | string | SourceObject | Array; -export type Style = { +export type ImageStyle = { ...AnimationStyles, ...BorderStyles, ...InteractionStyles, @@ -83,3 +95,19 @@ export type Style = { resizeMode?: ResizeMode, tintColor?: ColorValue }; + +export type ImageProps = { + ...ViewProps, + blurRadius?: number, + defaultSource?: Source, + draggable?: boolean, + onError?: (e: any) => void, + onLayout?: (e: any) => void, + onLoad?: (e: any) => void, + onLoadEnd?: (e: any) => void, + onLoadStart?: (e: any) => void, + onProgress?: (e: any) => void, + resizeMode?: ResizeMode, + source: Source, + style?: GenericStyleProp +}; diff --git a/yarn.lock b/yarn.lock index 3674c324..6c10a9a0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6875,6 +6875,13 @@ eslint-config-prettier@^6.4.0: dependencies: get-stdin "^6.0.0" +eslint-plugin-flowtype@^4.7.0: + version "4.7.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-4.7.0.tgz#903a6ea3eb5cbf4c7ba7fa73cc43fc39ab7e4a70" + integrity sha512-M+hxhSCk5QBEValO5/UqrS4UunT+MgplIJK5wA1sCtXjzBcZkpTGRwxmLHhGpbHcrmQecgt6ZL/KDdXWqGB7VA== + dependencies: + lodash "^4.17.15" + eslint-plugin-promise@^4.2.1: version "4.2.1" resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-4.2.1.tgz#845fd8b2260ad8f82564c1222fce44ad71d9418a"