-
Notifications
You must be signed in to change notification settings - Fork 8
/
css-in-head.js
41 lines (31 loc) · 1.03 KB
/
css-in-head.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
/**
* @file rule: css-in-head
* @author nighca<nighca@live.cn>
*/
module.exports = {
name: 'css-in-head',
desc: 'All css contents are recommended to be imported in <head>.',
lint: function (getCfg, document, reporter) {
var head = document.querySelector('head');
document.querySelectorAll('link[rel="stylesheet"], style').forEach(function (css) {
if (!getCfg(css)) {
return;
}
if (!(head && head.contains(css))) {
reporter.warn(css.startIndex, '008', 'CSS contents are recommended to be imported in <head>.');
}
});
},
format: function (getCfg, document, options) {
if (!getCfg()) {
return;
}
var head = document.querySelector('head');
head && document.querySelectorAll('link[rel="stylesheet"], style').forEach(function (css) {
if (!getCfg(css) || head.contains(css)) {
return;
}
head.appendChild(css);
});
}
};