Skip to content

Commit 9736694

Browse files
troZeeferrannp
authored andcommitted
chore: add eslint from react-native-community (#76)
1 parent 3c28332 commit 9736694

17 files changed

+762
-137
lines changed

.circleci/config.yml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ android_defaults: &android_defaults
1919
<<: *defaults
2020
docker:
2121
- image: circleci/android:api-27-node8-alpha
22-
resource_class: "large"
2322
environment:
2423
- TERM: "dumb"
2524
- ADB_INSTALL_TIMEOUT: 10
@@ -30,7 +29,6 @@ android_defaults: &android_defaults
3029
# MACOS
3130
macos_defaults: &macos_defaults
3231
<<: *defaults
33-
resource_class: "large"
3432
macos:
3533
xcode: "10.1.0"
3634

@@ -65,9 +63,9 @@ aliases:
6563
yarn install --network-concurrency 1 --non-interactive --cache-folder ~/.cache/yarn & wait
6664
6765
# ANALYSE
68-
# - &eslint
69-
# name: ESLint Checks
70-
# command: yarn test:eslint
66+
- &eslint
67+
name: ESLint Checks
68+
command: yarn lint
7169

7270
- &flow
7371
name: Flow Checks
@@ -96,12 +94,12 @@ jobs:
9694
root: .
9795
paths: .
9896

99-
# eslint:
100-
# <<: *linux_defaults
101-
# steps:
102-
# - attach_workspace:
103-
# at: ~/react-native-viewpager
104-
# - run: *eslint
97+
eslint:
98+
<<: *linux_defaults
99+
steps:
100+
- attach_workspace:
101+
at: ~/react-native-viewpager
102+
- run: *eslint
105103

106104
flow:
107105
<<: *linux_defaults
@@ -166,9 +164,9 @@ workflows:
166164
Test:
167165
jobs:
168166
- linux-checkout
169-
# - eslint:
170-
# requires:
171-
# - linux-checkout
167+
- eslint:
168+
requires:
169+
- linux-checkout
172170
- flow:
173171
requires:
174172
- linux-checkout

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: '@react-native-community',
4+
};

.prettierrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
bracketSpacing: false,
3+
jsxBracketSameLine: true,
4+
singleQuote: true,
5+
trailingComma: 'all',
6+
};

babel.config.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module.exports = {
2-
presets: ["module:metro-react-native-babel-preset"],
2+
presets: ['module:metro-react-native-babel-preset'],
33
plugins: [
44
[
5-
"module-resolver",
5+
'module-resolver',
66
{
77
alias: {
8-
"@react-native-community/viewpager": "./js"
8+
'@react-native-community/viewpager': './js',
99
},
10-
cwd: "babelrc"
11-
}
12-
]
13-
]
14-
};
10+
cwd: 'babelrc',
11+
},
12+
],
13+
],
14+
};

example/ViewPagerExample.js

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99

1010
'use strict';
1111

12-
import * as React from "react";
13-
import { Image,
14-
StyleSheet,
15-
Text,
16-
View,
17-
SafeAreaView,
18-
} from 'react-native'
12+
import * as React from 'react';
13+
import {Image, StyleSheet, Text, View, SafeAreaView} from 'react-native';
1914

2015
import ViewPager from '@react-native-community/viewpager';
21-
import { PAGES, BGCOLOR, IMAGE_URIS, createPage } from "./utils";
22-
import { Button } from "./src/component/Button";
23-
import { LikeCount } from "./src/component/LikeCount";
24-
import { ProgressBar } from "./src/component/ProgressBar";
25-
import type { CreatePage } from "./utils"
26-
import type {PageScrollEvent, PageScrollState, PageScrollStateChangedEvent, PageSelectedEvent} from "../js";
16+
import {PAGES, createPage} from './utils';
17+
import {Button} from './src/component/Button';
18+
import {LikeCount} from './src/component/LikeCount';
19+
import {ProgressBar} from './src/component/ProgressBar';
20+
import type {CreatePage} from './utils';
21+
import type {
22+
PageScrollEvent,
23+
PageScrollState,
24+
PageScrollStateChangedEvent,
25+
PageSelectedEvent,
26+
} from '../js';
2727

2828
type State = {
2929
page: number,
@@ -34,11 +34,10 @@ type State = {
3434
offset: number,
3535
},
3636
pages: Array<CreatePage>,
37-
scrollState: PageScrollState
37+
scrollState: PageScrollState,
3838
};
3939

4040
export default class ViewPagerExample extends React.Component<*, State> {
41-
4241
viewPager: React.Ref<typeof ViewPager>;
4342

4443
constructor(props: any) {
@@ -58,28 +57,32 @@ export default class ViewPagerExample extends React.Component<*, State> {
5857
offset: 0,
5958
},
6059
pages: pages,
61-
scrollState: 'idle'
60+
scrollState: 'idle',
6261
};
6362
this.viewPager = React.createRef();
64-
};
63+
}
6564

6665
onPageSelected = (e: PageSelectedEvent) => {
6766
this.setState({page: e.nativeEvent.position});
6867
};
6968

70-
onPageScroll = (e: PageScrollEvent)=> {
71-
this.setState({progress: {
72-
position: e.nativeEvent.position,
73-
offset: e.nativeEvent.offset,
74-
}});
69+
onPageScroll = (e: PageScrollEvent) => {
70+
this.setState({
71+
progress: {
72+
position: e.nativeEvent.position,
73+
offset: e.nativeEvent.offset,
74+
},
75+
});
7576
};
7677

7778
onPageScrollStateChanged = (e: PageScrollStateChangedEvent) => {
7879
this.setState({scrollState: e.nativeEvent.pageScrollState});
7980
};
8081

8182
addPage = () => {
82-
this.setState(prevState => ({ pages: [...prevState.pages, createPage(prevState.pages.length)]}));
83+
this.setState(prevState => ({
84+
pages: [...prevState.pages, createPage(prevState.pages.length)],
85+
}));
8386
};
8487

8588
move = (delta: number) => {
@@ -100,14 +103,11 @@ export default class ViewPagerExample extends React.Component<*, State> {
100103
renderPage(page: CreatePage) {
101104
return (
102105
<View key={page.key} style={page.style} collapsable={false}>
103-
<Image
104-
style={styles.image}
105-
source={page.imgSource}
106-
/>
106+
<Image style={styles.image} source={page.imgSource} />
107107
<LikeCount />
108108
</View>
109109
);
110-
};
110+
}
111111

112112
render() {
113113
const {page, pages, animationsAreEnabled} = this.state;
@@ -124,9 +124,9 @@ export default class ViewPagerExample extends React.Component<*, State> {
124124
// Lib does not support dynamically orientation change
125125
orientation="horizontal"
126126
// Lib does not support dynamically transitionStyle change
127-
transitionStyle="scroll"
127+
transitionStyle="scroll"
128128
ref={this.viewPager}>
129-
{ pages.map( page => this.renderPage(page)) }
129+
{pages.map(page => this.renderPage(page))}
130130
</ViewPager>
131131
<View style={styles.buttons}>
132132
<Button
@@ -177,8 +177,15 @@ export default class ViewPagerExample extends React.Component<*, State> {
177177
/>
178178
</View>
179179
<View style={styles.progress}>
180-
<Text style={styles.buttonText}> Page {page + 1} / {pages.length} </Text>
181-
<ProgressBar numberOfPages={pages.length} size={300} progress={this.state.progress} />
180+
<Text style={styles.buttonText}>
181+
{' '}
182+
Page {page + 1} / {pages.length}{' '}
183+
</Text>
184+
<ProgressBar
185+
numberOfPages={pages.length}
186+
size={300}
187+
progress={this.state.progress}
188+
/>
182189
</View>
183190
</SafeAreaView>
184191
);

example/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import React from 'react';
44
import {AppRegistry} from 'react-native';
55

6-
import {name as appName} from './app.json';
7-
import ViewPagerExample from "./ViewPagerExample";
6+
import {name as appName} from './app.json';
7+
import ViewPagerExample from './ViewPagerExample';
88

99
class ExampleApp extends React.Component<{}> {
1010
render() {
11-
return (
12-
<ViewPagerExample />
13-
)
11+
return <ViewPagerExample />;
1412
}
1513
}
1614

example/src/component/Button.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
*/
99

1010
import React from 'react';
11-
import {
12-
StyleSheet,
13-
Text,
14-
TouchableWithoutFeedback,
15-
View,
16-
} from 'react-native'
11+
import {StyleSheet, Text, TouchableWithoutFeedback, View} from 'react-native';
1712

1813
type Props = $ReadOnly<{|
1914
enabled?: boolean,

example/src/component/LikeCount.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@
88
*/
99

1010
import React from 'react';
11-
import {
12-
StyleSheet,
13-
Text,
14-
TouchableOpacity,
15-
View,
16-
} from 'react-native'
11+
import {StyleSheet, Text, TouchableOpacity, View} from 'react-native';
1712

18-
import { thumbsUp } from '../../utils'
13+
import {thumbsUp} from '../../utils';
1914

2015
type Props = $ReadOnly<{||}>;
2116
type State = {|likes: number|};
@@ -26,7 +21,7 @@ export class LikeCount extends React.Component<Props, State> {
2621
};
2722

2823
onClick = () => {
29-
this.setState(state => ({ likes: state.likes + 1}));
24+
this.setState(state => ({likes: state.likes + 1}));
3025
};
3126

3227
render() {
@@ -47,10 +42,10 @@ const styles = StyleSheet.create({
4742
height: 45,
4843
},
4944
likesText: {
50-
flex: 1,
51-
fontSize: 18,
52-
alignSelf: 'center',
53-
},
45+
flex: 1,
46+
fontSize: 18,
47+
alignSelf: 'center',
48+
},
5449
likeButton: {
5550
backgroundColor: 'rgba(0, 0, 0, 0.1)',
5651
borderColor: '#333333',

example/src/component/ProgressBar.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import React from 'react';
11-
import {StyleSheet, View} from 'react-native'
11+
import {StyleSheet, View} from 'react-native';
1212

1313
type Props = {
1414
progress: {
@@ -17,12 +17,14 @@ type Props = {
1717
},
1818
numberOfPages: number,
1919
size: number,
20-
}
20+
};
2121

2222
export class ProgressBar extends React.Component<Props> {
2323
render() {
24-
const fractionalPosition = this.props.progress.position + this.props.progress.offset;
25-
const progressBarSize = (fractionalPosition / (this.props.numberOfPages - 1)) * this.props.size;
24+
const fractionalPosition =
25+
this.props.progress.position + this.props.progress.offset;
26+
const progressBarSize =
27+
(fractionalPosition / (this.props.numberOfPages - 1)) * this.props.size;
2628
return (
2729
<View style={[styles.progressBarContainer, {width: this.props.size}]}>
2830
<View style={[styles.progressBar, {width: progressBarSize}]} />
@@ -32,15 +34,15 @@ export class ProgressBar extends React.Component<Props> {
3234
}
3335

3436
const styles = StyleSheet.create({
35-
progressBarContainer: {
36-
height: 10,
37-
margin: 10,
38-
borderColor: '#eeeeee',
39-
borderWidth: 2,
40-
},
41-
progressBar: {
42-
alignSelf: 'flex-start',
43-
flex: 1,
44-
backgroundColor: '#eeeeee',
45-
},
46-
});
37+
progressBarContainer: {
38+
height: 10,
39+
margin: 10,
40+
borderColor: '#eeeeee',
41+
borderWidth: 2,
42+
},
43+
progressBar: {
44+
alignSelf: 'flex-start',
45+
flex: 1,
46+
backgroundColor: '#eeeeee',
47+
},
48+
});

example/utils.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ export const IMAGE_URIS = [
1717
'https://apod.nasa.gov/apod/image/1510/lunareclipse_27Sep_beletskycrop4.jpg',
1818
];
1919
export const thumbsUp = '\uD83D\uDC4D';
20-
import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';
20+
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';
2121

2222
export type CreatePage = {
2323
key: number,
2424
style: ViewStyleProp,
25-
imgSource: { uri: string }
26-
}
25+
imgSource: {uri: string},
26+
};
2727

2828
export const createPage = (key: number): CreatePage => {
29-
return {
30-
key: key,
31-
style: {
32-
backgroundColor: BGCOLOR[key % BGCOLOR.length],
33-
alignItems: 'center',
34-
padding: 20,
35-
},
36-
imgSource: { uri: IMAGE_URIS[key % BGCOLOR.length] }
37-
}
29+
return {
30+
key: key,
31+
style: {
32+
backgroundColor: BGCOLOR[key % BGCOLOR.length],
33+
alignItems: 'center',
34+
padding: 20,
35+
},
36+
imgSource: {uri: IMAGE_URIS[key % BGCOLOR.length]},
3837
};
38+
};

0 commit comments

Comments
 (0)