diff --git a/packages/config-array/package.json b/packages/config-array/package.json index db98465..276dd11 100644 --- a/packages/config-array/package.json +++ b/packages/config-array/package.json @@ -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", diff --git a/packages/config-array/src/config-array.js b/packages/config-array/src/config-array.js index 9e41e38..2dce1e7 100644 --- a/packages/config-array/src/config-array.js +++ b/packages/config-array/src/config-array.js @@ -60,6 +60,7 @@ const negatedMinimatchCache = new Map(); const MINIMATCH_OPTIONS = { // matchBase: true, dot: true, + allowWindowsEscape: true, }; /** diff --git a/packages/config-array/tests/config-array.test.js b/packages/config-array/tests/config-array.test.js index 5d6f892..c5270ab 100644 --- a/packages/config-array/tests/config-array.test.js +++ b/packages/config-array/tests/config-array.test.js @@ -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", () => {