Browse Source

tslint instead of xo and eslint

Daniel Zlotin 6 years ago
parent
commit
1945e247ed

+ 14
- 14
lib/src/Navigation.ts View File

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

+ 3
- 3
lib/src/adapters/Element.tsx View File

13
   static propTypes = {
13
   static propTypes = {
14
     elementId: PropTypes.string.isRequired,
14
     elementId: PropTypes.string.isRequired,
15
     resizeMode: PropTypes.string
15
     resizeMode: PropTypes.string
16
-  }
16
+  };
17
+
17
   static defaultProps = {
18
   static defaultProps = {
18
     resizeMode: ''
19
     resizeMode: ''
19
-  }
20
+  };
20
 
21
 
21
   render() {
22
   render() {
22
     return (
23
     return (
26
 }
27
 }
27
 
28
 
28
 RNNElement = requireNativeComponent('RNNElement', Element);
29
 RNNElement = requireNativeComponent('RNNElement', Element);
29
-

+ 4
- 4
lib/src/commands/LayoutTreeCrawler.ts View File

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

+ 0
- 1
lib/src/commands/LayoutTreeParser.test.ts View File

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

+ 2
- 2
lib/src/commands/LayoutTreeParser.ts View File

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

+ 1
- 1
lib/src/commands/LayoutType.test.ts View File

7
 
7
 
8
     const name = 'Stack';
8
     const name = 'Stack';
9
     expect(LayoutType[name]).toEqual(LayoutType.Stack);
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
   it('isLayoutType', () => {
13
   it('isLayoutType', () => {

+ 1
- 1
lib/src/commands/LayoutType.ts View File

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

+ 1
- 1
lib/src/commands/OptionsProcessor.ts View File

5
 export class OptionsProcessor {
5
 export class OptionsProcessor {
6
   static processOptions(options) {
6
   static processOptions(options) {
7
     _.forEach(options, (value, key) => {
7
     _.forEach(options, (value, key) => {
8
-      if (!value) return
8
+      if (!value) { return; }
9
 
9
 
10
       if (_.isEqual(key, 'color') || _.endsWith(key, 'Color')) {
10
       if (_.isEqual(key, 'color') || _.endsWith(key, 'Color')) {
11
         options[key] = processColor(value);
11
         options[key] = processColor(value);

+ 1
- 1
lib/src/components/ComponentRegistry.test.tsx View File

45
   it('resulting in a normal component', () => {
45
   it('resulting in a normal component', () => {
46
     uut.registerComponent('example.MyComponent.name', () => MyComponent);
46
     uut.registerComponent('example.MyComponent.name', () => MyComponent);
47
     const Component = mockRegistry.mock.calls[0][1]();
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
     expect(tree.toJSON()!.children).toEqual(['Hello, World!']);
49
     expect(tree.toJSON()!.children).toEqual(['Hello, World!']);
50
   });
50
   });
51
 });
51
 });

+ 1
- 3
lib/src/components/ComponentWrapper.test.tsx View File

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

+ 3
- 3
lib/src/components/ComponentWrapper.tsx View File

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

+ 0
- 1
lib/src/components/Store.test.ts View File

47
     expect(uut.getPropsForComponentId('refUniqueId')).toEqual({});
47
     expect(uut.getPropsForComponentId('refUniqueId')).toEqual({});
48
   });
48
   });
49
 });
49
 });
50
-

+ 1
- 1
lib/src/events/PrivateEventsListener.ts View File

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

+ 3
- 3
lib/src/events/PublicEventsRegistry.ts View File

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

+ 1
- 1
lib/src/index.ts View File

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

+ 9
- 89
package.json View File

50
   "dependencies": {
50
   "dependencies": {
51
     "lodash": "4.x.x",
51
     "lodash": "4.x.x",
52
     "prop-types": "15.x.x",
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
   "devDependencies": {
61
   "devDependencies": {
56
     "detox": "6.x.x",
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
     "jest": "22.x.x",
63
     "jest": "22.x.x",
61
     "mocha": "4.x.x",
64
     "mocha": "4.x.x",
62
     "react": "16.0.0-beta.5",
65
     "react": "16.0.0-beta.5",
67
     "remx": "2.x.x",
70
     "remx": "2.x.x",
68
     "semver": "5.x.x",
71
     "semver": "5.x.x",
69
     "shell-utils": "1.x.x",
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
   "babel": {
76
   "babel": {
80
     "env": {
77
     "env": {
128
         "name": "iPhone SE"
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 View File

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

+ 3
- 3
scripts/test-js.js View File

4
 const fix = _.includes(process.argv, '--fix') ? '--fix' : '';
4
 const fix = _.includes(process.argv, '--fix') ? '--fix' : '';
5
 
5
 
6
 const dirs = [
6
 const dirs = [
7
-  'lib/dist',
7
+  'lib/src',
8
   'integration',
8
   'integration',
9
   'e2e',
9
   'e2e',
10
   'scripts',
10
   'scripts',
14
 run();
14
 run();
15
 
15
 
16
 function run() {
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
   exec.execSync(`jest --coverage`);
19
   exec.execSync(`jest --coverage`);
20
 }
20
 }

+ 1
- 1
scripts/test.all.js View File

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

+ 1
- 1
scripts/test.e2e.android.js View File

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

+ 1
- 1
tsconfig-strict.json View File

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

+ 45
- 0
tslint.json View File

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
+}