-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathid-class-ad-disabled.js
43 lines (34 loc) · 1.21 KB
/
id-class-ad-disabled.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
/**
* @file rule: id-class-ad-disabled
* @author nighca<[email protected]>
*/
module.exports = {
name: 'id-class-ad-disabled',
desc: 'Id and class can not use ad-relative keyword, it will be blocked by adblock software.',
target: 'parser',
lint: function (getCfg, parser, reporter) {
parser.tokenizer.on('attribdata', function (value) {
var cfg = getCfg();
if (!cfg) {
return;
}
var name = parser._attribname;
var keywords = Array.isArray(cfg) ? cfg : ['ad'];
if (['id', 'class'].indexOf(name) >= 0) {
var pos = this._sectionStart;
var parts = value.split(/[\_\-]+/);
keywords.forEach(function (keyword) {
if (parts.indexOf(keyword) >= 0) {
reporter.warn(
pos,
'031',
'Id and class can not use ad-relative keyword ('
+ keyword
+ '), it will be blocked by adblock software.'
);
}
});
}
});
}
};