-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathself-close.js
60 lines (48 loc) · 1.56 KB
/
self-close.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
52
53
54
55
56
57
58
59
60
/**
* @file rule: self-close
* @author nighca<[email protected]>
*/
// http://www.w3.org/TR/html5/syntax.html#elements-0
var voidTags = [
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'
];
module.exports = {
name: 'self-close',
desc: 'Should void tags close themeselves with "/".',
target: 'parser',
lint: function (getCfg, parser, reporter) {
var tokenizer = parser.tokenizer;
var current;
tokenizer.on('opentagname', function (name) {
current = {
pos: this._sectionStart - 1,
tag: name.toLowerCase()
};
});
tokenizer.on('opentagend', function () {
if (!current || voidTags.indexOf(current.tag) < 0) {
return;
}
var cfg = getCfg();
var selfClosed = this._buffer[this._index - 1] === '/';
if (selfClosed && cfg === 'no-close') {
reporter.warn(
current.pos,
'039',
'Void tags should not close themeselves with "/".'
);
}
if (!selfClosed && cfg === 'close') {
reporter.warn(
current.pos,
'040',
'Void tags should close themeselves with "/".'
);
}
});
},
format: function (getCfg, document, options) {
options['self-close'] = {close: 'close'}[getCfg()] || 'no-close';
}
};