Repository: eslint/eslint
File: lib/eslint/eslint-helpers.js (JavaScript)

Code before:
 *      or an empty array if there are no matches.
 */
async function globSearch({ cwd, patterns, configs }) {

    if (patterns.length === 0) {
        return [];
    }

    const matchers = patterns.map(pattern => new minimatch.Minimatch(pattern));

    return (await doFsWalk(cwd, {

        deepFilter(entry) {
            return !configs.isDirectoryIgnored(entry.path);
        },

        entryFilter(entry) {

            // entries may be directories or files so filter out directories
            if (entry.dirent.isDirectory()) {
                return false;
            }

            const posixName = normalizeToPosix(path.relative(cwd, entry.path));
            const matchesPattern = matchers.some(matcher => {

                /*
                 * Patterns can either be relative, like `foo/bar` or
                 * absolute like `c:/foo/bar/**` and so we need to apply
                 * the match either against the relative or absolute filename,
                 * respectively.
                 */
                if (path.isAbsolute(matcher.pattern)) {
                    return matcher.match(entry.path);
                }

                return matcher.match(posixName);
            });

            return matchesPattern && !configs.isFileIgnored(entry.path);
        }
    })).map(entry => entry.path);

}

/**
 * Determines if a given glob pattern will return any results.
 * Used primarily to help with useful error messages.
 * @param {Object} options The options for the function.
 * @param {string} options.cwd The directory to search.
 * @param {string} options.pattern A glob pattern to match.

Review comment (suggestion):
`entryFilter` determines which entries will show up in the results, so I filter out directories and check patterns here.

Code after:
 * @returns {Promise<Array<string>>} An array of matching file paths
 *      or an empty array if there are no matches.
 */
async function globSearch({ cwd, patterns, configs }) {

    if (patterns.length === 0) {
        return [];
    }

    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, {

        deepFilter(entry) {
            const relativePath = normalizeToPosix(path.relative(cwd, entry.path));
            const matchesPattern = matchers.some(matcher => matcher.match(relativePath, true));

            return matchesPattern && !configs.isDirectoryIgnored(entry.path);
        },
        entryFilter(entry) {
            const relativePath = normalizeToPosix(path.relative(cwd, entry.path));

            // entries may be directories or files so filter out directories
            if (entry.dirent.isDirectory()) {
                return false;
            }

            const matchesPattern = matchers.some(matcher => matcher.match(relativePath));

            return matchesPattern && !configs.isFileIgnored(entry.path);
        }
    })).map(entry => entry.path);

}

/**
 * Determines if a given glob pattern will return any results.
 * Used primarily to help with useful error messages.
 * @param {Object} options The options for the function.
 * @param {string} options.cwd The directory to search.
 * @param {string} options.pattern A glob pattern to match.
 * @returns {Promise<boolean>} True if there is a glob match, false if not.
 */
function globMatch({ cwd, pattern }) {