-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathrel-stylesheet.js
More file actions
37 lines (28 loc) · 930 Bytes
/
Copy pathrel-stylesheet.js
File metadata and controls
37 lines (28 loc) · 930 Bytes
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
/**
* @file rule: rel-stylesheet
* @author nighca<nighca@live.cn>
*/
module.exports = {
name: 'rel-stylesheet',
desc: 'Attribute "rel" of <link> should be set as "stylesheet".',
lint: function (getCfg, document, reporter) {
document.querySelectorAll('link').forEach(function (element) {
if (!getCfg(element)) {
return;
}
if (!element.getAttribute('rel')) {
reporter.warn(element.startIndex, '022', 'Attribute "rel" of <link> should be set as "stylesheet".');
}
});
},
format: function (getCfg, document, options) {
document.querySelectorAll('link').forEach(function (element) {
if (!getCfg(element)) {
return;
}
if (!element.getAttribute('rel')) {
element.setAttribute('rel', 'stylesheet');
}
});
}
};