Skip to content

Commit

Permalink
Fix remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Oct 6, 2022
1 parent 832f964 commit f409b02
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lib/eslint/eslint-helpers.js
Expand Up @@ -17,6 +17,7 @@ const hash = require("../cli-engine/hash");
const minimatch = require("minimatch");
const util = require("util");
const fswalk = require("@nodelib/fs.walk");
const { Minimatch } = require("minimatch");

//-----------------------------------------------------------------------------
// Fix fswalk
Expand Down Expand Up @@ -124,7 +125,13 @@ async function globSearch({ cwd, patterns, configs }) {
return [];
}

const matchers = patterns.map(pattern => new minimatch.Minimatch(pattern));
const matchers = patterns.map(pattern => {
const patternToUse = path.isAbsolute(pattern)
? normalizeToPosix(path.relative(cwd, pattern))
: pattern;

return new minimatch.Minimatch(patternToUse);
});

return (await doFsWalk(cwd, {

Expand Down Expand Up @@ -161,11 +168,18 @@ async function globSearch({ cwd, patterns, configs }) {
function globMatch({ cwd, pattern }) {

let found = false;
const patternToUse = path.isAbsolute(pattern)
? normalizeToPosix(path.relative(cwd, pattern))
: pattern;

const matcher = new Minimatch(patternToUse);

const fsWalkSettings = {

deepFilter() {
return !found;
deepFilter(entry) {
const relativePath = normalizeToPosix(path.relative(cwd, entry.path));

return !found && matcher.match(relativePath, true);
},

entryFilter(entry) {
Expand All @@ -175,7 +189,7 @@ function globMatch({ cwd, pattern }) {

const relativePath = normalizeToPosix(path.relative(cwd, entry.path));

if (minimatch(relativePath, pattern)) {
if (matcher.match(relativePath)) {
found = true;
return true;
}
Expand Down Expand Up @@ -233,7 +247,6 @@ async function findFiles({

// check to see if we have explicit files and directories
const filePaths = patterns.map(filePath => path.resolve(cwd, filePath));
const relativePatterns = filePaths.map(filePath => path.relative(cwd, filePath));
const stats = await Promise.all(
filePaths.map(
filePath => fsp.stat(filePath).catch(() => { })
Expand All @@ -243,7 +256,7 @@ async function findFiles({
stats.forEach((stat, index) => {

const filePath = filePaths[index];
const pattern = normalizeToPosix(relativePatterns[index]);
const pattern = normalizeToPosix(patterns[index]);

if (stat) {

Expand Down

0 comments on commit f409b02

Please sign in to comment.