Issues (117)

lib/patternlibrary/list-patterns.js (1 issue)

1
/**
2
 * retrieve current pattern-library data
3
 */
4 View Code Duplication
function getPatterns ( type_or_category ) { 
5 225
    if (type_or_category) {
6 125
        var patterns = {};
7 125
        for (var patternkey in this.data.patterns) {
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
            var pattern = this.data.patterns[patternkey];
9 2
            if ( 
10
                ( String(patternkey).indexOf(type_or_category) != -1 ) ||
11
                ( pattern.pattern.categories && ( pattern.pattern.categories.indexOf(type_or_category) != -1 ) )
12
            ) {
13
                patterns[patternkey] = pattern;                
14
            }
15
        }
16 125
        return patterns;
17
    }
18
    
19 100
    return this.data.patterns; 
20
21
}
22
23
module.exports = getPatterns;