-
Notifications
You must be signed in to change notification settings - Fork 8
/
spec-char-escape.js
45 lines (34 loc) · 1.05 KB
/
spec-char-escape.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
/**
* @file rule: spec-char-escape
* @author nighca<nighca@live.cn>
*/
module.exports = {
name: 'spec-char-escape',
desc: 'Special characters must be escaped..',
target: 'parser',
lint: function (getCfg, parser, reporter) {
var specialChars = ['<', '>'];
// exclude-tags
var excludeTags = ['script', 'style'];
parser.on('text', function (data) {
if (!getCfg()) {
return;
}
var currentTag = this._stack[this._stack.length - 1];
// if should be excluded
if (excludeTags.indexOf(currentTag) >= 0) {
return;
}
// check for special chars
for (var i = 0, l = data.length; i < l; i++) {
if (specialChars.indexOf(data[i]) >= 0) {
reporter.warn(
this.startIndex + i,
'033',
'Special characters must be escaped.'
);
}
}
});
}
};