Skip to content

Commit a4439dd

Browse files
committed
eslint的引入,以及选择性的忽略eslint校验
1 parent 0406853 commit a4439dd

File tree

15 files changed

+642
-279
lines changed

15 files changed

+642
-279
lines changed

.eslintignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# service-center/src/views/ServiceAgreement.vue
2+
# service-landing/src/views/ServiceAgreement.vue
3+
# service-landing/src/views/RealName.vue
4+
serviceWorker.js
5+
history.js
6+
src/router/index.js
7+
src/page/echartBox/index.js
8+
src/page/heightEchart/index.js
9+
src/page/chinaMap/index.js

.eslintrc.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
"extends": "airbnb",
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+
},
13+
"env": {
14+
"browser": true,
15+
}
16+
};

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"dotenv": "6.2.0",
2222
"dotenv-expand": "4.2.0",
2323
"echarts": "^4.3.0",
24+
"eslint": "^6.6.0",
25+
"eslint-config-airbnb": "^18.0.1",
2426
"eslint-config-react-app": "^5.0.0",
2527
"eslint-loader": "2.2.1",
2628
"eslint-plugin-flowtype": "3.13.0",
@@ -45,6 +47,7 @@
4547
"postcss-normalize": "7.0.1",
4648
"postcss-preset-env": "6.7.0",
4749
"postcss-safe-parser": "4.0.1",
50+
"prop-types": "^15.7.2",
4851
"react": "^16.9.0",
4952
"react-app-polyfill": "^1.0.2",
5053
"react-app-rewired": "^2.1.4",
@@ -75,11 +78,6 @@
7578
"build": "node scripts/build.js",
7679
"test": "node scripts/test.js"
7780
},
78-
"husky": {
79-
"hooks": {
80-
"pre-commit": "npm run lint"
81-
}
82-
},
8381
"eslintConfig": {
8482
"extends": "react-app"
8583
},

src/App.test.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/page/About/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
// 验证路由传参
22

33
import React from 'react';
4+
import PropTypes from 'prop-types';
45

5-
function Page({location}) {
6-
return (<h2>About: { location.query ? location.query.name : 'No Click' }</h2>);
6+
function Page({ location }) {
7+
return (
8+
<h2>
9+
About:
10+
{ location.query ? location.query.name : 'No Click' }
11+
</h2>
12+
);
713
}
814

9-
export default Page;
15+
Page.propTypes = {
16+
location: PropTypes.object.isRequired,
17+
};
18+
19+
export default Page;

src/page/Counter/index.js

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
11
import { connect } from 'react-redux';
2+
import PropTypes from 'prop-types';
23
import React from 'react';
34

4-
const mapStateToProps = (state) => {
5-
// console.log('state对象', state);
6-
return {
7-
value: state.count,
8-
phone: state.phone,
9-
}
10-
}
11-
5+
const mapStateToProps = (state) => ({
6+
value: state.count,
7+
phone: state.phone,
8+
});
9+
1210
const mapDispatchToProps = {
13-
onIncreaseClick: () => {
14-
return {
15-
type: 'increase',
16-
count: 10,
17-
}
18-
},
19-
onDecreaseClick: () => {
20-
return {
21-
type: 'decrease',
22-
count: 10,
23-
}
24-
},
25-
changeMessageCount: () => {
26-
return {
27-
type: 'changeMessageCount',
28-
}
29-
},
30-
}
11+
onIncreaseClick: () => ({
12+
type: 'increase',
13+
count: 10,
14+
}),
15+
onDecreaseClick: () => ({
16+
type: 'decrease',
17+
count: 10,
18+
}),
19+
changeMessageCount: () => ({
20+
type: 'changeMessageCount',
21+
}),
22+
};
3123

32-
function Page({ value, phone, onIncreaseClick, onDecreaseClick, changeMessageCount }) {
24+
25+
function Page({
26+
value, phone, onIncreaseClick, onDecreaseClick, changeMessageCount,
27+
}) {
3328
return (
3429
<div style={{ marginLeft: 50 }}>
3530
<h1>{value}</h1>
36-
<button onClick={onIncreaseClick}>+</button>
37-
<button style={{ marginLeft: 50 }} onClick={onDecreaseClick}>-</button>
38-
<button style={{ marginLeft: 50 }} onClick={changeMessageCount}>redux异步</button>
31+
<button type="button" onClick={onIncreaseClick}>+</button>
32+
<button type="button" style={{ marginLeft: 50 }} onClick={onDecreaseClick}>-</button>
33+
<button type="button" style={{ marginLeft: 50 }} onClick={changeMessageCount}>redux异步</button>
3934
<h2 style={{ marginTop: 20 }}>{phone}</h2>
4035
</div>
41-
)
36+
);
4237
}
4338

44-
export default connect(mapStateToProps, mapDispatchToProps)(Page);
39+
Page.propTypes = {
40+
value: PropTypes.number.isRequired,
41+
phone: PropTypes.number.isRequired,
42+
onIncreaseClick: PropTypes.func.isRequired,
43+
onDecreaseClick: PropTypes.func.isRequired,
44+
changeMessageCount: PropTypes.func.isRequired,
45+
};
46+
47+
export default connect(mapStateToProps, mapDispatchToProps)(Page);

src/page/CssTest/index.js

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

55
const StyledDiv = styled.div`
66
width: 300px;
@@ -21,4 +21,4 @@ function Page() {
2121
);
2222
}
2323

24-
export default Page;
24+
export default Page;

src/page/Single/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React from "react";
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
23
import { connect } from 'react-redux';
34

45
function mapStateToProps(state) {
@@ -11,4 +12,7 @@ function Page({ num }) {
1112
return (<h1>{num}</h1>);
1213
}
1314

15+
Page.propTypes = {
16+
num: PropTypes.number.isRequired,
17+
};
1418
export default connect(mapStateToProps)(Page);

src/page/form/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { TextArea } = Input;
1010
/**
1111
* 用户名弹窗
1212
*/
13-
function Page({form}) {
13+
function Page({ form }) {
1414
const { getFieldDecorator, validateFields, getFieldValue } = form;
1515
useEffect(() => {
1616
message.success('111');
@@ -43,9 +43,9 @@ function Page({form}) {
4343
<TextArea placeholder="请输入拒绝原因,必填" />,
4444
)}
4545
</Form.Item>
46-
<Button onClick={() => onSubmit()} disabled={getFieldValue('text') ? false : true }>提交</Button>
46+
<Button onClick={() => onSubmit()} disabled={!getFieldValue('text')}>提交</Button>
4747
</Form>
48-
)
48+
);
4949
}
5050

5151
Page.propTypes = {

src/page/memo/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11

22
import React from 'react';
3+
import PropTypes from 'prop-types';
34

4-
function MyComponent({name}) {
5+
function MyComponent({ name }) {
56
/* 使用 props 渲染 */
67
console.log('子组件渲染了');
78
return (
89
<div>
910
{name}
1011
</div>
11-
)
12+
);
1213
}
13-
function areEqual(prevProps, nextProps) {
14-
//true则不重新渲染, 相反则重新渲染
14+
function areEqual() {
15+
// areEqual(prevProps, nextProps)
16+
// true则不重新渲染, 相反则重新渲染
1517
return true;
1618
}
19+
20+
MyComponent.propTypes = {
21+
name: PropTypes.string.isRequired,
22+
};
23+
1724
export default React.memo(MyComponent, areEqual);

0 commit comments

Comments
 (0)