| 2 | import { FormatterCallback } from '../formatter' |
| 3 | |
| 4 | const defaultFormatter: FormatterCallback = function ( |
| 5 | formatter, |
| 6 | HTMLHint, |
| 7 | options |
| 8 | ) { |
| 9 | const nocolor = !!options.nocolor |
| 10 | |
| 11 | formatter.on('start', () => { |
| 12 | console.log('') |
| 13 | }) |
| 14 | |
| 15 | formatter.on('config', (event) => { |
| 16 | const configPath = event.configPath! |
| 17 | console.log( |
| 18 | ' Config loaded: %s', |
| 19 | nocolor ? configPath : chalk.cyan(configPath) |
| 20 | ) |
| 21 | console.log('') |
| 22 | }) |
| 23 | |
| 24 | formatter.on('file', (event) => { |
| 25 | console.log(` ${chalk.white(event.file)}`) |
| 26 | |
| 27 | const arrLogs = HTMLHint.format(event.messages, { |
| 28 | colors: !nocolor, |
| 29 | indent: 6, |
| 30 | }) |
| 31 | |
| 32 | arrLogs.forEach((str) => { |
| 33 | console.log(str) |
| 34 | }) |
| 35 | |
| 36 | console.log('') |
| 37 | }) |
| 38 | |
| 39 | formatter.on('end', (event) => { |
| 40 | const allFileCount = event.allFileCount |
| 41 | const allHintCount = event.allHintCount |
| 42 | const allHintFileCount = event.allHintFileCount |
| 43 | const time = event.time |
| 44 | let message |
| 45 | |
| 46 | if (allHintCount > 0) { |
| 47 | message = 'Scanned %d files, found %d errors in %d files (%d ms)' |
| 48 | console.log( |
| 49 | nocolor ? message : chalk.red(message), |
| 50 | allFileCount, |
| 51 | allHintCount, |
| 52 | allHintFileCount, |
| 53 | time |
| 54 | ) |
| 55 | } else { |
| 56 | message = 'Scanned %d files, no errors found (%d ms).' |
| 57 | console.log(nocolor ? message : chalk.green(message), allFileCount, time) |
| 58 | } |
| 59 | }) |
| 60 | } |
| 61 | |