Skip to content

Commit

Permalink
fix!: Allow escaping characters on Windows (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic authored Jun 24, 2024
1 parent 3702ec7 commit 8501890
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
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

0 comments on commit 8501890

Please sign in to comment.