From 0f6565145d885b91efcc70917626ca608c0c45bf Mon Sep 17 00:00:00 2001 From: jonschlinkert Date: Mon, 29 May 2017 02:09:18 -0400 Subject: [PATCH] lint --- index.js | 34 ++++++---------------- lib/compilers.js | 12 +------- lib/parsers.js | 5 +--- lib/utils.js | 73 ++++++------------------------------------------ package.json | 8 ++++-- 5 files changed, 24 insertions(+), 108 deletions(-) diff --git a/index.js b/index.js index 6c9d8a89..9f0acacf 100644 --- a/index.js +++ b/index.js @@ -184,7 +184,7 @@ micromatch.isMatch = function(str, pattern, options) { }; /** - * Returns true if some of the elements in the given `list` match any of the + * Returns true if some of the strings in the given `list` match any of the * given glob `patterns`. * * ```js @@ -207,19 +207,17 @@ micromatch.some = function(list, patterns, options) { if (typeof list === 'string') { list = [list]; } - for (var i = 0; i < list.length; i++) { if (micromatch(list[i], patterns, options).length === 1) { return true; } } - return false; }; /** - * Returns true if every element in the given `list` matches - * at least one of the given glob `patterns`. + * Returns true if every string in the given `list` matches + * any of the given glob `patterns`. * * ```js * var mm = require('micromatch'); @@ -245,13 +243,11 @@ micromatch.every = function(list, patterns, options) { if (typeof list === 'string') { list = [list]; } - for (var i = 0; i < list.length; i++) { if (micromatch(list[i], patterns, options).length !== 1) { return false; } } - return true; }; @@ -297,8 +293,8 @@ micromatch.any = function(str, patterns, options) { }; /** - * Returns true if **all** of the given `patterns` - * match the specified string. + * Returns true if **all** of the given `patterns` match + * the specified string. * * ```js * var mm = require('micromatch'); @@ -327,11 +323,9 @@ micromatch.all = function(str, patterns, options) { if (typeof str !== 'string') { throw new TypeError('expected a string: "' + util.inspect(str) + '"'); } - if (typeof patterns === 'string') { patterns = [patterns]; } - for (var i = 0; i < patterns.length; i++) { if (!micromatch.isMatch(str, patterns[i], options)) { return false; @@ -478,12 +472,6 @@ micromatch.matchKeys = function(obj, patterns, options) { */ micromatch.matcher = function matcher(pattern, options) { - if (isEmptyString(pattern)) { - return function() { - return false; - } - } - if (Array.isArray(pattern)) { return compose(pattern, options, matcher); } @@ -552,10 +540,6 @@ micromatch.matcher = function matcher(pattern, options) { */ micromatch.makeRe = function(pattern, options) { - if (pattern instanceof RegExp) { - return pattern; - } - if (typeof pattern !== 'string') { throw new TypeError('expected pattern to be a string'); } @@ -763,11 +747,11 @@ micromatch.parse = function(pattern, options) { */ micromatch.compile = function(ast, options) { - return memoize('compile', ast.input, options, function() { - if (typeof ast === 'string') { - ast = micromatch.parse(ast, options); - } + if (typeof ast === 'string') { + ast = micromatch.parse(ast, options); + } + return memoize('compile', ast.input, options, function() { var snapdragon = utils.instantiate(ast, options); compilers(snapdragon, options); return snapdragon.compile(ast, options); diff --git a/lib/compilers.js b/lib/compilers.js index 016a330e..d39f27dd 100644 --- a/lib/compilers.js +++ b/lib/compilers.js @@ -7,8 +7,6 @@ module.exports = function(snapdragon) { var compilers = snapdragon.compiler.compilers; var opts = snapdragon.options; - snapdragon.state = snapdragon.state || {}; - // register nanomatch compilers snapdragon.use(nanomatch.compilers); @@ -46,15 +44,7 @@ module.exports = function(snapdragon) { .set('slash', slash) .set('qmark', qmark) .set('star', star) - .set('text', text) - - // customize end-of-string compiler - .set('eos', function(node) { - if (typeof eos === 'function') { - return eos.apply(this, arguments); - } - return this.emit(node.val, node); - }); + .set('text', text); }; function escapeExtglobs(compiler) { diff --git a/lib/parsers.js b/lib/parsers.js index 7edfa65e..f80498ce 100644 --- a/lib/parsers.js +++ b/lib/parsers.js @@ -4,7 +4,6 @@ var extglob = require('extglob'); var nanomatch = require('nanomatch'); var regexNot = require('regex-not'); var toRegex = require('to-regex'); -var cached; var not; /** @@ -78,9 +77,7 @@ module.exports = function(snapdragon) { */ function textRegex(pattern) { - if (cached) return cached; var notStr = regexNot.create(pattern, {contains: true, strictClose: false}); var prefix = '(?:[\\^]|\\\\|'; - var re = toRegex(prefix + notStr + ')', {strictClose: false}); - return (cached = re); + return toRegex(prefix + notStr + ')', {strictClose: false}); } diff --git a/lib/utils.js b/lib/utils.js index 962523be..0dc0982e 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -26,14 +26,6 @@ utils.isWindows = function() { return path.sep === '\\' || process.platform === 'win32'; }; -/** - * Return the last element from an array - */ - -utils.last = function(arr, n) { - return arr[arr.length - (n || 1)]; -}; - /** * Get the `Snapdragon` instance to use */ @@ -92,13 +84,13 @@ utils.createKey = function(pattern, options) { if (typeof options === 'undefined') { return pattern; } - var key = pattern; - for (var prop in options) { - if (options.hasOwnProperty(prop)) { - key += ';' + prop + '=' + String(options[prop]); - } + var val = pattern; + var keys = Object.keys(options); + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + val += ';' + key + '=' + String(options[key]); } - return key; + return val; }; /** @@ -119,14 +111,6 @@ utils.isString = function(val) { return typeof val === 'string'; }; -/** - * Return true if `val` is a non-empty string - */ - -utils.isRegex = function(val) { - return utils.typeOf(val) === 'regexp'; -}; - /** * Return true if `val` is a non-empty string */ @@ -135,14 +119,6 @@ utils.isObject = function(val) { return utils.typeOf(val) === 'object'; }; -/** - * Escape regex characters in the given string - */ - -utils.escapeRegex = function(str) { - return str.replace(/[-[\]{}()^$|*+?.\\\/\s]/g, '\\$&'); -}; - /** * Combines duplicate characters in the provided string. * @param {String} `str` @@ -150,11 +126,8 @@ utils.escapeRegex = function(str) { */ utils.combineDuplicates = function(str, val) { - if (typeof val === 'string') { - var re = new RegExp('(' + val + ')(?=(?:' + val + ')*\\1)', 'g'); - return str.replace(re, ''); - } - return str.replace(/(.)(?=.*\1)/g, ''); + var re = new RegExp('(' + val + ')(?=(?:' + val + ')*\\1)', 'g'); + return str.replace(re, ''); }; /** @@ -187,16 +160,6 @@ utils.unescape = function(str) { return utils.toPosixPath(str.replace(/\\(?=[*+?!.])/g, '')); }; -/** - * Strip the drive letter from a windows filepath - * @param {String} `fp` - * @return {String} - */ - -utils.stripDrive = function(fp) { - return utils.isWindows() ? fp.replace(/^[a-z]:[\\\/]+?/i, '/') : fp; -}; - /** * Strip the prefix from a filepath * @param {String} `fp` @@ -214,17 +177,6 @@ utils.stripPrefix = function(str) { return str; }; -/** - * Returns true if `str` is a common character that doesn't need - * to be processed to be used for matching. - * @param {String} `str` - * @return {Boolean} - */ - -utils.isSimpleChar = function(str) { - return str === '' || str === ' ' || str === '.'; -}; - /** * Returns true if the given str is an escaped or * unescaped path character @@ -324,15 +276,6 @@ utils.matchBasename = function(re) { }; }; -/** - * Returns the given value unchanced. - * @return {any} - */ - -utils.identity = function(val) { - return val; -}; - /** * Determines the filepath to return based on the provided options. * @return {any} diff --git a/package.json b/package.json index 7ea50928..4c78130a 100644 --- a/package.json +++ b/package.json @@ -104,14 +104,14 @@ ] }, "files": [ - "gulpfile.js", "examples/*.js", + "gulpfile.js", "test/**/*.js" ] } }, "verb": { - "toc": true, + "toc": "collapsible", "layout": "default", "tasks": [ "readme" @@ -138,7 +138,9 @@ "extglob", "glob-object", "minimatch", - "snapdragon" + "multimatch", + "snapdragon", + "expand-brackets" ] } }