Skip to content

Commit 47a919f

Browse files
Merge pull request #4111 from github/robertbrignull/typescript-eslint/restrict-template-expressions
Enable the @typescript-eslint/restrict-template-expressions rule
2 parents 57899e9 + 25ba228 commit 47a919f

25 files changed

+70
-45
lines changed

extensions/ql-vscode/eslint.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export default tseslint.config(
6969

7070
// Rules disabled during eslint 9 migration
7171
"github/filenames-match-regex": "off",
72-
"@typescript-eslint/restrict-template-expressions": "off",
7372
"@typescript-eslint/no-unsafe-assignment": "off",
7473
"@typescript-eslint/no-unsafe-argument": "off",
7574
"@typescript-eslint/no-unsafe-member-access": "off",

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export class CodeQLCliServer implements Disposable {
314314
} catch (e) {
315315
// We are probably fine here, the process has already closed stdin.
316316
void this.logger.log(
317-
`Shutdown request failed: process stdin may have already closed. The error was ${e}`,
317+
`Shutdown request failed: process stdin may have already closed. The error was ${getErrorMessage(e)}`,
318318
);
319319
void this.logger.log("Stopping the process anyway.");
320320
}
@@ -748,7 +748,7 @@ export class CodeQLCliServer implements Disposable {
748748
} else {
749749
reject(
750750
new Error(
751-
`${command} ${commandArgs.join(" ")} failed with code ${code}`,
751+
`${command.join(" ")} ${commandArgs.join(" ")} failed with code ${code}`,
752752
),
753753
);
754754
}

extensions/ql-vscode/src/codeql-cli/distribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ class ExtensionSpecificDistributionManager {
385385
} catch (e) {
386386
void extLogger.log(
387387
"WARNING: Tried to remove corrupted CodeQL CLI at " +
388-
`${this.getDistributionStoragePath()} but encountered an error: ${e}.`,
388+
`${this.getDistributionStoragePath()} but encountered an error: ${getErrorMessage(e)}.`,
389389
);
390390
}
391391
}
@@ -457,7 +457,7 @@ class ExtensionSpecificDistributionManager {
457457
} catch (e) {
458458
void extLogger.log(
459459
`Tried to clean up old version of CLI at ${this.getDistributionStoragePath()} ` +
460-
`but encountered an error: ${e}.`,
460+
`but encountered an error: ${getErrorMessage(e)}.`,
461461
);
462462
}
463463

extensions/ql-vscode/src/codeql-cli/query-language.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export async function askForLanguage(
8989
if (!isQueryLanguage(language)) {
9090
void showAndLogErrorMessage(
9191
extLogger,
92-
`Language '${language}' is not supported. Only languages ${Object.values(
92+
`Language '${language as string}' is not supported. Only languages ${Object.values(
9393
QueryLanguage,
9494
).join(", ")} are supported.`,
9595
);

extensions/ql-vscode/src/codeql-cli/query-metadata.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { CodeQLCliServer } from "./cli";
22
import type { QueryMetadata } from "../common/interface-types";
33
import { extLogger } from "../common/logging/vscode";
4+
import { getErrorMessage } from "../common/helpers-pure";
45

56
/**
67
* Gets metadata for a query, if it exists.
@@ -16,7 +17,9 @@ export async function tryGetQueryMetadata(
1617
return await cliServer.resolveMetadata(queryPath);
1718
} catch (e) {
1819
// Ignore errors and provide no metadata.
19-
void extLogger.log(`Couldn't resolve metadata for ${queryPath}: ${e}`);
20+
void extLogger.log(
21+
`Couldn't resolve metadata for ${queryPath}: ${getErrorMessage(e)}`,
22+
);
2023
return;
2124
}
2225
}

extensions/ql-vscode/src/common/short-paths.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ async function expandShortPathComponent(
9292
}
9393
} catch (e) {
9494
// Can't read stats for the child, so skip it.
95-
void logger.log(`Error reading stats for child: ${e}`);
95+
void logger.log(`Error reading stats for child: ${getErrorMessage(e)}`);
9696
}
9797
}
9898
} catch (e) {
9999
// Can't read the directory, so we won't be able to find this in the directory listing.
100-
void logger.log(`Error reading directory: ${e}`);
100+
void logger.log(`Error reading directory: ${getErrorMessage(e)}`);
101101
return shortBase;
102102
}
103103

extensions/ql-vscode/src/common/vscode/archive-filesystem-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const sourceArchiveUriAuthorityPattern = /^(\d+)-(\d+)$/;
135135
class InvalidSourceArchiveUriError extends Error {
136136
constructor(uri: Uri) {
137137
super(
138-
`Can't decode uri ${uri}: authority should be of the form startIndex-endIndex (where both indices are integers).`,
138+
`Can't decode uri ${uri.toString()}: authority should be of the form startIndex-endIndex (where both indices are integers).`,
139139
);
140140
}
141141
}

extensions/ql-vscode/src/common/vscode/webview-html.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function getHtmlForWebview(
8989
<body>
9090
<div id=root data-view="${view}">
9191
</div>
92-
<script nonce="${nonce}" src="${scriptWebviewUri}">
92+
<script nonce="${nonce}" src="${scriptWebviewUri.toString()}">
9393
</script>
9494
</body>
9595
</html>`;
@@ -101,9 +101,9 @@ function getNonce(): string {
101101
}
102102

103103
function createStylesLinkWithNonce(nonce: string, uri: Uri): string {
104-
return `<link nonce="${nonce}" rel="stylesheet" href="${uri}">`;
104+
return `<link nonce="${nonce}" rel="stylesheet" href="${uri.toString()}">`;
105105
}
106106

107107
function createStylesLinkWithoutNonce(uri: Uri): string {
108-
return `<link rel="stylesheet" href="${uri}">`;
108+
return `<link rel="stylesheet" href="${uri.toString()}">`;
109109
}

extensions/ql-vscode/src/databases/local-databases-ui.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ export class DatabaseUI extends DisposableObject {
380380
// This specifically refers to the database folder in
381381
// https://github.com/github/codespaces-codeql
382382
const uri = Uri.parse(
383-
`${workspace.workspaceFolders[0].uri}/.tours/codeql-tutorial-database`,
383+
`${workspace.workspaceFolders[0].uri.toString()}/.tours/codeql-tutorial-database`,
384384
);
385385

386386
const databaseItem = this.databaseManager.findDatabaseItem(uri);
@@ -1062,14 +1062,14 @@ export class DatabaseUI extends DisposableObject {
10621062

10631063
if (!validFileTypes.includes(entry[1])) {
10641064
void this.app.logger.log(
1065-
`Skipping import for '${entry}', invalid file type: ${entry[1]}`,
1065+
`Skipping import for '${entry[0]}', invalid file type: ${entry[1]}`,
10661066
);
10671067
continue;
10681068
}
10691069

10701070
try {
10711071
const databaseUri = Uri.joinPath(uri, entry[0]);
1072-
void this.app.logger.log(`Importing from ${databaseUri}`);
1072+
void this.app.logger.log(`Importing from ${databaseUri.toString()}`);
10731073

10741074
const database = await this.importDatabase(
10751075
databaseUri,

extensions/ql-vscode/src/databases/local-databases/database-manager.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ const DB_LIST = "databaseList";
6464
*/
6565
function eventFired<T>(
6666
event: vscode.Event<T>,
67+
eventName: string,
6768
timeoutMs = 1000,
6869
): Promise<T | undefined> {
6970
return new Promise((res, _rej) => {
7071
const timeout = setTimeout(() => {
7172
void extLogger.log(
72-
`Waiting for event ${event} timed out after ${timeoutMs}ms`,
73+
`Waiting for event '${eventName}' timed out after ${timeoutMs}ms`,
7374
);
7475
res(undefined);
7576
dispose();
@@ -256,7 +257,7 @@ export class DatabaseManager extends DisposableObject {
256257
private async reimportTestDatabase(databaseUri: vscode.Uri): Promise<void> {
257258
const dbItem = this.findDatabaseItem(databaseUri);
258259
if (dbItem === undefined || dbItem.origin?.type !== "testproj") {
259-
throw new Error(`Database ${databaseUri} is not a testproj.`);
260+
throw new Error(`Database ${databaseUri.toString()} is not a testproj.`);
260261
}
261262

262263
await this.removeDatabaseItem(dbItem);
@@ -474,7 +475,10 @@ export class DatabaseManager extends DisposableObject {
474475
});
475476
// vscode api documentation says we must to wait for this event
476477
// between multiple `updateWorkspaceFolders` calls.
477-
await eventFired(vscode.workspace.onDidChangeWorkspaceFolders);
478+
await eventFired(
479+
vscode.workspace.onDidChangeWorkspaceFolders,
480+
"vscode.workspace.onDidChangeWorkspaceFolders",
481+
);
478482
}
479483
}
480484

@@ -561,7 +565,7 @@ export class DatabaseManager extends DisposableObject {
561565
// When loading from persisted state, leave invalid databases in the list. They will be
562566
// marked as invalid, and cannot be set as the current database.
563567
void this.logger.log(
564-
`Error loading database ${database.uri}: ${e}.`,
568+
`Error loading database ${database.uri}: ${getErrorMessage(e)}.`,
565569
);
566570
}
567571
}

0 commit comments

Comments
 (0)