Skip to content

Commit 6749ce7

Browse files
committed
fix eslint
1 parent 547c7c1 commit 6749ce7

13 files changed

+202
-186
lines changed

.eslintrc

+37-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
11
{
2-
"extends": "eslint-config-rackt",
2+
"parser": "babel-eslint",
3+
"extends": "airbnb",
34
"env": {
4-
"browser": true,
5-
"mocha": true,
6-
"node": true
5+
"mocha": true
76
},
87
"rules": {
9-
"semi": [ 2, "always" ],
10-
"no-unused-vars": 1,
11-
"valid-jsdoc": 2,
12-
"react/jsx-uses-react": 1,
13-
"react/jsx-no-undef": 2,
14-
"react/wrap-multilines": 2
8+
"generator-star-spacing": [0],
9+
"consistent-return": [0],
10+
"react/forbid-prop-types": [0],
11+
"react/jsx-filename-extension": [1, { "extensions": [".js"] }],
12+
"global-require": [1],
13+
"import/prefer-default-export": [0],
14+
"react/jsx-no-bind": [0],
15+
"react/prop-types": [0],
16+
"react/prefer-stateless-function": [0],
17+
"no-else-return": [0],
18+
"no-restricted-syntax": [0],
19+
"import/no-extraneous-dependencies": [0],
20+
"no-use-before-define": [0],
21+
"jsx-a11y/no-static-element-interactions": [0],
22+
"no-nested-ternary": [0],
23+
"arrow-body-style": [0],
24+
"import/extensions": [0],
25+
"no-bitwise": [0],
26+
"no-cond-assign": [0],
27+
"import/no-unresolved": [0],
28+
"require-yield": [1],
29+
"no-param-reassign": [0],
30+
"no-shadow": [0],
31+
"no-underscore-dangle": [0]
1532
},
16-
"plugins": [
17-
"react"
18-
]
19-
}
33+
"globals": {
34+
"document": true
35+
},
36+
"parserOptions": {
37+
"ecmaFeatures": {
38+
"experimentalObjectRestSpread": true
39+
}
40+
}
41+
}
42+

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@
7979
"coveralls": "^2.11.11",
8080
"cross-env": "^2.0.1",
8181
"envify": "^3.4.1",
82-
"eslint": "^3.4.0",
83-
"eslint-config-rackt": "^1.1.1",
84-
"eslint-plugin-react": "^6.0.0",
82+
"eslint": "^3.12.2",
83+
"eslint-config-airbnb": "^13.0.0",
84+
"eslint-plugin-import": "^2.2.0",
85+
"eslint-plugin-jsx-a11y": "^2.2.3",
86+
"eslint-plugin-react": "^6.8.0",
8587
"expect": "^1.20.2",
8688
"jsdom": "^9.5.0",
8789
"mocha": "^3.0.2",

src/createDva.js

+48-45
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import React from 'react';
22
import { Provider } from 'react-redux';
33
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
44
import createSagaMiddleware from 'redux-saga/lib/internal/middleware';
5-
import {
6-
takeEveryHelper as takeEvery,
7-
takeLatestHelper as takeLatest,
8-
throttleHelper as throttle
9-
} from 'redux-saga/lib/internal/sagaHelpers';
10-
import handleActions from './handleActions';
115
import * as sagaEffects from 'redux-saga/effects';
126
import isPlainObject from 'is-plain-object';
137
import invariant from 'invariant';
148
import warning from 'warning';
159
import flatten from 'flatten';
1610
import window from 'global/window';
11+
import {
12+
takeEveryHelper as takeEvery,
13+
takeLatestHelper as takeLatest,
14+
throttleHelper as throttle,
15+
} from 'redux-saga/lib/internal/sagaHelpers';
16+
import handleActions from './handleActions';
1717
import Plugin from './plugin';
1818

1919
const SEP = '/';
@@ -55,7 +55,7 @@ export default function createDva(createOpts) {
5555
};
5656
return app;
5757

58-
////////////////////////////////////
58+
// //////////////////////////////////
5959
// Methods
6060

6161
/**
@@ -117,14 +117,14 @@ export default function createDva(createOpts) {
117117
// support selector
118118
if (typeof container === 'string') {
119119
container = document.querySelector(container);
120-
invariant(container, 'app.start: could not query selector: ' + container);
120+
invariant(container, `app.start: could not query selector: ${container}`);
121121
}
122122

123123
invariant(!container || isHTMLElement(container), 'app.start: container should be HTMLElement');
124124
invariant(this._router, 'app.start: router should be defined');
125125

126126
// error wrapper
127-
const onError = plugin.apply('onError', function(err) {
127+
const onError = plugin.apply('onError', (err) => {
128128
throw new Error(err.stack || err);
129129
});
130130
const onErrorWrapper = (err) => {
@@ -135,9 +135,9 @@ export default function createDva(createOpts) {
135135
};
136136

137137
// get reducers and sagas from model
138-
let sagas = [];
139-
let reducers = { ...initialReducer };
140-
for (let m of this._models) {
138+
const sagas = [];
139+
const reducers = { ...initialReducer };
140+
for (const m of this._models) {
141141
reducers[m.namespace] = getReducer(m.reducers, m.state);
142142
if (m.effects) sagas.push(getSaga(m.effects, m, onErrorWrapper));
143143
}
@@ -146,7 +146,7 @@ export default function createDva(createOpts) {
146146
const extraReducers = plugin.get('extraReducers');
147147
invariant(
148148
Object.keys(extraReducers).every(key => !(key in reducers)),
149-
'app.start: extraReducers is conflict with other reducers'
149+
'app.start: extraReducers is conflict with other reducers',
150150
);
151151

152152
// create store
@@ -168,7 +168,7 @@ export default function createDva(createOpts) {
168168
const store = this._store = createStore(
169169
createReducer(),
170170
initialState,
171-
compose(...enhancers)
171+
compose(...enhancers),
172172
);
173173

174174
function createReducer(asyncReducers) {
@@ -185,7 +185,7 @@ export default function createDva(createOpts) {
185185

186186
// store change
187187
const listeners = plugin.get('onStateChange');
188-
for (let listener of listeners) {
188+
for (const listener of listeners) {
189189
store.subscribe(listener);
190190
}
191191

@@ -196,7 +196,7 @@ export default function createDva(createOpts) {
196196
if (setupHistory) setupHistory.call(this, history);
197197

198198
// run subscriptions
199-
for (let model of this._models) {
199+
for (const model of this._models) {
200200
if (model.subscriptions) {
201201
runSubscriptions(model.subscriptions, model, this, onErrorWrapper);
202202
}
@@ -214,11 +214,11 @@ export default function createDva(createOpts) {
214214
}
215215
}
216216

217-
////////////////////////////////////
217+
// //////////////////////////////////
218218
// Helpers
219219

220220
function getProvider(store, app, router) {
221-
return (extraProps) => (
221+
return extraProps => (
222222
<Provider store={store}>
223223
{ router({ app, history: app._history, ...extraProps }) }
224224
</Provider>
@@ -237,41 +237,41 @@ export default function createDva(createOpts) {
237237

238238
invariant(
239239
namespace,
240-
'app.model: namespace should be defined'
240+
'app.model: namespace should be defined',
241241
);
242242

243243
invariant(
244244
!app._models.some(model => model.namespace === namespace),
245-
'app.model: namespace should be unique'
245+
'app.model: namespace should be unique',
246246
);
247247

248248
invariant(
249249
mobile || namespace !== 'routing',
250-
'app.model: namespace should not be routing, it\'s used by react-redux-router'
250+
'app.model: namespace should not be routing, it\'s used by react-redux-router',
251251
);
252252
invariant(
253253
!model.subscriptions || isPlainObject(model.subscriptions),
254-
'app.model: subscriptions should be Object'
254+
'app.model: subscriptions should be Object',
255255
);
256256
invariant(
257257
!reducers || isPlainObject(reducers) || Array.isArray(reducers),
258-
'app.model: reducers should be Object or array'
258+
'app.model: reducers should be Object or array',
259259
);
260260
invariant(
261261
!Array.isArray(reducers) || (isPlainObject(reducers[0]) && typeof reducers[1] === 'function'),
262-
'app.model: reducers with array should be app.model({ reducers: [object, function] })'
262+
'app.model: reducers with array should be app.model({ reducers: [object, function] })',
263263
);
264264
invariant(
265265
!effects || isPlainObject(effects),
266-
'app.model: effects should be Object'
266+
'app.model: effects should be Object',
267267
);
268268

269269
function applyNamespace(type) {
270270
function getNamespacedReducers(reducers) {
271271
return Object.keys(reducers).reduce((memo, key) => {
272272
warning(
273273
key.indexOf(`${namespace}${SEP}`) !== 0,
274-
`app.model: ${type.slice(0, -1)} ${key} should not be prefixed with namespace ${namespace}`
274+
`app.model: ${type.slice(0, -1)} ${key} should not be prefixed with namespace ${namespace}`,
275275
);
276276
memo[`${namespace}${SEP}${key}`] = reducers[key];
277277
return memo;
@@ -309,11 +309,13 @@ export default function createDva(createOpts) {
309309

310310
function getSaga(effects, model, onError) {
311311
return function *() {
312-
for (let key in effects) {
313-
const watcher = getWatcher(key, effects[key], model, onError);
314-
yield sagaEffects.fork(watcher);
312+
for (const key in effects) {
313+
if (Object.prototype.hasOwnProperty.call(effects, key)) {
314+
const watcher = getWatcher(key, effects[key], model, onError);
315+
yield sagaEffects.fork(watcher);
316+
}
315317
}
316-
}
318+
};
317319
}
318320

319321
function getWatcher(key, _effect, model, onError) {
@@ -329,21 +331,21 @@ export default function createDva(createOpts) {
329331
if (type === 'throttle') {
330332
invariant(
331333
opts.ms,
332-
'app.start: opts.ms should be defined if type is throttle'
334+
'app.start: opts.ms should be defined if type is throttle',
333335
);
334336
ms = opts.ms;
335337
}
336338
}
337339
invariant(
338340
['watcher', 'takeEvery', 'takeLatest', 'throttle'].indexOf(type) > -1,
339-
'app.start: effect type should be takeEvery, takeLatest, throttle or watcher'
341+
'app.start: effect type should be takeEvery, takeLatest, throttle or watcher',
340342
);
341343
}
342344

343345
function *sagaWithCatch(...args) {
344346
try {
345347
yield effect(...args.concat(createEffects(model)));
346-
} catch(e) {
348+
} catch (e) {
347349
onError(e);
348350
}
349351
}
@@ -371,13 +373,15 @@ export default function createDva(createOpts) {
371373
}
372374

373375
function runSubscriptions(subs, model, app, onError) {
374-
for (let key in subs) {
375-
const sub = subs[key];
376-
invariant(typeof sub === 'function', 'app.start: subscription should be function');
377-
sub({
378-
dispatch: createDispatch(app._store.dispatch, model),
379-
history: app._history,
380-
}, onError);
376+
for (const key in subs) {
377+
if (Object.prototype.hasOwnProperty.call(subs, key)) {
378+
const sub = subs[key];
379+
invariant(typeof sub === 'function', 'app.start: subscription should be function');
380+
sub({
381+
dispatch: createDispatch(app._store.dispatch, model),
382+
history: app._history,
383+
}, onError);
384+
}
381385
}
382386
}
383387

@@ -396,31 +400,30 @@ export default function createDva(createOpts) {
396400
invariant(type, 'dispatch: action should be a plain Object with type');
397401
warning(
398402
type.indexOf(`${model.namespace}${SEP}`) !== 0,
399-
`effects.put: ${type} should not be prefixed with namespace ${model.namespace}`
403+
`effects.put: ${type} should not be prefixed with namespace ${model.namespace}`,
400404
);
401405
return sagaEffects.put({ ...action, type: prefixType(type, model) });
402406
}
403407
return { ...sagaEffects, put };
404408
}
405409

406410
function createDispatch(dispatch, model) {
407-
return action => {
411+
return (action) => {
408412
const { type } = action;
409413
invariant(type, 'dispatch: action should be a plain Object with type');
410414
warning(
411415
type.indexOf(`${model.namespace}${SEP}`) !== 0,
412-
`dispatch: ${type} should not be prefixed with namespace ${model.namespace}`
416+
`dispatch: ${type} should not be prefixed with namespace ${model.namespace}`,
413417
);
414418
return dispatch({ ...action, type: prefixType(type, model) });
415419
};
416420
}
417421

418422
function applyOnEffect(fns, effect, model, key) {
419-
for (let fn of fns) {
423+
for (const fn of fns) {
420424
effect = fn(effect, sagaEffects, model, key);
421425
}
422426
return effect;
423427
}
424-
425428
};
426429
}

src/handleActions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function reduceReducers(...reducers) {
1717
return (previous, current) =>
1818
reducers.reduce(
1919
(p, r) => r(p, current),
20-
previous
20+
previous,
2121
);
2222
}
2323

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import hashHistory from 'react-router/lib/hashHistory';
22
import {
33
routerMiddleware,
44
syncHistoryWithStore,
5-
routerReducer as routing
5+
routerReducer as routing,
66
} from 'react-router-redux';
77
import createDva from './createDva';
88

@@ -12,7 +12,7 @@ export default createDva({
1212
routing,
1313
},
1414
defaultHistory: hashHistory,
15-
routerMiddleware: routerMiddleware,
15+
routerMiddleware,
1616

1717
setupHistory(history) {
1818
this._history = syncHistoryWithStore(history, this._store);

0 commit comments

Comments
 (0)