From a2e5be4632a7e5bd3e05230f869c12b832d65484 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Thu, 8 Sep 2022 14:23:29 -0700 Subject: [PATCH 1/3] fix: Ensure that glob patterns are normalized Glob patterns must be normalized to posix-style file paths before being passed in to globby. Fixes #16259 --- lib/eslint/eslint-helpers.js | 2 +- tests/lib/cli.js | 13 ++++++++++--- tests/lib/eslint/flat-eslint.js | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/eslint/eslint-helpers.js b/lib/eslint/eslint-helpers.js index 442686e56bf..92f37453232 100644 --- a/lib/eslint/eslint-helpers.js +++ b/lib/eslint/eslint-helpers.js @@ -133,7 +133,7 @@ async function findFiles({ stats.forEach((stat, index) => { const filePath = filePaths[index]; - const pattern = patterns[index]; + const pattern = normalizeToPosix(patterns[index]); if (stat) { diff --git a/tests/lib/cli.js b/tests/lib/cli.js index 60fdac64602..2b1fce7bd30 100644 --- a/tests/lib/cli.js +++ b/tests/lib/cli.js @@ -171,11 +171,18 @@ describe("cli", () => { }); }); - describe("when there is a local config file", () => { - const code = "lib/cli.js"; + describe.only("when there is a local config file", () => { it(`should load the local config file with configType:${configType}`, async () => { - await cli.execute(code, null, useFlatConfig); + await cli.execute("lib/cli.js", null, useFlatConfig); + }); + + it(`should load the local config file with glob pattern and configType:${configType}`, async () => { + await cli.execute("lib/cli*.js", null, useFlatConfig); + }); + + it(`should load the local config file with Windows slashes glob pattern and configType:${configType}`, async () => { + await cli.execute("lib\\cli*.js", null, useFlatConfig); }); }); diff --git a/tests/lib/eslint/flat-eslint.js b/tests/lib/eslint/flat-eslint.js index 1af6c2e1d8b..0dc4cf27e68 100644 --- a/tests/lib/eslint/flat-eslint.js +++ b/tests/lib/eslint/flat-eslint.js @@ -818,6 +818,23 @@ describe("FlatESLint", () => { assert.strictEqual(results[1].suppressedMessages.length, 0); }); + it("should resolve globs with Windows slashes when 'globInputPaths' option is true", async () => { + eslint = new FlatESLint({ + ignore: false, + cwd: getFixturePath(".."), + overrideConfig: { files: ["**/*.js", "**/*.js2"] }, + overrideConfigFile: getFixturePath("eslint.config.js") + + }); + const results = await eslint.lintFiles(["fixtures\\files\\*"]); + + assert.strictEqual(results.length, 2); + assert.strictEqual(results[0].messages.length, 0); + assert.strictEqual(results[1].messages.length, 0); + assert.strictEqual(results[0].suppressedMessages.length, 0); + assert.strictEqual(results[1].suppressedMessages.length, 0); + }); + it("should not resolve globs when 'globInputPaths' option is false", async () => { eslint = new FlatESLint({ ignore: false, From bf9c14f88d0f6ba6836e8aa92301733c8c6cc2ea Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Fri, 9 Sep 2022 13:17:33 -0700 Subject: [PATCH 2/3] Remove .only; fix failing test --- tests/lib/cli.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/lib/cli.js b/tests/lib/cli.js index 2b1fce7bd30..1553d8163b1 100644 --- a/tests/lib/cli.js +++ b/tests/lib/cli.js @@ -171,7 +171,7 @@ describe("cli", () => { }); }); - describe.only("when there is a local config file", () => { + describe("when there is a local config file", () => { it(`should load the local config file with configType:${configType}`, async () => { await cli.execute("lib/cli.js", null, useFlatConfig); @@ -487,9 +487,13 @@ describe("cli", () => { describe("when executing without no-error-on-unmatched-pattern flag", () => { it(`should throw an error on unmatched glob pattern with configType:${configType}`, async () => { - const filePath = getFixturePath("unmatched-patterns"); + let filePath = getFixturePath("unmatched-patterns"); const globPattern = "unmatched*.js"; + if (useFlatConfig) { + filePath = filePath.replace(/\\/gu, "/"); + } + await stdAssert.rejects(async () => { await cli.execute(`"${filePath}/${globPattern}"`, null, useFlatConfig); }, new Error(`No files matching '${filePath}/${globPattern}' were found.`)); From bb2ddf1bb1126b948a39c2ca84671d5546e0e435 Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Fri, 9 Sep 2022 13:32:24 -0700 Subject: [PATCH 3/3] Fix Windows tests --- tests/lib/cli.js | 17 +++++++++++------ tests/lib/eslint/flat-eslint.js | 32 +++++++++++++++++++------------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/tests/lib/cli.js b/tests/lib/cli.js index 1553d8163b1..a58a8c910fc 100644 --- a/tests/lib/cli.js +++ b/tests/lib/cli.js @@ -177,13 +177,18 @@ describe("cli", () => { await cli.execute("lib/cli.js", null, useFlatConfig); }); - it(`should load the local config file with glob pattern and configType:${configType}`, async () => { - await cli.execute("lib/cli*.js", null, useFlatConfig); - }); + if (useFlatConfig) { + it(`should load the local config file with glob pattern and configType:${configType}`, async () => { + await cli.execute("lib/cli*.js", null, useFlatConfig); + }); + } - it(`should load the local config file with Windows slashes glob pattern and configType:${configType}`, async () => { - await cli.execute("lib\\cli*.js", null, useFlatConfig); - }); + // only works on Windows + if (os.platform() === "win32") { + it(`should load the local config file with Windows slashes glob pattern and configType:${configType}`, async () => { + await cli.execute("lib\\cli*.js", null, useFlatConfig); + }); + } }); describe("Formatters", () => { diff --git a/tests/lib/eslint/flat-eslint.js b/tests/lib/eslint/flat-eslint.js index 0dc4cf27e68..d6d034fdb7b 100644 --- a/tests/lib/eslint/flat-eslint.js +++ b/tests/lib/eslint/flat-eslint.js @@ -818,22 +818,28 @@ describe("FlatESLint", () => { assert.strictEqual(results[1].suppressedMessages.length, 0); }); - it("should resolve globs with Windows slashes when 'globInputPaths' option is true", async () => { - eslint = new FlatESLint({ - ignore: false, - cwd: getFixturePath(".."), - overrideConfig: { files: ["**/*.js", "**/*.js2"] }, - overrideConfigFile: getFixturePath("eslint.config.js") + // only works on a Windows machine + if (os.platform() === "win32") { + + it("should resolve globs with Windows slashes when 'globInputPaths' option is true", async () => { + eslint = new FlatESLint({ + ignore: false, + cwd: getFixturePath(".."), + overrideConfig: { files: ["**/*.js", "**/*.js2"] }, + overrideConfigFile: getFixturePath("eslint.config.js") + + }); + const results = await eslint.lintFiles(["fixtures\\files\\*"]); + assert.strictEqual(results.length, 2); + assert.strictEqual(results[0].messages.length, 0); + assert.strictEqual(results[1].messages.length, 0); + assert.strictEqual(results[0].suppressedMessages.length, 0); + assert.strictEqual(results[1].suppressedMessages.length, 0); }); - const results = await eslint.lintFiles(["fixtures\\files\\*"]); - assert.strictEqual(results.length, 2); - assert.strictEqual(results[0].messages.length, 0); - assert.strictEqual(results[1].messages.length, 0); - assert.strictEqual(results[0].suppressedMessages.length, 0); - assert.strictEqual(results[1].suppressedMessages.length, 0); - }); + } + it("should not resolve globs when 'globInputPaths' option is false", async () => { eslint = new FlatESLint({