Browse Source

added lint rules for JS

Daniel Zlotin 8 years ago
parent
commit
b362871c38
6 changed files with 553 additions and 15 deletions
  1. 8
    0
      .babelrc
  2. 529
    0
      .eslintrc
  3. 7
    0
      package.json
  4. 6
    4
      src/Navigation.js
  5. 3
    9
      src/index.js
  6. 0
    2
      src/modules/RctActivity.js

+ 8
- 0
.babelrc View File

@@ -0,0 +1,8 @@
1
+{
2
+  "presets": [
3
+    "es2015",
4
+    "react",
5
+    "stage-0"
6
+  ],
7
+  "retainLines": true
8
+}

+ 529
- 0
.eslintrc View File

@@ -0,0 +1,529 @@
1
+{
2
+  "parser": "babel-eslint",
3
+  "env": {
4
+    "es6": true,
5
+    "node": true
6
+  },
7
+  "parserOptions": {
8
+    "ecmaVersion": 7,
9
+    "sourceType": "module",
10
+    "ecmaFeatures": {
11
+      "impliedStrict": true,
12
+      "jsx": true,
13
+      "experimentalObjectRestSpread": true
14
+    }
15
+  },
16
+  "plugins": [
17
+    "react",
18
+    "react-native",
19
+    "babel"
20
+  ],
21
+  "rules": {
22
+    /*
23
+     *                          possible errors
24
+     */
25
+    "comma-dangle": "error",
26
+    "no-cond-assign": [
27
+      "error",
28
+      "except-parens"
29
+    ],
30
+    "no-console": "warn",
31
+    "no-constant-condition": "error",
32
+    "no-control-regex": "error",
33
+    "no-debugger": "warn",
34
+    "no-dupe-args": "error",
35
+    "no-dupe-keys": "error",
36
+    "no-duplicate-case": "error",
37
+    "no-empty": "error",
38
+    "no-empty-character-class": "error",
39
+    "no-ex-assign": "error",
40
+    "no-extra-boolean-cast": "error",
41
+    "no-extra-parens": 0,
42
+    "no-extra-semi": "error",
43
+    "no-func-assign": "error",
44
+    "no-inner-declarations": "error",
45
+    "no-invalid-regexp": "error",
46
+    "no-irregular-whitespace": "error",
47
+    "no-negated-in-lhs": "error",
48
+    "no-obj-calls": "error",
49
+    "no-regex-spaces": "error",
50
+    "no-sparse-arrays": "error",
51
+    "no-unexpected-multiline": "error",
52
+    "no-unreachable": "error",
53
+    "use-isnan": "error",
54
+    "valid-jsdoc": 0,
55
+    "valid-typeof": "error",
56
+    /*
57
+     *                          best practices
58
+     */
59
+    "accessor-pairs": "warn",
60
+    "array-callback-return": 0,
61
+    "block-scoped-var": "error",
62
+    "complexity": 0,
63
+    "consistent-return": "error",
64
+    "curly": [
65
+      "error",
66
+      "all"
67
+    ],
68
+    "default-case": "error",
69
+    "dot-location": [
70
+      "error",
71
+      "property"
72
+    ],
73
+    "dot-notation": "error",
74
+    "eqeqeq": "error",
75
+    "guard-for-in": "error",
76
+    "no-alert": "error",
77
+    "no-caller": "error",
78
+    "no-case-declarations": "error",
79
+    "no-div-regex": 0,
80
+    "no-else-return": 0,
81
+    "no-empty-function": "error",
82
+    "no-empty-pattern": "error",
83
+    "no-eq-null": "error",
84
+    "no-eval": "error",
85
+    "no-extend-native": "error",
86
+    "no-extra-bind": "error",
87
+    "no-extra-label": "error",
88
+    "no-fallthrough": "error",
89
+    "no-floating-decimal": "error",
90
+    "no-implicit-coercion": "error",
91
+    "no-implicit-globals": 0,
92
+    "no-implied-eval": "error",
93
+    "no-invalid-this": 0,
94
+    "no-iterator": "error",
95
+    "no-labels": "error",
96
+    "no-lone-blocks": "error",
97
+    "no-loop-func": "error",
98
+    "no-magic-numbers": 0,
99
+    "no-multi-spaces": "error",
100
+    "no-multi-str": 0,
101
+    "no-native-reassign": "error",
102
+    "no-new": "error",
103
+    "no-new-func": "error",
104
+    "no-new-wrappers": "error",
105
+    "no-octal": "error",
106
+    "no-octal-escape": "error",
107
+    "no-param-reassign": "error",
108
+    "no-proto": "error",
109
+    "no-redeclare": 0,
110
+    "no-return-assign": "error",
111
+    "no-script-url": "error",
112
+    "no-self-assign": "error",
113
+    "no-self-compare": "error",
114
+    "no-sequences": "error",
115
+    "no-throw-literal": "error",
116
+    "no-unmodified-loop-condition": 0,
117
+    "no-unused-expressions": "error",
118
+    "no-unused-labels": 0,
119
+    "no-useless-call": "error",
120
+    "no-useless-concat": "error",
121
+    "no-void": "error",
122
+    "no-warning-comments": 0,
123
+    "no-with": "error",
124
+    "radix": 0,
125
+    "vars-on-top": 0,
126
+    "wrap-iife": "error",
127
+    "yoda": 0,
128
+    "strict": [
129
+      "error",
130
+      "never"
131
+    ],
132
+    /*
133
+     *                           variables
134
+     */
135
+    "init-declarations": 0,
136
+    "no-catch-shadow": "error",
137
+    "no-delete-var": "error",
138
+    "no-label-var": "error",
139
+    "no-restricted-globals": "error",
140
+    "no-shadow": "error",
141
+    "no-shadow-restricted-names": "error",
142
+    "no-undef": 0,
143
+    "no-undef-init": "error",
144
+    "no-undefined": 0,
145
+    "no-unused-vars": 0,
146
+    "no-use-before-define": 0,
147
+    /*
148
+     *                          Node.js
149
+     */
150
+    "callback-return": 0,
151
+    "global-require": 0,
152
+    "handle-callback-err": 0,
153
+    "no-mixed-requires": "error",
154
+    "no-new-require": "error",
155
+    "no-path-concat": "error",
156
+    "no-process-env": 0,
157
+    "no-process-exit": "error",
158
+    "no-restricted-modules": 0,
159
+    "no-sync": 0,
160
+    /*
161
+     *                          style
162
+     */
163
+    "array-bracket-spacing": [
164
+      "error",
165
+      "never"
166
+    ],
167
+    "block-spacing": "error",
168
+    "brace-style": [
169
+      "error",
170
+      "1tbs"
171
+    ],
172
+    "camelcase": [
173
+      "error",
174
+      {
175
+        "properties": "never"
176
+      }
177
+    ],
178
+    "comma-spacing": [
179
+      "error",
180
+      {
181
+        "before": false,
182
+        "after": true
183
+      }
184
+    ],
185
+    "comma-style": [
186
+      "error",
187
+      "last"
188
+    ],
189
+    "computed-property-spacing": [
190
+      "error",
191
+      "never"
192
+    ],
193
+    "consistent-this": [
194
+      "error",
195
+      "self"
196
+    ],
197
+    "eol-last": [
198
+      "error",
199
+      "unix"
200
+    ],
201
+    "func-names": 0,
202
+    "func-style": 0,
203
+    "id-blacklist": 0,
204
+    "id-length": 0,
205
+    "id-match": 0,
206
+    "indent": [
207
+      "error",
208
+      2,
209
+      {
210
+        "SwitchCase": 1
211
+      }
212
+    ],
213
+    "jsx-quotes": "error",
214
+    "key-spacing": [
215
+      "error",
216
+      {
217
+        "singleLine": {
218
+          "beforeColon": false,
219
+          "afterColon": true,
220
+          "mode": "strict"
221
+        },
222
+        "multiLine": {
223
+          "beforeColon": false,
224
+          "afterColon": true,
225
+          "mode": "strict"
226
+        }
227
+      }
228
+    ],
229
+    "keyword-spacing": [
230
+      "error",
231
+      {
232
+        "before": true,
233
+        "after": true
234
+      }
235
+    ],
236
+    "linebreak-style": [
237
+      "error",
238
+      "unix"
239
+    ],
240
+    "lines-around-comment": 0,
241
+    "max-depth": [
242
+      "error",
243
+      4
244
+    ],
245
+    "max-len": [
246
+      "warn",
247
+      150
248
+    ],
249
+    "max-nested-callbacks": [
250
+      "error",
251
+      4
252
+    ],
253
+    "max-params": [
254
+      "error",
255
+      6
256
+    ],
257
+    "max-statements": [
258
+      "error",
259
+      15,
260
+      {
261
+        "ignoreTopLevelFunctions": true
262
+      }
263
+    ],
264
+    "new-cap": [
265
+      "error",
266
+      {
267
+        "capIsNewExceptions": [
268
+          "Immutable"
269
+        ]
270
+      }
271
+    ],
272
+    "new-parens": "error",
273
+    "newline-after-var": 0,
274
+    "newline-before-return": 0,
275
+    "newline-per-chained-call": 0,
276
+    "no-array-constructor": "error",
277
+    "no-bitwise": 0,
278
+    "no-continue": 0,
279
+    "no-inline-comments": 0,
280
+    "no-lonely-if": "error",
281
+    "no-mixed-spaces-and-tabs": 0,
282
+    "no-multiple-empty-lines": [
283
+      "error",
284
+      {
285
+        "max": 1
286
+      }
287
+    ],
288
+    "no-negated-condition": 0,
289
+    "no-nested-ternary": "error",
290
+    "no-new-object": "error",
291
+    "no-plusplus": 0,
292
+    "no-restricted-syntax": 0,
293
+    "no-spaced-func": "error",
294
+    "no-ternary": 0,
295
+    "no-trailing-spaces": [
296
+      "error",
297
+      {
298
+        "skipBlankLines": true
299
+      }
300
+    ],
301
+    "no-underscore-dangle": 0,
302
+    "no-unneeded-ternary": "error",
303
+    "no-whitespace-before-property": "error",
304
+    "object-curly-spacing": [
305
+      "error",
306
+      "never"
307
+    ],
308
+    "one-var": 0,
309
+    "one-var-declaration-per-line": 0,
310
+    "operator-assignment": 0,
311
+    "operator-linebreak": [
312
+      "error",
313
+      "before"
314
+    ],
315
+    "padded-blocks": [
316
+      "error",
317
+      "never"
318
+    ],
319
+    "quote-props": [
320
+      "error",
321
+      "consistent-as-needed"
322
+    ],
323
+    "quotes": 0,
324
+    "require-jsdoc": 0,
325
+    "semi": [
326
+      "error",
327
+      "always"
328
+    ],
329
+    "semi-spacing": [
330
+      "error",
331
+      {
332
+        "before": false,
333
+        "after": true
334
+      }
335
+    ],
336
+    "sort-imports": 0,
337
+    "sort-vars": 0,
338
+    "space-before-blocks": [
339
+      "error",
340
+      "always"
341
+    ],
342
+    "space-before-function-paren": [
343
+      "error",
344
+      "never"
345
+    ],
346
+    "space-in-parens": [
347
+      "error",
348
+      "never"
349
+    ],
350
+    "space-infix-ops": "error",
351
+    "space-unary-ops": "error",
352
+    "spaced-comment": 0,
353
+    "wrap-regex": "error",
354
+    /*
355
+     *                             ECMAScript 6
356
+     */
357
+    "arrow-body-style": 0,
358
+    "arrow-parens": 0,
359
+    "arrow-spacing": [
360
+      "error",
361
+      {
362
+        "before": true,
363
+        "after": true
364
+      }
365
+    ],
366
+    "constructor-super": "error",
367
+    "generator-star-spacing": 0,
368
+    "no-class-assign": "error",
369
+    "no-confusing-arrow": "error",
370
+    "no-const-assign": "error",
371
+    "no-dupe-class-members": "error",
372
+    "no-new-symbol": "error",
373
+    "no-restricted-imports": 0,
374
+    "no-this-before-super": "error",
375
+    "no-useless-constructor": 0,
376
+    "no-var": "error",
377
+    "object-shorthand": 0,
378
+    "prefer-arrow-callback": 0,
379
+    "prefer-const": "error",
380
+    "prefer-reflect": 0,
381
+    "prefer-rest-params": "error",
382
+    "prefer-spread": "error",
383
+    "prefer-template": 0,
384
+    "require-yield": 0,
385
+    "template-curly-spacing": [
386
+      "error",
387
+      "never"
388
+    ],
389
+    "yield-star-spacing": [
390
+      "error",
391
+      "after"
392
+    ],
393
+    /*
394
+     *                              react plugin
395
+     */
396
+    "react/display-name": 0,
397
+    "react/forbid-prop-types": [
398
+      "error",
399
+      {
400
+        "forbid": [
401
+          "any"
402
+        ]
403
+      }
404
+    ],
405
+    "react/no-danger": "error",
406
+    "react/no-deprecated": "error",
407
+    "react/no-did-mount-set-state": [
408
+      "error",
409
+      "allow-in-func"
410
+    ],
411
+    "react/no-did-update-set-state": [
412
+      "error",
413
+      "allow-in-func"
414
+    ],
415
+    "react/no-direct-mutation-state": "error",
416
+    "react/no-is-mounted": "error",
417
+    "react/no-multi-comp": "error",
418
+    "react/no-set-state": 0,
419
+    "react/no-string-refs": 0,
420
+    "react/no-unknown-property": 0,
421
+    "react/prefer-es6-class": [
422
+      "error",
423
+      "always"
424
+    ],
425
+    "react/prefer-stateless-function": 0,
426
+    "react/prop-types": "error",
427
+    "react/react-in-jsx-scope": "error",
428
+    "react/require-extension": 0,
429
+    "react/self-closing-comp": "error",
430
+    "react/sort-comp": [
431
+      "error",
432
+      {
433
+        "order": [
434
+          "static-methods",
435
+          "lifecycle",
436
+          "/^on.+$/",
437
+          "/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/",
438
+          "everything-else",
439
+          "/^render.+$/",
440
+          "render"
441
+        ]
442
+      }
443
+    ],
444
+    "react/sort-prop-types": 0,
445
+    "react/wrap-multilines": "error",
446
+    "react/jsx-boolean-value": [
447
+      "error",
448
+      "always"
449
+    ],
450
+    "react/jsx-closing-bracket-location": "error",
451
+    "react/jsx-curly-spacing": [
452
+      "error",
453
+      "never"
454
+    ],
455
+    "react/jsx-equals-spacing": [
456
+      "error",
457
+      "never"
458
+    ],
459
+    "react/jsx-handler-names": [
460
+      "error",
461
+      {
462
+        "eventHandlerPropPrefix": "handle"
463
+      }
464
+    ],
465
+    "react/jsx-indent-props": [
466
+      0,
467
+      2
468
+    ],
469
+    "react/jsx-indent": [
470
+      "error",
471
+      2
472
+    ],
473
+    "react/jsx-key": "error",
474
+    "react/jsx-max-props-per-line": [
475
+      "error",
476
+      {
477
+        "maximum": 2
478
+      }
479
+    ],
480
+    "react/jsx-no-bind": 0,
481
+    "react/jsx-no-duplicate-props": [
482
+      "error",
483
+      {
484
+        "ignoreCase": true
485
+      }
486
+    ],
487
+    "react/jsx-no-literals": "error",
488
+    "react/jsx-no-undef": "error",
489
+    "react/jsx-pascal-case": "error",
490
+    "react/jsx-sort-props": 0,
491
+    "react/jsx-space-before-closing": 0,
492
+    "react/jsx-uses-react": "error",
493
+    "react/jsx-uses-vars": "error",
494
+    /*
495
+     *                              react-native plugin
496
+     */
497
+    "react-native/no-unused-styles": "error",
498
+    "react-native/split-platform-components": "error",
499
+    /*
500
+     *                              babel plugin
501
+     */
502
+    "babel/generator-star-spacing": [
503
+      "error",
504
+      "after"
505
+    ],
506
+    "babel/new-cap": [
507
+      "error",
508
+      {
509
+        "capIsNewExceptions": [
510
+          "Immutable"
511
+        ]
512
+      }
513
+    ],
514
+    "babel/array-bracket-spacing": [
515
+      "error",
516
+      "never"
517
+    ],
518
+    "babel/object-curly-spacing": [
519
+      "error",
520
+      "never"
521
+    ],
522
+    "babel/object-shorthand": 0,
523
+    "babel/arrow-parens": [
524
+      "error",
525
+      "always"
526
+    ],
527
+    "babel/no-await-in-loop": 0
528
+  }
529
+}

+ 7
- 0
package.json View File

@@ -18,6 +18,13 @@
18 18
   "main": "src/index.js",
19 19
   "author": "Tal Kol <talkol@gmail.com>",
20 20
   "license": "MIT",
21
+  "scripts": {
22
+    "build": ":",
23
+    "lint": "eslint src test",
24
+    "pretest": "npm run lint",
25
+    "test": ":",
26
+    "release": ":"
27
+  },
21 28
   "peerDependencies": {
22 29
     "react-native": ">=0.25.1",
23 30
     "react": ">=0.14.5"

+ 6
- 4
src/Navigation.js View File

@@ -1,5 +1,5 @@
1 1
 import React from 'react';
2
-import { AppRegistry } from 'react-native';
2
+import {AppRegistry} from 'react-native';
3 3
 import platformSpecific from './platformSpecific';
4 4
 import Screen from './Screen';
5 5
 
@@ -24,6 +24,7 @@ function _registerComponentNoRedux(screenID, generator) {
24 24
     return class extends Screen {
25 25
       static navigatorStyle = InternalComponent.navigatorStyle || {};
26 26
       static navigatorButtons = InternalComponent.navigatorButtons || {};
27
+
27 28
       render() {
28 29
         return (
29 30
           <InternalComponent navigator={this.navigator} {...this.props} />
@@ -41,6 +42,7 @@ function _registerComponentRedux(screenID, generator, store, Provider) {
41 42
     return class extends Screen {
42 43
       static navigatorStyle = InternalComponent.navigatorStyle || {};
43 44
       static navigatorButtons = InternalComponent.navigatorButtons || {};
45
+
44 46
       render() {
45 47
         return (
46 48
           <Provider store={store}>
@@ -57,7 +59,7 @@ function _registerComponentRedux(screenID, generator, store, Provider) {
57 59
 function getRegisteredScreen(screenID) {
58 60
   const generator = registeredScreens[screenID];
59 61
   if (!generator) {
60
-    console.error('Navigation.getRegisteredScreen: ' + screenID + ' used but not yet registered');
62
+    console.error(`Navigation.getRegisteredScreen: ${screenID} used but not yet registered`);
61 63
     return;
62 64
   }
63 65
   return generator();
@@ -91,7 +93,7 @@ function dismissInAppNotification(params = {}) {
91 93
   return platformSpecific.dismissInAppNotification(params);
92 94
 }
93 95
 
94
-export default {
96
+module.exports = {
95 97
   registerScreen,
96 98
   getRegisteredScreen,
97 99
   registerComponent,
@@ -104,4 +106,4 @@ export default {
104 106
   dismissInAppNotification,
105 107
   startTabBasedApp: platformSpecific.startTabBasedApp,
106 108
   startSingleScreenApp: platformSpecific.startSingleScreenApp
107
-}
109
+};

+ 3
- 9
src/index.js View File

@@ -1,11 +1,5 @@
1
-import Navigation from './src/Navigation';
2
-import Screen from './src/Screen';
3
-import RctActivity from './src/modules/RctActivity';
4
-import { NavigationToolBarIOS } from 'react-native-controllers';
1
+import Navigation from './Navigation';
5 2
 
6
-export {
7
-  Navigation,
8
-  Screen,
9
-  RctActivity,
10
-  NavigationToolBarIOS
3
+module.exports = {
4
+  Navigation
11 5
 };

+ 0
- 2
src/modules/RctActivity.js View File

@@ -1,2 +0,0 @@
1
-import { NativeModules } from 'react-native';
2
-module.exports = NativeModules.RctActivity;