Skip to content

Commit c6d7a8a

Browse files
committed
tslint fixes
1 parent 04e0897 commit c6d7a8a

File tree

7 files changed

+161
-147
lines changed

7 files changed

+161
-147
lines changed

src/api/pickServer.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
1-
import * as vscode from 'vscode';
2-
import { addServer } from './addServer';
3-
import { getServerNames } from './getServerNames';
1+
import * as vscode from "vscode";
2+
import { addServer } from "./addServer";
3+
import { getServerNames } from "./getServerNames";
44

5-
export async function pickServer(scope?: vscode.ConfigurationScope, options: vscode.QuickPickOptions = {}): Promise<string | undefined> {
5+
export async function pickServer(
6+
scope?: vscode.ConfigurationScope,
7+
options: vscode.QuickPickOptions = {},
8+
): Promise<string | undefined> {
69
const names = getServerNames(scope);
710

8-
let qpItems: vscode.QuickPickItem[] = [];
11+
const qpItems: vscode.QuickPickItem[] = [];
912

1013
options.matchOnDescription = options?.matchOnDescription || true;
11-
options.placeHolder = options?.placeHolder || 'Pick an InterSystems server';
14+
options.placeHolder = options?.placeHolder || "Pick an InterSystems server";
1215
options.canPickMany = false;
1316

14-
names.forEach(element => {
15-
qpItems.push({label: element.name, description: element.description, detail: options?.matchOnDetail ? element.detail : undefined});
17+
names.forEach((element) => {
18+
qpItems.push({
19+
description: element.description,
20+
detail: options?.matchOnDetail ? element.detail : undefined,
21+
label: element.name,
22+
});
1623
});
1724

1825
return await new Promise<string | undefined>((resolve, reject) => {
19-
var result:string
20-
var resolveOnHide = true;
26+
let result: string;
27+
let resolveOnHide = true;
2128
const quickPick = vscode.window.createQuickPick();
2229
quickPick.title = "Choose server or use '+' to add one" ;
2330
quickPick.placeholder = options.placeHolder;
2431
quickPick.matchOnDescription = options.matchOnDescription || true;
2532
quickPick.matchOnDetail = options.matchOnDetail || false;
2633
quickPick.ignoreFocusOut = options.ignoreFocusOut || false;
2734
quickPick.items = qpItems;
28-
const btnAdd: vscode.QuickInputButton = { iconPath: new vscode.ThemeIcon('add'), tooltip: 'Define New Server' }
35+
const btnAdd: vscode.QuickInputButton = { iconPath: new vscode.ThemeIcon("add"), tooltip: "Define New Server" };
2936
quickPick.buttons = [btnAdd];
3037

3138
async function addAndResolve() {
@@ -46,11 +53,11 @@ export async function pickServer(scope?: vscode.ConfigurationScope, options: vsc
4653
result = items[0].label;
4754
});
4855

49-
quickPick.onDidChangeValue(value => {
50-
if (value === '+') {
56+
quickPick.onDidChangeValue((value) => {
57+
if (value === "+") {
5158
addAndResolve();
5259
}
53-
})
60+
});
5461

5562
quickPick.onDidTriggerButton((button) => {
5663
if (button === btnAdd) {
@@ -71,7 +78,7 @@ export async function pickServer(scope?: vscode.ConfigurationScope, options: vsc
7178
}
7279
quickPick.dispose();
7380
});
74-
81+
7582
quickPick.show();
7683
});
77-
}
84+
}

src/commands/importFromRegistry.ts

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ export async function importFromRegistry(scope?: vscode.ConfigurationScope) {
1616
regQueryCache.clear();
1717

1818
return vscode.window.withProgress({
19-
"location": vscode.ProgressLocation.Notification,
20-
"cancellable": true
19+
cancellable: true,
20+
location: vscode.ProgressLocation.Notification,
2121
}, async (progress, cancellationToken) => {
2222
progress.report({message: "Loading server definitions from Windows registry..."});
2323
cancellationToken.onCancellationRequested(() => {
2424
vscode.window.showInformationMessage("Cancelled server import.");
2525
});
2626

2727
// This forces the progress bar to actually show before the possibly long-running load of registry data
28-
await new Promise(resolve => setTimeout(resolve,0));
28+
await new Promise((resolve) => setTimeout(resolve, 0));
2929

3030
overwriteCount = await loadRegistryData(config, serverDefinitions, serversMissingUsernames, newServerNames);
3131

@@ -37,9 +37,9 @@ export async function importFromRegistry(scope?: vscode.ConfigurationScope) {
3737
if (!keepGoing) {
3838
return;
3939
}
40-
40+
4141
if (overwriteCount > 0) {
42-
if (await vscode.window.showWarningMessage(`${overwriteCount} existing definition${overwriteCount > 1 ? "s" : ""} will be overwritten. Continue?`, { modal: true }, "Yes") !=="Yes") {
42+
if (await vscode.window.showWarningMessage(`${overwriteCount} existing definition${overwriteCount > 1 ? "s" : ""} will be overwritten. Continue?`, { modal: true }, "Yes") !== "Yes") {
4343
vscode.window.showInformationMessage("Cancelled server import.");
4444
return;
4545
}
@@ -62,7 +62,12 @@ export async function importFromRegistry(scope?: vscode.ConfigurationScope) {
6262
});
6363
}
6464

65-
async function loadRegistryData(config: vscode.WorkspaceConfiguration, serverDefinitions, serversMissingUsernames: string[], newServerNames: string[]): Promise<number> {
65+
async function loadRegistryData(
66+
config: vscode.WorkspaceConfiguration,
67+
serverDefinitions,
68+
serversMissingUsernames: string[],
69+
newServerNames: string[],
70+
): Promise<number> {
6671
const cmd = require("node-cmd");
6772
const subFolder = "\\Intersystems\\Cache\\Servers";
6873
const fullPaths: string[] = [];
@@ -85,14 +90,14 @@ async function loadRegistryData(config: vscode.WorkspaceConfiguration, serverDef
8590
return;
8691
}
8792
// For WOW6432Node, skip the line for the subfolder itself
88-
if ((serverName.split(subFolder).pop()?? "").length === 0) {
93+
if ((serverName.split(subFolder).pop() ?? "").length === 0) {
8994
return;
9095
}
9196

9297
// remove HKEY_LOCAL_MACHINE\ and whitespace from the server name
9398
const path = serverName.substring(hive.length + 1).trim();
9499

95-
const originalName: string = (serverName.split("\\").pop()?? "").trim();
100+
const originalName: string = (serverName.split("\\").pop() ?? "").trim();
96101
// Enforce the rules from package.json on the server name
97102
const name = originalName.toLowerCase().replace(/[^a-z0-9-_~]/g, "~");
98103
if (name === "") {
@@ -126,13 +131,12 @@ async function loadRegistryData(config: vscode.WorkspaceConfiguration, serverDef
126131
username,
127132
webServer: {
128133
host: getProperty("WebServerAddress") || getProperty("Address"),
129-
pathPrefix: instanceName ? '/' + instanceName : undefined,
134+
pathPrefix: instanceName ? "/" + instanceName : undefined,
130135
port: parseInt(getProperty("WebServerPort") || "", 10),
131136
scheme: usesHttps ? "https" : "http",
132137
},
133-
}
134-
}
135-
else if (!name.startsWith("/")) {
138+
};
139+
} else if (!name.startsWith("/")) {
136140
if (!existingUserNames.includes(name)) {
137141
existingUserNames.push(name);
138142
overwriteCount++;
@@ -145,7 +149,7 @@ async function loadRegistryData(config: vscode.WorkspaceConfiguration, serverDef
145149

146150
async function promptForUsernames(serverDefinitions: any, serversMissingUsernames: string[]): Promise<boolean> {
147151
if (serversMissingUsernames.length) {
148-
let serverName = serversMissingUsernames.splice(0,1)[0];
152+
let serverName = serversMissingUsernames.splice(0, 1)[0];
149153
let username = await vscode.window.showInputBox({
150154
ignoreFocusOut: true,
151155
placeHolder: "Enter a username. Leave empty to be prompted at connect time.",
@@ -155,7 +159,7 @@ async function promptForUsernames(serverDefinitions: any, serversMissingUsername
155159
// Was cancelled
156160
return false;
157161
}
158-
if (username === '') {
162+
if (username === "") {
159163
// If unspecified, actually set to undefined to leave it empty in serverDefinitions
160164
username = undefined;
161165
}
@@ -171,7 +175,7 @@ async function promptForUsernames(serverDefinitions: any, serversMissingUsername
171175
const result = await vscode.window.showQuickPick(items, {
172176
canPickMany: false,
173177
ignoreFocusOut: true,
174-
placeHolder: `${serversMissingUsernames.length} more servers lack a username. What do you want to do?`
178+
placeHolder: `${serversMissingUsernames.length} more servers lack a username. What do you want to do?`,
175179
});
176180
if (result === undefined || result.label === items[2].label) {
177181
return false;
@@ -202,10 +206,10 @@ async function promptForUsernames(serverDefinitions: any, serversMissingUsername
202206

203207
async function promptForPasswords(serverDefinitions: any, newServerNames: string[]): Promise<void> {
204208
let reusePassword;
205-
let password : string | undefined = '';
209+
let password: string | undefined = "";
206210
const promptServerNames = new Array();
207211
// Only prompt for servers with a username specified, of course.
208-
newServerNames.forEach(name => {
212+
newServerNames.forEach((name) => {
209213
if (serverDefinitions[name].username !== undefined) {
210214
promptServerNames.push(name);
211215
}
@@ -217,20 +221,20 @@ async function promptForPasswords(serverDefinitions: any, newServerNames: string
217221
password: true,
218222
placeHolder: "Enter password to store in keychain. Leave empty to be prompted at connect time.",
219223
prompt: `Password for connection to InterSystems server '${serverName}'
220-
as ${serverDefinitions[serverName].username}`
224+
as ${serverDefinitions[serverName].username}`,
221225
});
222226

223227
if (password === undefined) {
224228
return;
225229
}
226230

227-
if (password === '') {
231+
if (password === "") {
228232
password = undefined;
229233
}
230234
}
231235

232236
if ((reusePassword === undefined) && (promptServerNames.length > 1)) {
233-
const placeHolder = (password === undefined) ? `Enter password later for remaining ${promptServerNames.length - 1} server(s)?` : `Store the same password for remaining ${promptServerNames.length - 1} server(s)?`
237+
const placeHolder = (password === undefined) ? `Enter password later for remaining ${promptServerNames.length - 1} server(s)?` : `Store the same password for remaining ${promptServerNames.length - 1} server(s)?`;
234238
const items = [
235239
`No`,
236240
`Yes`,
@@ -240,7 +244,7 @@ async function promptForPasswords(serverDefinitions: any, newServerNames: string
240244
const result = await vscode.window.showQuickPick(items, {
241245
canPickMany: false,
242246
ignoreFocusOut: true,
243-
placeHolder
247+
placeHolder,
244248
});
245249
if (result === undefined || result.label === items[2].label) {
246250
return;
@@ -261,10 +265,10 @@ function preloadRegistryCache(cmd, fullPath) {
261265
if (!regData.data) {
262266
return;
263267
}
264-
regData.data.split("\r\n\r\n").forEach(pathResult => {
268+
regData.data.split("\r\n\r\n").forEach((pathResult) => {
265269
// Equivalent of running "reg query " + queryPath
266270
const lines = pathResult.split("\r\n");
267-
const queryPath = lines.splice(0,1)[0];
271+
const queryPath = lines.splice(0, 1)[0];
268272
const queryResult = lines.join("\r\n");
269273
regQueryCache.set(queryPath, { data: queryResult });
270274
});
@@ -279,14 +283,14 @@ function getStringRegKey(cmd, hive, path, key): string | undefined {
279283
regQueryCache.set(queryPath, regData);
280284
const results = regData.data.split("\r\n")
281285
// Result lines from reg query are 4-space-delimited
282-
.map(line => line.split(' '))
286+
.map((line) => line.split(" "))
283287
// Registry has format [<empty>, key, type, value]
284-
.filter(line => line.length === 4)
288+
.filter((line) => line.length === 4)
285289
// We're only interested in the specified key
286-
.filter(line => line[1] === key)
290+
.filter((line) => line[1] === key)
287291
// We want the value...
288-
.map(line => line[3])
292+
.map((line) => line[3])
289293
// ... and we'll treat empty strings as undefined
290-
.filter(result => result != '');
294+
.filter((result) => result !== "");
291295
return results[0];
292296
}

src/commands/managePasswords.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import * as vscode from 'vscode';
2-
import { extensionId } from '../extension';
3-
import { Keychain } from '../keychain';
4-
import { credentialCache } from '../api/getServerSpec';
5-
import { getServerNames } from '../api/getServerNames';
6-
import { ServerTreeItem } from '../ui/serverManagerView';
1+
import * as vscode from "vscode";
2+
import { getServerNames } from "../api/getServerNames";
3+
import { credentialCache } from "../api/getServerSpec";
4+
import { extensionId } from "../extension";
5+
import { Keychain } from "../keychain";
6+
import { ServerTreeItem } from "../ui/serverManagerView";
77

88
export async function storePassword(treeItem?: ServerTreeItem): Promise<string> {
99
if (treeItem && !getServerNames().some((value) => value.name === treeItem?.label)) {
1010
treeItem = undefined;
1111
}
1212
const name = treeItem?.name || await commonPickServer({matchOnDetail: true});
13-
let reply = '';
13+
let reply = "";
1414
if (name) {
1515
await vscode.window
1616
.showInputBox({
17+
ignoreFocusOut: true,
1718
password: true,
18-
placeHolder: 'Password to store in keychain',
19+
placeHolder: "Password to store in keychain",
1920
prompt: `For connection to InterSystems server '${name}'`,
20-
validateInput: (value => {
21-
return value.length > 0 ? '' : 'Mandatory field';
21+
validateInput: ((value) => {
22+
return value.length > 0 ? "" : "Mandatory field";
2223
}),
23-
ignoreFocusOut: true,
2424
})
2525
.then((password) => {
2626
if (password) {
@@ -29,7 +29,7 @@ export async function storePassword(treeItem?: ServerTreeItem): Promise<string>
2929
});
3030
reply = name;
3131
}
32-
})
32+
});
3333
}
3434
return reply;
3535
}
@@ -43,13 +43,13 @@ export async function clearPassword(treeItem?: ServerTreeItem): Promise<string>
4343
if (treeItem && !getServerNames().some((value) => value.name === treeItem?.label)) {
4444
treeItem = undefined;
4545
}
46-
let reply = '';
46+
let reply = "";
4747
const name = treeItem?.name || await commonPickServer({matchOnDetail: true});
4848
if (name) {
4949
credentialCache[name] = undefined;
5050
const keychain = new Keychain(name);
5151
if (!await keychain.getPassword()) {
52-
vscode.window.showWarningMessage(`No password for '${name}' found in keychain.`);
52+
vscode.window.showWarningMessage(`No password for '${name}' found in keychain.`);
5353
} else if (await keychain.deletePassword()) {
5454
vscode.window.showInformationMessage(`Password for '${name}' removed from keychain.`);
5555
reply = name;
@@ -64,7 +64,7 @@ async function commonPickServer(options?: vscode.QuickPickOptions): Promise<stri
6464
// Deliberately uses its own API to illustrate how other extensions would
6565
const serverManagerExtension = vscode.extensions.getExtension(extensionId);
6666
if (!serverManagerExtension) {
67-
vscode.window.showErrorMessage(`Extension '${extensionId}' is not installed, or has been disabled.`)
67+
vscode.window.showErrorMessage(`Extension '${extensionId}' is not installed, or has been disabled.`);
6868
return;
6969
}
7070
if (!serverManagerExtension.isActive) {
@@ -73,4 +73,4 @@ async function commonPickServer(options?: vscode.QuickPickOptions): Promise<stri
7373
const myApi = serverManagerExtension.exports;
7474

7575
return await myApi.pickServer(undefined, options);
76-
}
76+
}

0 commit comments

Comments
 (0)