Issues (117)

lib/util/filter-patterns.js (1 issue)

1
/**
2
 * retrieve filtered given list by type or category slug
3
 */
4 View Code Duplication
function filterPatterns ( type_or_category, data ) { 
5 2
    if (type_or_category) {
6 1
        var patterns = {};
7 1
        for (var patternkey in data) {
0 ignored issues
show
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
8 5
            var pattern = data[patternkey];
9 5
            if ( 
10
                ( String(patternkey).indexOf(type_or_category) != -1 ) ||
11
                ( pattern.pattern.categories && ( pattern.pattern.categories.indexOf(type_or_category) != -1 ) )
12
            ) {
13 4
                patterns[patternkey] = pattern;                
14
            }
15
        }
16 1
        return patterns;
17
    }
18
    
19 1
    return data; 
20
21
}
22
23
module.exports = filterPatterns;