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) { |
|
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 = {}; |
|
0 ignored issues
–
show
|
|||
29 | |||
30 | 738 | this.adapters[name] = func; |
|
31 | |||
32 | 738 | return this; |
|
33 | } |
||
34 |
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.