| 2 | import { FormatterCallback } from '../formatter' |
| 3 | |
| 4 | const unixFormatter: FormatterCallback = function ( |
| 5 | formatter, |
| 6 | HTMLHint, |
| 7 | options |
| 8 | ) { |
| 9 | const nocolor = options.nocolor |
| 10 | |
| 11 | const chalkInstance = |
| 12 | nocolor !== false ? new chalk.Instance({ level: 1 }) : chalk |
| 13 | |
| 14 | formatter.on('file', (event) => { |
| 15 | event.messages.forEach((message) => { |
| 16 | console.log( |
| 17 | [ |
| 18 | event.file, |
| 19 | message.line, |
| 20 | message.col, |
| 21 | ` ${message.message} [${message.type}/${message.rule.id}]`, |
| 22 | ].join(':') |
| 23 | ) |
| 24 | }) |
| 25 | }) |
| 26 | |
| 27 | formatter.on('end', (event) => { |
| 28 | const allHintCount = event.allHintCount |
| 29 | if (allHintCount > 0) { |
| 30 | console.log('') |
| 31 | const message = '%d problems' |
| 32 | console.log( |
| 33 | nocolor ? message : chalkInstance.red(message), |
| 34 | event.allHintCount |
| 35 | ) |
| 36 | } |
| 37 | }) |
| 38 | } |
| 39 | |
| 40 | module.exports = unixFormatter |