(tree, sectionName)
| 21 | } |
| 22 | |
| 23 | function getHook(tree, sectionName) { |
| 24 | const section = getSection(tree, sectionName); |
| 25 | |
| 26 | if (section.length === 0) return; |
| 27 | if (section.length > 1) |
| 28 | throw Error( |
| 29 | `# ${sectionName} section must only contain a single code block` |
| 30 | ); |
| 31 | |
| 32 | const codeNode = section[0]; |
| 33 | |
| 34 | if (codeNode.type !== 'code') |
| 35 | throw Error(`# ${sectionName} section must contain a code block`); |
| 36 | if (codeNode.lang !== 'javascript' && codeNode.lang !== 'js') |
| 37 | throw Error(`# ${sectionName} hook must be written in JavaScript`); |
| 38 | |
| 39 | return codeNode.value; |
| 40 | } |
| 41 | |
| 42 | module.exports = plugin; |
no test coverage detected