Issues (117)

lib/patternlibrary/adapter.js (1 issue)

1 1
var path = require('path');
2
3 1
module.exports = function(name, func) {
4
    // Load a built-in module if available
5 741
    if (typeof func === 'undefined') {
6 738
	    try {
7 738
	        func = require(path.join('../adapters/', name));
8
	    }
9
	    catch (e) {
10 1
	        throw new Error('"'+name+'" is not a built-in Patternlibrary adapter. '+e.message);
11
	    }
12
    }
13
14
    // Don't use one of the built-in meta terms
15 740
    var reserved = ['docs', 'fileName', '_adapterData'];
16 740
    for (var i in reserved) {
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...
17 2218
	    if (name === reserved[i]) {
18 1
	        throw new Error('"'+name+'" is a reserved keyword, and can\'t be used as the name of a Patternlibrary adapter.');
19
	    }
20
    }
21
22
    // Make sure the adapter is an object with both of the required methods.
23 739
    if (typeof func !== 'function') {
24 1
        throw new Error('Patternlibrary adapters must be functions.')
25
    }
26
27
    // If no config object exists, add it
28 738
    if (!func.config) func.config = {};
29
30 738
    this.adapters[name] = func;
31
32 738
    return this;
33
}
34