-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathexample-html-hint.js
More file actions
58 lines (50 loc) · 1.67 KB
/
example-html-hint.js
File metadata and controls
58 lines (50 loc) · 1.67 KB
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
52
53
54
55
56
57
58
const gfmCodeBlocks = require('gfm-code-blocks')
const htmlHint = require('htmlhint')
const describeRule = require('../../test-utils/describe-rule')
const htmlHintRules = {
// 'ON'
'tagname-lowercase': true,
'attr-lowercase': true,
'attr-value-double-quotes': true,
'attr-no-duplication': true,
'tag-pair': true,
'spec-char-escape': true,
'id-unique': true,
'src-not-empty': true,
'title-require': true,
'alt-require': true,
'attr-unsafe-chars': true,
// 'OFF'
'doctype-first': false,
'doctype-html5': false,
'attr-value-not-empty': false,
'style-disabled': false,
'inline-style-disabled': false,
'inline-script-disabled': false,
'id-class-ad-disabled': false,
'href-abs-or-rel': false,
'space-tab-mixed-disabled': false,
'head-script-disabled': false,
'id-class-value': false,
'empty-tag-not-self-closed': false,
}
describeRule('testcases', ruleData => {
const { frontmatter, body } = ruleData
const { id, name, htmlHintIgnore = [] } = frontmatter
const codeBlocks = gfmCodeBlocks(body)
const codeSnippets = codeBlocks.filter(({ block }) => /html/gm.test(block.substring(0, 25))).map(({ code }) => code)
test.each(codeSnippets)('is valid HTML code - `%s`', snippet => {
const rules = { ...htmlHintRules }
/**
* Ignore `rules` specified in frontmatter of certain rules (if any)
*/
htmlHintIgnore.forEach(ignoreRule => (rules[ignoreRule] = false))
const errors = htmlHint.HTMLHint.verify(snippet, rules)
if (errors.length) {
console.log(`Rule Name: ${name} \n`)
console.log(`Rule Id: ${id} \n`)
console.table(errors.map(({ message, raw, line, col, rule }) => ({ message, raw, line, col, rule: rule.id })))
}
expect(errors.length).toEqual(0)
})
})