From d14c57c8b621ef23304b643a1c00e17739232d74 Mon Sep 17 00:00:00 2001 From: Mohammad Rajabifard Date: Thu, 14 Sep 2017 23:49:46 +0430 Subject: [PATCH] refactor: run prettier standard on all files --- components/ConversionPanel.js | 295 ++-- components/Layout.js | 208 +-- pages/css-to-js.js | 34 +- pages/graphql-to-flow.js | 39 +- pages/graphql-to-typescript.js | 39 +- pages/html-to-jsx.js | 42 +- pages/index.js | 54 +- pages/js-object-to-json.js | 30 +- pages/json-schema-to-ts.js | 26 +- pages/json-to-big-query.js | 32 +- pages/json-to-flow-types.js | 28 +- pages/json-to-go.js | 30 +- pages/json-to-mobx-state-tree.js | 34 +- pages/json-to-mongoose.js | 32 +- pages/json-to-mysql.js | 32 +- pages/json-to-rust-serde.js | 28 +- pages/json-to-scala-case-class.js | 28 +- pages/json-to-ts-interface.js | 30 +- pages/xml-to-json.js | 32 +- ...babel-plugin-js-to-immutable-prop-types.js | 81 +- utils/babel-plugin-js-to-mobx-state-tree.js | 72 +- utils/dummy-json.js | 4 +- utils/dummy-object-json.js | 4 +- utils/graphql-schema.js | 1298 ++++++++--------- utils/json-to-go.js | 290 ++-- utils/loadWorker.js | 14 +- utils/routes.js | 178 +-- workers/css-to-js.js | 10 +- workers/graphql-to-flow-ts.js | 10 +- workers/json-to-proptypes.js | 18 +- workers/prettier.js | 52 +- 31 files changed, 1550 insertions(+), 1554 deletions(-) diff --git a/components/ConversionPanel.js b/components/ConversionPanel.js index 3157816..ccac26b 100644 --- a/components/ConversionPanel.js +++ b/components/ConversionPanel.js @@ -1,58 +1,58 @@ -import React, { PureComponent } from "react"; -import cn from "classnames"; -import isBrowser from "is-in-browser"; -import copy from "copy-text-to-clipboard"; -import unfetch from "unfetch"; -import loadWorker from "../utils/loadWorker"; +import React, { PureComponent } from 'react' +import cn from 'classnames' +import isBrowser from 'is-in-browser' +import copy from 'copy-text-to-clipboard' +import unfetch from 'unfetch' +import loadWorker from '../utils/loadWorker' -let CodeMirror; +let CodeMirror if (isBrowser) { - CodeMirror = require("react-codemirror2").default; + CodeMirror = require('react-codemirror2').default - require("codemirror-graphql/mode"); - require("codemirror/mode/javascript/javascript"); - require("codemirror/mode/xml/xml"); - require("codemirror/mode/jsx/jsx"); - require("codemirror/mode/css/css"); - require("codemirror/mode/rust/rust"); - require("codemirror/mode/sql/sql"); - require("codemirror/mode/clike/clike"); - require("codemirror/mode/go/go"); + require('codemirror-graphql/mode') + require('codemirror/mode/javascript/javascript') + require('codemirror/mode/xml/xml') + require('codemirror/mode/jsx/jsx') + require('codemirror/mode/css/css') + require('codemirror/mode/rust/rust') + require('codemirror/mode/sql/sql') + require('codemirror/mode/clike/clike') + require('codemirror/mode/go/go') } const prettierParsers = { - css: "postcss", - javascript: "babylon", - jsx: "babylon", - graphql: "graphql", - json: "json", - typescript: "typescript", - flow: "flow" -}; + css: 'postcss', + javascript: 'babylon', + jsx: 'babylon', + graphql: 'graphql', + json: 'json', + typescript: 'typescript', + flow: 'flow' +} const modeMapping = { javascript: { - name: "javascript" + name: 'javascript' }, json: { - name: "javascript", + name: 'javascript', json: true }, typescript: { - name: "javascript", + name: 'javascript', typescript: true }, html: { - name: "xml", + name: 'xml', htmlMode: true }, flow: { - name: "javascript", + name: 'javascript', typescript: true }, - mysql: "text/x-mysql", - scala: "text/x-scala" -}; + mysql: 'text/x-mysql', + scala: 'text/x-scala' +} type Props = { leftMode: ?string, @@ -72,158 +72,159 @@ type Props = { showFetchButton: boolean, fetchButtonText: ?string, getTransformedValue: Function -}; +} export default class ConversionPanel extends PureComponent { - props: Props; + props: Props - constructor(props) { - super(props); + constructor (props) { + super(props) this.state = { - resultValue: "", + resultValue: '', value: props.defaultText, - splitValue: "", - info: "", - infoType: "", + splitValue: '', + info: '', + infoType: '', isPrettierAvailable: true - }; + } } static defaultProps = { - leftMode: "javascript", - rightMode: "javascript", - pathname: "/", + leftMode: 'javascript', + rightMode: 'javascript', + pathname: '/', prettifyRightPanel: true, splitLeft: false, showFetchButton: true, - fetchButtonText: "Fetch JSON from URL" - }; + fetchButtonText: 'Fetch JSON from URL' + } - componentDidMount() { - const { defaultText, splitValue } = this.props; + componentDidMount () { + const { defaultText, splitValue } = this.props - this.onChange(defaultText, splitValue); + this.onChange(defaultText, splitValue) - const { worker, promiseWorker } = loadWorker("prettier.js"); - this.worker = worker; - this.promiseWorker = promiseWorker; + const { worker, promiseWorker } = loadWorker('prettier.js') + this.worker = worker + this.promiseWorker = promiseWorker - this.worker.onmessage = this.setPrettierAvailability; + this.worker.onmessage = this.setPrettierAvailability } setPrettierAvailability = ({ data }) => { - if (!data.available || this.state.isPrettierAvailable === data.available) - return; + if (!data.available || this.state.isPrettierAvailable === data.available) { + return + } this.setState({ isPrettierAvailable: data.available - }); - }; + }) + } passCodeToWorker = (code, mode, section) => { this.promiseWorker.postMessage({ code, mode, section }).then(response => { - const { available, prettyCode, section } = response; + const { available, prettyCode, section } = response this.setState({ isPrettierAvailable: available, [section]: prettyCode - }); - }); - }; + }) + }) + } fetchJSON = async () => { - const url = window.prompt("Enter URL to fetch JSON from a remote server."); - if (!url) return; + const url = window.prompt('Enter URL to fetch JSON from a remote server.') + if (!url) return try { - const res = await unfetch(url); - const json = await res.json(); - this.onChange(JSON.stringify(json, null, 2)); + const res = await unfetch(url) + const json = await res.json() + this.onChange(JSON.stringify(json, null, 2)) } catch (e) { this.setState({ info: e.message, - infoType: "error" - }); + infoType: 'error' + }) } - }; + } onChange = async (newValue, leftSplitValue) => { - const { prettifyRightPanel, rightMode } = this.props; + const { prettifyRightPanel, rightMode } = this.props - const nValue = newValue || this.state.value; + const nValue = newValue || this.state.value const splitValue = - leftSplitValue && typeof leftSplitValue === "string" + leftSplitValue && typeof leftSplitValue === 'string' ? leftSplitValue - : this.state.splitValue; + : this.state.splitValue try { - let code = await this.props.getTransformedValue(nValue, splitValue); - code = code.prettyCode || code; + let code = await this.props.getTransformedValue(nValue, splitValue) + code = code.prettyCode || code if (prettifyRightPanel) { - this.passCodeToWorker(code, rightMode, "resultValue"); + this.passCodeToWorker(code, rightMode, 'resultValue') } else { this.setState({ resultValue: code - }); + }) } this.setState({ - info: "", - infoType: "" - }); + info: '', + infoType: '' + }) } catch (e) { this.setState({ info: e.message, - infoType: "error" - }); + infoType: 'error' + }) } this.setState({ value: nValue, splitValue: splitValue - }); - }; + }) + } toggleCheckbox = e => { - const checked = e.currentTarget.checked; + const checked = e.currentTarget.checked if (this.props.onCheckboxChange) { this.props.onCheckboxChange(checked, () => { - this.onChange(); - }); + this.onChange() + }) } - }; + } prettifyCode = () => { - if (!this.state.isPrettierAvailable) return; - const { leftMode } = this.props; - const { value } = this.state; + if (!this.state.isPrettierAvailable) return + const { leftMode } = this.props + const { value } = this.state - this.passCodeToWorker(value, leftMode, "value"); - }; + this.passCodeToWorker(value, leftMode, 'value') + } prettifySplitCode = () => { - if (!this.state.isPrettierAvailable) return; - const { splitMode } = this.props; - const { splitValue } = this.state; + if (!this.state.isPrettierAvailable) return + const { splitMode } = this.props + const { splitValue } = this.state - this.passCodeToWorker(splitValue, splitMode, "splitValue"); - }; + this.passCodeToWorker(splitValue, splitMode, 'splitValue') + } copyCode = () => { - const { resultValue } = this.state; + const { resultValue } = this.state - copy(resultValue); + copy(resultValue) this.setState({ - info: "Code copied to clipboard.", - infoType: "success" - }); - }; + info: 'Code copied to clipboard.', + infoType: 'success' + }) + } getPrettifyClass = () => { - return cn("btn", { + return cn('btn', { disabled: !this.state.isPrettierAvailable - }); - }; + }) + } - render() { + render () { const { leftMode, rightMode, @@ -237,35 +238,35 @@ export default class ConversionPanel extends PureComponent { splitMode, showFetchButton, fetchButtonText - } = this.props; - const { infoType, resultValue, value, info, splitValue } = this.state; + } = this.props + const { infoType, resultValue, value, info, splitValue } = this.state - const leftClass = cn("section left", { + const leftClass = cn('section left', { split: splitLeft - }); + }) const codeMirrorOptions = { lineNumbers: true, - theme: "chrome-devtools", + theme: 'chrome-devtools', lineWrapping: true, scrollbarStyle: null - }; + } // hide success footer bannner after 2 seconds. Let other types be visible until fixed. - clearTimeout(this.footerTimeout); - if (infoType === "success") { + clearTimeout(this.footerTimeout) + if (infoType === 'success') { this.footerTimeout = setTimeout( () => this.setState({ - info: "", - infoType: "" + info: '', + infoType: '' }), 2000 - ); + ) } return ( -
+
-
+
-
-
-

{leftTitle}

- {leftMode === "json" && +
+
+

{leftTitle}

+ {leftMode === 'json' && showFetchButton && ( - )} @@ -470,9 +471,9 @@ export default class ConversionPanel extends PureComponent {
{splitLeft && isBrowser && ( -
-
-

{splitTitle}

+
+
+

{splitTitle}

{prettierParsers[splitMode] && (
-
-
-
-

{rightTitle}

+
+
+
+

{rightTitle}

{onCheckboxChange && ( -
@@ -527,12 +528,12 @@ export default class ConversionPanel extends PureComponent {
- {infoType !== "" && ( + {infoType !== '' && (
- {info} + {info}
)}
- ); + ) } } diff --git a/components/Layout.js b/components/Layout.js index 1299a5f..4c3cef0 100644 --- a/components/Layout.js +++ b/components/Layout.js @@ -1,64 +1,64 @@ -import React, { PureComponent } from "react"; -import isBrowser from "is-in-browser"; -import Link from "next/link"; -import Head from "next/head"; -import NProgress from "nprogress"; -import Router from "next/router"; -import GithubCorner from "react-github-corner"; -import FuzzyPicker, { FuzzyWrapper } from "react-fuzzy-picker"; -import Collapse, { Panel } from "rc-collapse"; -import findIndex from "lodash/findIndex"; -import { categorizedRoutes, routes, activeRouteData } from "../utils/routes"; +import React, { PureComponent } from 'react' +import isBrowser from 'is-in-browser' +import Link from 'next/link' +import Head from 'next/head' +import NProgress from 'nprogress' +import Router from 'next/router' +import GithubCorner from 'react-github-corner' +import FuzzyPicker, { FuzzyWrapper } from 'react-fuzzy-picker' +import Collapse, { Panel } from 'rc-collapse' +import findIndex from 'lodash/findIndex' +import { categorizedRoutes, routes, activeRouteData } from '../utils/routes' -NProgress.configure({ showSpinner: false }); +NProgress.configure({ showSpinner: false }) Router.onRouteChangeStart = url => { - if (url.indexOf("code=") === -1) { - NProgress.start(); + if (url.indexOf('code=') === -1) { + NProgress.start() } -}; -Router.onRouteChangeComplete = () => NProgress.done(); -Router.onRouteChangeError = () => NProgress.done(); +} +Router.onRouteChangeComplete = () => NProgress.done() +Router.onRouteChangeError = () => NProgress.done() -function Logo() { +function Logo () { return ( - + - ); + ) } -function trackingScript() { - (function(i, s, o, g, r, a, m) { - i["GoogleAnalyticsObject"] = r; - (i[r] = +function trackingScript () { + ;(function (i, s, o, g, r, a, m) { + i['GoogleAnalyticsObject'] = r + ;(i[r] = i[r] || - function() { - (i[r].q = i[r].q || []).push(arguments); + function () { + ;(i[r].q = i[r].q || []).push(arguments) }), - (i[r].l = 1 * new Date()); - (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]); - a.async = 1; - a.src = g; - m.parentNode.insertBefore(a, m); + (i[r].l = 1 * new Date()) + ;(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]) + a.async = 1 + a.src = g + m.parentNode.insertBefore(a, m) })( window, document, - "script", - "https://www.google-analytics.com/analytics.js", - "ga" - ); + 'script', + 'https://www.google-analytics.com/analytics.js', + 'ga' + ) - ga("create", "UA-60624235-5", "auto"); - ga("send", "pageview"); + ga('create', 'UA-60624235-5', 'auto') + ga('send', 'pageview') } -function renderFuzzyPicker(isOpen, onClose) { +function renderFuzzyPicker (isOpen, onClose) { return ( item.label} renderItem={item => {item.label}} /> - ); + ) } // Here, we check what key must be pressed to open the fuzzy picker // We'll use the '/' key for this example. -function isCorrectKeyPressed(event) { - return event.metaKey && event.key === "p"; +function isCorrectKeyPressed (event) { + return event.metaKey && event.key === 'p' } export default class Layout extends PureComponent { - state = {}; + state = {} - getClass(path) { - return path === this.props.pathname ? "active" : ""; + getClass (path) { + return path === this.props.pathname ? 'active' : '' } - componentWillMount() { - this.setKey(this.props.pathname); + componentWillMount () { + this.setKey(this.props.pathname) } - componentDidMount() { - routes.forEach(({ path }) => Router.prefetch(path)); + componentDidMount () { + routes.forEach(({ path }) => Router.prefetch(path)) } - componentWillReceiveProps({ pathname }) { - this.setKey(pathname); + componentWillReceiveProps ({ pathname }) { + this.setKey(pathname) } setKey = pathname => { @@ -102,52 +102,52 @@ export default class Layout extends PureComponent { categorizedRoutes, o => o.content.filter(a => a.path === pathname).length ) + 1}` - }); - }; + }) + } onChange = activeKey => { this.setState({ activeKey - }); - }; + }) + } - render() { - const { label, desc, title } = activeRouteData(this.props.pathname); + render () { + const { label, desc, title } = activeRouteData(this.props.pathname) return ( -
+
{title || label} - - + + - + - - - - - - - - - + + + + + + + + + - - + +