Skip to content

Commit 5f8d5f2

Browse files
committed
Don't count files that are not example<number>.ql
When we try to determine the next file name for our example query, we only look at `example<n>.ql` files. e.g. if the files in the folder are: - `example.ql` - `example2.ql` - `MyQuery.ql` we will create an `example3.ql` file. Previously we were counting all existing `.ql` files.
1 parent 9cd9111 commit 5f8d5f2

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

extensions/ql-vscode/src/skeleton-query-wizard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class SkeletonQueryWizard {
185185
const folderUri = Uri.file(join(this.storagePath, folderName));
186186
const files = await workspace.fs.readDirectory(folderUri);
187187
const qlFiles = files.filter(([filename, _fileType]) =>
188-
filename.endsWith(".ql"),
188+
filename.match(/example[0-9]*.ql/),
189189
);
190190

191191
return `example${qlFiles.length + 1}.ql`;

extensions/ql-vscode/test/vscode-tests/cli-integration/skeleton-query-wizard.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { TextDocument, window, workspace, WorkspaceFolder } from "vscode";
99
import { extLogger } from "../../../src/common";
1010
import { QlPackGenerator } from "../../../src/qlpack-generator";
1111
import * as helpers from "../../../src/helpers";
12-
import { ensureDirSync, removeSync } from "fs-extra";
12+
import { createFileSync, ensureDirSync, removeSync } from "fs-extra";
1313
import { join } from "path";
1414
import { CancellationTokenSource } from "vscode-jsonrpc";
1515
import { testCredentialsWithStub } from "../../factories/authentication";
@@ -165,6 +165,16 @@ describe("SkeletonQueryWizard", () => {
165165
expect(createExampleQlFileSpy).toHaveBeenCalledWith("example2.ql");
166166
});
167167

168+
it("should only take into account example QL files", async () => {
169+
createFileSync(
170+
join(dir.name, `codeql-custom-queries-${chosenLanguage}`, "MyQuery.ql"),
171+
);
172+
173+
await wizard.execute();
174+
175+
expect(createExampleQlFileSpy).toHaveBeenCalledWith("example2.ql");
176+
});
177+
168178
describe("if QL pack has no query file", () => {
169179
it("should create new query file in the same QL pack folder", async () => {
170180
removeSync(

0 commit comments

Comments
 (0)