(filePath, extensions, attrPattern, scriptPattern)
| 138 | } |
| 139 | |
| 140 | function validateFile(filePath, extensions, attrPattern, scriptPattern) { |
| 141 | const content = fs.readFileSync(filePath, 'utf-8'); |
| 142 | const ext = path.extname(filePath); |
| 143 | const errors = []; |
| 144 | |
| 145 | if (ext === '._hs') { |
| 146 | // Entire file is hyperscript |
| 147 | parseAndCollect(content, 0, null); |
| 148 | } else { |
| 149 | // HTML-like file - extract regions |
| 150 | const regions = extractRegions(content, attrPattern, scriptPattern); |
| 151 | for (const region of regions) { |
| 152 | if (!region.source.trim()) continue; |
| 153 | parseAndCollect(region.source, region.offset, region); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | function parseAndCollect(source, offset, region) { |
| 158 | var result; |
| 159 | try { |
| 160 | result = _hyperscript.parse(source); |
| 161 | } catch (e) { |
| 162 | // Tokenizer can throw on unterminated strings, etc. |
| 163 | errors.push(formatError(filePath, content, { |
| 164 | message: e.message, |
| 165 | token: { start: 0, value: '', line: 1, column: 0 }, |
| 166 | }, offset, region)); |
| 167 | return; |
| 168 | } |
| 169 | if (result.errors?.length) { |
| 170 | for (const err of result.errors) { |
| 171 | errors.push(formatError(filePath, content, err, offset, region)); |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | return errors; |
| 176 | } |
| 177 | |
| 178 | // ===== Region extraction (adapted from tools/lsp/src/regions.js) ===== |
| 179 |
no test coverage detected