From 944f292cb2c1bf90e882bd4a19ac823d3026540a Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 24 Apr 2017 14:01:22 +0200 Subject: [PATCH] Fix eslint issues and turn on prettier by default (#1195) * Automatically generate prop-types from Flow * Remove propTypes usage * Fix flow * Modify some eslint settings * Fix flowtype * Lint tweaks * use prop-types pkg * Run prettier * Fix flow * Fix few lint issues * Make eslint pass * Run lint on tests * Fix flow * Fixes * Alphabetical * Trailing comma: ES5 for website compat, also fix config/paths * Apply eslint --fix only to src now * Fix missing transitionconfig * Update TypeDefinition.js * New stuff * Unstage website and examples * reformat code * Update circle.yml --- packages/react-navigation/.eslintrc | 43 +- packages/react-navigation/circle.yml | 3 - packages/react-navigation/package.json | 7 +- .../react-navigation/src/NavigationActions.js | 35 +- .../src/PlatformHelpers.native.js | 11 +- packages/react-navigation/src/StateUtils.js | 14 +- .../react-navigation/src/TypeDefinition.js | 111 +++-- .../src/__tests__/NavigationActions-test.js | 42 +- .../__tests__/NavigationStateUtils-test.js | 161 +++++--- .../__tests__/addNavigationHelpers-test.js | 61 ++- .../src/addNavigationHelpers.js | 30 +- .../src/createNavigationContainer.js | 52 +-- .../src/navigators/DrawerNavigator.js | 62 +-- .../src/navigators/NavigatorTypes.js | 9 +- .../src/navigators/StackNavigator.js | 30 +- .../src/navigators/TabNavigator.js | 34 +- .../src/navigators/createNavigator.js | 19 +- .../react-navigation/src/react-navigation.js | 75 +++- .../src/react-navigation.web.js | 35 +- .../src/routers/StackRouter.js | 158 +++++--- .../react-navigation/src/routers/TabRouter.js | 99 +++-- .../src/routers/__tests__/Routers-test.js | 67 ++- .../src/routers/__tests__/StackRouter-test.js | 380 +++++++++++++----- .../src/routers/__tests__/TabRouter-test.js | 283 +++++++++---- .../__tests__/createConfigGetter-test.js | 107 +++-- .../__tests__/validateRouteConfigMap-test.js | 2 + .../src/routers/createConfigGetter.js | 23 +- .../src/routers/getScreenConfigDeprecated.js | 9 +- .../src/routers/getScreenForRouteName.js | 10 +- .../src/routers/validateRouteConfigMap.js | 49 ++- .../src/routers/validateScreenOptions.js | 73 ++-- packages/react-navigation/src/views/Card.js | 11 +- .../react-navigation/src/views/CardStack.js | 157 ++++---- .../src/views/CardStackStyleInterpolator.js | 38 +- .../src/views/CardStackTransitioner.js | 10 +- .../src/views/Drawer/DrawerNavigatorItems.js | 76 ++-- .../src/views/Drawer/DrawerScreen.js | 16 +- .../src/views/Drawer/DrawerSidebar.js | 24 +- .../src/views/Drawer/DrawerView.js | 49 ++- packages/react-navigation/src/views/Header.js | 57 +-- .../src/views/HeaderBackButton.js | 58 +-- .../src/views/HeaderStyleInterpolator.js | 14 +- .../react-navigation/src/views/HeaderTitle.js | 19 +- .../src/views/PointerEventsContainer.js | 14 +- .../react-navigation/src/views/SceneView.js | 6 +- .../src/views/ScenesReducer.js | 38 +- .../src/views/TabView/TabBarBottom.js | 63 +-- .../src/views/TabView/TabBarIcon.js | 14 +- .../src/views/TabView/TabBarTop.js | 50 ++- .../src/views/TabView/TabView.js | 99 ++--- .../src/views/TouchableItem.js | 35 +- .../src/views/TransitionConfigs.js | 43 +- .../src/views/Transitioner.js | 81 ++-- .../__tests__/NavigationScenesReducer-test.js | 54 ++- .../src/views/withNavigation.js | 11 +- .../src/withCachedChildNavigation.js | 12 +- packages/react-navigation/yarn.lock | 104 ++++- 57 files changed, 1983 insertions(+), 1264 deletions(-) diff --git a/packages/react-navigation/.eslintrc b/packages/react-navigation/.eslintrc index ed710b1e..6c83ced1 100644 --- a/packages/react-navigation/.eslintrc +++ b/packages/react-navigation/.eslintrc @@ -1,13 +1,27 @@ { - "extends": "airbnb", + "extends": [ + "airbnb", + "prettier", + "prettier/flowtype", + "prettier/react" + ], "parser": "babel-eslint", "plugins": [ - "flowtype" + "flowtype", + "prettier" ], "env": { "jasmine": true }, + "globals": { + "ReactClass": true + }, "rules": { + "prettier/prettier": ["error", { + "trailingComma": "all", + "singleQuote": true + }], + "no-underscore-dangle": 0, "no-use-before-define": 0, "no-unused-expressions": 0, @@ -36,11 +50,6 @@ 2, "boolean" ], - "flowtype/define-flow-type": 1, - "flowtype/generic-spacing": [ - 2, - "never" - ], "flowtype/no-weak-types": 1, "flowtype/require-parameter-type": 2, "flowtype/require-return-type": [ @@ -51,26 +60,6 @@ } ], "flowtype/require-valid-file-annotation": 2, - "flowtype/semi": [ - 2, - "always" - ], - "flowtype/space-after-type-colon": [ - 2, - "always" - ], - "flowtype/space-before-generic-bracket": [ - 2, - "never" - ], - "flowtype/space-before-type-colon": [ - 2, - "never" - ], - "flowtype/union-intersection-spacing": [ - 2, - "always" - ], "flowtype/use-flow-type": 1, "flowtype/valid-syntax": 1 }, diff --git a/packages/react-navigation/circle.yml b/packages/react-navigation/circle.yml index b6d7efeb..dffb3a4b 100644 --- a/packages/react-navigation/circle.yml +++ b/packages/react-navigation/circle.yml @@ -17,6 +17,3 @@ deployment: commands: - yarn run build-docs - ./scripts/deploy-website.sh -test: - pre: - - yarn run flow diff --git a/packages/react-navigation/package.json b/packages/react-navigation/package.json index 87e9684a..ac3956c6 100644 --- a/packages/react-navigation/package.json +++ b/packages/react-navigation/package.json @@ -27,8 +27,10 @@ "start": "node ./node_modules/react-native/local-cli/cli.js start --config ./rn-cli.config.js", "run-playground-ios": "cd examples/NavigationPlayground && react-native run-ios", "run-playground-android": "cd examples/NavigationPlayground && react-native run-android", - "test": "jest", + "test": "npm run lint && npm run flow && npm run jest", + "jest": "jest", "lint": "eslint src", + "format": "eslint --fix src", "flow": "flow", "prepublish": "npm run clean && npm run build" }, @@ -50,12 +52,15 @@ "babel-preset-stage-1": "^6.16.0", "eslint": "^3.17.1", "eslint-config-airbnb": "^14.1.0", + "eslint-config-prettier": "^1.5.0", "eslint-plugin-flowtype": "^2.30.3", "eslint-plugin-import": "^2.2.0", "eslint-plugin-jsx-a11y": "^4.0.0", + "eslint-plugin-prettier": "^2.0.1", "eslint-plugin-react": "^6.10.0", "flow-bin": "^0.40.0", "jest": "^19.0.2", + "prettier": "^0.22.0", "react": "16.0.0-alpha.6", "react-native": "^0.43.2", "react-native-vector-icons": "^3.0.0", diff --git a/packages/react-navigation/src/NavigationActions.js b/packages/react-navigation/src/NavigationActions.js index 5c911a1a..7e8158b3 100644 --- a/packages/react-navigation/src/NavigationActions.js +++ b/packages/react-navigation/src/NavigationActions.js @@ -7,10 +7,11 @@ const RESET = namespacedAction('RESET'); const SET_PARAMS = namespacedAction('SET_PARAMS'); const URI = namespacedAction('URI'); -const createAction = (type: string) => (payload: object = {}) => ({ - type, - ...payload, -}); +const createAction = (type: string) => + (payload: Object = {}) => ({ + type, + ...payload, + }); const back = createAction(BACK); const init = createAction(INIT); @@ -28,19 +29,23 @@ const deprecatedActionMap = { Uri: URI, }; -const mapDeprecatedActionAndWarn = (action: object) => { +const mapDeprecatedActionAndWarn = (action: Object) => { const mappedType = deprecatedActionMap[action.type]; - if (!mappedType) { return action; } + if (!mappedType) { + return action; + } - console.warn([ - `The action type '${action.type}' has been renamed to '${mappedType}'.`, - `'${action.type}' will continue to work while in beta but will be removed`, - 'in the first major release. Moving forward, you should use the', - 'action constants and action creators exported by this library in', - "the 'actions' object.", - 'See https://github.com/react-community/react-navigation/pull/120 for', - 'more details.', - ].join(' ')); + console.warn( + [ + `The action type '${action.type}' has been renamed to '${mappedType}'.`, + `'${action.type}' will continue to work while in beta but will be removed`, + 'in the first major release. Moving forward, you should use the', + 'action constants and action creators exported by this library in', + "the 'actions' object.", + 'See https://github.com/react-community/react-navigation/pull/120 for', + 'more details.', + ].join(' '), + ); return { ...action, diff --git a/packages/react-navigation/src/PlatformHelpers.native.js b/packages/react-navigation/src/PlatformHelpers.native.js index 13196408..8c59c95a 100644 --- a/packages/react-navigation/src/PlatformHelpers.native.js +++ b/packages/react-navigation/src/PlatformHelpers.native.js @@ -1,12 +1,5 @@ /* @flow */ -import { - BackAndroid, - Linking, -} from 'react-native'; - -export { - BackAndroid, - Linking, -}; +import { BackAndroid, Linking } from 'react-native'; +export { BackAndroid, Linking }; diff --git a/packages/react-navigation/src/StateUtils.js b/packages/react-navigation/src/StateUtils.js index c553e52b..3a686ad7 100644 --- a/packages/react-navigation/src/StateUtils.js +++ b/packages/react-navigation/src/StateUtils.js @@ -2,10 +2,7 @@ import invariant from 'fbjs/lib/invariant'; -import type { - NavigationRoute, - NavigationState, -} from './TypeDefinition'; +import type { NavigationRoute, NavigationState } from './TypeDefinition'; /** * Utilities to perform atomic operation with navigate state and routes. @@ -16,12 +13,11 @@ import type { * ``` */ const StateUtils = { - /** * Gets a route by key. If the route isn't found, returns `null`. */ get(state: NavigationState, key: string): ?NavigationRoute { - return state.routes.find(route => route.key === key) || null; + return state.routes.find((route: *) => route.key === key) || null; }, /** @@ -29,7 +25,7 @@ const StateUtils = { * routes of the navigation state, or -1 if it is not present. */ indexOf(state: NavigationState, key: string): number { - return state.routes.map(route => route.key).indexOf(key); + return state.routes.map((route: *) => route.key).indexOf(key); }, /** @@ -37,7 +33,7 @@ const StateUtils = { * routes of the navigation state. */ has(state: NavigationState, key: string): boolean { - return !!state.routes.some(route => route.key === key); + return !!state.routes.some((route: *) => route.key === key); }, /** @@ -185,7 +181,7 @@ const StateUtils = { const nextIndex: number = index === undefined ? routes.length - 1 : index; if (state.routes.length === routes.length && state.index === nextIndex) { - const compare = (route, ii) => routes[ii] === route; + const compare = (route: *, ii: *) => routes[ii] === route; if (state.routes.every(compare)) { return state; } diff --git a/packages/react-navigation/src/TypeDefinition.js b/packages/react-navigation/src/TypeDefinition.js index f9dcadf7..35916beb 100644 --- a/packages/react-navigation/src/TypeDefinition.js +++ b/packages/react-navigation/src/TypeDefinition.js @@ -11,7 +11,9 @@ export type HeaderMode = 'float' | 'screen' | 'none'; export type HeaderProps = NavigationSceneRendererProps & { mode: HeaderMode, router: NavigationRouter, - getScreenDetails: NavigationScene => NavigationScreenDetails, + getScreenDetails: ( + NavigationScene, + ) => NavigationScreenDetails, }; /** @@ -75,18 +77,21 @@ export type NavigationRouter = { * an optional previous state. When the action is considered handled but the * state is unchanged, the output state is null. */ - getStateForAction: ( - action: Action, - lastState: ?State, - ) => ?State, + getStateForAction: (action: Action, lastState: ?State) => ?State, /** * Maps a URI-like string to an action. This can be mapped to a state * using `getStateForAction`. */ - getActionForPathAndParams: (path: string, params?: NavigationParams) => ?Action, + getActionForPathAndParams: ( + path: string, + params?: NavigationParams, + ) => ?Action, - getPathAndParamsForState: (state: State) => {path: string, params?: NavigationParams}, + getPathAndParamsForState: (state: State) => { + path: string, + params?: NavigationParams, + }, getComponentForRouteName: (routeName: string) => NavigationComponent, @@ -100,15 +105,23 @@ export type NavigationRouter = { * * {routeName: 'Foo', key: '123'} */ - getScreenOptions: NavigationScreenOptionsGetter + getScreenOptions: NavigationScreenOptionsGetter, }; export type NavigationScreenOption = | T - | (navigation: NavigationScreenProp, - config: T) => T; + | (( + navigation: NavigationScreenProp, + config: T, + ) => T); -export type Style = { [key: string]: any } | number | false | null | void | Array