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!: Allow escaping characters on Windows #61

Merged
merged 2 commits into from
Jun 24, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/config-array/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"dependencies": {
"@eslint/object-schema": "^2.1.4",
"debug": "^4.3.1",
"minimatch": "^3.0.5"
"minimatch": "^3.1.2"
},
"devDependencies": {
"@types/minimatch": "^3.0.5",
Expand Down
1 change: 1 addition & 0 deletions packages/config-array/src/config-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const negatedMinimatchCache = new Map();
const MINIMATCH_OPTIONS = {
// matchBase: true,
dot: true,
allowWindowsEscape: true,
};

/**
Expand Down
101 changes: 101 additions & 0 deletions packages/config-array/tests/config-array.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,107 @@ describe("ConfigArray", () => {
assert.strictEqual(config, undefined);
});

// https://github.com/eslint/eslint/issues/18597
it("should correctly handle escaped characters in `files` patterns", () => {
configs = new ConfigArray(
[
{
files: ["src/\\{a,b}.js"],
defs: {
severity: "error",
},
},
],
{ basePath, schema },
);

configs.normalizeSync();

assert.strictEqual(
configs.getConfig(path.resolve(basePath, "src", "a.js")),
undefined,
);
assert.strictEqual(
configs.getConfig(path.resolve(basePath, "src", "b.js")),
undefined,
);
assert.strictEqual(
configs.getConfig(path.resolve(basePath, "src", "{a,b}.js"))
.defs.severity,
"error",
);
});

it("should correctly handle escaped characters in `ignores` patterns", () => {
configs = new ConfigArray(
[
{
files: ["**/*.js"],
ignores: ["src/\\{a,b}.js"],
defs: {
severity: "error",
},
},
],
{ basePath, schema },
);

configs.normalizeSync();

assert.strictEqual(
configs.getConfig(path.resolve(basePath, "src", "a.js"))
.defs.severity,
"error",
);
assert.strictEqual(
configs.getConfig(path.resolve(basePath, "src", "b.js"))
.defs.severity,
"error",
);
assert.strictEqual(
configs.getConfig(
path.resolve(basePath, "src", "{a,b}.js"),
),
undefined,
);
});

it("should correctly handle escaped characters in global `ignores` patterns", () => {
configs = new ConfigArray(
[
{
files: ["**/*.js"],
defs: {
severity: "error",
},
},
{
ignores: ["src/\\{a,b}.js"],
},
],
{ basePath, schema },
);

configs.normalizeSync();

assert.strictEqual(
configs.getConfig(path.resolve(basePath, "src", "a.js"))
.defs.severity,
"error",
);
assert.strictEqual(
configs.getConfig(path.resolve(basePath, "src", "b.js"))
.defs.severity,
"error",
);
assert.strictEqual(
configs.getConfig(
path.resolve(basePath, "src", "{a,b}.js"),
),
undefined,
);
});

// https://github.com/eslint/eslint/issues/17103
describe("ignores patterns should be properly applied", () => {
it("should return undefined when a filename matches an ignores pattern but not a files pattern", () => {
Expand Down