Skip to content

Commit b13849d

Browse files
authored
refactor: remove dead code (#5188)
* refactor: delete unused code * refactor: move onLine to test helpers * Revert "refactor: move onLine to test helpers" This reverts commit 32cc27b. * fixup! refactor: delete unused code
1 parent 7a8d487 commit b13849d

File tree

7 files changed

+1
-149
lines changed

7 files changed

+1
-149
lines changed

src/common/util.ts

-30
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/**
2-
* Split a string up to the delimiter. If the delimiter doesn't exist the first
3-
* item will have all the text and the second item will be an empty string.
4-
*/
5-
export const split = (str: string, delimiter: string): [string, string] => {
6-
const index = str.indexOf(delimiter)
7-
return index !== -1 ? [str.substring(0, index).trim(), str.substring(index + 1)] : [str, ""]
8-
}
9-
101
/**
112
* Appends an 's' to the provided string if count is greater than one;
123
* otherwise the string is returned
@@ -34,27 +25,6 @@ export const normalize = (url: string, keepTrailing = false): string => {
3425
return url.replace(/\/\/+/g, "/").replace(/\/+$/, keepTrailing ? "/" : "")
3526
}
3627

37-
/**
38-
* Remove leading and trailing slashes.
39-
*/
40-
export const trimSlashes = (url: string): string => {
41-
return url.replace(/^\/+|\/+$/g, "")
42-
}
43-
44-
/**
45-
* Wrap the value in an array if it's not already an array. If the value is
46-
* undefined return an empty array.
47-
*/
48-
export const arrayify = <T>(value?: T | T[]): T[] => {
49-
if (Array.isArray(value)) {
50-
return value
51-
}
52-
if (typeof value === "undefined") {
53-
return []
54-
}
55-
return [value]
56-
}
57-
5828
// TODO: Might make sense to add Error handling to the logger itself.
5929
export function logError(logger: { error: (msg: string) => void }, prefix: string, err: unknown): void {
6030
if (err instanceof Error) {

src/node/app.ts

-23
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,6 @@ export const ensureAddress = (server: http.Server, protocol: string): URL | stri
102102
return addr
103103
}
104104

105-
/**
106-
* Handles error events from the server.
107-
*
108-
* If the outlying Promise didn't resolve
109-
* then we reject with the error.
110-
*
111-
* Otherwise, we log the error.
112-
*
113-
* We extracted into a function so that we could
114-
* test this logic more easily.
115-
*/
116-
export const handleServerError = (resolved: boolean, err: Error, reject: (err: Error) => void) => {
117-
// Promise didn't resolve earlier so this means it's an error
118-
// that occurs before the server can successfully listen.
119-
// Possibly triggered by listening on an invalid port or socket.
120-
if (!resolved) {
121-
reject(err)
122-
} else {
123-
// Promise resolved earlier so this is an unrelated error.
124-
util.logError(logger, "http server error", err)
125-
}
126-
}
127-
128105
/**
129106
* Handles the error that occurs in the catch block
130107
* after we try fs.unlink(args.socket).

src/node/constants.ts

-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import type { JSONSchemaForNPMPackageJsonFiles } from "@schemastore/package"
33
import * as os from "os"
44
import * as path from "path"
55

6-
export const WORKBENCH_WEB_CONFIG_ID = "vscode-workbench-web-configuration"
7-
86
export function getPackageJson(relativePath: string): JSONSchemaForNPMPackageJsonFiles {
97
let pkg = {}
108
try {
@@ -21,7 +19,6 @@ export const vsRootPath = path.join(rootPath, "lib/vscode")
2119
const PACKAGE_JSON = "package.json"
2220
const pkg = getPackageJson(`${rootPath}/${PACKAGE_JSON}`)
2321
const codePkg = getPackageJson(`${vsRootPath}/${PACKAGE_JSON}`) || { version: "0.0.0" }
24-
export const pkgName = pkg.name || "code-server"
2522
export const version = pkg.version || "development"
2623
export const commit = pkg.commit || "development"
2724
export const codeVersion = codePkg.version || "development"

src/node/util.ts

-9
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,6 @@ export const enumToArray = (t: any): string[] => {
426426
return values
427427
}
428428

429-
/**
430-
* For displaying all allowed options in an enum.
431-
*/
432-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
433-
export const buildAllowedMessage = (t: any): string => {
434-
const values = enumToArray(t)
435-
return `Allowed value${values.length === 1 ? " is" : "s are"} ${values.map((t) => `'${t}'`).join(", ")}`
436-
}
437-
438429
/**
439430
* Return a promise that resolves with whether the socket path is active.
440431
*/

test/unit/common/util.test.ts

-47
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ describe("util", () => {
2424
})
2525
})
2626

27-
describe("split", () => {
28-
it("should split at a comma", () => {
29-
expect(util.split("Hello,world", ",")).toStrictEqual(["Hello", "world"])
30-
})
31-
32-
it("shouldn't split if the delimiter doesn't exist", () => {
33-
expect(util.split("Hello world", ",")).toStrictEqual(["Hello world", ""])
34-
})
35-
})
36-
3727
describe("plural", () => {
3828
it("should add an s if count is greater than 1", () => {
3929
expect(util.plural(2, "dog")).toBe("dogs")
@@ -57,43 +47,6 @@ describe("util", () => {
5747
})
5848
})
5949

60-
describe("trimSlashes", () => {
61-
it("should remove leading slashes", () => {
62-
expect(util.trimSlashes("/hello-world")).toBe("hello-world")
63-
})
64-
65-
it("should remove trailing slashes", () => {
66-
expect(util.trimSlashes("hello-world/")).toBe("hello-world")
67-
})
68-
69-
it("should remove both leading and trailing slashes", () => {
70-
expect(util.trimSlashes("/hello-world/")).toBe("hello-world")
71-
})
72-
73-
it("should remove multiple leading and trailing slashes", () => {
74-
expect(util.trimSlashes("///hello-world////")).toBe("hello-world")
75-
})
76-
})
77-
78-
describe("arrayify", () => {
79-
it("should return value it's already an array", () => {
80-
expect(util.arrayify(["hello", "world"])).toStrictEqual(["hello", "world"])
81-
})
82-
83-
it("should wrap the value in an array if not an array", () => {
84-
expect(
85-
util.arrayify({
86-
name: "Coder",
87-
version: "3.8",
88-
}),
89-
).toStrictEqual([{ name: "Coder", version: "3.8" }])
90-
})
91-
92-
it("should return an empty array if the value is undefined", () => {
93-
expect(util.arrayify(undefined)).toStrictEqual([])
94-
})
95-
})
96-
9750
describe("logError", () => {
9851
beforeAll(() => {
9952
mockLogger()

test/unit/node/app.test.ts

+1-33
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { promises } from "fs"
33
import * as http from "http"
44
import * as https from "https"
55
import * as path from "path"
6-
import { createApp, ensureAddress, handleArgsSocketCatchError, handleServerError, listen } from "../../../src/node/app"
6+
import { createApp, ensureAddress, handleArgsSocketCatchError, listen } from "../../../src/node/app"
77
import { OptionalString, setDefaults } from "../../../src/node/cli"
88
import { generateCertificate } from "../../../src/node/util"
99
import { clean, mockLogger, getAvailablePort, tmpdir } from "../../utils/helpers"
@@ -169,38 +169,6 @@ describe("ensureAddress", () => {
169169
})
170170
})
171171

172-
describe("handleServerError", () => {
173-
beforeAll(() => {
174-
mockLogger()
175-
})
176-
177-
afterEach(() => {
178-
jest.clearAllMocks()
179-
})
180-
181-
it("should call reject if resolved is false", async () => {
182-
const resolved = false
183-
const reject = jest.fn((err: Error) => undefined)
184-
const error = new Error("handleServerError Error")
185-
186-
handleServerError(resolved, error, reject)
187-
188-
expect(reject).toHaveBeenCalledTimes(1)
189-
expect(reject).toHaveBeenCalledWith(error)
190-
})
191-
192-
it("should log an error if resolved is true", async () => {
193-
const resolved = true
194-
const reject = jest.fn((err: Error) => undefined)
195-
const error = new Error("handleServerError Error")
196-
197-
handleServerError(resolved, error, reject)
198-
199-
expect(logger.error).toHaveBeenCalledTimes(1)
200-
expect(logger.error).toHaveBeenCalledWith(`http server error: ${error.message} ${error.stack}`)
201-
})
202-
})
203-
204172
describe("handleArgsSocketCatchError", () => {
205173
beforeAll(() => {
206174
mockLogger()

test/unit/node/constants.test.ts

-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ describe("constants", () => {
3434
jest.resetModules()
3535
})
3636

37-
it("should provide the package name", () => {
38-
expect(constants.pkgName).toBe(mockPackageJson.name)
39-
})
40-
4137
it("should provide the commit", () => {
4238
expect(constants.commit).toBe(mockPackageJson.commit)
4339
})

0 commit comments

Comments
 (0)