瀏覽代碼

add eslint for ts

afrokick 5 年之前
父節點
當前提交
42a626629b

+ 2 - 0
.eslintignore

@@ -0,0 +1,2 @@
+src/
+dist/

+ 22 - 0
.eslintrc.json

@@ -0,0 +1,22 @@
+{
+    "parser": "@typescript-eslint/parser",
+    "extends": [
+        "eslint:recommended",
+        "plugin:@typescript-eslint/eslint-recommended",
+        "plugin:@typescript-eslint/recommended"
+    ],
+    "env": {
+        "node": true,
+        "es6": true,
+        "mocha": true
+    },
+    "parserOptions": {
+        "ecmaVersion": 2018,
+        "sourceType": "module"
+    },
+    "rules": {
+        "no-var": "error",
+        "no-console": "off",
+        "@typescript-eslint/camelcase": "off"
+    }
+}

File diff suppressed because it is too large
+ 671 - 38
package-lock.json


+ 6 - 4
package.json

@@ -15,10 +15,10 @@
   "scripts": {
     "build": "tsc",
     "clean": "rimraf ./dist",
-    "lint": "tslint -c tslint.json -p tsconfig.json --fix",
+    "lint": "eslint --ext .js,.ts .",
     "tsc": "tsc",
     "prebuild": "npm run lint",
-    "test": "npm run lint && npm run build && mocha \"test/**/*.js\"",
+    "test": "npm run lint && mocha -r ts-node/register \"test/**/*\"",
     "start": "bin/peerjs --port ${PORT:=9000}",
     "dev:start": "npm-run-all build start",
     "dev": "nodemon --watch src -e ts --exec npm run dev:start"
@@ -40,17 +40,19 @@
     "@types/chai": "^4.1.7",
     "@types/mocha": "^5.2.7",
     "@types/node": "^10.14.16",
+    "@typescript-eslint/eslint-plugin": "^2.0.0",
+    "@typescript-eslint/parser": "^2.0.0",
     "chai": "^4.2.0",
+    "eslint": "^6.2.1",
     "mocha": "^6.2.0",
     "nodemon": "^1.19.1",
     "npm-run-all": "^4.1.5",
     "rimraf": "^3.0.0",
     "sinon": "^7.4.1",
     "ts-node": "^8.3.0",
-    "tslint": "^5.19.0",
     "typescript": "^3.5.3"
   },
   "engines": {
     "node": "^10"
   }
-}
+}

+ 4 - 2
src/services/checkBrokenConnections/index.ts

@@ -4,17 +4,19 @@ import { IRealm } from "../../models/realm";
 
 const DEFAULT_CHECK_INTERVAL = 300;
 
+type CustomConfig = Pick<IConfig, 'alive_timeout'>;
+
 export class CheckBrokenConnections {
 
   public readonly checkInterval: number;
   private timeoutId: NodeJS.Timeout;
   private readonly realm: IRealm;
-  private readonly config: IConfig;
+  private readonly config: CustomConfig;
   private readonly onClose?: (client: IClient) => void;
 
   constructor({ realm, config, checkInterval = DEFAULT_CHECK_INTERVAL, onClose }: {
     realm: IRealm,
-    config: IConfig,
+    config: CustomConfig,
     checkInterval?: number,
     onClose?: (client: IClient) => void
   }) {

+ 3 - 3
test/messageHandler/handlers/heartbeat/index.js → test/messageHandler/handlers/heartbeat/index.ts

@@ -1,6 +1,6 @@
-const { expect } = require('chai');
-const { Client } = require('../../../../dist/src/models/client');
-const { HeartbeatHandler } = require('../../../../dist/src/messageHandler/handlers');
+import { expect } from 'chai';
+import { Client } from '../../../../src/models/client';
+import { HeartbeatHandler } from '../../../../src/messageHandler/handlers';
 
 describe('Heartbeat handler', () => {
     it('should update last ping time', () => {

+ 3 - 3
test/models/realm.js → test/models/realm.ts

@@ -1,6 +1,6 @@
-const { expect } = require('chai');
-const { Realm } = require('../../dist/src/models/realm');
-const { Client } = require('../../dist/src/models/client');
+import { expect } from 'chai';
+import { Realm } from '../../src/models/realm';
+import { Client } from '../../src/models/client';
 
 describe('Realm', () => {
   describe('#generateClientId', () => {

+ 4 - 4
test/services/checkBrokenConnections/index.js → test/services/checkBrokenConnections/index.ts

@@ -1,7 +1,7 @@
-const { expect } = require('chai');
-const { Client } = require('../../../dist/src/models/client');
-const { Realm } = require('../../../dist/src/models/realm');
-const { CheckBrokenConnections } = require('../../../dist/src/services/checkBrokenConnections');
+import { expect } from 'chai';
+import { Client } from '../../../src/models/client';
+import { Realm } from '../../../src/models/realm';
+import { CheckBrokenConnections } from '../../../src/services/checkBrokenConnections';
 
 describe('checkBrokenConnections service', () => {
     it('should remove client after 2 checks', (done) => {

+ 0 - 20
tslint.json

@@ -1,20 +0,0 @@
-{
-    "defaultSeverity": "error",
-    "extends": [
-        "tslint:recommended"
-    ],
-    "jsRules": {},
-    "rules": {
-        "trailing-comma": [
-            false
-        ],
-        "object-literal-sort-keys": false
-    },
-    "rulesDirectory": [],
-    "linterOptions": {
-        "exclude": [
-            "./bin/",
-            "./test/"
-        ]
-    }
-}

Some files were not shown because too many files changed in this diff