diff --git a/lib/util/glob-utils.js b/lib/util/glob-utils.js index b05c354439d..33cb8e7c885 100644 --- a/lib/util/glob-utils.js +++ b/lib/util/glob-utils.js @@ -70,6 +70,10 @@ function processPath(options) { * @private */ return function(pathname) { + if (pathname === "") { + return ""; + } + let newPath = pathname; const resolvedPath = path.resolve(cwd, pathname); @@ -201,6 +205,13 @@ function listFilesToProcess(globPatterns, providedOptions) { debug("Creating list of files to process."); const resolvedPathsByGlobPattern = resolvedGlobPatterns.map(pattern => { + if (pattern === "") { + return [{ + filename: "", + behavior: SILENTLY_IGNORE + }]; + } + const file = path.resolve(cwd, pattern); if (options.globInputPaths === false || (fs.existsSync(file) && fs.statSync(file).isFile())) { @@ -240,7 +251,7 @@ function listFilesToProcess(globPatterns, providedOptions) { }); const allPathDescriptors = resolvedPathsByGlobPattern.reduce((pathsForAllGlobs, pathsForCurrentGlob, index) => { - if (pathsForCurrentGlob.every(pathDescriptor => pathDescriptor.behavior === SILENTLY_IGNORE)) { + if (pathsForCurrentGlob.every(pathDescriptor => pathDescriptor.behavior === SILENTLY_IGNORE && pathDescriptor.filename !== "")) { throw new (pathsForCurrentGlob.length ? AllFilesIgnoredError : NoFilesFoundError)(globPatterns[index]); } diff --git a/tests/lib/util/glob-utils.js b/tests/lib/util/glob-utils.js index 6b61f8b4061..9bafcfa0779 100644 --- a/tests/lib/util/glob-utils.js +++ b/tests/lib/util/glob-utils.js @@ -329,6 +329,13 @@ describe("globUtils", () => { }, `No files matching '${patterns[0]}' were found.`); }); + it("should ignore empty patterns", () => { + const patterns = [""]; + const result = globUtils.listFilesToProcess(patterns); + + assert.deepStrictEqual(result, []); + }); + it("should return an ignored file, if ignore option is turned off", () => { const options = { ignore: false }; const patterns = [getFixturePath("glob-util", "ignored", "**/*.js")];