Skip to content

Commit e057d5b

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

18 files changed

+283
-248
lines changed

.eslintrc.js

Lines changed: 17 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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) {

package-lock.json

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"scripts": {
1717
"clean": "rimraf lib dist es coverage",
18-
"lint": "eslint src test build",
18+
"lint": "eslint src test build --fix",
1919
"test": "cross-env BABEL_ENV=commonjs jest",
2020
"test:watch": "npm test -- --watch",
2121
"test:cov": "npm test -- --coverage",
@@ -99,14 +99,17 @@
9999
"babel-register": "^6.26.0",
100100
"cross-env": "^5.1.0",
101101
"eslint": "^4.9.0",
102+
"eslint-config-prettier": "^2.6.0",
102103
"eslint-config-react-app": "^2.0.1",
103104
"eslint-plugin-flowtype": "^2.39.1",
104105
"eslint-plugin-import": "^2.2.0",
105106
"eslint-plugin-jsx-a11y": "^5.1.1",
107+
"eslint-plugin-prettier": "^2.3.1",
106108
"eslint-plugin-react": "^7.4.0",
107109
"gitbook-cli": "^2.3.2",
108110
"glob": "^7.1.1",
109111
"jest": "^21.2.1",
112+
"prettier": "^1.7.4",
110113
"rimraf": "^2.6.2",
111114
"rollup": "^0.50.0",
112115
"rollup-plugin-babel": "^3.0.2",

src/applyMiddleware.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import compose from './compose'
1717
* @returns {Function} A store enhancer applying the middleware.
1818
*/
1919
export default function applyMiddleware(...middlewares) {
20-
return (createStore) => (...args) => {
20+
return createStore => (...args) => {
2121
const store = createStore(...args)
2222
let dispatch = store.dispatch
2323
let chain = []

src/bindActionCreators.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
function bindActionCreator(actionCreator, dispatch) {
2-
return function() { return dispatch(actionCreator.apply(this, arguments)) }
2+
return function() {
3+
return dispatch(actionCreator.apply(this, arguments))
4+
}
35
}
46

57
/**
@@ -30,8 +32,11 @@ export default function bindActionCreators(actionCreators, dispatch) {
3032

3133
if (typeof actionCreators !== 'object' || actionCreators === null) {
3234
throw new Error(
33-
`bindActionCreators expected an object or a function, instead received ${actionCreators === null ? 'null' : typeof actionCreators}. ` +
34-
`Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?`
35+
`bindActionCreators expected an object or a function, instead received ${actionCreators ===
36+
null
37+
? 'null'
38+
: typeof actionCreators}. ` +
39+
`Did you write "import ActionCreators from" instead of "import * as ActionCreators from"?`
3540
)
3641
}
3742

src/combineReducers.js

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import warning from './utils/warning'
44

55
function getUndefinedStateErrorMessage(key, action) {
66
const actionType = action && action.type
7-
const actionDescription = (actionType && `action "${String(actionType)}"`) || 'an action'
7+
const actionDescription =
8+
(actionType && `action "${String(actionType)}"`) || 'an action'
89

910
return (
1011
`Given ${actionDescription}, reducer "${key}" returned undefined. ` +
@@ -13,11 +14,17 @@ function getUndefinedStateErrorMessage(key, action) {
1314
)
1415
}
1516

16-
function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
17+
function getUnexpectedStateShapeWarningMessage(
18+
inputState,
19+
reducers,
20+
action,
21+
unexpectedKeyCache
22+
) {
1723
const reducerKeys = Object.keys(reducers)
18-
const argumentName = action && action.type === ActionTypes.INIT ?
19-
'preloadedState argument passed to createStore' :
20-
'previous state received by the reducer'
24+
const argumentName =
25+
action && action.type === ActionTypes.INIT
26+
? 'preloadedState argument passed to createStore'
27+
: 'previous state received by the reducer'
2128

2229
if (reducerKeys.length === 0) {
2330
return (
@@ -29,15 +36,14 @@ function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, une
2936
if (!isPlainObject(inputState)) {
3037
return (
3138
`The ${argumentName} has unexpected type of "` +
32-
({}).toString.call(inputState).match(/\s([a-z|A-Z]+)/)[1] +
39+
{}.toString.call(inputState).match(/\s([a-z|A-Z]+)/)[1] +
3340
`". Expected argument to be an object with the following ` +
3441
`keys: "${reducerKeys.join('", "')}"`
3542
)
3643
}
3744

38-
const unexpectedKeys = Object.keys(inputState).filter(key =>
39-
!reducers.hasOwnProperty(key) &&
40-
!unexpectedKeyCache[key]
45+
const unexpectedKeys = Object.keys(inputState).filter(
46+
key => !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]
4147
)
4248

4349
unexpectedKeys.forEach(key => {
@@ -62,22 +68,28 @@ function assertReducerShape(reducers) {
6268
if (typeof initialState === 'undefined') {
6369
throw new Error(
6470
`Reducer "${key}" returned undefined during initialization. ` +
65-
`If the state passed to the reducer is undefined, you must ` +
66-
`explicitly return the initial state. The initial state may ` +
67-
`not be undefined. If you don't want to set a value for this reducer, ` +
68-
`you can use null instead of undefined.`
71+
`If the state passed to the reducer is undefined, you must ` +
72+
`explicitly return the initial state. The initial state may ` +
73+
`not be undefined. If you don't want to set a value for this reducer, ` +
74+
`you can use null instead of undefined.`
6975
)
7076
}
7177

72-
const type = '@@redux/PROBE_UNKNOWN_ACTION_' + Math.random().toString(36).substring(7).split('').join('.')
78+
const type =
79+
'@@redux/PROBE_UNKNOWN_ACTION_' +
80+
Math.random()
81+
.toString(36)
82+
.substring(7)
83+
.split('')
84+
.join('.')
7385
if (typeof reducer(undefined, { type }) === 'undefined') {
7486
throw new Error(
7587
`Reducer "${key}" returned undefined when probed with a random type. ` +
76-
`Don't try to handle ${ActionTypes.INIT} or other actions in "redux/*" ` +
77-
`namespace. They are considered private. Instead, you must return the ` +
78-
`current state for any unknown actions, unless it is undefined, ` +
79-
`in which case you must return the initial state, regardless of the ` +
80-
`action type. The initial state may not be undefined, but can be null.`
88+
`Don't try to handle ${ActionTypes.INIT} or other actions in "redux/*" ` +
89+
`namespace. They are considered private. Instead, you must return the ` +
90+
`current state for any unknown actions, unless it is undefined, ` +
91+
`in which case you must return the initial state, regardless of the ` +
92+
`action type. The initial state may not be undefined, but can be null.`
8193
)
8294
}
8395
})
@@ -135,7 +147,12 @@ export default function combineReducers(reducers) {
135147
}
136148

137149
if (process.env.NODE_ENV !== 'production') {
138-
const warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache)
150+
const warningMessage = getUnexpectedStateShapeWarningMessage(
151+
state,
152+
finalReducers,
153+
action,
154+
unexpectedKeyCache
155+
)
139156
if (warningMessage) {
140157
warning(warningMessage)
141158
}

src/createStore.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ export default function createStore(reducer, preloadedState, enhancer) {
150150
if (!isPlainObject(action)) {
151151
throw new Error(
152152
'Actions must be plain objects. ' +
153-
'Use custom middleware for async actions.'
153+
'Use custom middleware for async actions.'
154154
)
155155
}
156156

157157
if (typeof action.type === 'undefined') {
158158
throw new Error(
159159
'Actions may not have an undefined "type" property. ' +
160-
'Have you misspelled a constant?'
160+
'Have you misspelled a constant?'
161161
)
162162
}
163163

@@ -172,7 +172,7 @@ export default function createStore(reducer, preloadedState, enhancer) {
172172
isDispatching = false
173173
}
174174

175-
const listeners = currentListeners = nextListeners
175+
const listeners = (currentListeners = nextListeners)
176176
for (let i = 0; i < listeners.length; i++) {
177177
const listener = listeners[i]
178178
listener()

src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ if (
1717
isCrushed.name !== 'isCrushed'
1818
) {
1919
warning(
20-
'You are currently using minified code outside of NODE_ENV === \'production\'. ' +
21-
'This means that you are running a slower development build of Redux. ' +
22-
'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' +
23-
'or DefinePlugin for webpack (http://stackoverflow.com/questions/30030031) ' +
24-
'to ensure you have the correct code for your production build.'
20+
"You are currently using minified code outside of NODE_ENV === 'production'. " +
21+
'This means that you are running a slower development build of Redux. ' +
22+
'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' +
23+
'or DefinePlugin for webpack (http://stackoverflow.com/questions/30030031) ' +
24+
'to ensure you have the correct code for your production build.'
2525
)
2626
}
2727

src/utils/warning.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@ export default function warning(message) {
1515
// "break on all exceptions" in your console,
1616
// it would pause the execution at this line.
1717
throw new Error(message)
18-
/* eslint-disable no-empty */
19-
} catch (e) { }
20-
/* eslint-enable no-empty */
18+
} catch (e) {} // eslint-disable-line no-empty
2119
}

test/applyMiddleware.spec.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ describe('applyMiddleware', () => {
2323
expect(spy.mock.calls[0][0]).toHaveProperty('getState')
2424
expect(spy.mock.calls[0][0]).toHaveProperty('dispatch')
2525

26-
expect(store.getState()).toEqual([ { id: 1, text: 'Use Redux' }, { id: 2, text: 'Flux FTW!' } ])
26+
expect(store.getState()).toEqual([
27+
{ id: 1, text: 'Use Redux' },
28+
{ id: 2, text: 'Flux FTW!' }
29+
])
2730
})
2831

2932
it('passes recursive dispatches through the middleware chain', () => {
@@ -92,25 +95,28 @@ describe('applyMiddleware', () => {
9295
})
9396
})
9497

95-
it('passes through all arguments of dispatch calls from within middleware', () => {
96-
const spy = jest.fn()
97-
const testCallArgs = ['test']
98-
function multiArgMiddleware() {
99-
return next => (action, callArgs) => {
100-
if (Array.isArray(callArgs)) {
101-
return action(...callArgs)
102-
}
103-
return next(action)
104-
}
105-
}
106-
function dummyMiddleware({ dispatch }) {
107-
return next => action => dispatch(action, testCallArgs)
98+
it('passes through all arguments of dispatch calls from within middleware', () => {
99+
const spy = jest.fn()
100+
const testCallArgs = ['test']
101+
function multiArgMiddleware() {
102+
return next => (action, callArgs) => {
103+
if (Array.isArray(callArgs)) {
104+
return action(...callArgs)
108105
}
106+
return next(action)
107+
}
108+
}
109+
function dummyMiddleware({ dispatch }) {
110+
return next => action => dispatch(action, testCallArgs)
111+
}
109112

110-
const store = createStore(reducers.todos, applyMiddleware(multiArgMiddleware, dummyMiddleware))
111-
store.dispatch(spy)
112-
expect(spy.mock.calls[0]).toEqual(testCallArgs)
113-
})
113+
const store = createStore(
114+
reducers.todos,
115+
applyMiddleware(multiArgMiddleware, dummyMiddleware)
116+
)
117+
store.dispatch(spy)
118+
expect(spy.mock.calls[0]).toEqual(testCallArgs)
119+
})
114120

115121
it('keeps unwrapped dispatch available while middleware is initializing', () => {
116122
// This is documenting the existing behavior in Redux 3.x.

0 commit comments

Comments
 (0)