()
| 95 | * or match the case of the source file |
| 96 | */ |
| 97 | function assertSrcContents() { |
| 98 | var logs = []; |
| 99 | |
| 100 | // require'd built-in modules |
| 101 | var BUILTINS = ['events']; |
| 102 | |
| 103 | var getComputedStyleCnt = 0; |
| 104 | |
| 105 | glob(combineGlobs([srcGlob, libGlob])).then((files) => { |
| 106 | files.forEach(function(file) { |
| 107 | var code = fs.readFileSync(file, 'utf-8'); |
| 108 | |
| 109 | // parse through code string while keeping track of comments |
| 110 | var comments = []; |
| 111 | falafel(code, { ecmaVersion: 'latest', locations: true, onComment: comments }, function(node) { |
| 112 | // look for .classList |
| 113 | if(node.type === 'MemberExpression') { |
| 114 | var source = node.source(); |
| 115 | if(source === 'window.getComputedStyle') { |
| 116 | getComputedStyleCnt++; |
| 117 | } |
| 118 | } else if(node.type === 'Identifier' && node.source() === 'getComputedStyle') { |
| 119 | if(node.parent.source() !== 'window.getComputedStyle') { |
| 120 | logs.push(file + ' : getComputedStyle must be called as a `window` property.'); |
| 121 | } |
| 122 | } else if(node.type === 'CallExpression' && node.callee.name === 'require') { |
| 123 | var pathNode = node.arguments[0]; |
| 124 | var pathStr = pathNode.value; |
| 125 | if(pathNode.type !== 'Literal') { |
| 126 | logs.push(file + ' : You may only `require` literals.'); |
| 127 | } else if(BUILTINS.indexOf(pathStr) === -1) { |
| 128 | // node version 8.9.0+ can use require.resolve(request, {paths: [...]}) |
| 129 | // and avoid this explicit conversion to the current location |
| 130 | if(pathStr.charAt(0) === '.') { |
| 131 | pathStr = path.relative(__dirname, path.join(path.dirname(file), pathStr)); |
| 132 | } |
| 133 | var fullPath = require.resolve(pathStr); |
| 134 | var casedPath = trueCasePath(fullPath); |
| 135 | |
| 136 | if(fullPath !== trueCasePath(fullPath)) { |
| 137 | logs.push(file + ' : `require` path is not case-correct:\n' + |
| 138 | fullPath + ' -> ' + casedPath); |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | }); |
| 143 | }); |
| 144 | |
| 145 | /* |
| 146 | * window.getComputedStyle calls are restricted, so we want to be |
| 147 | * explicit about it whenever we add or remove these calls. This is |
| 148 | * the reason d3.selection.style is forbidden as a getter. |
| 149 | * |
| 150 | * The rule is: |
| 151 | * - You MAY NOT call getComputedStyle during rendering a plot, EXCEPT |
| 152 | * in calculating autosize for the plot (which only makes sense if |
| 153 | * the plot is displayed). Other uses of getComputedStyle while |
| 154 | * rendering will fail, at least in Chrome, if the plot div is not |
no test coverage detected
searching dependent graphs…