@@ -76,7 +76,7 @@ class UnmatchedSearchPatternsError extends Error {
7676 constructor ( { basePath, unmatchedPatterns, patterns, rawPatterns } ) {
7777 super ( `No files matching '${ rawPatterns } ' in '${ basePath } ' were found.` ) ;
7878 this . basePath = basePath ;
79- this . patternsToCheck = unmatchedPatterns ;
79+ this . unmatchedPatterns = unmatchedPatterns ;
8080 this . patterns = patterns ;
8181 this . rawPatterns = rawPatterns ;
8282 }
@@ -337,49 +337,43 @@ async function globSearch({
337337}
338338
339339/**
340- * Checks to see if there are any ignored results for a given search. This
341- * happens either when there are unmatched patterns during a search or if
342- * a search returns no results.
340+ * Throws an error for unmatched patterns. The error will only contain information about the first one.
341+ * Checks to see if there are any ignored results for a given search.
343342 * @param {Object } options The options for this function.
344343 * @param {string } options.basePath The directory to search.
345344 * @param {Array<string> } options.patterns An array of glob patterns
346345 * that were used in the original search.
347346 * @param {Array<string> } options.rawPatterns An array of glob patterns
348347 * as the user inputted them. Used for errors.
349- * @param {Array<string> } options.patternsToCheck An array of glob patterns
350- * to use for this check .
351- * @returns {void }
352- * @throws {NoFilesFoundError } If there is a pattern that doesn't match
353- * any files and `errorOnUnmatchedPattern` is true .
354- * @throws {AllFilesIgnoredError } If there is a pattern that matches files
355- * when there are no ignores.
348+ * @param {Array<string> } options.unmatchedPatterns A non-empty array of glob patterns
349+ * that were unmatched in the original search .
350+ * @returns {void } Always throws an error.
351+ * @throws {NoFilesFoundError } If the first unmatched pattern
352+ * doesn't match any files even when there are no ignores .
353+ * @throws {AllFilesIgnoredError } If the first unmatched pattern
354+ * matches some files when there are no ignores.
356355 */
357- async function checkForIgnoredResults ( {
356+ async function throwErrorForUnmatchedPatterns ( {
358357 basePath,
359358 patterns,
360359 rawPatterns,
361- patternsToCheck = patterns
360+ unmatchedPatterns
362361} ) {
363362
364- for ( const pattern of patternsToCheck ) {
363+ const pattern = unmatchedPatterns [ 0 ] ;
364+ const rawPattern = rawPatterns [ patterns . indexOf ( pattern ) ] ;
365365
366- const patternHasMatch = await globMatch ( {
367- basePath,
368- pattern
369- } ) ;
366+ const patternHasMatch = await globMatch ( {
367+ basePath,
368+ pattern
369+ } ) ;
370370
371- if ( patternHasMatch ) {
372- throw new AllFilesIgnoredError (
373- rawPatterns [ patterns . indexOf ( pattern ) ]
374- ) ;
375- }
371+ if ( patternHasMatch ) {
372+ throw new AllFilesIgnoredError ( rawPattern ) ;
376373 }
377374
378375 // if we get here there are truly no matches
379- throw new NoFilesFoundError (
380- rawPatterns [ patterns . indexOf ( patternsToCheck [ 0 ] ) ] ,
381- true
382- ) ;
376+ throw new NoFilesFoundError ( rawPattern , true ) ;
383377}
384378
385379/**
@@ -446,9 +440,9 @@ async function globMultiSearch({ searches, configs, errorOnUnmatchedPattern }) {
446440
447441 if ( errorOnUnmatchedPattern ) {
448442
449- await checkForIgnoredResults ( {
443+ await throwErrorForUnmatchedPatterns ( {
450444 ...currentSearch ,
451- patternsToCheck : error . patternsToCheck
445+ unmatchedPatterns : error . unmatchedPatterns
452446 } ) ;
453447
454448 }
0 commit comments