Browse Source

eslint main.ts

Paul 5 years ago
parent
commit
599f032578
6 changed files with 91 additions and 17 deletions
  1. 11
    11
      example/main.ts
  2. 2
    0
      package.json
  3. 1
    1
      src/client.ts
  4. 1
    1
      src/packet.ts
  5. 11
    2
      webpack.config.js
  6. 65
    2
      yarn.lock

+ 11
- 11
example/main.ts View File

@@ -4,23 +4,23 @@ const url = 'ws://127.0.0.1:8081';
4 4
 const client = new Client(
5 5
   url,
6 6
   new (class {
7
-    onOpen(ev: Event) {
7
+    public onOpen(): void {
8 8
       client.ping(
9 9
         {},
10 10
         new (class {
11
-          onStart(): void {
11
+          public onStart(): void {
12 12
             console.log('start ping');
13 13
           }
14 14
 
15
-          onSuccess(data: string): void {
15
+          public onSuccess(data: string): void {
16 16
             console.log('ping successful:', data);
17 17
           }
18 18
 
19
-          onError(code: number, message: string): void {
19
+          public onError(code: number, message: string): void {
20 20
             console.log('ping error:', message);
21 21
           }
22 22
 
23
-          onEnd(): void {
23
+          public onEnd(): void {
24 24
             console.log('end ping');
25 25
           }
26 26
         })(),
@@ -30,31 +30,31 @@ const client = new Client(
30 30
         '/v1/healthy',
31 31
         {},
32 32
         new (class {
33
-          onStart(): void {
33
+          public onStart(): void {
34 34
             console.log('start request');
35 35
           }
36 36
 
37
-          onSuccess(data: string): void {
37
+          public onSuccess(data: string): void {
38 38
             console.log('request successful:', data);
39 39
           }
40 40
 
41
-          onError(code: number, message: string): void {
41
+          public onError(code: number, message: string): void {
42 42
             console.log('request error:', message);
43 43
           }
44 44
 
45
-          onEnd(): void {
45
+          public onEnd(): void {
46 46
             console.log('end request');
47 47
           }
48 48
         })(),
49 49
       );
50 50
     }
51 51
 
52
-    onClose(ev: Event) {
52
+    public onClose(ev: Event): void {
53 53
       console.log('connection error', ev);
54 54
       console.log(ev);
55 55
     }
56 56
 
57
-    onError(ev: Event) {
57
+    public onError(): void {
58 58
       console.log('close connection');
59 59
     }
60 60
   })(),

+ 2
- 0
package.json View File

@@ -39,6 +39,8 @@
39 39
     "babel-preset-env": "^1.7.0",
40 40
     "eslint": "^5.16.0",
41 41
     "eslint-config-prettier": "^4.2.0",
42
+    "eslint-friendly-formatter": "^4.0.1",
43
+    "eslint-loader": "^2.1.2",
42 44
     "html-webpack-plugin": "^3.2.0",
43 45
     "jest": "^24.5.0",
44 46
     "ts-jest": "^24.0.0",

+ 1
- 1
src/client.ts View File

@@ -265,7 +265,7 @@ class Client {
265 265
         reader.readAsArrayBuffer(ev.data);
266 266
         reader.onload = (): void => {
267 267
           try {
268
-            let packet = new Packet().unPack(reader.result);
268
+            let packet = new Packet().unPack(reader.result as ArrayBuffer);
269 269
             let packetLength = packet.headerLength + packet.bodyLength + 20;
270 270
             if (packetLength > this._maxPayload) {
271 271
               throw new Error('the packet is big than ' + this._maxPayload);

+ 1
- 1
src/packet.ts View File

@@ -45,7 +45,7 @@ export class Packet {
45 45
     return buf;
46 46
   }
47 47
 
48
-  public unPack(data: any): Packet {
48
+  public unPack(data: ArrayBuffer | SharedArrayBuffer): Packet {
49 49
     const dataView = new DataView(data);
50 50
 
51 51
     this.operator = dataView.getUint32(0, false);

+ 11
- 2
webpack.config.js View File

@@ -21,11 +21,20 @@ module.exports = {
21 21
     },
22 22
     resolve: { extensions: ['.js', '.jsx', '.tsx', '.ts', '.json'] },
23 23
     module: {
24
-      rules: [{
24
+      rules: [
25
+      {
25 26
           // Include ts, tsx, js, and jsx files.
26 27
           test: /\.(ts|js)x?$/,
27 28
           exclude: /node_modules/,
28 29
           loader: 'babel-loader',
29
-      }],
30
+      },
31
+      {
32
+          test: /\.(ts|js)x?$/,
33
+          loader: 'eslint-loader',
34
+          options: {
35
+            formatter: require('eslint-friendly-formatter')
36
+        }
37
+      }
38
+    ],
30 39
     }
31 40
 };

+ 65
- 2
yarn.lock View File

@@ -2192,6 +2192,10 @@ co@^4.6.0:
2192 2192
   version "4.6.0"
2193 2193
   resolved "http://registry.npm.taobao.org/co/download/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
2194 2194
 
2195
+coalescy@1.0.0:
2196
+  version "1.0.0"
2197
+  resolved "https://registry.yarnpkg.com/coalescy/-/coalescy-1.0.0.tgz#4b065846b836361ada6c4b4a4abf4bc1cac31bf1"
2198
+
2195 2199
 code-point-at@^1.0.0:
2196 2200
   version "1.1.0"
2197 2201
   resolved "http://registry.npm.taobao.org/code-point-at/download/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
@@ -2794,6 +2798,27 @@ eslint-config-prettier@^4.2.0:
2794 2798
   dependencies:
2795 2799
     get-stdin "^6.0.0"
2796 2800
 
2801
+eslint-friendly-formatter@^4.0.1:
2802
+  version "4.0.1"
2803
+  resolved "https://registry.yarnpkg.com/eslint-friendly-formatter/-/eslint-friendly-formatter-4.0.1.tgz#27d504dc837f7caddbf201b2e84a4ee730ba3efa"
2804
+  dependencies:
2805
+    chalk "^2.0.1"
2806
+    coalescy "1.0.0"
2807
+    extend "^3.0.0"
2808
+    minimist "^1.2.0"
2809
+    strip-ansi "^4.0.0"
2810
+    text-table "^0.2.0"
2811
+
2812
+eslint-loader@^2.1.2:
2813
+  version "2.1.2"
2814
+  resolved "https://registry.yarnpkg.com/eslint-loader/-/eslint-loader-2.1.2.tgz#453542a1230d6ffac90e4e7cb9cadba9d851be68"
2815
+  dependencies:
2816
+    loader-fs-cache "^1.0.0"
2817
+    loader-utils "^1.0.2"
2818
+    object-assign "^4.0.1"
2819
+    object-hash "^1.1.4"
2820
+    rimraf "^2.6.1"
2821
+
2797 2822
 eslint-scope@^4.0.0, eslint-scope@^4.0.3:
2798 2823
   version "4.0.3"
2799 2824
   resolved "https://registry.npm.taobao.org/eslint-scope/download/eslint-scope-4.0.3.tgz#ca03833310f6889a3264781aa82e63eb9cfe7848"
@@ -3008,7 +3033,7 @@ extend-shallow@^3.0.0, extend-shallow@^3.0.2:
3008 3033
     assign-symbols "^1.0.0"
3009 3034
     is-extendable "^1.0.1"
3010 3035
 
3011
-extend@~3.0.2:
3036
+extend@^3.0.0, extend@~3.0.2:
3012 3037
   version "3.0.2"
3013 3038
   resolved "http://registry.npm.taobao.org/extend/download/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa"
3014 3039
 
@@ -3115,6 +3140,14 @@ finalhandler@1.1.1:
3115 3140
     statuses "~1.4.0"
3116 3141
     unpipe "~1.0.0"
3117 3142
 
3143
+find-cache-dir@^0.1.1:
3144
+  version "0.1.1"
3145
+  resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-0.1.1.tgz#c8defae57c8a52a8a784f9e31c57c742e993a0b9"
3146
+  dependencies:
3147
+    commondir "^1.0.1"
3148
+    mkdirp "^0.5.1"
3149
+    pkg-dir "^1.0.0"
3150
+
3118 3151
 find-cache-dir@^2.0.0:
3119 3152
   version "2.1.0"
3120 3153
   resolved "https://registry.npm.taobao.org/find-cache-dir/download/find-cache-dir-2.1.0.tgz#8d0f94cd13fe43c6c7c261a0d86115ca918c05f7"
@@ -3123,6 +3156,13 @@ find-cache-dir@^2.0.0:
3123 3156
     make-dir "^2.0.0"
3124 3157
     pkg-dir "^3.0.0"
3125 3158
 
3159
+find-up@^1.0.0:
3160
+  version "1.1.2"
3161
+  resolved "https://registry.yarnpkg.com/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f"
3162
+  dependencies:
3163
+    path-exists "^2.0.0"
3164
+    pinkie-promise "^2.0.0"
3165
+
3126 3166
 find-up@^3.0.0:
3127 3167
   version "3.0.0"
3128 3168
   resolved "http://registry.npm.taobao.org/find-up/download/find-up-3.0.0.tgz#49169f1d7993430646da61ecc5ae355c21c97b73"
@@ -4459,6 +4499,13 @@ load-json-file@^4.0.0:
4459 4499
     pify "^3.0.0"
4460 4500
     strip-bom "^3.0.0"
4461 4501
 
4502
+loader-fs-cache@^1.0.0:
4503
+  version "1.0.2"
4504
+  resolved "https://registry.yarnpkg.com/loader-fs-cache/-/loader-fs-cache-1.0.2.tgz#54cedf6b727e1779fd8f01205f05f6e88706f086"
4505
+  dependencies:
4506
+    find-cache-dir "^0.1.1"
4507
+    mkdirp "0.5.1"
4508
+
4462 4509
 loader-runner@^2.3.0:
4463 4510
   version "2.4.0"
4464 4511
   resolved "https://registry.npm.taobao.org/loader-runner/download/loader-runner-2.4.0.tgz#ed47066bfe534d7e84c4c7b9998c2a75607d9357"
@@ -4725,7 +4772,7 @@ mixin-deep@^1.2.0:
4725 4772
     for-in "^1.0.2"
4726 4773
     is-extendable "^1.0.1"
4727 4774
 
4728
-mkdirp@0.5.x, mkdirp@0.x, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0:
4775
+mkdirp@0.5.1, mkdirp@0.5.x, mkdirp@0.x, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0:
4729 4776
   version "0.5.1"
4730 4777
   resolved "http://registry.npm.taobao.org/mkdirp/download/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
4731 4778
   dependencies:
@@ -4968,6 +5015,10 @@ object-copy@^0.1.0:
4968 5015
     define-property "^0.2.5"
4969 5016
     kind-of "^3.0.3"
4970 5017
 
5018
+object-hash@^1.1.4:
5019
+  version "1.3.1"
5020
+  resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-1.3.1.tgz#fde452098a951cb145f039bb7d455449ddc126df"
5021
+
4971 5022
 object-keys@^1.0.12:
4972 5023
   version "1.1.0"
4973 5024
   resolved "http://registry.npm.taobao.org/object-keys/download/object-keys-1.1.0.tgz#11bd22348dd2e096a045ab06f6c85bcc340fa032"
@@ -5190,6 +5241,12 @@ path-dirname@^1.0.0:
5190 5241
   version "1.0.2"
5191 5242
   resolved "https://registry.npm.taobao.org/path-dirname/download/path-dirname-1.0.2.tgz#cc33d24d525e099a5388c0336c6e32b9160609e0"
5192 5243
 
5244
+path-exists@^2.0.0:
5245
+  version "2.1.0"
5246
+  resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-2.1.0.tgz#0feb6c64f0fc518d9a754dd5efb62c7022761f4b"
5247
+  dependencies:
5248
+    pinkie-promise "^2.0.0"
5249
+
5193 5250
 path-exists@^3.0.0:
5194 5251
   version "3.0.0"
5195 5252
   resolved "http://registry.npm.taobao.org/path-exists/download/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515"
@@ -5262,6 +5319,12 @@ pirates@^4.0.1:
5262 5319
   dependencies:
5263 5320
     node-modules-regexp "^1.0.0"
5264 5321
 
5322
+pkg-dir@^1.0.0:
5323
+  version "1.0.0"
5324
+  resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-1.0.0.tgz#7a4b508a8d5bb2d629d447056ff4e9c9314cf3d4"
5325
+  dependencies:
5326
+    find-up "^1.0.0"
5327
+
5265 5328
 pkg-dir@^3.0.0:
5266 5329
   version "3.0.0"
5267 5330
   resolved "http://registry.npm.taobao.org/pkg-dir/download/pkg-dir-3.0.0.tgz#2749020f239ed990881b1f71210d51eb6523bea3"