Bläddra i källkod

tslint instead of xo and eslint

Daniel Zlotin 6 år sedan
förälder
incheckning
1945e247ed

+ 14
- 14
lib/src/Navigation.ts Visa fil

@@ -47,7 +47,7 @@ class Navigation {
47 47
    * @param {string} componentName Unique component name
48 48
    * @param {function} getComponentClassFunc generator function, typically `() => require('./myComponent')`
49 49
    */
50
-  registerComponent(componentName: string, getComponentClassFunc: ComponentProvider) {
50
+  public registerComponent(componentName: string, getComponentClassFunc: ComponentProvider) {
51 51
     this.componentRegistry.registerComponent(componentName, getComponentClassFunc);
52 52
   }
53 53
 
@@ -55,7 +55,7 @@ class Navigation {
55 55
    * Reset the navigation stack to a new component (the stack root is changed).
56 56
    * @param {Root} root
57 57
    */
58
-  setRoot(params) {
58
+  public setRoot(params) {
59 59
     return this.commands.setRoot(params);
60 60
   }
61 61
 
@@ -63,7 +63,7 @@ class Navigation {
63 63
    * Set default options to all screens. Useful for declaring a consistent style across the app.
64 64
    * @param {options:Options} options
65 65
    */
66
-  setDefaultOptions(options) {
66
+  public setDefaultOptions(options) {
67 67
     this.commands.setDefaultOptions(options);
68 68
   }
69 69
 
@@ -72,7 +72,7 @@ class Navigation {
72 72
    * @param {string} componentId The component's id.
73 73
    * @param {options:Options} options
74 74
    */
75
-  setOptions(componentId, options) {
75
+  public setOptions(componentId, options) {
76 76
     this.commands.setOptions(componentId, options);
77 77
   }
78 78
 
@@ -80,7 +80,7 @@ class Navigation {
80 80
    * Show a screen as a modal.
81 81
    * @param {object} params
82 82
    */
83
-  showModal(params) {
83
+  public showModal(params) {
84 84
     return this.commands.showModal(params);
85 85
   }
86 86
 
@@ -88,14 +88,14 @@ class Navigation {
88 88
    * Dismiss a modal by componentId. The dismissed modal can be anywhere in the stack.
89 89
    * @param {string} componentId The component's id.
90 90
    */
91
-  dismissModal(componentId) {
91
+  public dismissModal(componentId) {
92 92
     return this.commands.dismissModal(componentId);
93 93
   }
94 94
 
95 95
   /**
96 96
    * Dismiss all Modals
97 97
    */
98
-  dismissAllModals() {
98
+  public dismissAllModals() {
99 99
     return this.commands.dismissAllModals();
100 100
   }
101 101
 
@@ -104,7 +104,7 @@ class Navigation {
104 104
    * @param {string} componentId The component's id.
105 105
    * @param {Component} component
106 106
    */
107
-  push(componentId, component) {
107
+  public push(componentId, component) {
108 108
     return this.commands.push(componentId, component);
109 109
   }
110 110
 
@@ -113,7 +113,7 @@ class Navigation {
113 113
    * @param {string} componentId The component's id.
114 114
    * @param {*} params
115 115
    */
116
-  pop(componentId, params) {
116
+  public pop(componentId, params) {
117 117
     return this.commands.pop(componentId, params);
118 118
   }
119 119
 
@@ -121,7 +121,7 @@ class Navigation {
121 121
    * Pop the stack to a given component
122 122
    * @param {string} componentId The component's id.
123 123
    */
124
-  popTo(componentId: string) {
124
+  public popTo(componentId: string) {
125 125
     return this.commands.popTo(componentId);
126 126
   }
127 127
 
@@ -129,7 +129,7 @@ class Navigation {
129 129
    * Pop the component's stack to root.
130 130
    * @param {*} componentId
131 131
    */
132
-  popToRoot(componentId: string) {
132
+  public popToRoot(componentId: string) {
133 133
     return this.commands.popToRoot(componentId);
134 134
   }
135 135
 
@@ -137,7 +137,7 @@ class Navigation {
137 137
    * Show overlay on top of the window
138 138
    * @param {*} params
139 139
    */
140
-  showOverlay(params) {
140
+  public showOverlay(params) {
141 141
     return this.commands.showOverlay(params);
142 142
   }
143 143
 
@@ -145,14 +145,14 @@ class Navigation {
145 145
    * dismiss overlay by componentId
146 146
    * @param {string} componentId
147 147
    */
148
-  dismissOverlay(componentId: string) {
148
+  public dismissOverlay(componentId: string) {
149 149
     return this.commands.dismissOverlay(componentId);
150 150
   }
151 151
 
152 152
   /**
153 153
    * Obtain the events registry instance
154 154
    */
155
-  events() {
155
+  public events() {
156 156
     return this.publicEventsRegistry;
157 157
   }
158 158
 }

+ 3
- 3
lib/src/adapters/Element.tsx Visa fil

@@ -13,10 +13,11 @@ export class Element extends React.Component<ElementProps, any> {
13 13
   static propTypes = {
14 14
     elementId: PropTypes.string.isRequired,
15 15
     resizeMode: PropTypes.string
16
-  }
16
+  };
17
+
17 18
   static defaultProps = {
18 19
     resizeMode: ''
19
-  }
20
+  };
20 21
 
21 22
   render() {
22 23
     return (
@@ -26,4 +27,3 @@ export class Element extends React.Component<ElementProps, any> {
26 27
 }
27 28
 
28 29
 RNNElement = requireNativeComponent('RNNElement', Element);
29
-

+ 4
- 4
lib/src/commands/LayoutTreeCrawler.ts Visa fil

@@ -6,7 +6,7 @@ export interface LayoutNode {
6 6
   id?: string;
7 7
   type: LayoutType;
8 8
   data: object;
9
-  children: Array<LayoutNode>;
9
+  children: LayoutNode[];
10 10
 }
11 11
 
12 12
 interface IdProvider {
@@ -19,8 +19,8 @@ interface Store {
19 19
 }
20 20
 
21 21
 export class LayoutTreeCrawler {
22
-  private uniqueIdProvider: IdProvider
23
-  private store: Store
22
+  private uniqueIdProvider: IdProvider;
23
+  private store: Store;
24 24
 
25 25
   constructor(uniqueIdProvider: IdProvider, store: Store) {
26 26
     this.uniqueIdProvider = uniqueIdProvider;
@@ -33,7 +33,7 @@ export class LayoutTreeCrawler {
33 33
     node.id = this.uniqueIdProvider.generate(node.type);
34 34
     node.data = node.data || {};
35 35
     node.children = node.children || [];
36
-    if (node.type == LayoutType.Component) {
36
+    if (node.type === LayoutType.Component) {
37 37
       this._handleComponent(node);
38 38
     }
39 39
     _.forEach(node.children, this.crawl);

+ 0
- 1
lib/src/commands/LayoutTreeParser.test.ts Visa fil

@@ -118,7 +118,6 @@ describe('LayoutTreeParser', () => {
118 118
   });
119 119
 
120 120
   it('options for all containing types', () => {
121
-    const options = {};
122 121
     expect(uut.parse({ component: { options } }).data.options).toBe(options);
123 122
     expect(uut.parse({ stack: { options } }).data.options).toBe(options);
124 123
     expect(uut.parse({ bottomTabs: { options } }).data.options).toBe(options);

+ 2
- 2
lib/src/commands/LayoutTreeParser.ts Visa fil

@@ -38,11 +38,11 @@ export class LayoutTreeParser {
38 38
     };
39 39
   }
40 40
 
41
-  _sideMenuChildren(api): Array<LayoutNode> {
41
+  _sideMenuChildren(api): LayoutNode[] {
42 42
     if (!api.center) {
43 43
       throw new Error(`sideMenu.center is required`);
44 44
     }
45
-    const children: Array<LayoutNode> = [];
45
+    const children: LayoutNode[] = [];
46 46
     if (api.left) {
47 47
       children.push({
48 48
         type: LayoutType.SideMenuLeft,

+ 1
- 1
lib/src/commands/LayoutType.test.ts Visa fil

@@ -7,7 +7,7 @@ describe.only('LayoutType', () => {
7 7
 
8 8
     const name = 'Stack';
9 9
     expect(LayoutType[name]).toEqual(LayoutType.Stack);
10
-    expect(LayoutType['asdasd']).toEqual(undefined);
10
+    expect(LayoutType['asdasd']).toEqual(undefined); //tslint:disable-line
11 11
   });
12 12
 
13 13
   it('isLayoutType', () => {

+ 1
- 1
lib/src/commands/LayoutType.ts Visa fil

@@ -7,7 +7,7 @@ export enum LayoutType {
7 7
   SideMenuLeft = 'SideMenuLeft',
8 8
   SideMenuRight = 'SideMenuRight',
9 9
   TopTabs = 'TopTabs'
10
-};
10
+}
11 11
 
12 12
 export function isLayoutType(name: string): boolean {
13 13
   return !!LayoutType[name];

+ 1
- 1
lib/src/commands/OptionsProcessor.ts Visa fil

@@ -5,7 +5,7 @@ import * as resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSo
5 5
 export class OptionsProcessor {
6 6
   static processOptions(options) {
7 7
     _.forEach(options, (value, key) => {
8
-      if (!value) return
8
+      if (!value) { return; }
9 9
 
10 10
       if (_.isEqual(key, 'color') || _.endsWith(key, 'Color')) {
11 11
         options[key] = processColor(value);

+ 1
- 1
lib/src/components/ComponentRegistry.test.tsx Visa fil

@@ -45,7 +45,7 @@ describe('ComponentRegistry', () => {
45 45
   it('resulting in a normal component', () => {
46 46
     uut.registerComponent('example.MyComponent.name', () => MyComponent);
47 47
     const Component = mockRegistry.mock.calls[0][1]();
48
-    const tree = renderer.create(<Component componentId="123" />);
48
+    const tree = renderer.create(<Component componentId='123' />);
49 49
     expect(tree.toJSON()!.children).toEqual(['Hello, World!']);
50 50
   });
51 51
 });

+ 1
- 3
lib/src/components/ComponentWrapper.test.tsx Visa fil

@@ -21,8 +21,6 @@ describe('ComponentWrapper', () => {
21 21
     }
22 22
   }
23 23
 
24
-
25
-
26 24
   class TestParent extends React.Component<any, { propsFromState: {} }> {
27 25
     private ChildClass;
28 26
 
@@ -36,7 +34,7 @@ describe('ComponentWrapper', () => {
36 34
       return (
37 35
         <this.ChildClass
38 36
           ref={(r) => childRef = r}
39
-          componentId="component1"
37
+          componentId='component1'
40 38
           {...this.state.propsFromState}
41 39
         />
42 40
       );

+ 3
- 3
lib/src/components/ComponentWrapper.tsx Visa fil

@@ -2,8 +2,8 @@ import * as React from 'react';
2 2
 import * as  _ from 'lodash';
3 3
 
4 4
 interface State {
5
-  componentId: string,
6
-  allProps: {}
5
+  componentId: string;
6
+  allProps: {};
7 7
 }
8 8
 
9 9
 export class ComponentWrapper {
@@ -75,7 +75,7 @@ export class ComponentWrapper {
75 75
           />
76 76
         );
77 77
       }
78
-    };
78
+    }
79 79
 
80 80
     return WrappedComponent;
81 81
   }

+ 0
- 1
lib/src/components/Store.test.ts Visa fil

@@ -47,4 +47,3 @@ describe('Store', () => {
47 47
     expect(uut.getPropsForComponentId('refUniqueId')).toEqual({});
48 48
   });
49 49
 });
50
-

+ 1
- 1
lib/src/events/PrivateEventsListener.ts Visa fil

@@ -9,7 +9,7 @@ export class PrivateEventsListener {
9 9
     this.lifecycle = new Lifecycle(store);
10 10
   }
11 11
 
12
-  listenAndHandlePrivateEvents() {
12
+  public listenAndHandlePrivateEvents() {
13 13
     this.nativeEventsReceiver.registerComponentDidAppear(this.lifecycle.componentDidAppear);
14 14
     this.nativeEventsReceiver.registerComponentDidDisappear(this.lifecycle.componentDidDisappear);
15 15
     this.nativeEventsReceiver.registerNavigationButtonPressed(this.lifecycle.onNavigationButtonPressed);

+ 3
- 3
lib/src/events/PublicEventsRegistry.ts Visa fil

@@ -5,15 +5,15 @@ export class PublicEventsRegistry {
5 5
     this.nativeEventsReceiver = nativeEventsReceiver;
6 6
   }
7 7
 
8
-  onAppLaunched(callback) {
8
+  public onAppLaunched(callback) {
9 9
     this.nativeEventsReceiver.registerAppLaunched(callback);
10 10
   }
11 11
 
12
-  navigationCommands(callback) {
12
+  public navigationCommands(callback) {
13 13
     this.nativeEventsReceiver.registerNavigationCommands(callback);
14 14
   }
15 15
 
16
-  componentLifecycle(callback) {
16
+  public componentLifecycle(callback) {
17 17
     this.nativeEventsReceiver.registerComponentLifecycle(callback);
18 18
   }
19 19
 }

+ 1
- 1
lib/src/index.ts Visa fil

@@ -1,3 +1,3 @@
1
-import { singleton } from "./Navigation";
1
+import { singleton } from './Navigation';
2 2
 
3 3
 export const Navigation = singleton;

+ 9
- 89
package.json Visa fil

@@ -50,13 +50,16 @@
50 50
   "dependencies": {
51 51
     "lodash": "4.x.x",
52 52
     "prop-types": "15.x.x",
53
-    "tslib": "1.x.x"
53
+    "tslib": "1.x.x",
54
+    "@types/react": "16.x.x",
55
+    "@types/react-native": "0.49.x",
56
+    "@types/lodash": "4.x.x",
57
+    "@types/prop-types": "15.x.x",
58
+    "@types/react-test-renderer": "16.x.x",
59
+    "@types/jest": "22.x.x"
54 60
   },
55 61
   "devDependencies": {
56 62
     "detox": "6.x.x",
57
-    "eslint-config-xo": "0.18.x",
58
-    "eslint-config-xo-react": "0.13.x",
59
-    "eslint-plugin-react": "7.x.x",
60 63
     "jest": "22.x.x",
61 64
     "mocha": "4.x.x",
62 65
     "react": "16.0.0-beta.5",
@@ -67,14 +70,8 @@
67 70
     "remx": "2.x.x",
68 71
     "semver": "5.x.x",
69 72
     "shell-utils": "1.x.x",
70
-    "xo": "0.18.x",
71
-    "typescript": "2.x.x",
72
-    "@types/react": "16.x.x",
73
-    "@types/react-native": "0.49.x",
74
-    "@types/lodash": "4.x.x",
75
-    "@types/prop-types": "15.x.x",
76
-    "@types/react-test-renderer": "16.x.x",
77
-    "@types/jest": "22.x.x"
73
+    "tslint": "5.x.x",
74
+    "typescript": "2.x.x"
78 75
   },
79 76
   "babel": {
80 77
     "env": {
@@ -128,82 +125,5 @@
128 125
         "name": "iPhone SE"
129 126
       }
130 127
     }
131
-  },
132
-  "xo": {
133
-    "extends": "xo-react",
134
-    "space": true,
135
-    "env": [
136
-      "node",
137
-      "jest",
138
-      "es6"
139
-    ],
140
-    "globals": [
141
-      "alert"
142
-    ],
143
-    "overrides": [
144
-      {
145
-        "files": "e2e/**/*",
146
-        "env": [
147
-          "mocha"
148
-        ],
149
-        "globals": [
150
-          "before",
151
-          "after",
152
-          "beforeEach",
153
-          "afterEach",
154
-          "expect",
155
-          "element",
156
-          "by",
157
-          "device"
158
-        ]
159
-      }
160
-    ],
161
-    "settings": {
162
-      "import/core-modules": [
163
-        "react-native-navigation"
164
-      ]
165
-    },
166
-    "rules": {
167
-      "unicorn/filename-case": 0,
168
-      "unicorn/number-literal-case": 0,
169
-      "import/order": 0,
170
-      "import/named": 0,
171
-      "import/no-unassigned-import": 0,
172
-      "import/prefer-default-export": 0,
173
-      "import/no-unresolved": [
174
-        2,
175
-        {
176
-          "ignore": [
177
-            "react-native-navigation"
178
-          ]
179
-        }
180
-      ],
181
-      "react/jsx-tag-spacing": 0,
182
-      "react/jsx-sort-props": 0,
183
-      "react/jsx-boolean-value": 0,
184
-      "react/prop-types": 0,
185
-      "react/jsx-no-bind": 0,
186
-      "react/jsx-handler-names": 0,
187
-      "react/forbid-component-props": 0,
188
-      "react/jsx-curly-brace-presence": 0,
189
-      "capitalized-comments": 0,
190
-      "no-use-before-define": [
191
-        2,
192
-        {
193
-          "functions": false,
194
-          "variables": false
195
-        }
196
-      ],
197
-      "promise/param-names": 0,
198
-      "no-return-assign": 0,
199
-      "arrow-parens": [
200
-        2,
201
-        "always"
202
-      ],
203
-      "object-curly-spacing": [
204
-        2,
205
-        "always"
206
-      ]
207
-    }
208 128
   }
209 129
 }

+ 1
- 1
scripts/release.js Visa fil

@@ -1,4 +1,4 @@
1
-/* eslint-disable no-console */
1
+/* tslint:disable: no-console */
2 2
 const exec = require('shell-utils').exec;
3 3
 const semver = require('semver');
4 4
 const fs = require('fs');

+ 3
- 3
scripts/test-js.js Visa fil

@@ -4,7 +4,7 @@ const _ = require('lodash');
4 4
 const fix = _.includes(process.argv, '--fix') ? '--fix' : '';
5 5
 
6 6
 const dirs = [
7
-  'lib/dist',
7
+  'lib/src',
8 8
   'integration',
9 9
   'e2e',
10 10
   'scripts',
@@ -14,7 +14,7 @@ const dirs = [
14 14
 run();
15 15
 
16 16
 function run() {
17
-  const paths = _.chain(dirs).map((d) => `'${d}/**'`).join(' ').value();
18
-  exec.execSync(`xo ${paths} ${fix}`);
17
+  const paths = _.chain(dirs).map((d) => `'${d}/**/*.[tj]s*'`).join(' ').value();
18
+  exec.execSync(`tslint ${paths} ${fix} --format verbose`);
19 19
   exec.execSync(`jest --coverage`);
20 20
 }

+ 1
- 1
scripts/test.all.js Visa fil

@@ -1,4 +1,4 @@
1
-/* eslint-disable no-console */
1
+/* tslint:disable: no-console */
2 2
 const exec = require('shell-utils').exec;
3 3
 
4 4
 async function run() {

+ 1
- 1
scripts/test.e2e.android.js Visa fil

@@ -1,4 +1,4 @@
1
-/* eslint-disable no-console */
1
+/* tslint:disable: no-console */
2 2
 const _ = require('lodash');
3 3
 const exec = require('shell-utils').exec;
4 4
 

+ 1
- 1
tsconfig-strict.json Visa fil

@@ -18,6 +18,6 @@
18 18
     "strictFunctionTypes": true,
19 19
     "strictNullChecks": true,
20 20
     "strict": true,
21
-    "noImplicitAny": true
21
+    "noImplicitAny": false
22 22
   }
23 23
 }

+ 45
- 0
tslint.json Visa fil

@@ -0,0 +1,45 @@
1
+{
2
+  "defaultSeverity": "error",
3
+  "extends": [
4
+    "tslint:recommended"
5
+  ],
6
+  "jsRules": {
7
+    "quotemark": [
8
+      true,
9
+      "single"
10
+    ],
11
+    "max-line-length": [
12
+      true,
13
+      180
14
+    ],
15
+    "ordered-imports": false,
16
+    "trailing-comma": [
17
+      true,
18
+      "never"
19
+    ],
20
+    "member-access": false,
21
+    "interface-name": false,
22
+    "object-literal-sort-keys": false,
23
+    "max-classes-per-file": false
24
+  },
25
+  "rules": {
26
+    "quotemark": [
27
+      true,
28
+      "single"
29
+    ],
30
+    "max-line-length": [
31
+      true,
32
+      180
33
+    ],
34
+    "ordered-imports": false,
35
+    "trailing-comma": [
36
+      true,
37
+      "never"
38
+    ],
39
+    "member-access": false,
40
+    "interface-name": false,
41
+    "object-literal-sort-keys": false,
42
+    "max-classes-per-file": false
43
+  },
44
+  "rulesDirectory": []
45
+}