Skip to content

Commit 3f1f90e

Browse files
DiamondYuansorrycc
authored andcommitted
style: add .prettierrc and fix lint error (#2117)
1 parent c752cd9 commit 3f1f90e

29 files changed

+291
-241
lines changed

.eslintrc

+153-45
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,163 @@
11
{
22
"parser": "babel-eslint",
3-
"extends": "airbnb",
3+
"plugins": [
4+
"prettier"
5+
],
6+
"extends": [
7+
"airbnb",
8+
"prettier"
9+
],
410
"env": {
511
"browser": true,
612
"jest": true
713
},
814
"rules": {
9-
"jsx-a11y/href-no-hash": [0],
10-
"jsx-a11y/click-events-have-key-events": [0],
11-
"jsx-a11y/anchor-is-valid": [ "error", {
12-
"components": [ "Link" ],
13-
"specialLink": [ "to" ]
14-
}],
15-
"generator-star-spacing": [0],
16-
"consistent-return": [0],
17-
"react/react-in-jsx-scope": [0],
18-
"react/forbid-prop-types": [0],
19-
"react/jsx-filename-extension": [1, { "extensions": [".js"] }],
20-
"global-require": [1],
21-
"import/prefer-default-export": [0],
22-
"react/jsx-no-bind": [0],
23-
"react/prop-types": [0],
24-
"react/prefer-stateless-function": [0],
25-
"no-else-return": [0],
26-
"no-restricted-syntax": [0],
27-
"import/no-extraneous-dependencies": [0],
28-
"no-use-before-define": [0],
29-
"jsx-a11y/no-static-element-interactions": [0],
30-
"no-nested-ternary": [0],
31-
"arrow-body-style": [0],
32-
"import/extensions": [0],
33-
"no-bitwise": [0],
34-
"no-cond-assign": [0],
35-
"import/no-unresolved": [0],
36-
"require-yield": [1],
37-
"no-param-reassign": [0],
38-
"no-shadow": [0],
39-
"no-underscore-dangle": [0],
40-
"spaced-comment": [0],
41-
"indent": [0],
42-
"quotes": [0],
43-
"func-names": [0],
44-
"arrow-parens": [0],
45-
"space-before-function-paren": [0],
46-
"no-useless-escape": [0],
47-
"object-curly-newline": [0],
48-
"function-paren-newline": [0],
49-
"class-methods-use-this": [0],
50-
"no-new": [0],
51-
"import/newline-after-import": [0],
52-
"no-console": [0]
15+
"prettier/prettier": "error",
16+
"jsx-a11y/href-no-hash": [
17+
0
18+
],
19+
"jsx-a11y/click-events-have-key-events": [
20+
0
21+
],
22+
"jsx-a11y/anchor-is-valid": [
23+
"error",
24+
{
25+
"components": [
26+
"Link"
27+
],
28+
"specialLink": [
29+
"to"
30+
]
31+
}
32+
],
33+
"generator-star-spacing": [
34+
0
35+
],
36+
"consistent-return": [
37+
0
38+
],
39+
"radix": [
40+
1
41+
],
42+
"react/react-in-jsx-scope": [
43+
0
44+
],
45+
"react/forbid-prop-types": [
46+
0
47+
],
48+
"react/jsx-filename-extension": [
49+
1,
50+
{
51+
"extensions": [
52+
".js"
53+
]
54+
}
55+
],
56+
"global-require": [
57+
0
58+
],
59+
"import/prefer-default-export": [
60+
0
61+
],
62+
"react/jsx-no-bind": [
63+
0
64+
],
65+
"react/prop-types": [
66+
0
67+
],
68+
"react/prefer-stateless-function": [
69+
0
70+
],
71+
"react/jsx-one-expression-per-line": [
72+
0
73+
],
74+
"react/button-has-type": [
75+
0
76+
],
77+
"no-else-return": [
78+
0
79+
],
80+
"no-restricted-syntax": [
81+
0
82+
],
83+
"import/no-extraneous-dependencies": [
84+
0
85+
],
86+
"no-use-before-define": [
87+
0
88+
],
89+
"jsx-a11y/no-static-element-interactions": [
90+
0
91+
],
92+
"no-nested-ternary": [
93+
0
94+
],
95+
"arrow-body-style": [
96+
0
97+
],
98+
"import/extensions": [
99+
0
100+
],
101+
"no-bitwise": [
102+
0
103+
],
104+
"no-cond-assign": [
105+
0
106+
],
107+
"import/no-unresolved": [
108+
0
109+
],
110+
"require-yield": [
111+
1
112+
],
113+
"no-param-reassign": [
114+
0
115+
],
116+
"no-shadow": [
117+
0
118+
],
119+
"no-underscore-dangle": [
120+
0
121+
],
122+
"spaced-comment": [
123+
0
124+
],
125+
"indent": [
126+
0
127+
],
128+
"quotes": [
129+
0
130+
],
131+
"func-names": [
132+
0
133+
],
134+
"arrow-parens": [
135+
0
136+
],
137+
"space-before-function-paren": [
138+
0
139+
],
140+
"no-useless-escape": [
141+
0
142+
],
143+
"object-curly-newline": [
144+
0
145+
],
146+
"function-paren-newline": [
147+
0
148+
],
149+
"class-methods-use-this": [
150+
0
151+
],
152+
"no-new": [
153+
0
154+
],
155+
"import/newline-after-import": [
156+
0
157+
],
158+
"no-console": [
159+
0
160+
]
53161
},
54162
"parserOptions": {
55163
"ecmaFeatures": {

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 100,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"eslint-plugin-import": "^2.14.0",
2323
"eslint-plugin-jsx-a11y": "^6.0.2",
2424
"eslint-plugin-react": "^7.11.1",
25+
"eslint-config-prettier": "^4.3.0",
26+
"eslint-plugin-prettier": "^3.1.0",
2527
"husky": "^0.14.3",
2628
"lerna": "^3.4.0",
2729
"lerna-changelog": "^0.8.0",

packages/dva-core/src/Plugin.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ export default class Plugin {
3232
}
3333

3434
use(plugin) {
35-
invariant(
36-
isPlainObject(plugin),
37-
'plugin.use: plugin should be plain object'
38-
);
39-
const hooks = this.hooks;
35+
invariant(isPlainObject(plugin), 'plugin.use: plugin should be plain object');
36+
const { hooks } = this;
4037
for (const key in plugin) {
4138
if (Object.prototype.hasOwnProperty.call(plugin, key)) {
4239
invariant(hooks[key], `plugin.use: unknown plugin property: ${key}`);
@@ -52,12 +49,9 @@ export default class Plugin {
5249
}
5350

5451
apply(key, defaultHandler) {
55-
const hooks = this.hooks;
52+
const { hooks } = this;
5653
const validApplyHooks = ['onError', 'onHmr'];
57-
invariant(
58-
validApplyHooks.indexOf(key) > -1,
59-
`plugin.apply: hook ${key} cannot be applied`
60-
);
54+
invariant(validApplyHooks.indexOf(key) > -1, `plugin.apply: hook ${key} cannot be applied`);
6155
const fns = hooks[key];
6256

6357
return (...args) => {
@@ -72,7 +66,7 @@ export default class Plugin {
7266
}
7367

7468
get(key) {
75-
const hooks = this.hooks;
69+
const { hooks } = this;
7670
invariant(key in hooks, `plugin.get: hook ${key} cannot be got`);
7771
if (key === 'extraReducers') {
7872
return getExtraReducers(hooks[key]);

packages/dva-core/src/checkModel.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@ import invariant from 'invariant';
22
import { isArray, isFunction, isPlainObject } from './utils';
33

44
export default function checkModel(model, existModels) {
5-
const {
6-
namespace,
7-
reducers,
8-
effects,
9-
subscriptions,
10-
} = model;
5+
const { namespace, reducers, effects, subscriptions } = model;
116

127
// namespace 必须被定义
13-
invariant(
14-
namespace,
15-
`[app.model] namespace should be defined`,
16-
);
8+
invariant(namespace, `[app.model] namespace should be defined`);
179
// 并且是字符串
1810
invariant(
1911
typeof namespace === 'string',
@@ -56,10 +48,7 @@ export default function checkModel(model, existModels) {
5648
);
5749

5850
// subscription 必须为函数
59-
invariant(
60-
isAllFunction(subscriptions),
61-
`[app.model] subscription should be function`,
62-
);
51+
invariant(isAllFunction(subscriptions), `[app.model] subscription should be function`);
6352
}
6453
}
6554

packages/dva-core/src/constants.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
21
export const NAMESPACE_SEP = '/';

packages/dva-core/src/createStore.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ export default function({
2727
]);
2828

2929
const composeEnhancers =
30-
process.env.NODE_ENV !== 'production' &&
31-
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
30+
process.env.NODE_ENV !== 'production' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
3231
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ trace: true, maxAge: 30 })
3332
: compose;
3433

packages/dva-core/src/getReducer.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ export default function getReducer(reducers, state, handleActions) {
44
// Support reducer enhancer
55
// e.g. reducers: [realReducers, enhancer]
66
if (Array.isArray(reducers)) {
7-
return reducers[1](
8-
(handleActions || defaultHandleActions)(reducers[0], state)
9-
);
7+
return reducers[1]((handleActions || defaultHandleActions)(reducers[0], state));
108
} else {
119
return (handleActions || defaultHandleActions)(reducers || {}, state);
1210
}

packages/dva-core/src/getSaga.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,13 @@ function getWatcher(key, _effect, model, onError, onEffect) {
2525
let ms;
2626

2727
if (Array.isArray(_effect)) {
28-
effect = _effect[0];
28+
[effect] = _effect;
2929
const opts = _effect[1];
3030
if (opts && opts.type) {
31-
type = opts.type;
31+
({ type } = opts);
3232
if (type === 'throttle') {
33-
invariant(
34-
opts.ms,
35-
'app.start: opts.ms should be defined if type is throttle',
36-
);
37-
ms = opts.ms;
33+
invariant(opts.ms, 'app.start: opts.ms should be defined if type is throttle');
34+
({ ms } = opts);
3835
}
3936
}
4037
invariant(
@@ -89,9 +86,7 @@ function createEffects(model) {
8986
invariant(type, 'dispatch: action should be a plain Object with type');
9087
warning(
9188
type.indexOf(`${model.namespace}${NAMESPACE_SEP}`) !== 0,
92-
`[${name}] ${type} should not be prefixed with namespace ${
93-
model.namespace
94-
}`,
89+
`[${name}] ${type} should not be prefixed with namespace ${model.namespace}`,
9590
);
9691
}
9792
function put(action) {

packages/dva-core/src/handleActions.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ function handleAction(actionType, reducer = identify) {
1616
}
1717

1818
function reduceReducers(...reducers) {
19-
return (previous, current) =>
20-
reducers.reduce((p, r) => r(p, current), previous);
19+
return (previous, current) => reducers.reduce((p, r) => r(p, current), previous);
2120
}
2221

2322
function handleActions(handlers, defaultState) {
24-
const reducers = Object.keys(handlers).map(type =>
25-
handleAction(type, handlers[type])
26-
);
23+
const reducers = Object.keys(handlers).map(type => handleAction(type, handlers[type]));
2724
const reducer = reduceReducers(...reducers);
2825
return (state = defaultState, action) => reducer(state, action);
2926
}

0 commit comments

Comments
 (0)