Skip to content

Commit 6a923ff

Browse files
authored
fix: Ensure that glob patterns are normalized (#16287)
* 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 * Remove .only; fix failing test * Fix Windows tests
1 parent 38e8171 commit 6a923ff

3 files changed

Lines changed: 43 additions & 4 deletions

File tree

lib/eslint/eslint-helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ async function findFiles({
134134
stats.forEach((stat, index) => {
135135

136136
const filePath = filePaths[index];
137-
const pattern = patterns[index];
137+
const pattern = normalizeToPosix(patterns[index]);
138138

139139
if (stat) {
140140

tests/lib/cli.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,23 @@ describe("cli", () => {
172172
});
173173

174174
describe("when there is a local config file", () => {
175-
const code = "lib/cli.js";
176175

177176
it(`should load the local config file with configType:${configType}`, async () => {
178-
await cli.execute(code, null, useFlatConfig);
177+
await cli.execute("lib/cli.js", null, useFlatConfig);
179178
});
179+
180+
if (useFlatConfig) {
181+
it(`should load the local config file with glob pattern and configType:${configType}`, async () => {
182+
await cli.execute("lib/cli*.js", null, useFlatConfig);
183+
});
184+
}
185+
186+
// only works on Windows
187+
if (os.platform() === "win32") {
188+
it(`should load the local config file with Windows slashes glob pattern and configType:${configType}`, async () => {
189+
await cli.execute("lib\\cli*.js", null, useFlatConfig);
190+
});
191+
}
180192
});
181193

182194
describe("Formatters", () => {
@@ -480,9 +492,13 @@ describe("cli", () => {
480492

481493
describe("when executing without no-error-on-unmatched-pattern flag", () => {
482494
it(`should throw an error on unmatched glob pattern with configType:${configType}`, async () => {
483-
const filePath = getFixturePath("unmatched-patterns");
495+
let filePath = getFixturePath("unmatched-patterns");
484496
const globPattern = "unmatched*.js";
485497

498+
if (useFlatConfig) {
499+
filePath = filePath.replace(/\\/gu, "/");
500+
}
501+
486502
await stdAssert.rejects(async () => {
487503
await cli.execute(`"${filePath}/${globPattern}"`, null, useFlatConfig);
488504
}, new Error(`No files matching '${filePath}/${globPattern}' were found.`));

tests/lib/eslint/flat-eslint.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,29 @@ describe("FlatESLint", () => {
884884
assert.strictEqual(results[1].suppressedMessages.length, 0);
885885
});
886886

887+
// only works on a Windows machine
888+
if (os.platform() === "win32") {
889+
890+
it("should resolve globs with Windows slashes when 'globInputPaths' option is true", async () => {
891+
eslint = new FlatESLint({
892+
ignore: false,
893+
cwd: getFixturePath(".."),
894+
overrideConfig: { files: ["**/*.js", "**/*.js2"] },
895+
overrideConfigFile: getFixturePath("eslint.config.js")
896+
897+
});
898+
const results = await eslint.lintFiles(["fixtures\\files\\*"]);
899+
900+
assert.strictEqual(results.length, 2);
901+
assert.strictEqual(results[0].messages.length, 0);
902+
assert.strictEqual(results[1].messages.length, 0);
903+
assert.strictEqual(results[0].suppressedMessages.length, 0);
904+
assert.strictEqual(results[1].suppressedMessages.length, 0);
905+
});
906+
907+
}
908+
909+
887910
it("should not resolve globs when 'globInputPaths' option is false", async () => {
888911
eslint = new FlatESLint({
889912
ignore: false,

0 commit comments

Comments
 (0)