Skip to content

Commit d2d06f7

Browse files
authored
refactor: use / separator when adjusting ignorePatterns on Windows (#18613)
* refactor: use `/` separator when adjusting `ignorePatterns` on Windows * add explanation
1 parent 21d3766 commit d2d06f7

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/eslint/eslint.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ async function calculateConfigArray(eslint, {
421421
relativeIgnorePatterns = ignorePatterns;
422422
} else {
423423

424-
const relativeIgnorePath = path.relative(basePath, cwd);
424+
// In minimatch patterns, only `/` can be used as path separator
425+
const relativeIgnorePath = path.relative(basePath, cwd).replaceAll(path.sep, "/");
425426

426427
relativeIgnorePatterns = ignorePatterns.map(pattern => {
427428
const negated = pattern.startsWith("!");

tests/lib/eslint/eslint.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5144,6 +5144,16 @@ describe("ESLint", () => {
51445144
assert(!await engine.isPathIgnored("c.js"), "c.js should not be ignored");
51455145
});
51465146

5147+
it("should interpret ignorePatterns as relative to cwd", async () => {
5148+
const cwd = getFixturePath("ignored-paths", "subdir");
5149+
const engine = new ESLint({
5150+
ignorePatterns: ["undef.js"],
5151+
cwd // using ../../eslint.config.js
5152+
});
5153+
5154+
assert(await engine.isPathIgnored(path.join(cwd, "undef.js")));
5155+
});
5156+
51475157
it("should return true for files which match an ignorePattern even if they do not exist on the filesystem", async () => {
51485158
const cwd = getFixturePath("ignored-paths");
51495159
const engine = new ESLint({

0 commit comments

Comments
 (0)