diff --git a/.eslintrc b/.eslintrc index ed710b1..6c83ced 100644 --- a/.eslintrc +++ b/.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/circle.yml b/circle.yml index b6d7efe..dffb3a4 100644 --- a/circle.yml +++ b/circle.yml @@ -17,6 +17,3 @@ deployment: commands: - yarn run build-docs - ./scripts/deploy-website.sh -test: - pre: - - yarn run flow diff --git a/package.json b/package.json index 87e9684..ac3956c 100644 --- a/package.json +++ b/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/src/NavigationActions.js b/src/NavigationActions.js index 5c911a1..7e8158b 100644 --- a/src/NavigationActions.js +++ b/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/src/PlatformHelpers.native.js b/src/PlatformHelpers.native.js index 1319640..8c59c95 100644 --- a/src/PlatformHelpers.native.js +++ b/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/src/StateUtils.js b/src/StateUtils.js index c553e52..3a686ad 100644 --- a/src/StateUtils.js +++ b/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/src/TypeDefinition.js b/src/TypeDefinition.js index f9dcadf..35916be 100644 --- a/src/TypeDefinition.js +++ b/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