| 1 | import { FormatterCallback } from '../formatter' |
| 2 | |
| 3 | const markdownFormatter: FormatterCallback = function (formatter, HTMLHint) { |
| 4 | formatter.on('end', (event) => { |
| 5 | console.log('# TOC') |
| 6 | |
| 7 | const arrToc: string[] = [] |
| 8 | const arrContents: string[] = [] |
| 9 | const arrAllMessages = event.arrAllMessages |
| 10 | |
| 11 | arrAllMessages.forEach((fileInfo) => { |
| 12 | const filePath = fileInfo.file |
| 13 | const arrMessages = fileInfo.messages |
| 14 | let errorCount = 0 |
| 15 | let warningCount = 0 |
| 16 | |
| 17 | arrMessages.forEach((message) => { |
| 18 | if (message.type === 'error') { |
| 19 | errorCount++ |
| 20 | } else { |
| 21 | warningCount++ |
| 22 | } |
| 23 | }) |
| 24 | |
| 25 | arrToc.push(` - [${filePath}](#${filePath})`) |
| 26 | arrContents.push(`<a name="${filePath}" />`) |
| 27 | arrContents.push(`# ${filePath}`) |
| 28 | arrContents.push('') |
| 29 | arrContents.push(`Found ${errorCount} errors, ${warningCount} warnings`) |
| 30 | |
| 31 | const arrLogs = HTMLHint.format(arrMessages) |
| 32 | arrContents.push('') |
| 33 | arrLogs.forEach((log) => { |
| 34 | arrContents.push(` ${log}`) |
| 35 | }) |
| 36 | arrContents.push('') |
| 37 | }) |
| 38 | |
| 39 | console.log(`${arrToc.join('\r\n')}\r\n`) |
| 40 | console.log(arrContents.join('\r\n')) |
| 41 | }) |
| 42 | } |
| 43 | |
| 44 | module.exports = markdownFormatter |