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.
This commit is contained in:
@@ -185,7 +185,7 @@ export class SkeletonQueryWizard {
|
||||
const folderUri = Uri.file(join(this.storagePath, folderName));
|
||||
const files = await workspace.fs.readDirectory(folderUri);
|
||||
const qlFiles = files.filter(([filename, _fileType]) =>
|
||||
filename.endsWith(".ql"),
|
||||
filename.match(/example[0-9]*.ql/),
|
||||
);
|
||||
|
||||
return `example${qlFiles.length + 1}.ql`;
|
||||
|
||||
@@ -9,7 +9,7 @@ import { TextDocument, window, workspace, WorkspaceFolder } from "vscode";
|
||||
import { extLogger } from "../../../src/common";
|
||||
import { QlPackGenerator } from "../../../src/qlpack-generator";
|
||||
import * as helpers from "../../../src/helpers";
|
||||
import { ensureDirSync, removeSync } from "fs-extra";
|
||||
import { createFileSync, ensureDirSync, removeSync } from "fs-extra";
|
||||
import { join } from "path";
|
||||
import { CancellationTokenSource } from "vscode-jsonrpc";
|
||||
import { testCredentialsWithStub } from "../../factories/authentication";
|
||||
@@ -158,6 +158,16 @@ describe("SkeletonQueryWizard", () => {
|
||||
expect(createExampleQlFileSpy).toHaveBeenCalledWith("example2.ql");
|
||||
});
|
||||
|
||||
it("should only take into account example QL files", async () => {
|
||||
createFileSync(
|
||||
join(dir.name, `codeql-custom-queries-${chosenLanguage}`, "MyQuery.ql"),
|
||||
);
|
||||
|
||||
await wizard.execute();
|
||||
|
||||
expect(createExampleQlFileSpy).toHaveBeenCalledWith("example2.ql");
|
||||
});
|
||||
|
||||
describe("if QL pack has no query file", () => {
|
||||
it("should create new query file in the same QL pack folder", async () => {
|
||||
removeSync(
|
||||
|
||||
Reference in New Issue
Block a user