Skip to content

Commit a920527

Browse files
author
Aditya Vohra
committed
[chore] Added prettier via eslint
1 parent 1b19650 commit a920527

File tree

131 files changed

+1527
-1425
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+1527
-1425
lines changed

.eslintrc.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
module.exports = {
2-
extends: 'react-app',
2+
extends: ['react-app', 'prettier'],
3+
4+
plugins: ['prettier'],
5+
6+
rules: {
7+
'prettier/prettier': [
8+
'error',
9+
{
10+
semi: false,
11+
singleQuote: true
12+
}
13+
]
14+
},
315

416
overrides: [
517
{
618
files: 'test/**/*.js',
719
env: {
8-
jest: true,
9-
},
10-
},
11-
],
20+
jest: true
21+
}
22+
}
23+
]
1224
}

build/use-lodash-es.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function () {
1+
module.exports = function() {
22
return {
33
visitor: {
44
ImportDeclaration(path) {

examples/async/src/components/Picker.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@ import PropTypes from 'prop-types'
44
const Picker = ({ value, onChange, options }) => (
55
<span>
66
<h1>{value}</h1>
7-
<select onChange={e => onChange(e.target.value)}
8-
value={value}>
9-
{options.map(option =>
7+
<select onChange={e => onChange(e.target.value)} value={value}>
8+
{options.map(option => (
109
<option value={option} key={option}>
1110
{option}
12-
</option>)
13-
}
11+
</option>
12+
))}
1413
</select>
1514
</span>
1615
)
1716

1817
Picker.propTypes = {
19-
options: PropTypes.arrayOf(
20-
PropTypes.string.isRequired
21-
).isRequired,
18+
options: PropTypes.arrayOf(PropTypes.string.isRequired).isRequired,
2219
value: PropTypes.string.isRequired,
2320
onChange: PropTypes.func.isRequired
2421
}

examples/async/src/components/Posts.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
33

4-
const Posts = ({posts}) => (
5-
<ul>
6-
{posts.map((post, i) =>
7-
<li key={i}>{post.title}</li>
8-
)}
9-
</ul>
4+
const Posts = ({ posts }) => (
5+
<ul>{posts.map((post, i) => <li key={i}>{post.title}</li>)}</ul>
106
)
117

128
Posts.propTypes = {

examples/async/src/containers/App.js

+25-23
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,42 @@ class App extends Component {
4343
const isEmpty = posts.length === 0
4444
return (
4545
<div>
46-
<Picker value={selectedReddit}
47-
onChange={this.handleChange}
48-
options={[ 'reactjs', 'frontend' ]} />
46+
<Picker
47+
value={selectedReddit}
48+
onChange={this.handleChange}
49+
options={['reactjs', 'frontend']}
50+
/>
4951
<p>
50-
{lastUpdated &&
52+
{lastUpdated && (
5153
<span>
52-
Last updated at {new Date(lastUpdated).toLocaleTimeString()}.
53-
{' '}
54+
Last updated at {new Date(lastUpdated).toLocaleTimeString()}.{' '}
5455
</span>
55-
}
56-
{!isFetching &&
57-
<button onClick={this.handleRefreshClick}>
58-
Refresh
59-
</button>
60-
}
56+
)}
57+
{!isFetching && (
58+
<button onClick={this.handleRefreshClick}>Refresh</button>
59+
)}
6160
</p>
62-
{isEmpty
63-
? (isFetching ? <h2>Loading...</h2> : <h2>Empty.</h2>)
64-
: <div style={{ opacity: isFetching ? 0.5 : 1 }}>
65-
<Posts posts={posts} />
66-
</div>
67-
}
61+
{isEmpty ? (
62+
isFetching ? (
63+
<h2>Loading...</h2>
64+
) : (
65+
<h2>Empty.</h2>
66+
)
67+
) : (
68+
<div style={{ opacity: isFetching ? 0.5 : 1 }}>
69+
<Posts posts={posts} />
70+
</div>
71+
)}
6872
</div>
6973
)
7074
}
7175
}
7276

7377
const mapStateToProps = state => {
7478
const { selectedReddit, postsByReddit } = state
75-
const {
76-
isFetching,
77-
lastUpdated,
78-
items: posts
79-
} = postsByReddit[selectedReddit] || {
79+
const { isFetching, lastUpdated, items: posts } = postsByReddit[
80+
selectedReddit
81+
] || {
8082
isFetching: true,
8183
items: []
8284
}

examples/async/src/index.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@ import { createLogger } from 'redux-logger'
77
import reducer from './reducers'
88
import App from './containers/App'
99

10-
const middleware = [ thunk ]
10+
const middleware = [thunk]
1111
if (process.env.NODE_ENV !== 'production') {
1212
middleware.push(createLogger())
1313
}
1414

15-
const store = createStore(
16-
reducer,
17-
applyMiddleware(...middleware)
18-
)
15+
const store = createStore(reducer, applyMiddleware(...middleware))
1916

2017
render(
2118
<Provider store={store}>

examples/async/src/reducers/index.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { combineReducers } from 'redux'
22
import {
3-
SELECT_REDDIT, INVALIDATE_REDDIT,
4-
REQUEST_POSTS, RECEIVE_POSTS
3+
SELECT_REDDIT,
4+
INVALIDATE_REDDIT,
5+
REQUEST_POSTS,
6+
RECEIVE_POSTS
57
} from '../actions'
68

79
const selectedReddit = (state = 'reactjs', action) => {
@@ -13,11 +15,14 @@ const selectedReddit = (state = 'reactjs', action) => {
1315
}
1416
}
1517

16-
const posts = (state = {
17-
isFetching: false,
18-
didInvalidate: false,
19-
items: []
20-
}, action) => {
18+
const posts = (
19+
state = {
20+
isFetching: false,
21+
didInvalidate: false,
22+
items: []
23+
},
24+
action
25+
) => {
2126
switch (action.type) {
2227
case INVALIDATE_REDDIT:
2328
return {
@@ -43,7 +48,7 @@ const posts = (state = {
4348
}
4449
}
4550

46-
const postsByReddit = (state = { }, action) => {
51+
const postsByReddit = (state = {}, action) => {
4752
switch (action.type) {
4853
case INVALIDATE_REDDIT:
4954
case RECEIVE_POSTS:

examples/counter/src/components/Counter.js

+7-20
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import PropTypes from 'prop-types'
33

44
class Counter extends Component {
55
constructor(props) {
6-
super(props);
7-
this.incrementAsync = this.incrementAsync.bind(this);
8-
this.incrementIfOdd = this.incrementIfOdd.bind(this);
6+
super(props)
7+
this.incrementAsync = this.incrementAsync.bind(this)
8+
this.incrementIfOdd = this.incrementIfOdd.bind(this)
99
}
1010

1111
incrementIfOdd() {
@@ -22,23 +22,10 @@ class Counter extends Component {
2222
const { value, onIncrement, onDecrement } = this.props
2323
return (
2424
<p>
25-
Clicked: {value} times
26-
{' '}
27-
<button onClick={onIncrement}>
28-
+
29-
</button>
30-
{' '}
31-
<button onClick={onDecrement}>
32-
-
33-
</button>
34-
{' '}
35-
<button onClick={this.incrementIfOdd}>
36-
Increment if odd
37-
</button>
38-
{' '}
39-
<button onClick={this.incrementAsync}>
40-
Increment async
41-
</button>
25+
Clicked: {value} times <button onClick={onIncrement}>+</button>{' '}
26+
<button onClick={onDecrement}>-</button>{' '}
27+
<button onClick={this.incrementIfOdd}>Increment if odd</button>{' '}
28+
<button onClick={this.incrementAsync}>Increment async</button>
4229
</p>
4330
)
4431
}

examples/counter/src/components/Counter.spec.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ function setup(value = 0) {
77
onIncrement: jest.fn(),
88
onDecrement: jest.fn()
99
}
10-
const component = shallow(
11-
<Counter value={value} {...actions} />
12-
)
10+
const component = shallow(<Counter value={value} {...actions} />)
1311

1412
return {
1513
component: component,
@@ -55,7 +53,7 @@ describe('Counter component', () => {
5553
expect(actions.onIncrement).toBeCalled()
5654
})
5755

58-
it('fourth button should call onIncrement in a second', (done) => {
56+
it('fourth button should call onIncrement in a second', done => {
5957
const { buttons, actions } = setup()
6058
buttons.at(3).simulate('click')
6159
setTimeout(() => {

examples/counter/src/index.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import counter from './reducers'
77
const store = createStore(counter)
88
const rootEl = document.getElementById('root')
99

10-
const render = () => ReactDOM.render(
11-
<Counter
12-
value={store.getState()}
13-
onIncrement={() => store.dispatch({ type: 'INCREMENT' })}
14-
onDecrement={() => store.dispatch({ type: 'DECREMENT' })}
15-
/>,
16-
rootEl
17-
)
10+
const render = () =>
11+
ReactDOM.render(
12+
<Counter
13+
value={store.getState()}
14+
onIncrement={() => store.dispatch({ type: 'INCREMENT' })}
15+
onDecrement={() => store.dispatch({ type: 'DECREMENT' })}
16+
/>,
17+
rootEl
18+
)
1819

1920
render()
2021
store.subscribe(render)

examples/real-world/src/actions/index.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ export const USER_FAILURE = 'USER_FAILURE'
88
// Relies on the custom API middleware defined in ../middleware/api.js.
99
const fetchUser = login => ({
1010
[CALL_API]: {
11-
types: [ USER_REQUEST, USER_SUCCESS, USER_FAILURE ],
11+
types: [USER_REQUEST, USER_SUCCESS, USER_FAILURE],
1212
endpoint: `users/${login}`,
1313
schema: Schemas.USER
1414
}
1515
})
1616

1717
// Fetches a single user from Github API unless it is cached.
1818
// Relies on Redux Thunk middleware.
19-
export const loadUser = (login, requiredFields = []) => (dispatch, getState) => {
19+
export const loadUser = (login, requiredFields = []) => (
20+
dispatch,
21+
getState
22+
) => {
2023
const user = getState().entities.users[login]
2124
if (user && requiredFields.every(key => user.hasOwnProperty(key))) {
2225
return null
@@ -33,15 +36,18 @@ export const REPO_FAILURE = 'REPO_FAILURE'
3336
// Relies on the custom API middleware defined in ../middleware/api.js.
3437
const fetchRepo = fullName => ({
3538
[CALL_API]: {
36-
types: [ REPO_REQUEST, REPO_SUCCESS, REPO_FAILURE ],
39+
types: [REPO_REQUEST, REPO_SUCCESS, REPO_FAILURE],
3740
endpoint: `repos/${fullName}`,
3841
schema: Schemas.REPO
3942
}
4043
})
4144

4245
// Fetches a single repository from Github API unless it is cached.
4346
// Relies on Redux Thunk middleware.
44-
export const loadRepo = (fullName, requiredFields = []) => (dispatch, getState) => {
47+
export const loadRepo = (fullName, requiredFields = []) => (
48+
dispatch,
49+
getState
50+
) => {
4551
const repo = getState().entities.repos[fullName]
4652
if (repo && requiredFields.every(key => repo.hasOwnProperty(key))) {
4753
return null
@@ -59,7 +65,7 @@ export const STARRED_FAILURE = 'STARRED_FAILURE'
5965
const fetchStarred = (login, nextPageUrl) => ({
6066
login,
6167
[CALL_API]: {
62-
types: [ STARRED_REQUEST, STARRED_SUCCESS, STARRED_FAILURE ],
68+
types: [STARRED_REQUEST, STARRED_SUCCESS, STARRED_FAILURE],
6369
endpoint: nextPageUrl,
6470
schema: Schemas.REPO_ARRAY
6571
}
@@ -69,10 +75,8 @@ const fetchStarred = (login, nextPageUrl) => ({
6975
// Bails out if page is cached and user didn't specifically request next page.
7076
// Relies on Redux Thunk middleware.
7177
export const loadStarred = (login, nextPage) => (dispatch, getState) => {
72-
const {
73-
nextPageUrl = `users/${login}/starred`,
74-
pageCount = 0
75-
} = getState().pagination.starredByUser[login] || {}
78+
const { nextPageUrl = `users/${login}/starred`, pageCount = 0 } =
79+
getState().pagination.starredByUser[login] || {}
7680

7781
if (pageCount > 0 && !nextPage) {
7882
return null
@@ -90,7 +94,7 @@ export const STARGAZERS_FAILURE = 'STARGAZERS_FAILURE'
9094
const fetchStargazers = (fullName, nextPageUrl) => ({
9195
fullName,
9296
[CALL_API]: {
93-
types: [ STARGAZERS_REQUEST, STARGAZERS_SUCCESS, STARGAZERS_FAILURE ],
97+
types: [STARGAZERS_REQUEST, STARGAZERS_SUCCESS, STARGAZERS_FAILURE],
9498
endpoint: nextPageUrl,
9599
schema: Schemas.USER_ARRAY
96100
}
@@ -100,10 +104,8 @@ const fetchStargazers = (fullName, nextPageUrl) => ({
100104
// Bails out if page is cached and user didn't specifically request next page.
101105
// Relies on Redux Thunk middleware.
102106
export const loadStargazers = (fullName, nextPage) => (dispatch, getState) => {
103-
const {
104-
nextPageUrl = `repos/${fullName}/stargazers`,
105-
pageCount = 0
106-
} = getState().pagination.stargazersByRepo[fullName] || {}
107+
const { nextPageUrl = `repos/${fullName}/stargazers`, pageCount = 0 } =
108+
getState().pagination.stargazersByRepo[fullName] || {}
107109

108110
if (pageCount > 0 && !nextPage) {
109111
return null
@@ -116,5 +118,5 @@ export const RESET_ERROR_MESSAGE = 'RESET_ERROR_MESSAGE'
116118

117119
// Resets the currently visible error message.
118120
export const resetErrorMessage = () => ({
119-
type: RESET_ERROR_MESSAGE
121+
type: RESET_ERROR_MESSAGE
120122
})

0 commit comments

Comments
 (0)