Skip to content

Commit 0ffd57d

Browse files
committed
Setup eslint
1 parent 56e373a commit 0ffd57d

File tree

9 files changed

+550
-602
lines changed

9 files changed

+550
-602
lines changed

example/.eslintcache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.android.js":{"size":284,"mtime":1499290295000,"hashOfConfig":"1y1d1hv","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.android.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.ios.js":{"size":280,"mtime":1499290295000,"hashOfConfig":"1y1d1hv","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.ios.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/ExampleApp.js":{"size":1936,"mtime":1506268108000,"hashOfConfig":"1y1d1hv","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/ExampleApp.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/index.android.js":{"size":1097,"mtime":1499290295000,"hashOfConfig":"1y1d1hv","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/index.android.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/index.ios.js":{"size":215,"mtime":1505974689000,"hashOfConfig":"1y1d1hv","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/index.ios.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/index.js":{"size":2547,"mtime":1506407640000,"hashOfConfig":"1y1d1hv","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/index.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/NodeView.js":{"size":1428,"mtime":1506407813000,"hashOfConfig":"1y1d1hv","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/NodeView.js","messages":[],"errorCount":0,"warningCount":0}}}
1+
{"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/index.js":{"size":2551,"mtime":1506461476000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/index.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/NodeView.js":{"size":1522,"mtime":1506462022000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/nestedListView/NodeView.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.android.js":{"size":284,"mtime":1499290295000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.android.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.ios.js":{"size":280,"mtime":1499290295000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/__tests__/index.ios.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/index.android.js":{"size":178,"mtime":1506461733000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/index.android.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/index.ios.js":{"size":178,"mtime":1506461736000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/index.ios.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/morant84/Work/react-native-nested-listview/example/ExampleApp.js":{"size":2055,"mtime":1506462030000,"hashOfConfig":"2mvhf3","results":{"filePath":"/Users/morant84/Work/react-native-nested-listview/example/ExampleApp.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}}}

example/.eslintrc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
{
22
"parser": "babel-eslint",
33
"parserOptions": {
4-
"sourceType": "module"
4+
"sourceType": "module",
5+
"ecmaFeatures": {
6+
"jsx": true
7+
}
58
},
6-
"plugins": ["react", "react-native"],
7-
"ecmaFeatures": {
8-
"jsx": true
9+
"plugins": ["react", "react-native", "flowtype"],
10+
"extends": [
11+
"plugin:react/recommended",
12+
"plugin:react-native/all",
13+
"plugin:flowtype/recommended"
14+
],
15+
"rules": {
16+
"react-native/no-color-literals": 0
917
}
1018
}

example/ExampleApp.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/* @flow */
22

33
import React from 'react'
4-
import {StyleSheet, Text, View} from 'react-native'
4+
import {Alert, StyleSheet, Text, View} from 'react-native'
55
import NestedListView from './nestedListView'
66

7-
const styles = StyleSheet.create({})
8-
97
const generateXNumItems = (numItems, prefix) => {
108
const items = []
119

10+
let i
11+
1212
for (i = 0; i < numItems; i++) {
1313
items.push({
1414
name: `${prefix}.${i}`,
@@ -21,7 +21,7 @@ const generateXNumItems = (numItems, prefix) => {
2121
const data = [
2222
{
2323
name: 'Item level 1.1',
24-
items: generateXNumItems(100, 'Item level 1.1')
24+
items: generateXNumItems(100, 'Item level 1.1'),
2525
},
2626
{
2727
name: 'Item level 1.2',
@@ -31,7 +31,7 @@ const data = [
3131
},
3232
{
3333
name: 'Item level 1.2.2',
34-
children: generateXNumItems(2, 'Item level 1.2.2')
34+
children: generateXNumItems(2, 'Item level 1.2.2'),
3535
},
3636
],
3737
},
@@ -43,11 +43,23 @@ const data = [
4343

4444
const colorLevels = {
4545
0: 'white',
46-
1: 'blue',
47-
2: 'green',
48-
3: 'red',
46+
1: 'blue',
47+
2: 'green',
48+
3: 'red',
4949
}
5050

51+
const styles = StyleSheet.create({
52+
container: {flex: 1, backgroundColor: 'rgb(255, 255, 255)', padding: 10},
53+
node: {
54+
flex: 1,
55+
padding: 10,
56+
paddingLeft,
57+
borderWidth: 1,
58+
borderColor: 'rgb(0, 0, 0)',
59+
backgroundColor,
60+
},
61+
nestedListView: {padding: 10},
62+
})
5163
export default class ExampleApp extends React.Component {
5264
nestedListView: any
5365

@@ -56,18 +68,18 @@ export default class ExampleApp extends React.Component {
5668
const backgroundColor = colorLevels[level] || 'white'
5769

5870
return (
59-
<View style={{flex: 1, padding: 10, paddingLeft, borderWidth: 1, borderColor: 'rgb(0, 0, 0)', backgroundColor}}>
71+
<View style={styles.node}>
6072
<Text>{node.name}</Text>
6173
</View>
6274
)
6375
}
6476

6577
onNodePressed = (node: any) => {
66-
// alert(JSON.stringify(node))
78+
Alert.alert(node.id)
6779
}
6880

6981
getChildrenName = (node: Object) => {
70-
if(node.name === 'Item level 1.2.2') {
82+
if (node.name === 'Item level 1.2.2') {
7183
return 'children'
7284
}
7385

@@ -76,7 +88,7 @@ export default class ExampleApp extends React.Component {
7688

7789
render = () => {
7890
return (
79-
<View style={{flex: 1, backgroundColor: 'rgb(255, 255, 255)', padding: 10}}>
91+
<View style={styles.container}>
8092
<NestedListView
8193
data={data}
8294
getChildrenName={this.getChildrenName}
@@ -85,7 +97,7 @@ export default class ExampleApp extends React.Component {
8597
this.nestedListView = ref
8698
}}
8799
renderNode={this.renderNode}
88-
style={{padding: 10}}
100+
style={styles.nestedListView}
89101
/>
90102
</View>
91103
)

example/index.android.js

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,5 @@
1-
/**
2-
* Sample React Native App
3-
* https://github.com/facebook/react-native
4-
* @flow
5-
*/
1+
import React, {Component} from 'react'
2+
import {AppRegistry} from 'react-native'
3+
import ExampleApp from './ExampleApp'
64

7-
import React, { Component } from 'react';
8-
import {
9-
AppRegistry,
10-
StyleSheet,
11-
Text,
12-
View
13-
} from 'react-native';
14-
15-
export default class example extends Component {
16-
render() {
17-
return (
18-
<View style={styles.container}>
19-
<Text style={styles.welcome}>
20-
Welcome to React Native!
21-
</Text>
22-
<Text style={styles.instructions}>
23-
To get started, edit index.android.js
24-
</Text>
25-
<Text style={styles.instructions}>
26-
Double tap R on your keyboard to reload,{'\n'}
27-
Shake or press menu button for dev menu
28-
</Text>
29-
</View>
30-
);
31-
}
32-
}
33-
34-
const styles = StyleSheet.create({
35-
container: {
36-
flex: 1,
37-
justifyContent: 'center',
38-
alignItems: 'center',
39-
backgroundColor: '#F5FCFF',
40-
},
41-
welcome: {
42-
fontSize: 20,
43-
textAlign: 'center',
44-
margin: 10,
45-
},
46-
instructions: {
47-
textAlign: 'center',
48-
color: '#333333',
49-
marginBottom: 5,
50-
},
51-
});
52-
53-
AppRegistry.registerComponent('example', () => example);
5+
AppRegistry.registerComponent('example', () => ExampleApp)

example/index.ios.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
2-
import React, { Component } from 'react'
3-
import {
4-
AppRegistry,
5-
StyleSheet,
6-
Text,
7-
View
8-
} from 'react-native'
1+
import React, {Component} from 'react'
2+
import {AppRegistry} from 'react-native'
93
import ExampleApp from './ExampleApp'
104

115
AppRegistry.registerComponent('example', () => ExampleApp)

example/nestedListView/NodeView.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ import React from 'react'
44
import {TouchableWithoutFeedback, View, FlatList} from 'react-native'
55

66
export default class NodeView extends React.PureComponent {
7+
props: {
8+
generateIds: Function,
9+
getChildren: Function,
10+
node: any,
11+
searchTree: Function,
12+
onNodePressed: Function,
13+
onLayout: Function,
14+
renderNode: Function,
15+
renderChildrenNode: Function,
16+
}
17+
718
componentWillMount = () => {
819
let rootChildren = this.props.getChildren(this.props.node)
920

@@ -18,27 +29,18 @@ export default class NodeView extends React.PureComponent {
1829

1930
onNodePressed = (node: any) => {
2031
if (this.state.data) {
21-
const newState = (rootChildren = this.state.data.map((child, index) => {
32+
const newRootChildren = this.state.data.map((child, index) => {
2233
return this.props.searchTree(this.state.data[index], node)
23-
}))
34+
})
2435

25-
this.setState({data: newState})
36+
this.setState({data: newRootChildren})
2637
}
2738

2839
this.props.onNodePressed(node)
2940
}
3041

3142
render() {
32-
const {
33-
getChildren,
34-
node,
35-
nodeStyle,
36-
onLayout,
37-
onNodePressed,
38-
renderNode,
39-
renderChildrenNode,
40-
} = this.props
41-
const children = getChildren(node)
43+
const {node, onLayout, renderNode, renderChildrenNode} = this.props
4244

4345
return (
4446
<View onLayout={onLayout}>

example/nestedListView/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @flow */
22

33
import React from 'react'
4-
import {ScrollView, FlatList} from 'react-native'
4+
import {FlatList} from 'react-native'
55
import NodeView from './NodeView'
66
import shortid from 'shortid'
77

@@ -11,6 +11,7 @@ export default class NestedListView extends React.PureComponent {
1111
renderNode: Function,
1212
onNodePressed: Function,
1313
getChildrenName: Function,
14+
style: any,
1415
}
1516

1617
state = {

example/package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88
"lint": "eslint --cache ."
99
},
1010
"dependencies": {
11-
"react": "16.0.0-alpha.12",
12-
"react-native": "0.48.3"
11+
"react": "16.0.0",
12+
"react-native": "0.48.4"
1313
},
1414
"devDependencies": {
15-
"babel-eslint": "7",
16-
"babel-jest": "20.0.3",
17-
"babel-preset-react-native": "2.1.0",
18-
"eslint": "3.x",
15+
"babel-eslint": "^8.0.1",
16+
"babel-jest": "^21.2.0",
17+
"babel-preset-react-native": "^4.0.0",
18+
"eslint": "^4.7.2",
19+
"eslint-plugin-flowtype": "^2.36.0",
1920
"eslint-plugin-react": "^7.4.0",
2021
"eslint-plugin-react-native": "^3.1.0",
21-
"jest": "20.0.4",
22+
"jest": "^21.2.0",
2223
"prettier": "^1.7.0",
2324
"prettier-eslint": "^8.1.1",
24-
"react-test-renderer": "16.0.0-alpha.12"
25+
"react-test-renderer": "16.0.0"
2526
},
2627
"jest": {
2728
"preset": "react-native"

0 commit comments

Comments
 (0)