Skip to content

Commit fe61628

Browse files
committed
Clean up
1 parent f2538ed commit fe61628

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

src/headers.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function getHeaderCommand(
2424
config.get<string>("coder.headerCommand")?.trim() ||
2525
process.env.CODER_HEADER_COMMAND?.trim();
2626

27-
return cmd ? cmd : undefined;
27+
return cmd || undefined;
2828
}
2929

3030
export function getHeaderArgs(config: WorkspaceConfiguration): string[] {
@@ -44,16 +44,13 @@ export function getHeaderArgs(config: WorkspaceConfiguration): string[] {
4444
return ["--header-command", escapeSubcommand(command)];
4545
}
4646

47-
// TODO: getHeaders might make more sense to directly implement on Storage
48-
// but it is difficult to test Storage right now since we use vitest instead of
49-
// the standard extension testing framework which would give us access to vscode
50-
// APIs. We should revert the testing framework then consider moving this.
51-
52-
// getHeaders executes the header command and parses the headers from stdout.
53-
// Both stdout and stderr are logged on error but stderr is otherwise ignored.
54-
// Throws an error if the process exits with non-zero or the JSON is invalid.
55-
// Returns undefined if there is no header command set. No effort is made to
56-
// validate the JSON other than making sure it can be parsed.
47+
/**
48+
* getHeaders executes the header command and parses the headers from stdout.
49+
* Both stdout and stderr are logged on error but stderr is otherwise ignored.
50+
* Throws an error if the process exits with non-zero or the JSON is invalid.
51+
* Returns undefined if there is no header command set. No effort is made to
52+
* validate the JSON other than making sure it can be parsed.
53+
*/
5754
export async function getHeaders(
5855
url: string | undefined,
5956
command: string | undefined,
@@ -90,8 +87,8 @@ export async function getHeaders(
9087
return headers;
9188
}
9289
const lines = result.stdout.replace(/\r?\n$/, "").split(/\r?\n/);
93-
for (let i = 0; i < lines.length; ++i) {
94-
const [key, value] = lines[i].split(/=(.*)/);
90+
for (const line of lines) {
91+
const [key, value] = line.split(/=(.*)/);
9592
// Header names cannot be blank or contain whitespace and the Coder CLI
9693
// requires that there be an equals sign (the value can be blank though).
9794
if (
@@ -100,7 +97,7 @@ export async function getHeaders(
10097
typeof value === "undefined"
10198
) {
10299
throw new Error(
103-
`Malformed line from header command: [${lines[i]}] (out: ${result.stdout})`,
100+
`Malformed line from header command: [${line}] (out: ${result.stdout})`,
104101
);
105102
}
106103
headers[key] = value;

src/remote/remote.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ export class Remote {
135135
let attempts = 0;
136136

137137
function initWriteEmitterAndTerminal(): vscode.EventEmitter<string> {
138-
if (!writeEmitter) {
139-
writeEmitter = new vscode.EventEmitter<string>();
140-
}
138+
writeEmitter ??= new vscode.EventEmitter<string>();
141139
if (!terminal) {
142140
terminal = vscode.window.createTerminal({
143141
name: "Build Log",
@@ -295,16 +293,14 @@ export class Remote {
295293

296294
if (result.type === "login") {
297295
return this.setup(remoteAuthority, firstConnect);
296+
} else if (!result.userChoice) {
297+
// User declined to log in.
298+
await this.closeRemote();
299+
return;
298300
} else {
299-
if (!result.userChoice) {
300-
// User declined to log in.
301-
await this.closeRemote();
302-
return;
303-
} else {
304-
// Log in then try again.
305-
await this.commands.login({ url: baseUrlRaw, label: parts.label });
306-
return this.setup(remoteAuthority, firstConnect);
307-
}
301+
// Log in then try again.
302+
await this.commands.login({ url: baseUrlRaw, label: parts.label });
303+
return this.setup(remoteAuthority, firstConnect);
308304
}
309305
};
310306

0 commit comments

Comments
 (0)