Skip to content

Commit 7a27d82

Browse files
authored
Prettier (#1)
* add prettier * remove old config
1 parent cf6755f commit 7a27d82

22 files changed

+755
-497
lines changed

.eslintrc .eslintrc.js

+22-33
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,8 @@
1-
{
2-
"extends": [
3-
"eslint:recommended",
4-
"plugin:import/errors",
5-
"plugin:import/warnings",
6-
"airbnb"
7-
],
8-
"plugins": [
9-
"react",
10-
"react-hooks"
11-
],
12-
"parser": "babel-eslint",
13-
"parserOptions": {
14-
"ecmaVersion": 6,
15-
"sourceType": "module",
16-
"ecmaFeatures": {
17-
"jsx": true,
18-
"experimentalObjectRestSpread": true
19-
}
20-
},
21-
"env": {
22-
"es6": true,
23-
"browser": true,
24-
"node": true,
25-
"jquery": true,
26-
"jest": true
27-
},
28-
"rules": {
1+
module.exports = {
2+
extends: ['airbnb', 'prettier', 'prettier/react'],
3+
plugins: ['prettier', 'react-hooks'],
4+
rules: {
5+
"prettier/prettier": ["error"],
296
"object-curly-newline": 0,
307
"no-class-assign": 0,
318
"no-param-reassign": 0,
@@ -39,7 +16,6 @@
3916
"no-console": [1, { "allow": ["warn", "error"] }],
4017
"no-debugger": 1,
4118
"no-var": 1,
42-
"semi": [1, "always"],
4319
"no-trailing-spaces": 1,
4420
"eol-last": 1,
4521
"no-underscore-dangle": 0,
@@ -102,10 +78,23 @@
10278
"import/no-named-as-default": 0,
10379
"react-hooks/rules-of-hooks": "error"
10480
},
105-
"settings": {
106-
"import/resolver": {
107-
"node": {
108-
"paths": ["src"]
81+
globals: {
82+
window: true,
83+
document: true,
84+
page: true,
85+
browser: true,
86+
navigator: true,
87+
fetch: true
88+
},
89+
env: {
90+
es6: true,
91+
jest: true
92+
},
93+
parser: 'babel-eslint',
94+
settings: {
95+
'import/resolver': {
96+
node: {
97+
paths: ['src']
10998
}
11099
}
111100
}

.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"semi": false
4+
}

package.json

+17-6
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,26 @@
1313
"start": "npm-run-all --parallel open:src lint",
1414
"open:src": "babel-node tools/srcServer.js",
1515
"open:dist": "babel-node tools/distServer.js",
16-
"lint:code": "eslint webpack/webpack.config.* src tools server --color",
16+
"lint:code": "eslint webpack/webpack.config.* src",
1717
"lint:style": "stylelint \"src/styles/**/*.scss\"",
1818
"lint": "npm run lint:code && npm run lint:style",
19+
"lint:fix": "eslint --fix webpack/webpack.config.* src",
1920
"clean-dist": "npm run remove-dist && mkdir dist",
2021
"remove-dist": "rimraf ./dist",
2122
"prebuild": "npm run clean-dist && npm run lint",
2223
"build": "babel-node tools/build.js",
24+
"prettier": "prettier --write './src/**/*.js'",
2325
"test": "jest",
2426
"test:cover": "npm run test -- --coverage",
2527
"test:watch": "npm run test -- --watch",
2628
"deploy": "npm run build && babel-node tools/deployS3",
2729
"analyze-bundle": "babel-node ./tools/analyzeBundle.js"
2830
},
31+
"husky": {
32+
"hooks": {
33+
"pre-commit": "yarn prettier --loglevel=silent && yarn lint:fix --quiet && git add . && yarn lint --quiet"
34+
}
35+
},
2936
"author": "Bernabe Gonzalez",
3037
"license": "MIT",
3138
"dependencies": {
@@ -77,15 +84,18 @@
7784
"dotenv-webpack": "1.5.7",
7885
"enzyme": "3.4.1",
7986
"enzyme-adapter-react-16": "1.5.0",
80-
"eslint": "4.19.1",
81-
"eslint-config-airbnb": "16.1.0",
82-
"eslint-plugin-import": "2.11.0",
83-
"eslint-plugin-jsx-a11y": "6.0.3",
84-
"eslint-plugin-react": "7.7.0",
87+
"eslint": "5.15.3",
88+
"eslint-config-airbnb": "17.1.0",
89+
"eslint-config-prettier": "4.1.0",
90+
"eslint-plugin-import": "2.16.0",
91+
"eslint-plugin-jsx-a11y": "6.2.1",
92+
"eslint-plugin-prettier": "3.0.1",
93+
"eslint-plugin-react": "7.12.4",
8594
"eslint-plugin-react-hooks": "1.0.0",
8695
"express": "4.16.3",
8796
"file-loader": "1.1.11",
8897
"html-webpack-plugin": "3.2.0",
98+
"husky": "1.3.1",
8999
"identity-obj-proxy": "3.0.0",
90100
"jest": "23.6.0",
91101
"json-loader": "0.5.7",
@@ -97,6 +107,7 @@
97107
"opn": "5.3.0",
98108
"optimize-css-assets-webpack-plugin": "5.0.1",
99109
"postcss-loader": "3.0.0",
110+
"prettier": "1.16.4",
100111
"prompt": "1.0.0",
101112
"react-hot-loader": "4.6.5",
102113
"react-test-renderer": "16.5.2",

src/components/App.js

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React, { Fragment } from 'react';
2-
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
3-
import { Helmet } from 'react-helmet';
4-
import { ThemeProvider } from 'styled-components';
1+
import React, { Fragment } from 'react'
2+
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
3+
import { Helmet } from 'react-helmet'
4+
import { ThemeProvider } from 'styled-components'
55

6-
import routes from '../routes';
7-
import theme from '../constants/theme';
6+
import routes from '../routes'
7+
import theme from '../constants/theme'
88

99
const App = () => (
1010
<ThemeProvider theme={theme}>
@@ -14,16 +14,13 @@ const App = () => (
1414
</Helmet>
1515
<Router>
1616
<Switch>
17-
{routes.map((route, index) =>
18-
<Route
19-
key={`route${index}`}
20-
{...route}
21-
/>)
22-
}
17+
{routes.map((route, index) => (
18+
<Route key={`route${index}`} {...route} />
19+
))}
2320
</Switch>
2421
</Router>
2522
</Fragment>
2623
</ThemeProvider>
27-
);
24+
)
2825

29-
export default App;
26+
export default App

src/constants/routesPaths.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ const routes = {
22
index: '/',
33
login: '/login',
44
signUp: '/sign-up'
5-
};
5+
}
66

7-
export default routes;
7+
export default routes

src/constants/theme.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ const theme = {
99
normal: '400',
1010
bold: '700'
1111
}
12-
};
12+
}
1313

14-
export default theme;
14+
export default theme
+26-18
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
1-
import React, { Fragment, useState } from 'react';
2-
import { Separator } from 'mc-components';
1+
import React, { Fragment, useState } from 'react'
2+
import PropTypes from 'prop-types'
3+
import { Separator } from 'mc-components'
34

4-
const ExecutionRow = (props) => {
5-
const [showData, setShowData] = useState(false);
5+
const ExecutionRow = props => {
6+
const [showData, setShowData] = useState(false)
67

7-
const onToggle = () => setShowData(!showData);
8+
const onToggle = () => setShowData(!showData)
9+
const { id, test, url, status, errorMessage } = props
810

911
return (
1012
<Fragment>
1113
<div>
12-
<p>{`Id: ${props.id}`}</p>
13-
<p>{`Test: ${props.test}`}</p>
14-
<p>{`URL: ${props.url}`}</p>
15-
<p>{`Status: ${props.status}`}</p>
16-
{props.errorMessage &&
14+
<p>{`Id: ${id}`}</p>
15+
<p>{`Test: ${test}`}</p>
16+
<p>{`URL: ${url}`}</p>
17+
<p>{`Status: ${status}`}</p>
18+
{errorMessage && (
1719
<Fragment>
1820
<p>Error:</p>
19-
<p>{unescape(props.errorMessage)}</p>
21+
<p>{unescape(errorMessage)}</p>
2022
</Fragment>
21-
}
23+
)}
2224
</div>
2325
<a onClick={onToggle}>Toggle data</a>
24-
{showData &&
25-
<div>{JSON.stringify(props)}</div>
26-
}
26+
{showData && <div>{JSON.stringify(props)}</div>}
2727
<Separator />
2828
</Fragment>
29-
);
30-
};
29+
)
30+
}
3131

32-
export default ExecutionRow;
32+
ExecutionRow.propTypes = {
33+
id: PropTypes.string.isRequired,
34+
test: PropTypes.string.isRequired,
35+
url: PropTypes.string.isRequired,
36+
status: PropTypes.string.isRequired,
37+
errorMessage: PropTypes.string
38+
}
39+
40+
export default ExecutionRow

src/containers/HomePage/Executions.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1-
import React from 'react';
2-
import { Separator } from 'mc-components';
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import { Separator } from 'mc-components'
34

4-
import ExecutionRow from './ExecutionRow';
5+
import ExecutionRow from './ExecutionRow'
56

67
const Executions = ({ executions }) => {
7-
const sortedExecutions = [...executions]
8-
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt));
8+
const sortedExecutions = [...executions].sort(
9+
(a, b) => new Date(b.createdAt) - new Date(a.createdAt)
10+
)
911

1012
return (
1113
<div className="container mc-p-5 mc-invert mc-background--color-light">
1214
<h5 className="mc-text-h5">All Executions</h5>
1315
<Separator />
1416
<div>
15-
{sortedExecutions.map(props =>
16-
<ExecutionRow key={props.id} {...props} />)}
17+
{sortedExecutions.map(({ id, ...props }) => (
18+
<ExecutionRow key={id} id={id} {...props} />
19+
))}
1720
</div>
1821
</div>
19-
);
20-
};
22+
)
23+
}
2124

22-
export default Executions;
25+
Executions.propTypes = {
26+
executions: PropTypes.array.isRequired
27+
}
28+
29+
export default Executions

src/containers/HomePage/RunTest.js

+30-33
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,46 @@
1-
import React, { useState } from 'react';
2-
import PropTypes from 'prop-types';
3-
import { Input, FormGroup, Button } from 'mc-components';
1+
import React, { useState } from 'react'
2+
import PropTypes from 'prop-types'
3+
import { Input, FormGroup, Button } from 'mc-components'
44

5-
import { applyQueryParams } from 'utils/helpers';
5+
import { applyQueryParams } from 'utils/helpers'
66

77
const RunTest = ({ onSuccess }) => {
8-
const [url, setUrl] = useState('');
9-
const [test, setTest] = useState('');
10-
const [urlError, setUrlError] = useState('');
11-
const [testError, setTestError] = useState('');
12-
const [loading, setLoading] = useState(false);
8+
const [url, setUrl] = useState('')
9+
const [test, setTest] = useState('')
10+
const [urlError, setUrlError] = useState('')
11+
const [testError, setTestError] = useState('')
12+
const [loading, setLoading] = useState(false)
1313

1414
const onSubmit = () => {
1515
if (!url) {
16-
setUrlError("URL can't be empty ");
16+
setUrlError("URL can't be empty ")
1717
}
1818
if (!test) {
19-
setTestError("Test path can't be empty ");
19+
setTestError("Test path can't be empty ")
2020
}
2121
if (!url || !test) {
22-
return;
22+
return
2323
}
24-
setLoading(true);
25-
const path = applyQueryParams(
26-
`${process.env.API_URL}/trigger`,
27-
{ test, url }
28-
);
24+
setLoading(true)
25+
const path = applyQueryParams(`${process.env.API_URL}/trigger`, {
26+
test,
27+
url
28+
})
2929
fetch(path)
30-
.then((res) => {
31-
setLoading(false);
30+
.then(res => {
31+
setLoading(false)
3232
if (res.ok) {
33-
onSuccess();
33+
onSuccess()
3434
}
3535
})
36-
.catch(() => setLoading(false));
37-
};
36+
.catch(() => setLoading(false))
37+
}
3838

3939
return (
4040
<div className="container mc-p-5 mc-invert mc-background--color-light">
4141
<h5 className="mc-text-h5">Run test</h5>
4242
<div className="mc-my-4">
43-
<FormGroup
44-
label="URL"
45-
name="url"
46-
error={urlError}
47-
touched={!!urlError}
48-
>
43+
<FormGroup label="URL" name="url" error={urlError} touched={!!urlError}>
4944
<Input
5045
onChange={e => setUrl(e.target.value)}
5146
value={url}
@@ -69,14 +64,16 @@ const RunTest = ({ onSuccess }) => {
6964
touched={!!testError}
7065
/>
7166
</FormGroup>
72-
<Button onClick={onSubmit} loading={loading}>RUN</Button>
67+
<Button onClick={onSubmit} loading={loading}>
68+
RUN
69+
</Button>
7370
</div>
7471
</div>
75-
);
76-
};
72+
)
73+
}
7774

7875
RunTest.propTypes = {
7976
onSuccess: PropTypes.func.isRequired
80-
};
77+
}
8178

82-
export default RunTest;
79+
export default RunTest

0 commit comments

Comments
 (0)