Skip to content

Commit 44378ea

Browse files
committed
test Prettier
1 parent 7a99711 commit 44378ea

File tree

24 files changed

+447
-489
lines changed

24 files changed

+447
-489
lines changed

.eslintrc.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
module.exports = {
2-
"extends": [
3-
"airbnb",
4-
"plugin:prettier/recommended",
5-
],
6-
"rules": {
7-
"react/jsx-filename-extension": "off",
8-
"react/forbid-prop-types": "off",
9-
"jsx-a11y/anchor-is-valid": "off",
10-
"jsx-a11y/click-events-have-key-events": "off",
11-
"jsx-a11y/no-static-element-interactions": "off",
12-
"jsx-a11y/interactive-supports-focus": "off",
13-
"jsx-a11y/anchor-is-valid": "off",
14-
"react/no-array-index-key": "off",
15-
"no-console": "off",
16-
"prettier/prettier": "error"
17-
},
18-
"env": {
19-
"browser": true,
20-
}
21-
};
2+
extends: ["airbnb", "plugin:prettier/recommended"],
3+
rules: {
4+
"react/jsx-filename-extension": "off",
5+
"react/forbid-prop-types": "off",
6+
"jsx-a11y/anchor-is-valid": "off",
7+
"jsx-a11y/click-events-have-key-events": "off",
8+
"jsx-a11y/no-static-element-interactions": "off",
9+
"jsx-a11y/interactive-supports-focus": "off",
10+
"jsx-a11y/anchor-is-valid": "off",
11+
"react/no-array-index-key": "off",
12+
"no-console": "off",
13+
"prettier/prettier": "error",
14+
"react/jsx-one-expression-per-line": "off"
15+
},
16+
env: {
17+
browser: true
18+
}
19+
};

config/webpack.config.js

Lines changed: 172 additions & 206 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
]
165165
},
166166
"devDependencies": {
167+
"eslint-config-prettier": "^6.7.0",
167168
"eslint-plugin-prettier": "^3.1.1",
168169
"husky": "^3.1.0",
169170
"lint-staged": "^9.4.3",

src/echarts/index.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
// import echarts from 'echarts';
2-
import echarts from 'echarts/lib/echarts';
2+
import echarts from "echarts/lib/echarts";
33

4-
import 'echarts/lib/chart/line';
5-
import 'echarts/lib/chart/bar';
6-
import 'echarts/lib/chart/lines';
7-
import 'echarts/lib/chart/pie';
8-
import 'echarts/lib/chart/effectScatter';
9-
import 'echarts/lib/chart/map';
10-
import 'echarts/lib/chart/scatter';
4+
import "echarts/lib/chart/line";
5+
import "echarts/lib/chart/bar";
6+
import "echarts/lib/chart/lines";
7+
import "echarts/lib/chart/pie";
8+
import "echarts/lib/chart/effectScatter";
9+
import "echarts/lib/chart/map";
10+
import "echarts/lib/chart/scatter";
1111

12-
import 'echarts/lib/component/geo';
13-
import 'echarts/lib/component/title';
14-
import 'echarts/lib/component/tooltip';
15-
import 'echarts/lib/component/legend';
16-
import 'echarts/lib/component/axis';
17-
import 'echarts/lib/component/grid';
18-
import 'echarts/lib/component/visualMap';
19-
import 'echarts/lib/component/dataZoom';
12+
import "echarts/lib/component/geo";
13+
import "echarts/lib/component/title";
14+
import "echarts/lib/component/tooltip";
15+
import "echarts/lib/component/legend";
16+
import "echarts/lib/component/axis";
17+
import "echarts/lib/component/grid";
18+
import "echarts/lib/component/visualMap";
19+
import "echarts/lib/component/dataZoom";
2020

21-
import chinaJson from './china';
21+
import chinaJson from "./china";
2222

23-
echarts.registerMap('china', chinaJson);
23+
echarts.registerMap("china", chinaJson);
2424

2525
export default echarts;

src/index.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,57 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import './index.css';
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import "./index.css";
44

5-
import { createStore, applyMiddleware } from 'redux';
5+
import { createStore, applyMiddleware } from "redux";
66
// import { createLogger } from 'redux-logger';
7-
import { Provider } from 'react-redux';
7+
import { Provider } from "react-redux";
88

9-
import reducer from './page/reducer/index';
10-
import req from './req/index';
11-
import AppRouter from './router/index';
9+
import reducer from "./page/reducer/index";
10+
import req from "./req/index";
11+
import AppRouter from "./router/index";
1212
// import thunkMiddleware from 'redux-thunk'
13-
import * as serviceWorker from './serviceWorker';
13+
import * as serviceWorker from "./serviceWorker";
1414

1515
/**
1616
* 官方自带的操作显示工具
1717
*/
1818
// const loggerMiddleware = createLogger();
1919

20-
const logger = (store) => (next) => (action) => {
21-
console.log('dispatching', action);
20+
const logger = store => next => action => {
21+
console.log("dispatching", action);
2222
const result = next(action);
23-
console.log('next state', store.getState());
23+
console.log("next state", store.getState());
2424
return result;
2525
};
2626

27-
const thunkMiddleware = (store) => (next) => (action) => {
28-
console.log('拦截了');
29-
if (action.type === 'changeMessageCount') {
30-
console.log('符合条件');
27+
const thunkMiddleware = store => next => action => {
28+
console.log("拦截了");
29+
if (action.type === "changeMessageCount") {
30+
console.log("符合条件");
3131
setTimeout(() => {
32-
req.user.getMyInfo()
33-
.then((res) => {
32+
req.user
33+
.getMyInfo()
34+
.then(res => {
3435
if (res.code !== 0) {
3536
req.err.show(res);
3637
return;
3738
}
38-
console.log('timerMiddleware', res.data);
39-
store.dispatch({ type: 'receiveCount', phone: res.data.mobile });
39+
console.log("timerMiddleware", res.data);
40+
store.dispatch({ type: "receiveCount", phone: res.data.mobile });
4041
})
4142
.catch(req.err.show);
4243
}, 2000);
4344
}
4445
next(action);
4546
};
4647

47-
const store = createStore(
48-
reducer,
49-
applyMiddleware(thunkMiddleware, logger),
50-
);
48+
const store = createStore(reducer, applyMiddleware(thunkMiddleware, logger));
5149

5250
ReactDOM.render(
5351
<Provider store={store}>
5452
<AppRouter />
55-
</Provider>, document.getElementById('root'),
53+
</Provider>,
54+
document.getElementById("root")
5655
);
5756

5857
// If you want your app to work offline and load faster, you can change

src/page/Counter/index.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
1-
import { connect } from 'react-redux';
2-
import PropTypes from 'prop-types';
3-
import React from 'react';
1+
import { connect } from "react-redux";
2+
import PropTypes from "prop-types";
3+
import React from "react";
44

5-
const mapStateToProps = (state) => ({
6-
value: state.count,
5+
const mapStateToProps = state => ({
6+
value: state.count
77
});
88

99
const mapDispatchToProps = {
1010
onIncreaseClick: () => ({
11-
type: 'increase',
12-
count: 10,
11+
type: "increase",
12+
count: 10
1313
}),
1414
onDecreaseClick: () => ({
15-
type: 'decrease',
16-
count: 10,
15+
type: "decrease",
16+
count: 10
1717
}),
1818
changeMessageCount: () => ({
19-
type: 'changeMessageCount',
20-
}),
19+
type: "changeMessageCount"
20+
})
2121
};
2222

23-
24-
function Page({
25-
value, onIncreaseClick, onDecreaseClick,
26-
}) {
23+
function Page({ value, onIncreaseClick, onDecreaseClick }) {
2724
return (
2825
<div style={{ marginLeft: 50 }}>
2926
<h1>{value}</h1>
30-
<button type="button" onClick={onIncreaseClick}>+</button>
31-
<button type="button" style={{ marginLeft: 50 }} onClick={onDecreaseClick}>-</button>
27+
<button type="button" onClick={onIncreaseClick}>
28+
+
29+
</button>
30+
<button type="button" style={{ marginLeft: 50 }} onClick={onDecreaseClick}>
31+
-
32+
</button>
3233
</div>
3334
);
3435
}
3536

3637
Page.propTypes = {
3738
value: PropTypes.number.isRequired,
3839
onIncreaseClick: PropTypes.func.isRequired,
39-
onDecreaseClick: PropTypes.func.isRequired,
40+
onDecreaseClick: PropTypes.func.isRequired
4041
};
4142

4243
export default connect(mapStateToProps, mapDispatchToProps)(Page);

src/page/CssTest/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React from 'react';
2-
import styled from 'styled-components';
3-
import style from './index.module.css';
1+
import React from "react";
2+
import styled from "styled-components";
3+
import style from "./index.module.css";
44

55
const StyledDiv = styled.div`
66
width: 300px;

src/page/Optimize/index.js

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import React, { useState } from 'react';
2-
import styled from 'styled-components';
3-
import PropTypes from 'prop-types';
4-
import {
5-
Radio, Button,
6-
} from 'antd';
7-
import { CSSTransition } from 'react-transition-group';
8-
1+
import React, { useState } from "react";
2+
import styled from "styled-components";
3+
import PropTypes from "prop-types";
4+
import { Radio, Button } from "antd";
5+
import { CSSTransition } from "react-transition-group";
96

107
const StyledDiv = styled.div`
118
width: 500px;
@@ -15,35 +12,33 @@ const StyledDiv = styled.div`
1512
height: 50px;
1613
line-height: 50px;
1714
}
18-
.line-height button{
15+
.line-height button {
1916
background-color: black;
2017
color: #fff;
2118
}
22-
.fade-enter{
19+
.fade-enter {
2320
opacity: 0;
24-
}
25-
.fade-enter-active{
21+
}
22+
.fade-enter-active {
2623
opacity: 1;
2724
transition: opacity 2000ms;
28-
29-
}
30-
.fade-enter-done{
25+
}
26+
.fade-enter-done {
3127
opacity: 1;
32-
}
33-
.fade-exit{
28+
}
29+
.fade-exit {
3430
opacity: 1;
35-
}
36-
.fade-exit-active{
31+
}
32+
.fade-exit-active {
3733
opacity: 0;
3834
transition: opacity 2000ms;
39-
40-
}
41-
.fade-exit-done{
35+
}
36+
.fade-exit-done {
4237
opacity: 0;
43-
}
38+
}
4439
`;
4540
function Page() {
46-
const [color, setColor] = useState('blue');
41+
const [color, setColor] = useState("blue");
4742
const [show, setShow] = useState(true);
4843
function changeTab(e) {
4944
if (color === e.target.value) {
@@ -61,7 +56,9 @@ function Page() {
6156
<Radio.Button value="red">red</Radio.Button>
6257
<Radio.Button value="yellow">yellow</Radio.Button>
6358
</Radio.Group>
64-
<Button style={{ marginLeft: 40 }} type="primary" onClick={() => setShow(!show)}>toggleShow</Button>
59+
<Button style={{ marginLeft: 40 }} type="primary" onClick={() => setShow(!show)}>
60+
toggleShow
61+
</Button>
6562
<CSSTransition
6663
in={show} // 用于判断是否出现的状态
6764
timeout={800} // 动画持续时间
@@ -77,25 +74,21 @@ function Page() {
7774
class Son extends React.Component {
7875
constructor(props) {
7976
super(props);
80-
this.state = {
81-
};
77+
this.state = {};
8278
}
8379

8480
shouldComponentUpdate(nextProps) {
85-
return nextProps.color !== 'yellow';
81+
return nextProps.color !== "yellow";
8682
}
8783

8884
render() {
89-
console.log('son render');
85+
console.log("son render");
9086
const { color } = this.props;
91-
return (
92-
<div style={{ color, marginTop: 20 }}>1111</div>
93-
);
87+
return <div style={{ color, marginTop: 20 }}>1111</div>;
9488
}
9589
}
9690
Son.propTypes = {
97-
color: PropTypes.string.isRequired,
91+
color: PropTypes.string.isRequired
9892
};
9993

100-
10194
export default Page;

0 commit comments

Comments
 (0)