-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (37 loc) · 1.2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// ------------------------------------
// #POSTHTML - HINT
// ------------------------------------
'use strict'
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const tab = require('text-table')
const log = require('log-symbols')
const render = require('posthtml-render')
const htmlhint = require('htmlhint').HTMLHint
const title = require('./lib/title')
const type = require('./lib/type')
const line = require('./lib/line')
const message = require('./lib/msg')
module.exports = function (options) {
options = options || {}
if (typeof options === 'string') {
options = fs.readFileSync(path.resolve(options), 'utf8')
}
return function postHTMLHint (tree) {
let messages = htmlhint.verify(render(tree), options)
title('\nPostHTML HINT')
const table = tab(messages.map(msg => [
`\n${type(msg.type)} ${line(msg.line, msg.col)}`,
`\n${message(msg.message)}`
]), { align: 'l', hsep: '' })
console.log(table)
const result = messages.length
if (result === 0) {
console.log(chalk.green(`${log.success} ${result} Errors`))
} else {
console.log(chalk.red(`\n${log.warning} ${result} Errors`))
}
return tree
}
}