From 08438b6911887b6b6967b22f75e9b939a3847f98 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Mon, 17 Jul 2017 16:32:47 -0700 Subject: [PATCH] Add flow to project --- .babelrc | 3 +- .eslintignore | 3 +- .eslintrc | 7 +++- .flowconfig | 14 +++++++ app/ui/components/response-pane.js | 67 +++++++++++++----------------- flow-typed/autobind-decorator.js | 4 ++ flow-typed/electron.js | 6 +++ flow-typed/mime-types.js | 4 ++ flow-typed/react-tabs.js | 10 +++++ package-lock.json | 18 ++++++++ package.json | 4 ++ 11 files changed, 99 insertions(+), 41 deletions(-) create mode 100644 .flowconfig create mode 100644 flow-typed/autobind-decorator.js create mode 100644 flow-typed/electron.js create mode 100644 flow-typed/mime-types.js create mode 100644 flow-typed/react-tabs.js diff --git a/.babelrc b/.babelrc index 9e527253d..84dadca19 100644 --- a/.babelrc +++ b/.babelrc @@ -1,6 +1,7 @@ { "presets": [ - "react" + "react", + "flow" ], "plugins": [ "transform-object-rest-spread", diff --git a/.eslintignore b/.eslintignore index 224cf9cbc..ea1d9a6e5 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,4 +4,5 @@ dist/**/* coverage/**/* node_modules/**/* webpack/**/* -**/__fixtures__/prettify/* \ No newline at end of file +**/__fixtures__/prettify/* +flow-typed/**/* \ No newline at end of file diff --git a/.eslintrc b/.eslintrc index 7f892224a..fe3614f1d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,7 @@ { "parser": "babel-eslint", "extends": ["semistandard"], - "plugins": ["react", "jest", "html", "json", "filenames"], + "plugins": ["flowtype", "react", "jest", "html", "json", "filenames"], "parserOptions": { "ecmaFeatures": { "jsx": true @@ -19,5 +19,10 @@ "react/jsx-uses-vars": "error", "react/prop-types": "error", "filenames/match-exported": ["error", "kebab"] + }, + "settings": { + "flowtype": { + "onlyFilesWithFlowAnnotation": false + } } } diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 000000000..c25e6ac2f --- /dev/null +++ b/.flowconfig @@ -0,0 +1,14 @@ + +[ignore] +.*/node_modules/.* +.*/__fixtures__/.* + +[include] + +[libs] +flow-typed/.* + +[options] +esproposal.decorators=ignore + +[lints] \ No newline at end of file diff --git a/app/ui/components/response-pane.js b/app/ui/components/response-pane.js index 806a313f9..4bb4460b0 100644 --- a/app/ui/components/response-pane.js +++ b/app/ui/components/response-pane.js @@ -1,4 +1,5 @@ -import React, {PropTypes, PureComponent} from 'react'; +// @flow +import React, {PureComponent} from 'react'; import autobind from 'autobind-decorator'; import fs from 'fs'; import mime from 'mime-types'; @@ -24,7 +25,33 @@ import Hotkey from './hotkey'; @autobind class ResponsePane extends PureComponent { - _trackTab (name) { + props: { + // Functions + handleSetFilter: Function, + showCookiesModal: Function, + handleSetPreviewMode: Function, + handleSetActiveResponse: Function, + handleDeleteResponses: Function, + handleDeleteResponse: Function, + handleShowRequestSettings: Function, + + // Required + previewMode: string, + filter: string, + filterHistory: Array, + editorFontSize: number, + editorIndentSize: number, + editorKeyMap: string, + editorLineWrapping: boolean, + loadStartTime: number, + responses: Array, + + // Other + request?: Object, + response?: Object + }; + + _trackTab (name: string) { trackEvent('Response Pane', 'View', name); } @@ -32,16 +59,6 @@ class ResponsePane extends PureComponent { return models.response.getBodyBuffer(this.props.response); } - async _getResponse (requestId, responseId) { - let response = responseId ? await models.response.getById(responseId) : null; - - if (!response) { - response = await models.response.getLatestForRequest(requestId); - } - - this.setState({response}); - } - async _handleDownloadResponseBody () { if (!this.props.response) { // Should never happen @@ -314,30 +331,4 @@ class ResponsePane extends PureComponent { } } -ResponsePane.propTypes = { - // Functions - handleSetFilter: PropTypes.func.isRequired, - showCookiesModal: PropTypes.func.isRequired, - handleSetPreviewMode: PropTypes.func.isRequired, - handleSetActiveResponse: PropTypes.func.isRequired, - handleDeleteResponses: PropTypes.func.isRequired, - handleDeleteResponse: PropTypes.func.isRequired, - handleShowRequestSettings: PropTypes.func.isRequired, - - // Required - previewMode: PropTypes.string.isRequired, - filter: PropTypes.string.isRequired, - filterHistory: PropTypes.arrayOf(PropTypes.string.isRequired).isRequired, - editorFontSize: PropTypes.number.isRequired, - editorIndentSize: PropTypes.number.isRequired, - editorKeyMap: PropTypes.string.isRequired, - editorLineWrapping: PropTypes.bool.isRequired, - loadStartTime: PropTypes.number.isRequired, - responses: PropTypes.arrayOf(PropTypes.object), - - // Other - request: PropTypes.object, - response: PropTypes.object -}; - export default ResponsePane; diff --git a/flow-typed/autobind-decorator.js b/flow-typed/autobind-decorator.js new file mode 100644 index 000000000..ee94d8c72 --- /dev/null +++ b/flow-typed/autobind-decorator.js @@ -0,0 +1,4 @@ +// @flow +declare module 'autobind-decorator' { + declare module.exports: * +} diff --git a/flow-typed/electron.js b/flow-typed/electron.js new file mode 100644 index 000000000..009e13a06 --- /dev/null +++ b/flow-typed/electron.js @@ -0,0 +1,6 @@ +// @flow +declare module 'electron' { + declare module.exports: { + remote: * + } +} diff --git a/flow-typed/mime-types.js b/flow-typed/mime-types.js new file mode 100644 index 000000000..862c7cbda --- /dev/null +++ b/flow-typed/mime-types.js @@ -0,0 +1,4 @@ +// @flow +declare module 'mime-types' { + declare module.exports: * +} diff --git a/flow-typed/react-tabs.js b/flow-typed/react-tabs.js new file mode 100644 index 000000000..9793eb727 --- /dev/null +++ b/flow-typed/react-tabs.js @@ -0,0 +1,10 @@ +import type {Component} from 'react-flow-types'; + +declare module 'react-tabs' { + declare module.exports: { + Tab: Component, + TabList: Component, + TabPanel: Component, + Tabs: Component + } +} diff --git a/package-lock.json b/package-lock.json index 435d42c83..a62a9a305 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2365,6 +2365,12 @@ } } }, + "eslint-plugin-flowtype": { + "version": "2.35.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.35.0.tgz", + "integrity": "sha512-zjXGjOsHds8b84C0Ad3VViKh+sUA9PeXKHwPRlSLwwSX0v1iUJf/6IX7wxc+w2T2tnDH8PT6B/YgtcEuNI3ssA==", + "dev": true + }, "eslint-plugin-html": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/eslint-plugin-html/-/eslint-plugin-html-2.0.1.tgz", @@ -2700,6 +2706,12 @@ "integrity": "sha1-2uRqnXj74lKSJYzB54CkHZXAN4I=", "dev": true }, + "flow-bin": { + "version": "0.50.0", + "resolved": "https://registry.npmjs.org/flow-bin/-/flow-bin-0.50.0.tgz", + "integrity": "sha1-1M2yQw3uGjWZ8Otv5VEUbjAnJWo=", + "dev": true + }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", @@ -6182,6 +6194,12 @@ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-15.4.2.tgz", "integrity": "sha1-AVNj8FsKH9Uq6e/dOgBg2QaVII8=" }, + "react-flow-types": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/react-flow-types/-/react-flow-types-0.1.1.tgz", + "integrity": "sha1-56L3eE1cI09z3RFzs1TxyGviMXk=", + "dev": true + }, "react-hot-loader": { "version": "3.0.0-beta.6", "resolved": "https://registry.npmjs.org/react-hot-loader/-/react-hot-loader-3.0.0-beta.6.tgz", diff --git a/package.json b/package.json index b2d8c2260..b8bc51968 100644 --- a/package.json +++ b/package.json @@ -163,6 +163,7 @@ "babel-plugin-transform-runtime": "^6.15.0", "babel-polyfill": "^6.23.0", "babel-preset-es2015": "^6.22.0", + "babel-preset-flow": "^6.23.0", "babel-preset-react": "^6.23.0", "babel-preset-react-hmre": "^1.1.1", "concurrently": "^2.0.0", @@ -175,6 +176,7 @@ "eslint-config-semistandard": "^7.0.0", "eslint-config-standard": "^7.0.0", "eslint-plugin-filenames": "^1.1.0", + "eslint-plugin-flowtype": "^2.35.0", "eslint-plugin-html": "^2.0.1", "eslint-plugin-jest": "^19.0.1", "eslint-plugin-json": "^1.2.0", @@ -182,9 +184,11 @@ "eslint-plugin-react": "^6.10.0", "eslint-plugin-standard": "^2.1.1", "file-loader": "^0.10.1", + "flow-bin": "^0.50.0", "jest": "^19.0.2", "less": "^2.7.2", "less-loader": "^2.2.3", + "react-flow-types": "^0.1.1", "react-hot-loader": "^3.0.0-beta.6", "redux-mock-store": "^1.0.2", "style-loader": "^0.13.2",