Skip to content

Commit cbd564e

Browse files
committed
Set up and use flow-type 💫
1 parent acffe89 commit cbd564e

9 files changed

+9280
-232
lines changed

.babelrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
"react-native",
4+
"flow"
5+
]
6+
}

.eslintrc

+194-83
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,200 @@
11
{
2-
"root": true,
3-
"parserOptions": {
4-
"sourceType": "module",
5-
"ecmaFeatures": {
6-
"jsx": true,
7-
"modules": true,
8-
"experimentalObjectRestSpread": true
9-
}
10-
},
11-
"env": {
12-
"browser": true,
13-
"node": true,
14-
"es6": true
15-
},
16-
"globals": {
17-
"jest": false,
18-
"describe": false,
19-
"it": false,
20-
"afterEach": false,
21-
"beforeEach": false,
22-
"expect": false,
23-
"spyOn": false
24-
},
2+
"parser": "babel-eslint",
3+
"extends": "airbnb",
254
"plugins": [
265
"react",
27-
"react-native"
6+
"flowtype",
7+
"jsx-a11y",
8+
"import"
289
],
29-
"extends": [
30-
"eslint:recommended",
31-
"plugin:react/recommended"
32-
],
33-
// details: https://github.com/yannickcr/eslint-plugin-react
3410
"rules": {
35-
"semi": ['error', "never"],
36-
"quotes": ['error', "single"],
37-
"no-unused-vars": 'error',
38-
"no-irregular-whitespace": ['error', { "skipComments": true }],
39-
"no-console": ['error', { "allow": ["log", "warn", 'error'] }],
40-
"no-mixed-spaces-and-tabs": ['error', "smart-tabs"],
41-
"react/display-name": ['error', { "ignoreTranspilerName": false }],
42-
"react/forbid-prop-types": 'error',
43-
"react/jsx-boolean-value": 'error',
44-
"react/jsx-closing-bracket-location": 'off',
45-
"react/jsx-curly-spacing": 'off',
46-
"react/jsx-handler-names": 'error',
47-
"react/jsx-indent-props": ['error',4],
48-
"react/jsx-indent": ['error',4],
49-
"react/jsx-key": 'error',
50-
"react/jsx-max-props-per-line": 'error',
51-
"react/jsx-no-bind": ['error', {
52-
"ignoreRefs": false,
53-
"allowArrowFunctions": true,
54-
"allowBind": false
55-
}],
56-
"react/jsx-no-duplicate-props": 'error',
57-
"react/jsx-no-literals": 'off',
58-
"react/jsx-no-undef": 'error',
59-
"react/jsx-pascal-case": 'error',
60-
"jsx-quotes": ['error', "prefer-double"],
61-
"react/sort-prop-types": 'error',
62-
"react/jsx-sort-props": 'off',
63-
"react/jsx-uses-react": 'error',
64-
"react/jsx-uses-vars": 'error',
65-
"react/no-danger": 'error',
66-
"react/no-deprecated": 'error',
67-
"react/no-did-mount-set-state": 'error',
68-
"react/no-did-update-set-state": 'error',
69-
"react/no-direct-mutation-state": 'error',
70-
"react/no-is-mounted": 'error',
71-
"react/no-multi-comp": 'error',
72-
"react/no-set-state": 'off',
73-
"react/no-string-refs": 'error',
74-
"react/no-unknown-property": 'error',
75-
"react/prefer-es6-class": 'error',
76-
"react/prop-types": 'error',
77-
"react/react-in-jsx-scope": 'error',
78-
"react/require-extension": 'error',
79-
"react/self-closing-comp": 'error',
80-
"react/sort-comp": 'error',
81-
"react/wrap-multilines": 'error',
82-
83-
// details: https://github.com/Intellicode/eslint-plugin-react-native
84-
"react-native/no-unused-styles": 2,
85-
"react-native/split-platform-components": 2,
86-
"react-native/no-inline-styles": 2,
87-
"react-native/no-color-literals": 2
11+
// Best Practices
12+
"accessor-pairs": 2,
13+
"block-scoped-var": 2,
14+
"complexity": [
15+
"error",
16+
10
17+
],
18+
"consistent-return": 2,
19+
"curly": 2,
20+
"default-case": 2,
21+
"dot-location": [
22+
2,
23+
"property"
24+
],
25+
"dot-notation": 2,
26+
"eqeqeq": [
27+
2,
28+
"allow-null"
29+
],
30+
"guard-for-in": 2,
31+
"no-alert": 2,
32+
"no-caller": 2,
33+
"no-case-declarations": 2,
34+
"no-div-regex": 2,
35+
"no-else-return": 2,
36+
"no-empty-pattern": 2,
37+
"no-eq-null": 2,
38+
"no-eval": 2,
39+
"no-extend-native": 2,
40+
"no-extra-bind": 2,
41+
"no-fallthrough": 2,
42+
"no-floating-decimal": 2,
43+
"no-implicit-coercion": 2,
44+
"no-implied-eval": 2,
45+
"no-invalid-this": 2,
46+
"no-iterator": 2,
47+
"no-labels": 2,
48+
"no-lone-blocks": 2,
49+
"no-loop-func": 2,
50+
"no-magic-numbers": 0,
51+
"no-multi-str": 2,
52+
"no-native-reassign": 2,
53+
"no-new-func": 2,
54+
"no-new-wrappers": 2,
55+
"no-new": 2,
56+
"no-octal-escape": 2,
57+
"no-octal": 2,
58+
"no-param-reassign": 2,
59+
"no-process-env": 0,
60+
"no-proto": 2,
61+
"no-redeclare": 2,
62+
"no-return-assign": 2,
63+
"no-script-url": 2,
64+
"no-self-compare": 2,
65+
"no-sequences": 2,
66+
"no-throw-literal": 2,
67+
"no-unsafe-negation": 2,
68+
"no-unused-expressions": 2,
69+
"no-useless-call": 2,
70+
"no-useless-concat": 2,
71+
"no-useless-rename": 0,
72+
"no-void": 2,
73+
"no-warning-comments": 1,
74+
"no-with": 2,
75+
"prefer-destructuring": [
76+
2,
77+
{
78+
"array": false,
79+
"object": true
80+
},
81+
{
82+
"enforceForRenamedProperties": false
83+
}
84+
],
85+
"radix": 2,
86+
"semi-spacing": 2,
87+
"vars-on-top": 0,
88+
"wrap-iife": 2,
89+
"yoda": 2,
90+
// Flow
91+
"flowtype/use-flow-type": 2,
92+
"flowtype/define-flow-type": 2,
93+
"flowtype/space-after-type-colon": [
94+
2,
95+
"always"
96+
],
97+
"flowtype/space-before-type-colon": [
98+
2,
99+
"never"
100+
],
101+
"flowtype/require-valid-file-annotation": [
102+
2,
103+
"always",
104+
{
105+
"annotationStyle": "block"
106+
}
107+
],
108+
// ES6
109+
"arrow-body-style": 0,
110+
"arrow-parens": 0,
111+
"arrow-spacing": 2,
112+
"constructor-super": 2,
113+
"generator-star-spacing": [
114+
2,
115+
{
116+
"before": true,
117+
"after": true
118+
}
119+
],
120+
"no-class-assign": 2,
121+
"no-confusing-arrow": 2,
122+
"no-const-assign": 2,
123+
"no-dupe-class-members": 2,
124+
"no-this-before-super": 2,
125+
"no-var": 2,
126+
"object-shorthand": 2,
127+
"prefer-arrow-callback": 2,
128+
"prefer-const": 2,
129+
"prefer-reflect": 0,
130+
"prefer-spread": 2,
131+
"prefer-template": 2,
132+
"rest-spread-spacing": [
133+
2,
134+
"never"
135+
],
136+
// Variables
137+
"init-declarations": 0,
138+
"no-catch-shadow": 2,
139+
"no-delete-var": 2,
140+
"no-label-var": 2,
141+
"no-shadow": 0,
142+
"no-shadow-restricted-names": 2,
143+
"no-undef": 2,
144+
"no-undef-init": 2,
145+
"no-undefined": 0,
146+
"no-unused-vars": [
147+
2,
148+
{
149+
"vars": "all",
150+
"args": "none"
151+
}
152+
],
153+
"no-use-before-define": 0,
154+
"react/require-default-props": 0,
155+
"react/prop-types": 0,
156+
"react/jsx-filename-extension": [
157+
1,
158+
{
159+
"extensions": [
160+
".js",
161+
".jsx"
162+
]
163+
}
164+
],
165+
"react/prefer-stateless-function": [
166+
2,
167+
{
168+
"ignorePureComponents": true
169+
}
170+
],
171+
"react/forbid-prop-types": [
172+
0,
173+
{
174+
"forbid": []
175+
}
176+
],
177+
"import/extensions": [
178+
1,
179+
"never",
180+
{
181+
"svg": "always"
182+
}
183+
],
184+
"import/no-extraneous-dependencies": [
185+
"error",
186+
{
187+
"devDependencies": true,
188+
"optionalDependencies": false,
189+
"peerDependencies": false
190+
}
191+
],
192+
"semi": [
193+
"error",
194+
"never"
195+
]
196+
},
197+
"env": {
198+
"jest": true
88199
}
89-
}
200+
}

.flowconfig

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
[ignore]
3+
.*/*[.]android.js
4+
5+
; Ignore unexpected extra "@providesModule"
6+
.*/node_modules/.*/node_modules/fbjs/.*
7+
8+
[include]
9+
10+
[untyped]
11+
.*/node_modules/react-native
12+
13+
[libs]
14+
15+
[version]
16+
^0.83.0
17+

Example/index.android.js

+4-22
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,14 @@
44
* @flow
55
*/
66

7-
import React, { Component } from 'react';
7+
import React from 'react'
88
import {
99
AppRegistry,
10-
StyleSheet,
11-
Text,
12-
View
13-
} from 'react-native';
10+
} from 'react-native'
1411

1512
import ExampleMain from './ExampleMain'
1613

17-
class Example extends Component {
18-
render() {
19-
return (
20-
<ExampleMain />
21-
);
22-
}
23-
}
2414

25-
const styles = StyleSheet.create({
26-
container: {
27-
flex: 1,
28-
justifyContent: 'center',
29-
alignItems: 'center',
30-
backgroundColor: 'white',
31-
padding: 10
32-
}
33-
});
15+
const Example = () => <ExampleMain />
3416

35-
AppRegistry.registerComponent('Example', () => Example);
17+
AppRegistry.registerComponent('Example', () => Example)

Example/index.ios.js

+4-23
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,13 @@
44
* @flow
55
*/
66

7-
import React, { Component } from 'react';
7+
import React from 'react'
88
import {
99
AppRegistry,
10-
StyleSheet,
11-
Text,
12-
View
13-
} from 'react-native';
10+
} from 'react-native'
1411

1512
import ExampleMain from './ExampleMain'
1613

17-
class Example extends Component {
18-
render() {
19-
return (
20-
<ExampleMain />
21-
);
22-
}
23-
}
14+
const Example = () => <ExampleMain />
2415

25-
const styles = StyleSheet.create({
26-
container: {
27-
flex: 1,
28-
justifyContent: 'center',
29-
alignItems: 'center',
30-
backgroundColor: 'white',
31-
padding: 10
32-
}
33-
});
34-
35-
AppRegistry.registerComponent('Example', () => Example);
16+
AppRegistry.registerComponent('Example', () => Example)

0 commit comments

Comments
 (0)