执行 micromatch

@param {string} filename 文件名
@param {Array<string>} patterns 匹配模式
@param {Array<string>} ignorePatterns 忽略模式

@returns {boolean} 是否匹配
976341
function match (filename, patterns, ignorePatterns) {
  function isMatch (ps) {
    return ps.some(p => {
      return mm.isMatch(filename, p, mmOptions)
    })
  }

  let isIgnore = false

  if (Array.isArray(ignorePatterns) && ignorePatterns.length) {
    isIgnore = isMatch(ignorePatterns)
  }

  if (isIgnore) {
    return false
  }

  return isMatch(patterns)
}
509632
def find(patterns)
      if patterns.empty?
        raise SCSSLint::Exceptions::NoFilesError,
              'No files, paths, or patterns were specified'
      end

      matched_files = extract_files_from(patterns)
      if matched_files.empty?
        raise SCSSLint::Exceptions::NoFilesError,
              "No SCSS files matched by the patterns: #{patterns.join(' ')}"
      end

      matched_files.reject { |file| @config.excluded_file?(file) }
    end
996462
public static WildcardPatternMatcher compile(String patterns) {
		if(patterns == null || patterns.isEmpty()) {
			return matchNone;
		} else {
			List<String> list = StringUtility.splitStringCommaSpace(patterns);
			// Match none shortcut
			if(list.isEmpty()) return matchNone;

			// Parse into a series of individual matchers
			final List<WildcardPatternMatcher> matchers = new ArrayList<>(list.size());
			for(String pattern : list) {
				int end = pattern.length();
				if(end > 0) {
					// Beginning wildcards
					int pos = 0;
					final boolean startsWildcard;
					if(pattern.charAt(0) == '*') {
						startsWildcard = true;
						pos++;
						// Skip consecutive beginning
						while(pos < end && pattern.charAt(pos) == '*') pos++;
						if(pos >= end) {
							// Is any number of '*' only, matchAll shortcut
							return matchAll;
						}
					} else {
						startsWildcard = false;
					}
					// Ending wildcards
					final boolean endsWildcard;
					if(pattern.charAt(end - 1) == '*') {
						endsWildcard = true;
						end--;
						// Skip consecutive ending
						while(end > pos && pattern.charAt(end - 1) == '*') end--;
						assert end > pos;
					} else {
						endsWildcard = false;
					}
					// Split the remaining pattern on any internal '*'
					final List<String> sequences = new ArrayList<>();
					while(pos < end) {
						assert pattern.charAt(pos) != '*';
						int starPos = pattern.indexOf('*', pos + 1);
						if(starPos == -1 || starPos >= end) {
							// Not more '*' found
							sequences.add(pattern.substring(pos, end));
							pos = end;
						} else {
							// Found
							sequences.add(pattern.substring(pos, starPos));
							pos = starPos + 1;
							// Skip consecutive
							while(pos < end && pattern.charAt(pos) == '*') pos++;
						}
					}
					int seqCount = sequences.size();
					assert seqCount >= 1;
					if(seqCount == 1) {
						final String sequence = sequences.get(0);
						if(startsWildcard) {
							if(endsWildcard) {
								// *infix*
								matchers.add(
									new WildcardPatternMatcher() {
										@Override
										public boolean isMatch(String paramName) {
											return paramName.contains(sequence);
										}
									}
								);
							} else {
								// *suffix
								matchers.add(
									new WildcardPatternMatcher() {
										@Override
										public boolean isMatch(String paramName) {
											return paramName.endsWith(sequence);
										}
									}
								);
							}
						} else {
							if(endsWildcard) {
								// prefix*
								matchers.add(
									new WildcardPatternMatcher() {
										@Override
										public boolean isMatch(String paramName) {
											return paramName.startsWith(sequence);
										}
									}
								);
							} else {
								// exact
								matchers.add(
									new WildcardPatternMatcher() {
										@Override
										public boolean isMatch(String paramName) {
											return paramName.equals(sequence);
										}
									}
								);
							}
						}
					} else {
						matchers.add(
							new WildcardPatternMatcher() {
								@Override
								public boolean isMatch(String paramName) {
									int index = 0;
									int indexEnd = sequences.size();
									int pos = 0;
									int end = paramName.length();
									// Handle non-wildcard start
									if(!startsWildcard) {
										String prefix = sequences.get(0);
										if(!paramName.startsWith(prefix)) {
											return false;
										}
										index++;
										pos += prefix.length();
									}
									// Handle non-wildcard end
									if(!endsWildcard) {
										indexEnd--;
										String suffix = sequences.get(indexEnd);
										if(!paramName.endsWith(suffix)) {
											return false;
										}
										end -= suffix.length();
									}
									// Check if overlapping prefix and suffix matches
									if(end < pos) return false;
									// Handle any remaining infixes
									while(index < indexEnd) {
										String sequence = sequences.get(index++);
										int sequenceLen = sequence.length();
										assert sequenceLen > 0;
										int foundAt = paramName.indexOf(sequence, pos);
										if(foundAt == -1 || foundAt > (end - sequenceLen)) {
											return false;
										}
										pos += sequenceLen;
									}
									return true;
								}
							}
						);
					}
				}
			}
			if(matchers.isEmpty()) {
				return matchNone;
			}
			if(matchers.size() == 1) return matchers.get(0);
			return new WildcardPatternMatcher() {
				@Override
				public boolean isMatch(String paramName) {
					for(WildcardPatternMatcher matcher : matchers) {
						if(matcher.isMatch(paramName)) return true;
					}
					return false;
				}
			};
		}
	}
1000691
function and(matches, pattern, file) {
  var categories = pattern.categories.concat()
  var note = pattern.note
  var id = pattern.id
  var length = matches.length
  var index = -1
  var phrases = []
  var suggestions = []
  var match
  var position
  var siblings
  var first

  while (++index < length) {
    match = matches[index]
    siblings = match.parent.children
    position = categories.indexOf(match.type)

    if (position !== -1) {
      categories.splice(position, 1)
      phrases.push(toString(siblings.slice(match.start, match.end + 1)))
      suggestions.push(byValue(pattern.considerate, match.type))

      if (!first) {
        first = match.nodes[0]
      }

      if (categories.length === 0) {
        warn(
          file,
          id,
          phrases,
          suggestions,
          first,
          note,
          pattern.condition,
          ' / '
        )
      }
    }
  }
}
1152819
protected static boolean matches( String text , String pattern , boolean ignoreCase )
    {
        if (text == null)
            return false;
        if (pattern.length() == 0)
            return text.length() == 0;
        
        int textPos = 0;
        boolean startWithAny = false;
        StringTokenizer st = new StringTokenizer(pattern,"*?",true);
        while (st.hasMoreTokens())
        {
            String subPattern = st.nextToken();
            
            if (subPattern.equals("*"))
            {
                startWithAny = true;
            }
            else
            if (subPattern.equals("?"))
            {
                if (textPos < text.length())
                    textPos++;
                else
                    return false;
            }
            else
            {
                if (startWithAny)
                {
                    textPos = indexOf(text,subPattern,textPos,ignoreCase);
                    if (textPos == -1) return false;
                    startWithAny = false;
                }
                else
                {
                    if (!startsWith(text,subPattern,textPos,ignoreCase))
                        return false;
                }
                textPos += subPattern.length();
            }
        }
        
        // Remaining text
        if (textPos < text.length())
            if (!startWithAny)
                return false;
        
        return true;
    }
473528
function globs(sourcePath, ignore, commands, done) {
  var expression = /\$g\[(.+?)\]/g;
  var result = [];
  each(commands, function(command, next) {
    var map = {};
    var match;
    var matches = [];
    while ((match = expression.exec(command))) matches.push(match);
    each(matches, function(patternMatch, next) {
      find(patternMatch[1], sourcePath, ignore, function(err, relativePaths) {
        if (err) return next(err);
        map[patternMatch[1]] = relativePaths;
        next();
      });
    }, function(err) {
      if (err) return next(err);
      result.push(command.replace(expression, function(match, matchKey) {
        return map[matchKey].join(' ');
      }));
      next();
    });
  }, function(err) {
    if (err) return done(err);
    done(undefined, result);
  });
}
93181
def match(self, filename):
        

        try:
            for regex, patterns in self._regex_patterns:
                match = regex.match(filename)

                debug_template = "%s against %s: %%s" % (filename, regex._real_regex.pattern)

                if match:
                    if self.debug:
                        logger.info(debug_template % "hit")
                    return patterns[match.lastindex -1]

                if self.debug:
                    logger.info(debug_template % "miss")

        except Exception as e:
            # We can't show the default e.msg to the user as thats for
            # the combined pattern we sent to regex. Instead we indicate to
            # the user that an ignore file needs fixing.
            logger.error('Invalid pattern found in regex: %s.', e.msg)
            e.msg = "File ~/.bazaar/ignore or .bzrignore contains error(s)."
            bad_patterns = ''
            for _, patterns in self._regex_patterns:
                for p in patterns:
                    if not Globster.is_pattern_valid(p):
                        bad_patterns += ('\n  %s' % p)
            e.msg += bad_patterns
            raise e
        

        return None
248295
function pattern(toMatch) {
  var regexps = getQMarkPaths(toMatch, [])

  //reassign array to compiled regular expressions
  regexps.forEach(function(aPath, ix) {
    regexps[ix] = compile(aPath, true).regexp //'true' tells regexp compiler to math till end => '$'
  })


  if (regexps.length === 1) { //fast case
    var reg = regexps[0]
    return reg.test.bind(reg)
  } else { //test each potential path
    return function (testAgainst) {
      for (var i = 0; i < regexps.length; i++) {
        if (regexps[i].test(testAgainst)) return true
      }

      return false
    }
  }
}
920124
def is_file_ignored(opts, fname):
    '''
    
    '''
    if opts['file_ignore_regex']:
        for regex in opts['file_ignore_regex']:
            if re.search(regex, fname):
                log.debug(
                    'File matching file_ignore_regex. Skipping: %s',
                    fname
                )
                return True

    if opts['file_ignore_glob']:
        for glob in opts['file_ignore_glob']:
            if fnmatch.fnmatch(fname, glob):
                log.debug(
                    'File matching file_ignore_glob. Skipping: %s',
                    fname
                )
                return True
    return False
207529
function simple(matches, pattern, file) {
  var note = pattern.note
  var id = pattern.id
  var length = matches.length
  var index = -1
  var match
  var nodes

  while (++index < length) {
    match = matches[index]
    nodes = match.nodes

    warn(
      file,
      id,
      toString(nodes),
      pattern.considerate,
      nodes[0],
      note,
      pattern.condition
    )
  }
}
1312910
public static boolean matchAny(final String pattern, final String[] candidate, boolean ignoreCase) {

        for (int i = 0; i < candidate.length; i++) {
            final String string = candidate[i];
            if (match(pattern, string, ignoreCase)) {
                return true;
            }
        }

        return false;
    }
1013416
function isIgnoringFiles(path){
    if (!ignoring_files.length) return false;

    for (var i = 0, l = ignoring_files.length; i < l; i++){
        if (minimatch(path, ignoring_files[i])) return true;
    }

    return false;
}
82027
function(pattern, callback) {
    glob(pattern, opts, function(err, globbedFiles) {
      if (isArray(globbedFiles) && globbedFiles.length && !err) {
        callback(null, globbedFiles);
      }
      else {
        console.error('The glob pattern ' + JSON.stringify(pattern) + ' did not match any files!');
        callback(null, []);
      }
    });
  }
598241
function (filename, types) {
    types = types.split(',');
    var pattern = '\.(';
    for (var i = 0; i < types.length; i++) {
        if (0 != i) {
            pattern += '|';
        }
        pattern += types[i].trim();
    }
    pattern += ')$';
    return new RegExp(pattern, 'i').test(filename);
}
902131
public CharSequence matchesPattern(final CharSequence input, final String pattern, final String message) {
        if (!Pattern.matches(pattern, input)) {
            fail(message);
        }
        return input;
    }
838701
function(patterns) {
        var results = [],
            processed = {},
            options = this.options,
            fileCache = this._fileCache,
            ignoredPaths = new IgnoredPaths(options),
            globOptions,
            stats,
            startTime,
            prevConfig; // the previous configuration used

        startTime = Date.now();

        globOptions = {
            nodir: true
        };

        var cwd = options.cwd || process.cwd;
        patterns = this.resolveFileGlobPatterns(patterns.map(function(pattern) {
            if (pattern.indexOf("/") > 0) {
                return path.join(cwd, pattern);
            }
            return pattern;
        }));


        /**
         * Executes the linter on a file defined by the `filename`. Skips
         * unsupported file extensions and any files that are already linted.
         * @param {string} filename The resolved filename of the file to be linted
         * @param {boolean} warnIgnored always warn when a file is ignored
         * @returns {void}
         */
        function executeOnFile(filename, warnIgnored) {
            var hashOfConfig;

            if (options.ignore !== false) {

                if (ignoredPaths.contains(filename, "custom")) {
                    if (warnIgnored) {
                        results.push(createIgnoreResult(filename));
                    }
                    return;
                }

                if (ignoredPaths.contains(filename, "default")) {
                    return;
                }

            }

            filename = path.resolve(filename);
            if (processed[filename]) {
                return;
            }

            if (options.cache) {
                // get the descriptor for this file
                // with the metadata and the flag that determines if
                // the file has changed
                var descriptor = fileCache.getFileDescriptor(filename);
                var meta = descriptor.meta || {};

                var changed = descriptor.changed;
                if (!changed) {
                    debug("Skipping file since hasn't changed: " + filename);

                    // Adding the filename to the processed hashmap
                    // so the reporting is not affected (showing a warning about .bemlintignore being used
                    // when it is not really used)

                    processed[filename] = true;

                    // Add the the cached results (always will be 0 error and 0 warnings)
                    // cause we don't save to cache files that failed
                    // to guarantee that next execution will process those files as well
                    results.push(descriptor.meta.results);

                    // move to the next file
                    return;
                }
            }

            debug("Processing " + filename);

            processed[filename] = true;

            var res = processFile(filename, options);

            if (options.cache) {
                // if a file contains errors or warnings we don't want to
                // store the file in the cache so we can guarantee that
                // next execution will also operate on this file
                if ( res.errorCount > 0 || res.warningCount > 0 ) {
                    debug("File has problems, skipping it: " + filename);
                    // remove the entry from the cache
                    fileCache.removeEntry( filename );
                } else {
                    // since the file passed we store the result here
                    // TODO: check this as we might not need to store the
                    // successful runs as it will always should be 0 error 0 warnings
                    descriptor.meta.results = res;
                }
            }

            results.push(res);
        }

        patterns.forEach(function(pattern) {

            var file = path.resolve(pattern);

            if (shell.test("-f", file)) {
                executeOnFile(fs.realpathSync(pattern), !shell.test("-d", file));
            } else {
                glob.sync(pattern, globOptions).forEach(function(globMatch) {
                    executeOnFile(globMatch, false);
                });
            }

        });

        stats = calculateStatsPerRun(results);

        if (options.cache) {
            // persist the cache to disk
            fileCache.reconcile();
        }

        debug("Linting complete in: " + (Date.now() - startTime) + "ms");

        return {
            results: results,
            errorCount: stats.errorCount,
            warningCount: stats.warningCount
        };
    }
589873
public static Pattern createFilePattern(String filePattern) {
      filePattern = StringUtils.isNullOrBlank(filePattern) ? "\\*" : filePattern;
      filePattern = filePattern.replaceAll("\\.", "\\.");
      filePattern = filePattern.replaceAll("\\*", ".*");
      return Pattern.compile("^" + filePattern + "$");
   }