diff --git a/.eslintrc.json b/.eslintrc.json index d721b29c06..30b2034d64 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -5,16 +5,17 @@ "es6": true }, "extends": [ - "standard" + "plugin:@typescript-eslint/recommended" ], "globals": { "Atomics": "readonly", "SharedArrayBuffer": "readonly" }, - "parserOptions": { - "ecmaVersion": 2018 - }, + "parser": "@typescript-eslint/parser", + "plugins": ["@typescript-eslint"], "rules": { - "standard/no-callback-literal": 0 + "standard/no-callback-literal": 0, + "@typescript-eslint/no-var-requires": 0, + "@typescript-eslint/ban-types": 0 } } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 6c1ba00a94..f88964d8f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -133,6 +133,18 @@ "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==" }, + "@types/eslint-visitor-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", + "integrity": "sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==", + "dev": true + }, + "@types/json-schema": { + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.5.tgz", + "integrity": "sha512-7+2BITlgjgDhH0vvwZU/HZJVyk+2XUlvxXe8dFMedNX/aMkaOq++rMAFXc0tM7ij15QaWlbdQASBR9dihi+bDQ==", + "dev": true + }, "@types/node": { "version": "14.0.5", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.5.tgz", @@ -148,6 +160,106 @@ "@types/node": "*" } }, + "@typescript-eslint/eslint-plugin": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.2.0.tgz", + "integrity": "sha512-t9RTk/GyYilIXt6BmZurhBzuMT9kLKw3fQoJtK9ayv0tXTlznXEAnx07sCLXdkN3/tZDep1s1CEV95CWuARYWA==", + "dev": true, + "requires": { + "@typescript-eslint/experimental-utils": "3.2.0", + "functional-red-black-tree": "^1.0.1", + "regexpp": "^3.0.0", + "semver": "^7.3.2", + "tsutils": "^3.17.1" + }, + "dependencies": { + "regexpp": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz", + "integrity": "sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==", + "dev": true + }, + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", + "dev": true + } + } + }, + "@typescript-eslint/experimental-utils": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-3.2.0.tgz", + "integrity": "sha512-UbJBsk+xO9dIFKtj16+m42EvUvsjZbbgQ2O5xSTSfVT1Z3yGkL90DVu0Hd3029FZ5/uBgl+F3Vo8FAcEcqc6aQ==", + "dev": true, + "requires": { + "@types/json-schema": "^7.0.3", + "@typescript-eslint/typescript-estree": "3.2.0", + "eslint-scope": "^5.0.0", + "eslint-utils": "^2.0.0" + }, + "dependencies": { + "eslint-utils": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.0.0.tgz", + "integrity": "sha512-0HCPuJv+7Wv1bACm8y5/ECVfYdfsAm9xmVb7saeFlxjPYALefjhbYoCkBjPdPzGH8wWyTpAez82Fh3VKYEZ8OA==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.1.0" + } + } + } + }, + "@typescript-eslint/parser": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-3.2.0.tgz", + "integrity": "sha512-Vhu+wwdevDLVDjK1lIcoD6ZbuOa93fzqszkaO3iCnmrScmKwyW/AGkzc2UvfE5TCoCXqq7Jyt6SOXjsIlpqF4A==", + "dev": true, + "requires": { + "@types/eslint-visitor-keys": "^1.0.0", + "@typescript-eslint/experimental-utils": "3.2.0", + "@typescript-eslint/typescript-estree": "3.2.0", + "eslint-visitor-keys": "^1.1.0" + } + }, + "@typescript-eslint/typescript-estree": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-3.2.0.tgz", + "integrity": "sha512-uh+Y2QO7dxNrdLw7mVnjUqkwO/InxEqwN0wF+Za6eo3coxls9aH9kQ/5rSvW2GcNanebRTmsT5w1/92lAOb1bA==", + "dev": true, + "requires": { + "debug": "^4.1.1", + "eslint-visitor-keys": "^1.1.0", + "glob": "^7.1.6", + "is-glob": "^4.0.1", + "lodash": "^4.17.15", + "semver": "^7.3.2", + "tsutils": "^3.17.1" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", + "dev": true + } + } + }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -3522,6 +3634,15 @@ "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==", "dev": true }, + "tsutils": { + "version": "3.17.1", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.17.1.tgz", + "integrity": "sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + }, "type-check": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", diff --git a/package.json b/package.json index 81d120cf1c..fcafec919b 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "test": "echo \"Error: no test specified\"", "start": "./lib/bin/remixd.js -s ./shared --remix-ide http://127.0.0.1:8080", "npip": "npip", - "lint": "eslint ./src", + "lint": "eslint ./src --ext .ts", "build": "tsc -p ./ && chmod +x ./lib/bin/remixd.js", "dev": "nodemon" }, @@ -49,6 +49,8 @@ "devDependencies": { "@types/node": "^14.0.5", "@types/ws": "^7.2.4", + "@typescript-eslint/eslint-plugin": "^3.2.0", + "@typescript-eslint/parser": "^3.2.0", "eslint": "6.8.0", "eslint-config-standard": "14.1.1", "eslint-plugin-import": "2.20.2", diff --git a/src/serviceList.ts b/src/serviceList.ts index 59f47b9cb9..32c446a176 100644 --- a/src/serviceList.ts +++ b/src/serviceList.ts @@ -1,3 +1,3 @@ import { RemixdClient as sharedfolder } from './services/remixdClient' -export { sharedfolder } \ No newline at end of file +export { sharedfolder } diff --git a/src/services/remixdClient.ts b/src/services/remixdClient.ts index ce618bef28..e5d093ee4d 100644 --- a/src/services/remixdClient.ts +++ b/src/services/remixdClient.ts @@ -21,7 +21,7 @@ export class RemixdClient extends PluginClient { this.readOnly = readOnly } - list (args: SharedFolderArgs): Filelist { + list (): Filelist { try { return utils.walkSync(this.currentSharedFolder, {}, this.currentSharedFolder) } catch (e) { @@ -97,7 +97,7 @@ export class RemixdClient extends PluginClient { fs.mkdirp(path).then(() => resolve()).catch((e: Error) => reject(e)) } else { fs.ensureFile(path).then(() => { - fs.writeFile(path, args.content, 'utf8', (error: Error, data: string) => { + fs.writeFile(path, args.content, 'utf8', (error: Error) => { if (error) { console.log(error) reject(error) @@ -124,7 +124,7 @@ export class RemixdClient extends PluginClient { const newpath = utils.absolutePath(args.newPath, this.currentSharedFolder) if (!isRealPath(oldpath)) return - fs.move(oldpath, newpath, (error: Error, data: string) => { + fs.move(oldpath, newpath, (error: Error) => { if (error) { console.log(error) reject(error.message) @@ -145,7 +145,7 @@ export class RemixdClient extends PluginClient { if (!fs.existsSync(path)) reject('File not found ' + path) if (!isRealPath(path)) return - return fs.remove(path, (error: Error, data: string) => { + return fs.remove(path, (error: Error) => { if (error) { console.log(error) reject('Failed to remove file/directory: ' + error) diff --git a/src/utils.ts b/src/utils.ts index 9aef4a3e54..1e5207c761 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -45,12 +45,14 @@ function walkSync (dir: string, filelist: Filelist, sharedFolder: string): Filel filelist = filelist || {} files.forEach(function (file) { - var subElement = path.join(dir, file) + const subElement = path.join(dir, file) + if (!fs.lstatSync(subElement).isSymbolicLink()) { if (fs.statSync(subElement).isDirectory()) { filelist = walkSync(subElement, filelist, sharedFolder) } else { - var relative = relativePath(subElement, sharedFolder) + const relative = relativePath(subElement, sharedFolder) + filelist[relative] = isbinaryfile.sync(subElement) } } diff --git a/src/websocket.ts b/src/websocket.ts index e412c70c62..1957156403 100644 --- a/src/websocket.ts +++ b/src/websocket.ts @@ -11,9 +11,7 @@ export default class WebSocket { constructor (public port: number, public opt: WebsocketOpt, public sharedFolder: SharedFolderClient) {} - start (callback?: Function) { - const obj = this - + start (callback?: Function): void { this.server = http.createServer((request, response) => { console.log((new Date()) + ' Received request for ' + request.url) response.writeHead(404) @@ -35,16 +33,16 @@ export default class WebSocket { done(true) } }) - this.wsServer.on('connection', function connection(ws, request) { - const { sharedFolder } = obj + this.wsServer.on('connection', (ws) => { + const { sharedFolder } = this - obj.connection = ws + this.connection = ws buildWebsocketClient(ws, sharedFolder) if(callback) callback(ws) }) } - close () { + close (): void { if (this.wsServer) { this.wsServer.close(() => { this.server.close() @@ -53,6 +51,6 @@ export default class WebSocket { } } -function originIsAllowed (origin: string, self: WebSocket) { +function originIsAllowed (origin: string, self: WebSocket): boolean { return origin === self.opt.remixIdeUrl }