From aa3bec41b464317b696d3b14ac39b6bf4a407d82 Mon Sep 17 00:00:00 2001 From: Darien Pardinas Diaz Date: Mon, 2 Dec 2024 09:35:17 -0500 Subject: [PATCH] Formatted all code with prettier --- package.json | 3 ++- src/extension.ts | 10 ++++---- src/services/formatter.ts | 8 +++---- src/services/logger.ts | 2 +- src/services/quickPick.ts | 2 +- src/test/suite/extension.test.ts | 18 +++++++++----- src/test/suite/sendPostRequest.ts | 8 +++---- webpack.config.js | 40 +++++++++++++++---------------- 8 files changed, 49 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index 1a8b509..22a302e 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,8 @@ "test-watch": "tsc -watch -p ./", "pretest": "npm run test-compile && npm run lint", "lint": "eslint src --ext ts", - "test": "xvfb-run -a node ./out/test/runTest.js" + "test": "xvfb-run -a node ./out/test/runTest.js", + "format": "npx prettier --write './**/*.{js,jsx,mjs,cjs,ts,tsx}'" }, "devDependencies": { "@types/glob": "^7.1.6", diff --git a/src/extension.ts b/src/extension.ts index 807edc0..8b27a6a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -40,7 +40,7 @@ const startHttpServer = async ( context: vscode.ExtensionContext, host: string, port: number, - fallbackPorts: number[] + fallbackPorts: number[], ): Promise => { let isInUse = false; if (port) { @@ -127,7 +127,7 @@ const startHttpServer = async ( function getDefaultPortForWorkspace(): number { const identifier = vscode.workspace.workspaceFile ? vscode.workspace.workspaceFile.toString() - : vscode.workspace.workspaceFolders?.map(f => f.uri.toString()).join(""); + : vscode.workspace.workspaceFolders?.map((f) => f.uri.toString()).join(""); if (!identifier) { return 37100; } @@ -135,7 +135,7 @@ function getDefaultPortForWorkspace(): number { a = (a << 5) - a + b.charCodeAt(0); return a & a; }, 0); - const port = 37100 + (Math.abs(hash) % (65535-37100)); + const port = 37100 + (Math.abs(hash) % (65535 - 37100)); return port; } @@ -149,7 +149,7 @@ function httpPortToPid(context: vscode.ExtensionContext, port: number): string { function killPreviousVscodeProcessIfUsingTcpPort( context: vscode.ExtensionContext, - port: number | undefined + port: number | undefined, ) { Logger.info(`Checking if we need to kill previous process using port = ${port}`); if (!port) { @@ -188,7 +188,7 @@ function setupRestControl(context: vscode.ExtensionContext) { context, "127.0.0.1", port, - (fallbackPorts || []).filter((p: number) => p !== port) + (fallbackPorts || []).filter((p: number) => p !== port), ); Logger.info("VSCode REST Control is now active!"); } else { diff --git a/src/services/formatter.ts b/src/services/formatter.ts index 9295107..127cd48 100644 --- a/src/services/formatter.ts +++ b/src/services/formatter.ts @@ -9,7 +9,7 @@ export async function registerExternalFormatter( formatterEndpoint: string, languages: string[], httpMethod: string, - onErrorMessage: string + onErrorMessage: string, ) { languages = languages || (await vscode.languages.getLanguages()); httpMethod = httpMethod || "POST"; @@ -21,7 +21,7 @@ export async function registerExternalFormatter( const url = new URL(formatterEndpoint); formatterRegistration = vscode.languages.registerDocumentFormattingEditProvider(languages, { provideDocumentFormattingEdits( - doc: vscode.TextDocument + doc: vscode.TextDocument, ): vscode.ProviderResult { const payload = JSON.stringify({ file: doc.fileName, @@ -40,7 +40,7 @@ export async function registerExternalFormatter( }; const range = new vscode.Range( doc.lineAt(0).range.start, - doc.lineAt(doc.lineCount - 1).range.end + doc.lineAt(doc.lineCount - 1).range.end, ); return new Promise((accept, reject) => { const httpModule = url.protocol.startsWith("https") ? https : http; @@ -56,7 +56,7 @@ export async function registerExternalFormatter( accept([]); // no edits vscode.window.showErrorMessage( `Failed to format document with custom formatter: ${err}`, - "OK" + "OK", ); }); }); diff --git a/src/services/logger.ts b/src/services/logger.ts index 2d2456e..dc0c9c5 100644 --- a/src/services/logger.ts +++ b/src/services/logger.ts @@ -22,7 +22,7 @@ export class Logger { } Logger.channel?.appendLine( - `["${type}" - ${new Date().getHours()}:${new Date().getMinutes()}] ${message}` + `["${type}" - ${new Date().getHours()}:${new Date().getMinutes()}] ${message}`, ); } diff --git a/src/services/quickPick.ts b/src/services/quickPick.ts index d04ad0e..6a7b804 100644 --- a/src/services/quickPick.ts +++ b/src/services/quickPick.ts @@ -22,7 +22,7 @@ export async function quickPick(data: any) { picker.onDidHide(() => { resolve(picker.selectedItems); disposable.dispose(); - }) + }), ); for (const item of picker.items) { if (item.label === defaultLabel) { diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index e40a955..33b6235 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -6,12 +6,14 @@ import { EXTENSION_ID } from "../../extension"; import { makeRequest } from "./sendPostRequest"; suite("Extension Test Suite", () => { - suiteSetup(async () => { }); + suiteSetup(async () => {}); - suiteTeardown(async () => { }); + suiteTeardown(async () => {}); test("check can list extensions", async () => { - const extensionIds: string[] = (await makeRequest("custom.listInstalledExtensions")) as string[]; + const extensionIds: string[] = (await makeRequest( + "custom.listInstalledExtensions", + )) as string[]; assert(extensionIds.includes(EXTENSION_ID)); }).timeout(5000); @@ -19,12 +21,17 @@ suite("Extension Test Suite", () => { const workspaceFolders = (await makeRequest("custom.workspaceFolders")) as string[]; assert(workspaceFolders.length === 1); const ws = workspaceFolders[0] as any; - assert(ws.name === 'workspace1'); + assert(ws.name === "workspace1"); assert(ws.index === 0); assert(ws.uri.startsWith("file://")); assert(ws.uri.endsWith("/workspace1")); - const workspaceFile = await makeRequest("custom.workspaceFile", undefined, undefined, false) as any; + const workspaceFile = (await makeRequest( + "custom.workspaceFile", + undefined, + undefined, + false, + )) as any; assert(workspaceFile === null); // no workspace file }); @@ -32,5 +39,4 @@ suite("Extension Test Suite", () => { const commands: string[] = (await makeRequest("custom.getCommands")) as string[]; assert(commands.length > 100); }); - }); diff --git a/src/test/suite/sendPostRequest.ts b/src/test/suite/sendPostRequest.ts index 5392851..3922064 100644 --- a/src/test/suite/sendPostRequest.ts +++ b/src/test/suite/sendPostRequest.ts @@ -5,18 +5,18 @@ export async function makeRequest( command: string, args: any[] = [], port: number = 0, - urlEncoded = true + urlEncoded = true, ) { return new Promise((resolve, reject) => { const path = urlEncoded ? `/?command=${command}&args=${encodeURIComponent(JSON.stringify(args))}` - : '/'; + : "/"; const req = http.request( { method: "POST", hostname: "localhost", port: port || getListeningPort(), - path: path + path: path, }, (res) => { const chunks: any[] = []; @@ -25,7 +25,7 @@ export async function makeRequest( const resBody = Buffer.concat(chunks); resolve(JSON.parse(resBody.toString())); }); - } + }, ); req.on("error", reject); if (!urlEncoded) { diff --git a/webpack.config.js b/webpack.config.js index ec5c0a4..7cfe026 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,30 +1,30 @@ //@ts-check -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); /**@type {import('webpack').Configuration}*/ const config = { - target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/ - mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production') + target: "node", // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/ + mode: "none", // this leaves the source code as close as possible to the original (when packaging we set this to 'production') - entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ + entry: "./src/extension.ts", // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ output: { // the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/ - path: path.resolve(__dirname, 'out'), - filename: 'extension.js', - libraryTarget: 'commonjs2' + path: path.resolve(__dirname, "out"), + filename: "extension.js", + libraryTarget: "commonjs2", }, - devtool: 'nosources-source-map', + devtool: "nosources-source-map", externals: { - bufferutil: 'bufferutil', - 'utf-8-validate': 'commonjs utf-8-validate', - vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/ + bufferutil: "bufferutil", + "utf-8-validate": "commonjs utf-8-validate", + vscode: "commonjs vscode", // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/ }, resolve: { // support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader - extensions: ['.ts', '.js'] + extensions: [".ts", ".js"], }, module: { rules: [ @@ -33,11 +33,11 @@ const config = { exclude: /node_modules/, use: [ { - loader: 'ts-loader' - } - ] - } - ] - } + loader: "ts-loader", + }, + ], + }, + ], + }, }; -module.exports = config; \ No newline at end of file +module.exports = config;