Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed May 29, 2017
1 parent 8d217f5 commit 0f65651
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 108 deletions.
34 changes: 9 additions & 25 deletions index.js
Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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;
};

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 1 addition & 11 deletions lib/compilers.js
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions lib/parsers.js
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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});
}
73 changes: 8 additions & 65 deletions lib/utils.js
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
};

/**
Expand All @@ -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
*/
Expand All @@ -135,26 +119,15 @@ 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`
* @returns {String}
*/

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, '');
};

/**
Expand Down Expand Up @@ -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`
Expand All @@ -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
Expand Down Expand Up @@ -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}
Expand Down
8 changes: 5 additions & 3 deletions package.json
Expand Up @@ -104,14 +104,14 @@
]
},
"files": [
"gulpfile.js",
"examples/*.js",
"gulpfile.js",
"test/**/*.js"
]
}
},
"verb": {
"toc": true,
"toc": "collapsible",
"layout": "default",
"tasks": [
"readme"
Expand All @@ -138,7 +138,9 @@
"extglob",
"glob-object",
"minimatch",
"snapdragon"
"multimatch",
"snapdragon",
"expand-brackets"
]
}
}

0 comments on commit 0f65651

Please sign in to comment.