Skip to content

Commit 8501890

Browse files
authored
fix!: Allow escaping characters on Windows (#61)
1 parent 3702ec7 commit 8501890

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

packages/config-array/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"dependencies": {
4949
"@eslint/object-schema": "^2.1.4",
5050
"debug": "^4.3.1",
51-
"minimatch": "^3.0.5"
51+
"minimatch": "^3.1.2"
5252
},
5353
"devDependencies": {
5454
"@types/minimatch": "^3.0.5",

packages/config-array/src/config-array.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const negatedMinimatchCache = new Map();
6060
const MINIMATCH_OPTIONS = {
6161
// matchBase: true,
6262
dot: true,
63+
allowWindowsEscape: true,
6364
};
6465

6566
/**

packages/config-array/tests/config-array.test.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,107 @@ describe("ConfigArray", () => {
970970
assert.strictEqual(config, undefined);
971971
});
972972

973+
// https://github.com/eslint/eslint/issues/18597
974+
it("should correctly handle escaped characters in `files` patterns", () => {
975+
configs = new ConfigArray(
976+
[
977+
{
978+
files: ["src/\\{a,b}.js"],
979+
defs: {
980+
severity: "error",
981+
},
982+
},
983+
],
984+
{ basePath, schema },
985+
);
986+
987+
configs.normalizeSync();
988+
989+
assert.strictEqual(
990+
configs.getConfig(path.resolve(basePath, "src", "a.js")),
991+
undefined,
992+
);
993+
assert.strictEqual(
994+
configs.getConfig(path.resolve(basePath, "src", "b.js")),
995+
undefined,
996+
);
997+
assert.strictEqual(
998+
configs.getConfig(path.resolve(basePath, "src", "{a,b}.js"))
999+
.defs.severity,
1000+
"error",
1001+
);
1002+
});
1003+
1004+
it("should correctly handle escaped characters in `ignores` patterns", () => {
1005+
configs = new ConfigArray(
1006+
[
1007+
{
1008+
files: ["**/*.js"],
1009+
ignores: ["src/\\{a,b}.js"],
1010+
defs: {
1011+
severity: "error",
1012+
},
1013+
},
1014+
],
1015+
{ basePath, schema },
1016+
);
1017+
1018+
configs.normalizeSync();
1019+
1020+
assert.strictEqual(
1021+
configs.getConfig(path.resolve(basePath, "src", "a.js"))
1022+
.defs.severity,
1023+
"error",
1024+
);
1025+
assert.strictEqual(
1026+
configs.getConfig(path.resolve(basePath, "src", "b.js"))
1027+
.defs.severity,
1028+
"error",
1029+
);
1030+
assert.strictEqual(
1031+
configs.getConfig(
1032+
path.resolve(basePath, "src", "{a,b}.js"),
1033+
),
1034+
undefined,
1035+
);
1036+
});
1037+
1038+
it("should correctly handle escaped characters in global `ignores` patterns", () => {
1039+
configs = new ConfigArray(
1040+
[
1041+
{
1042+
files: ["**/*.js"],
1043+
defs: {
1044+
severity: "error",
1045+
},
1046+
},
1047+
{
1048+
ignores: ["src/\\{a,b}.js"],
1049+
},
1050+
],
1051+
{ basePath, schema },
1052+
);
1053+
1054+
configs.normalizeSync();
1055+
1056+
assert.strictEqual(
1057+
configs.getConfig(path.resolve(basePath, "src", "a.js"))
1058+
.defs.severity,
1059+
"error",
1060+
);
1061+
assert.strictEqual(
1062+
configs.getConfig(path.resolve(basePath, "src", "b.js"))
1063+
.defs.severity,
1064+
"error",
1065+
);
1066+
assert.strictEqual(
1067+
configs.getConfig(
1068+
path.resolve(basePath, "src", "{a,b}.js"),
1069+
),
1070+
undefined,
1071+
);
1072+
});
1073+
9731074
// https://github.com/eslint/eslint/issues/17103
9741075
describe("ignores patterns should be properly applied", () => {
9751076
it("should return undefined when a filename matches an ignores pattern but not a files pattern", () => {

0 commit comments

Comments
 (0)