-
Notifications
You must be signed in to change notification settings - Fork 0
/
html-validate.js
executable file
·42 lines (37 loc) · 1.17 KB
/
html-validate.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
const { readFile } = require('fs/promises')
const klaw = require('klaw')
const path = require('path')
const validator = require('html-validator')
const skipFiles = [
]
const skip = [
'Illegal character in query: “|” is not allowed.'
]
const validate = function (file) {
return readFile(file, { encoding: 'utf8' }).then((data) => {
const options = {
data: data,
format: 'json'
}
return validator(options)
}).then((results) => {
console.log('Validation results:', file)
results.messages.filter((entry) => {
return !skip.some(s => entry.message.includes(s))
}).map((entry) => {
return console.log(`${entry.type.toUpperCase()}: ${entry.message} (line: ${entry.lastLine})`)
})
console.log()
}).catch((err) => {
console.log('Failed to validate', file, err)
})
}
new Promise((resolve, reject) => {
const files = []
klaw('./public').on('data', (file) => {
const skipFile = skipFiles.some(s => s === path.relative(process.cwd(), file.path))
return file.path.endsWith('.html') && !skipFile ? files.push(file.path) : null
}).on('end', () => resolve(files))
}).then((files) => {
Promise.all(files.map(validate))
})