Skip to content

Commit

Permalink
Fix: overrides handle relative paths as expected (fixes #11577) (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jun 5, 2019
1 parent 5509cdf commit 21f3131
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 11 additions & 1 deletion lib/cli-engine/config-array/override-tester.js
Expand Up @@ -55,7 +55,17 @@ function toMatcher(patterns) {
if (patterns.length === 0) {
return null;
}
return patterns.map(pattern => new Minimatch(pattern, minimatchOpts));
return patterns.map(pattern => {
if (/^\.[/\\]/u.test(pattern)) {
return new Minimatch(
pattern.slice(2),

// `./*.js` should not match with `subdir/foo.js`
{ ...minimatchOpts, matchBase: false }
);
}
return new Minimatch(pattern, minimatchOpts);
});
}

/**
Expand Down
12 changes: 6 additions & 6 deletions tests/lib/cli-engine/config-array/override-tester.js
Expand Up @@ -191,10 +191,10 @@ describe("OverrideTester", () => {
match("foo.js", ["*.js"], []);
match("foo.js", ["**/*.js"], []);
match("bar.js", ["*.js"], ["foo.js"]);
match("foo.js", ["./foo.js"], []);
match("foo.js", ["./*"], []);
match("foo.js", ["./**"], []);

noMatch("foo.js", ["./foo.js"], []);
noMatch("foo.js", ["./*"], []);
noMatch("foo.js", ["./**"], []);
noMatch("foo.js", ["*"], ["foo.js"]);
noMatch("foo.js", ["*.js"], ["foo.js"]);
noMatch("foo.js", ["**/*.js"], ["foo.js"]);
Expand All @@ -208,11 +208,11 @@ describe("OverrideTester", () => {
match("subdir/foo.js", ["subdir/foo.js"], []);
match("subdir/foo.js", ["subdir/*"], []);
match("subdir/second/foo.js", ["subdir/**"], []);
match("subdir/foo.js", ["./**"], []);
match("subdir/foo.js", ["./subdir/**"], []);
match("subdir/foo.js", ["./subdir/*"], []);

noMatch("subdir/foo.js", ["./foo.js"], []);
noMatch("subdir/foo.js", ["./**"], []);
noMatch("subdir/foo.js", ["./subdir/**"], []);
noMatch("subdir/foo.js", ["./subdir/*"], []);
noMatch("subdir/foo.js", ["*"], ["subdir/**"]);
noMatch("subdir/very/deep/foo.js", ["*.js"], ["subdir/**"]);
noMatch("subdir/second/foo.js", ["subdir/*"], []);
Expand Down

0 comments on commit 21f3131

Please sign in to comment.