Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure that glob patterns are normalized #16287

Merged
merged 3 commits into from Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/eslint/eslint-helpers.js
Expand Up @@ -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) {

Expand Down
22 changes: 19 additions & 3 deletions tests/lib/cli.js
Expand Up @@ -172,11 +172,23 @@ describe("cli", () => {
});

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

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);
});

if (useFlatConfig) {
it(`should load the local config file with 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", () => {
Expand Down Expand Up @@ -480,9 +492,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.`));
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/eslint/flat-eslint.js
Expand Up @@ -818,6 +818,29 @@ describe("FlatESLint", () => {
assert.strictEqual(results[1].suppressedMessages.length, 0);
});

// 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);
});

}


it("should not resolve globs when 'globInputPaths' option is false", async () => {
eslint = new FlatESLint({
ignore: false,
Expand Down