/** * Creates the function which checks whether a file path is matched with the given pattern or not. * * @param {string[]} includePatterns - The glob patterns to include files. * @param {string[]} excludePatterns - The glob patterns to exclude files. * @returns {function} Created predicate function. */ function createMatch(includePatterns, excludePatterns) { const include = includePatterns.map(pattern => new Minimatch(pattern)) const exclude = excludePatterns.map(pattern => new Minimatch(pattern)) return filePath => include.some(m => m.match(filePath)) && !exclude.some(m => m.match(filePath)) }
/** @typedef {import("../util/import-target")} ImportTarget */ /** * @typedef {Object} DefinitionData * @property {string | string[]} name The name to disallow. * @property {string} [message] The custom message to show. */ /** * Check if matched or not. * @param {InstanceType<Minimatch>} matcher The matcher. * @param {boolean} absolute The flag that the matcher is for absolute paths. * @param {ImportTarget} importee The importee information. */ function match(matcher, absolute, { filePath, name }) { if (absolute) { return filePath != null && matcher.match(filePath) } return matcher.match(name) }
wrapArgs(function (args) { if (args.length === 0) return function (msg) { return msg.type === "document"; }; args = args.map(function (name) { if (name instanceof String) { var mm = new Minimatch(name); return function (n) { return mm.match(n); }; } if (name instanceof RegExp) { return function (n) { return name.test(n); }; } throw new Error("Command names must be String or RegExp"); }); return function (msg) { if (!(msg.type === "document" && msg.filename)) return false; if (args.length === 0) return true; for (var n = 0; n < args.length; n++) if (args[n](msg.filename)) return true; }; })