Skip to content

Commit 0c048f0

Browse files
NMinhNguyentimdorr
authored andcommitted
Use Prettier (#1071)
* Use Prettier * Make sure linting and formatting are part of the testing process. * Run prettier on existing code.
1 parent 85fb553 commit 0c048f0

19 files changed

+199
-153
lines changed

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"extends": [
44
"eslint:recommended",
55
"plugin:import/recommended",
6-
"plugin:react/recommended"
6+
"plugin:react/recommended",
7+
"plugin:prettier/recommended"
78
],
89
"parserOptions": {
910
"ecmaVersion": 6,

.prettierrc

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

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ env:
88
- REACT=16.6
99
sudo: false
1010
script:
11-
- npm run lint
12-
- npm run test
11+
- npm test
1312
after_success:
1413
- npm run coverage

package-lock.json

+45
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
"build:umd:min": "cross-env NODE_ENV=production rollup -c -o dist/react-redux.min.js",
3535
"build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min",
3636
"clean": "rimraf lib dist es coverage",
37+
"format": "prettier --write '{src,test}/**/*.js'",
3738
"lint": "eslint src test/utils test/components",
3839
"prepare": "npm run clean && npm run build",
40+
"pretest": "npm run lint",
3941
"test": "node ./test/run-tests.js",
4042
"coverage": "codecov"
4143
},
@@ -68,12 +70,15 @@
6870
"cross-spawn": "^6.0.5",
6971
"es3ify": "^0.2.0",
7072
"eslint": "^4.19.1",
73+
"eslint-config-prettier": "^3.1.0",
7174
"eslint-plugin-import": "^2.12.0",
75+
"eslint-plugin-prettier": "^3.0.0",
7276
"eslint-plugin-react": "^7.9.1",
7377
"glob": "^7.1.1",
7478
"jest": "^23.6.0",
7579
"jest-dom": "^1.12.0",
7680
"npm-run": "^5.0.1",
81+
"prettier": "1.14.3",
7782
"react": "^16.6.0",
7883
"react-dom": "^16.6.0",
7984
"react-testing-library": "^5.0.0",

src/components/connectAdvanced.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ export default function connectAdvanced(
8686
invariant(
8787
isValidElementType(WrappedComponent),
8888
`You must pass a component to the function returned by ` +
89-
`${methodName}. Instead received ${JSON.stringify(WrappedComponent)}`
90-
);
89+
`${methodName}. Instead received ${JSON.stringify(WrappedComponent)}`
90+
)
9191
}
9292

9393
const wrappedComponentName =

src/connect/connect.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ function match(arg, factories, name) {
2929
}
3030

3131
return (dispatch, options) => {
32-
throw new Error(`Invalid value of type ${typeof arg} for ${name} argument when connecting component ${options.wrappedComponentName}.`)
32+
throw new Error(
33+
`Invalid value of type ${typeof arg} for ${name} argument when connecting component ${
34+
options.wrappedComponentName
35+
}.`
36+
)
3337
}
3438
}
3539

36-
function strictEqual(a, b) { return a === b }
40+
function strictEqual(a, b) {
41+
return a === b
42+
}
3743

3844
// createConnect with default args builds the 'official' connect behavior. Calling it with
3945
// different options opens up some testing and extensibility scenarios
@@ -57,15 +63,23 @@ export function createConnect({
5763
...extraOptions
5864
} = {}
5965
) {
60-
const initMapStateToProps = match(mapStateToProps, mapStateToPropsFactories, 'mapStateToProps')
61-
const initMapDispatchToProps = match(mapDispatchToProps, mapDispatchToPropsFactories, 'mapDispatchToProps')
66+
const initMapStateToProps = match(
67+
mapStateToProps,
68+
mapStateToPropsFactories,
69+
'mapStateToProps'
70+
)
71+
const initMapDispatchToProps = match(
72+
mapDispatchToProps,
73+
mapDispatchToPropsFactories,
74+
'mapDispatchToProps'
75+
)
6276
const initMergeProps = match(mergeProps, mergePropsFactories, 'mergeProps')
6377

6478
return connectHOC(selectorFactory, {
6579
// used in error messages
6680
methodName: 'connect',
6781

68-
// used to compute Connect's displayName from the wrapped component's displayName.
82+
// used to compute Connect's displayName from the wrapped component's displayName.
6983
getDisplayName: name => `Connect(${name})`,
7084

7185
// if mapStateToProps is falsy, the Connect component doesn't subscribe to store state changes

src/connect/mapDispatchToProps.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@ import { bindActionCreators } from 'redux'
22
import { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps'
33

44
export function whenMapDispatchToPropsIsFunction(mapDispatchToProps) {
5-
return (typeof mapDispatchToProps === 'function')
5+
return typeof mapDispatchToProps === 'function'
66
? wrapMapToPropsFunc(mapDispatchToProps, 'mapDispatchToProps')
77
: undefined
88
}
99

1010
export function whenMapDispatchToPropsIsMissing(mapDispatchToProps) {
11-
return (!mapDispatchToProps)
11+
return !mapDispatchToProps
1212
? wrapMapToPropsConstant(dispatch => ({ dispatch }))
1313
: undefined
1414
}
1515

1616
export function whenMapDispatchToPropsIsObject(mapDispatchToProps) {
17-
return (mapDispatchToProps && typeof mapDispatchToProps === 'object')
18-
? wrapMapToPropsConstant(dispatch => bindActionCreators(mapDispatchToProps, dispatch))
17+
return mapDispatchToProps && typeof mapDispatchToProps === 'object'
18+
? wrapMapToPropsConstant(dispatch =>
19+
bindActionCreators(mapDispatchToProps, dispatch)
20+
)
1921
: undefined
2022
}
2123

src/connect/mapStateToProps.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps'
22

33
export function whenMapStateToPropsIsFunction(mapStateToProps) {
4-
return (typeof mapStateToProps === 'function')
4+
return typeof mapStateToProps === 'function'
55
? wrapMapToPropsFunc(mapStateToProps, 'mapStateToProps')
66
: undefined
77
}
88

99
export function whenMapStateToPropsIsMissing(mapStateToProps) {
10-
return (!mapStateToProps)
11-
? wrapMapToPropsConstant(() => ({}))
12-
: undefined
10+
return !mapStateToProps ? wrapMapToPropsConstant(() => ({})) : undefined
1311
}
1412

15-
export default [
16-
whenMapStateToPropsIsFunction,
17-
whenMapStateToPropsIsMissing
18-
]
13+
export default [whenMapStateToPropsIsFunction, whenMapStateToPropsIsMissing]

src/connect/mergeProps.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export function defaultMergeProps(stateProps, dispatchProps, ownProps) {
66

77
export function wrapMergePropsFunc(mergeProps) {
88
return function initMergePropsProxy(
9-
dispatch, { displayName, pure, areMergedPropsEqual }
9+
dispatch,
10+
{ displayName, pure, areMergedPropsEqual }
1011
) {
1112
let hasRunOnce = false
1213
let mergedProps
@@ -17,7 +18,6 @@ export function wrapMergePropsFunc(mergeProps) {
1718
if (hasRunOnce) {
1819
if (!pure || !areMergedPropsEqual(nextMergedProps, mergedProps))
1920
mergedProps = nextMergedProps
20-
2121
} else {
2222
hasRunOnce = true
2323
mergedProps = nextMergedProps
@@ -32,18 +32,13 @@ export function wrapMergePropsFunc(mergeProps) {
3232
}
3333

3434
export function whenMergePropsIsFunction(mergeProps) {
35-
return (typeof mergeProps === 'function')
35+
return typeof mergeProps === 'function'
3636
? wrapMergePropsFunc(mergeProps)
3737
: undefined
3838
}
3939

4040
export function whenMergePropsIsOmitted(mergeProps) {
41-
return (!mergeProps)
42-
? () => defaultMergeProps
43-
: undefined
41+
return !mergeProps ? () => defaultMergeProps : undefined
4442
}
4543

46-
export default [
47-
whenMergePropsIsFunction,
48-
whenMergePropsIsOmitted
49-
]
44+
export default [whenMergePropsIsFunction, whenMergePropsIsOmitted]

src/connect/selectorFactory.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,21 @@ export function pureFinalPropsSelectorFactory(
9797
// props have not changed. If false, the selector will always return a new
9898
// object and shouldComponentUpdate will always return true.
9999

100-
export default function finalPropsSelectorFactory(dispatch, {
101-
initMapStateToProps,
102-
initMapDispatchToProps,
103-
initMergeProps,
104-
...options
105-
}) {
100+
export default function finalPropsSelectorFactory(
101+
dispatch,
102+
{ initMapStateToProps, initMapDispatchToProps, initMergeProps, ...options }
103+
) {
106104
const mapStateToProps = initMapStateToProps(dispatch, options)
107105
const mapDispatchToProps = initMapDispatchToProps(dispatch, options)
108106
const mergeProps = initMergeProps(dispatch, options)
109107

110108
if (process.env.NODE_ENV !== 'production') {
111-
verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps, options.displayName)
109+
verifySubselectors(
110+
mapStateToProps,
111+
mapDispatchToProps,
112+
mergeProps,
113+
options.displayName
114+
)
112115
}
113116

114117
const selectorFactory = options.pure

src/connect/verifySubselectors.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import warning from '../utils/warning'
33
function verify(selector, methodName, displayName) {
44
if (!selector) {
55
throw new Error(`Unexpected value for ${methodName} in ${displayName}.`)
6-
7-
} else if (methodName === 'mapStateToProps' || methodName === 'mapDispatchToProps') {
6+
} else if (
7+
methodName === 'mapStateToProps' ||
8+
methodName === 'mapDispatchToProps'
9+
) {
810
if (!selector.hasOwnProperty('dependsOnOwnProps')) {
911
warning(
1012
`The selector for ${methodName} of ${displayName} did not specify a value for dependsOnOwnProps.`
@@ -13,7 +15,12 @@ function verify(selector, methodName, displayName) {
1315
}
1416
}
1517

16-
export default function verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps, displayName) {
18+
export default function verifySubselectors(
19+
mapStateToProps,
20+
mapDispatchToProps,
21+
mergeProps,
22+
displayName
23+
) {
1724
verify(mapStateToProps, 'mapStateToProps', displayName)
1825
verify(mapDispatchToProps, 'mapDispatchToProps', displayName)
1926
verify(mergeProps, 'mergeProps', displayName)

0 commit comments

Comments
 (0)