From 633503f796b3200c97b4310a2c7cc9444025657f Mon Sep 17 00:00:00 2001 From: Vincent Cheung Date: Wed, 13 Nov 2024 12:49:01 -0800 Subject: [PATCH] Remove unused code --- src/shellEscape.ts | 34 ----------------- src/stripeTerminal.ts | 31 --------------- test/suite/shellEscape.test.ts | 70 ---------------------------------- 3 files changed, 135 deletions(-) delete mode 100644 src/shellEscape.ts delete mode 100644 test/suite/shellEscape.test.ts diff --git a/src/shellEscape.ts b/src/shellEscape.ts deleted file mode 100644 index 1a4d0ba3..00000000 --- a/src/shellEscape.ts +++ /dev/null @@ -1,34 +0,0 @@ -import {OSType, getOSType} from './utils'; - -export function shellEscape(args: Array): string { - var output: Array = []; - - if (getOSType() === OSType.windows) { - args.forEach(function (arg) { - // Check if the argument is a file path - const isFilePath = /^([a-zA-Z]:)?(\\[^<>:"/\\|?*]+)+\.exe$/.test(arg); - - if (!isFilePath && /[^A-Za-z0-9_\/:=-]/.test(arg)) { - arg = arg.replace(/\\/g, '\\\\'); - arg = '"' + arg.replace(/"/g, '\\"') + '"'; - arg = arg - .replace(/^(?:"")+/g, '') // unduplicate double-quote at the beginning - .replace(/\\"""/g, '\\"'); // remove non-escaped double-quote if there are enclosed between 2 escaped - } - output.push(arg); - }); - return output.join(' '); - } else { - args.forEach(function (arg) { - if (/[^A-Za-z0-9_\/:=-]/.test(arg)) { - arg = arg.replace(/\\/g, '\\\\'); - arg = "'" + arg.replace(/'/g, "'\\''") + "'"; - arg = arg - .replace(/^(?:'')+/g, '') // unduplicate single-quote at the beginning - .replace(/\\'''/g, "\\'"); // remove non-escaped single-quote if there are enclosed between 2 escaped - } - output.push(arg); - }); - return output.join(' '); - } -} diff --git a/src/stripeTerminal.ts b/src/stripeTerminal.ts index f02a42f1..e78916f3 100644 --- a/src/stripeTerminal.ts +++ b/src/stripeTerminal.ts @@ -50,37 +50,6 @@ export class StripeTerminal { )); } - private async createNewSplitTerminal(): Promise { - const lastTerminal = this.terminals[this.terminals.length - 1]; - lastTerminal.show(); - - // Note that this splits off of the user's currently visible terminal. That's why `.show()` is - // called above. - await vscode.commands.executeCommand('workbench.action.terminal.split'); - - // After `workbench.action.terminal.split`, the activeTerminal becomes the newly split terminal. - // Note that there is no API guarantee for this behavior; a prior implementation relied on - // different behavior entirely. Because historically this behavior has been in flux, we should - // move to an official API for creating split terminals once that lands in vscode. - return vscode.window.activeTerminal; - } - - private async createTerminal(): Promise { - if (this.terminals.length > 0) { - const terminal = await this.createNewSplitTerminal(); - if (!terminal) { - throw new Error('Failed to create a terminal for this Stripe command. Please try again.'); - } - - this.terminals.push(terminal); - return terminal; - } - - const terminal = vscode.window.createTerminal('Stripe'); - this.terminals.push(terminal); - return terminal; - } - // The Stripe CLI supports a number of flags for every command. See https://stripe.com/docs/cli/flags private getGlobalCLIFlags(): Array { const stripeConfig = vscode.workspace.getConfiguration('stripe'); diff --git a/test/suite/shellEscape.test.ts b/test/suite/shellEscape.test.ts deleted file mode 100644 index a4d565ba..00000000 --- a/test/suite/shellEscape.test.ts +++ /dev/null @@ -1,70 +0,0 @@ -/* eslint-disable quotes */ -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import * as utils from '../../src/utils'; -import {shellEscape} from '../../src/shellEscape'; - -suite('shellEscape', () => { - let sandbox: sinon.SinonSandbox; - - setup(() => { - sandbox = sinon.createSandbox(); - }); - - teardown(() => { - sandbox.restore(); - }); - - suite('shellEscape', () => { - test('non windows case: flag with spaces', () => { - sandbox.stub(utils, 'getOSType').returns(utils.OSType.macOSarm); - const output = shellEscape(['--project-name', 'test | whoami']); // test | whoami - assert.strictEqual(output, `--project-name 'test | whoami'`); // --project-name 'test | whoami' - }); - test('non windows case: flag with single quote around entire arg', () => { - sandbox.stub(utils, 'getOSType').returns(utils.OSType.macOSarm); - const output = shellEscape(['--project-name', `'test name'`]); // 'test name' - assert.strictEqual(output, `--project-name \\''test name'\\'`); // --project-name \''test name'\' - }); - test('non windows case: flag with double quote', () => { - sandbox.stub(utils, 'getOSType').returns(utils.OSType.macOSarm); - const output = shellEscape(['--project-name', `test "name"`]); // test "name" - assert.strictEqual(output, `--project-name 'test "name"'`); // --project-name 'test "name"' - }); - test('non windows case: flag with lots of quotes', () => { - sandbox.stub(utils, 'getOSType').returns(utils.OSType.macOSarm); - const output = shellEscape(['--project-name', `'test's "name"'`]); // 'test's "name"' - assert.strictEqual(output, `--project-name \\''test'\\''s "name"'\\'`); // --project-name \''test'\''s "name"'\' - }); - test('non windows case: flag with backspace character', () => { - sandbox.stub(utils, 'getOSType').returns(utils.OSType.macOSarm); - const output = shellEscape(['--project-name', `\\bte\\bst | whoami`]); - assert.strictEqual(output, `--project-name '\\\\bte\\\\bst | whoami'`); - }); - test('windows case: flag with space', () => { - sandbox.stub(utils, 'getOSType').returns(utils.OSType.windows); - const output = shellEscape(['--project-name', 'test | whoami']); // test | whoami - assert.strictEqual(output, `--project-name "test | whoami"`); // --project-name "test | whoami" - }); - test('windows case: flag with single quote around entire arg', () => { - sandbox.stub(utils, 'getOSType').returns(utils.OSType.windows); - const output = shellEscape(['--project-name', `'test name'`]); // 'test name' - assert.strictEqual(output, `--project-name "'test name'"`); // --project-name "'test name'" - }); - test('windows case: flag with double quote', () => { - sandbox.stub(utils, 'getOSType').returns(utils.OSType.windows); - const output = shellEscape(['--project-name', `test "name"`]); // test "name" - assert.strictEqual(output, `--project-name "test \\"name\\""`); // --project-name "test \"name\"" - }); - test('windows case: flag with lots of quotes', () => { - sandbox.stub(utils, 'getOSType').returns(utils.OSType.windows); - const output = shellEscape(['--project-name', `'test's "name"'`]); // 'test's "name"' - assert.strictEqual(output, `--project-name "'test's \\"name\\"'"`); // --project-name "'test's \"name\"'" - }); - test('windows case: flag with backspace character', () => { - sandbox.stub(utils, 'getOSType').returns(utils.OSType.windows); - const output = shellEscape(['--project-name', `\\bte\\bst | whoami`]); - assert.strictEqual(output, `--project-name "\\\\bte\\\\bst | whoami"`); - }); - }); -});