Skip to content

Commit 48a79a3

Browse files
committed
🇨🇳 eslint
1 parent c8d11a0 commit 48a79a3

10 files changed

+160
-124
lines changed

.eslintrc

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"rules": {
3+
"indent": [
4+
2,
5+
2
6+
],
7+
"quotes": [
8+
2,
9+
"single"
10+
],
11+
"linebreak-style": [
12+
2,
13+
"unix"
14+
],
15+
"semi": [
16+
2,
17+
"always"
18+
]
19+
},
20+
"env": {
21+
"es6": true,
22+
"node": true
23+
},
24+
"extends": "eslint:recommended",
25+
"ecmaFeatures": {
26+
"jsx": true,
27+
"experimentalObjectRestSpread": true
28+
},
29+
"plugins": [
30+
"react"
31+
]
32+
}

.vscode/settings.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"javascript.validate.enable": false,
4+
"eslint.enable": true,
5+
"eslint.options": {
6+
"rules": {
7+
"indent": [
8+
2,
9+
2
10+
],
11+
"quotes": [
12+
2,
13+
"single"
14+
],
15+
"linebreak-style": [
16+
2,
17+
"unix"
18+
],
19+
"semi": [
20+
2,
21+
"always"
22+
]
23+
},
24+
"env": {
25+
"es6": true,
26+
"node": true
27+
},
28+
"extends": "eslint:recommended",
29+
"ecmaFeatures": {
30+
"jsx": true,
31+
"experimentalObjectRestSpread": true
32+
},
33+
"plugins": [
34+
"react"
35+
]
36+
}
37+
}

apilist.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ var requestParamsWrapper = (api, ...params) => api + '?' + params.join('&');
77
// 分页获取
88
var fetchResourceWithPage = (request, offset=0, pageSize=20) => {
99
let _pageParams = [
10-
'offset=' + offset,
11-
'limit=' + pageSize,
10+
'offset=' + offset,
11+
'limit=' + pageSize
1212
].join('&');
1313

1414
if(request.endsWith('&')) {
@@ -18,18 +18,18 @@ var fetchResourceWithPage = (request, offset=0, pageSize=20) => {
1818
} else {
1919
return request + '/?' + _pageParams;
2020
}
21-
}
21+
};
2222

2323
// 默认主题列表
2424
var TOPIC_API = apiResourceWrapper('topics.json');
2525
// 最近主题
26-
var RECENT_TOP_API = requestParamsWrapper(TOPIC_API, 'type=recent')
26+
var RECENT_TOP_API = requestParamsWrapper(TOPIC_API, 'type=recent');
2727
// 热门主题
28-
var POP_TOPIC_API = requestParamsWrapper(TOPIC_API, 'type=popular')
28+
var POP_TOPIC_API = requestParamsWrapper(TOPIC_API, 'type=popular');
2929
// 精华主题
30-
var EXEC_TOPIC_API = requestParamsWrapper(TOPIC_API, 'type=excellent')
30+
var EXEC_TOPIC_API = requestParamsWrapper(TOPIC_API, 'type=excellent');
3131
// 还没有任何回复的
32-
var NO_REPLY_API = requestParamsWrapper(TOPIC_API, 'type=no_reply')
32+
var NO_REPLY_API = requestParamsWrapper(TOPIC_API, 'type=no_reply');
3333

3434
module.exports = {
3535
TOPIC_API,
@@ -38,4 +38,4 @@ module.exports = {
3838
NO_REPLY_API,
3939
RECENT_TOP_API,
4040
fetchResourceWithPage
41-
}
41+
};

components/a-AppMain.js

+41-54
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,43 @@ var apilist = require('../apilist');
44

55
var {
66
StyleSheet,
7-
Text,
8-
View,
9-
ListView,
10-
Image,
11-
ActivityIndicatorIOS,
127
TabBarIOS,
138
NavigatorIOS
149
} = React;
1510

1611

1712
var AppNavBar = React.createClass({
1813

19-
getInitialState() {
20-
return {
21-
selectedTab: 'indexTab',
22-
currentApi: ''
23-
}
24-
},
25-
26-
_renderPage(nav) {
27-
return (
14+
getInitialState() {
15+
return {
16+
selectedTab: 'indexTab',
17+
currentApi: ''
18+
};
19+
},
20+
21+
_renderPage(nav) {
22+
return (
2823
<NavigatorIOS
2924
style={styles.container}
30-
ref='INDEX_NAV'
25+
ref='INDEX_NAV'
3126
initialRoute={{
3227
component: TopicPage,
3328
title: 'TesterHome',
3429
passProps: {
3530
needSlideContents: nav
36-
},
31+
}
3732
}}
3833
shadowHidden={true}
3934
translucent={false}
4035
barTintColor='#e74c3c'
4136
titleTextColor='#ffffff'
4237
tintColor='#ffffff'
4338
/>
44-
)
45-
},
39+
);
40+
},
4641

47-
render() {
48-
return (
42+
render() {
43+
return (
4944
<TabBarIOS
5045
tintColor="#e74c3c"
5146
barTintColor="#f9f9f9"
@@ -56,80 +51,72 @@ var AppNavBar = React.createClass({
5651
icon={{uri: require('image!iconfont-zuijinfabu')}}
5752
selected={this.state.selectedTab === 'indexTab'}
5853
onPress={() => {
59-
this.setState({
60-
selectedTab: 'indexTab',
61-
});
62-
}}>
63-
{this._renderPage(
64-
[
54+
this.setState({
55+
selectedTab: 'indexTab'
56+
});
57+
}}>
58+
{this._renderPage([
6559
{api: apilist.RECENT_TOP_API, apiName: 'RECENT_TOP_API', tabLable: '最新'},
6660
{api: apilist.POP_TOPIC_API, apiName: 'POP_TOPIC_API', tabLable: '最热'},
6761
{api: apilist.NO_REPLY_API, apiName: 'NO_REPLY_API', tabLable: '沙发'},
68-
{api: apilist.EXEC_TOPIC_API, apiName: 'EXEC_TOPIC_API', tabLable: '精华'}
69-
]
62+
{api: apilist.EXEC_TOPIC_API, apiName: 'EXEC_TOPIC_API', tabLable: '精华'}]
7063
)}
7164
</TabBarIOS.Item>
7265
<TabBarIOS.Item
7366
title="话题"
7467
icon={{uri: require('image!iconfont-jinghua')}}
7568
selected={this.state.selectedTab === 'niceTab'}
7669
onPress={() => {
77-
this.setState({
78-
selectedTab: 'niceTab',
79-
});
80-
}}>
81-
{this._renderPage(
82-
[
70+
this.setState({
71+
selectedTab: 'niceTab'
72+
});
73+
}}>
74+
{this._renderPage([
8375
{api: apilist.RECENT_TOP_API, apiName: 'RECENT_TOP_API', tabLable: '北京'},
84-
{api: apilist.POP_TOPIC_API, apiName: 'POP_TOPIC_API', tabLable: '上海'},
85-
]
76+
{api: apilist.POP_TOPIC_API, apiName: 'POP_TOPIC_API', tabLable: '上海'}]
8677
)}
8778
</TabBarIOS.Item>
8879
<TabBarIOS.Item
8980
title="招聘"
9081
icon={{uri: require('image!iconfont-hot')}}
9182
selected={this.state.selectedTab === 'hotTab'}
9283
onPress={() => {
93-
this.setState({
94-
selectedTab: 'hotTab',
95-
});
96-
}}>
97-
{this._renderPage(
98-
[
84+
this.setState({
85+
selectedTab: 'hotTab'
86+
});
87+
}}>
88+
{this._renderPage([
9989
{api: apilist.RECENT_TOP_API, apiName: 'RECENT_TOP_API', tabLable: '最新'},
10090
{api: apilist.POP_TOPIC_API, apiName: 'POP_TOPIC_API', tabLable: '最热'},
10191
{api: apilist.NO_REPLY_API, apiName: 'NO_REPLY_API', tabLable: '沙发'},
102-
{api: apilist.EXEC_TOPIC_API, apiName: 'EXEC_TOPIC_API', tabLable: '精华'}
103-
]
92+
{api: apilist.EXEC_TOPIC_API, apiName: 'EXEC_TOPIC_API', tabLable: '精华'}]
10493
)}
10594
</TabBarIOS.Item>
10695
<TabBarIOS.Item
10796
title="我的"
10897
icon={{uri: require('image!iconfont-shafa')}}
10998
selected={this.state.selectedTab === 'needComment'}
11099
onPress={() => {
111-
this.setState({
112-
selectedTab: 'needComment',
113-
});
114-
}}>
115-
{this._renderPage(
116-
[
100+
this.setState({
101+
selectedTab: 'needComment'
102+
});
103+
}}>
104+
{this._renderPage([
117105
{api: apilist.RECENT_TOP_API, apiName: 'RECENT_TOP_API', tabLable: '最新'},
118106
{api: apilist.POP_TOPIC_API, apiName: 'POP_TOPIC_API', tabLable: '最热'},
119107
{api: apilist.NO_REPLY_API, apiName: 'NO_REPLY_API', tabLable: '沙发'},
120-
{api: apilist.EXEC_TOPIC_API, apiName: 'EXEC_TOPIC_API', tabLable: '精华'}
121-
]
108+
{api: apilist.EXEC_TOPIC_API, apiName: 'EXEC_TOPIC_API', tabLable: '精华'}]
122109
)}
123110
</TabBarIOS.Item>
124111
</TabBarIOS>
125112
);
126-
}
113+
}
127114
});
128115

129116
var styles = StyleSheet.create({
130117
container: {
131118
flex: 1
132119
}
133-
})
120+
});
134121

135122
module.exports = AppNavBar;

components/a-TopicCard.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,30 @@ var TopicCard = React.createClass({
1919
getInitialState() {
2020
return {
2121
dataSource: new ListView.DataSource({
22-
rowHasChanged: (row1, row2) => row1 !== row2,
22+
rowHasChanged: (row1, row2) => row1 !== row2
2323
}),
2424
loaded: false,
2525
currentOffset: 0
26-
}
26+
};
2727
},
2828

2929
componentDidMount() {
3030
this.fetchTopicsData();
3131
},
3232

33-
_avatarFilter(avatar: string): string {
33+
_avatarFilter(avatar) {
3434
return /testerhome/i.test(avatar) ?
3535
avatar :
3636
'https://testerhome.com' + avatar;
3737
},
3838

39-
_stringFilter(title: string, len: number): string {
39+
_stringFilter(title, len) {
4040
return title.length >= len ?
4141
title.slice(0, len) + '...' :
42-
title
42+
title;
4343
},
4444

45-
_countRate(count: number): string {
45+
_countRate(count) {
4646
let num = Number(count);
4747
if(num > 100) {
4848
return '热评';
@@ -65,9 +65,9 @@ var TopicCard = React.createClass({
6565
_reload() {
6666
this.fetchTopicsData(
6767
apilist.fetchResourceWithPage(
68-
apilist[this.props.currentReqName],
68+
apilist[this.props.currentReqName]
6969
)
70-
)
70+
);
7171
},
7272

7373
fetchTopicsData(api=this.props.resourceApi, more=0) {
@@ -79,7 +79,7 @@ var TopicCard = React.createClass({
7979
loaded: true,
8080
currentOffset: this.state.currentOffset + more
8181
});
82-
})
82+
});
8383
},
8484

8585
render() {
@@ -110,10 +110,10 @@ var TopicCard = React.createClass({
110110
minPulldownDistance={80}
111111
minBetweenTime={2000}
112112
/>
113-
)
113+
);
114114
},
115115

116-
renderTopicItem(topic: Object) {
116+
renderTopicItem(topic) {
117117
return (
118118
<View style={styles.topicCard}>
119119
<View style={styles.avatar}>
@@ -152,8 +152,8 @@ var indicatorStylesheet = StyleSheet.create({
152152
content: {
153153
marginTop: 10,
154154
marginBottom: 10,
155-
height: 60,
156-
},
155+
height: 60
156+
}
157157
});
158158

159159
var styles = StyleSheet.create({
@@ -185,7 +185,7 @@ var styles = StyleSheet.create({
185185
borderColor: '#f0f0f0',
186186
borderStyle: 'solid',
187187
borderWidth: 1,
188-
borderRadius: 0,
188+
borderRadius: 0
189189
},
190190
avatarImg: {
191191
width: 48,
@@ -200,7 +200,7 @@ var styles = StyleSheet.create({
200200
marginRight: 5
201201
},
202202
avatar: {
203-
flex: 2,
203+
flex: 2
204204
},
205205
titleMeta: {
206206
flex: 7,
@@ -249,4 +249,4 @@ var styles = StyleSheet.create({
249249
}
250250
});
251251

252-
module.exports = TopicCard
252+
module.exports = TopicCard;

0 commit comments

Comments
 (0)