-
Notifications
You must be signed in to change notification settings - Fork 8
/
img-width-height.js
34 lines (26 loc) · 1003 Bytes
/
img-width-height.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
/**
* @file rule: img-width-height
* @author nighca<[email protected]>
*/
module.exports = {
name: 'img-width-height',
desc: 'Attribute "width" & "height" of <img> is recommended to be set.',
lint: function (getCfg, document, reporter) {
document.querySelectorAll('img').forEach(function (img) {
if (!getCfg(img)) {
return;
}
var width = img.getAttribute('width');
var height = img.getAttribute('height');
if (!width && !height) {
reporter.warn(img.startIndex, '015', 'Attribute "width" & "height" of <img> is recommended to be set.');
}
else if (!width) {
reporter.warn(img.startIndex, '016', 'Attribute "width" of <img> is recommended to be set.');
}
else if (!height) {
reporter.warn(img.startIndex, '017', 'Attribute "height" of <img> is recommended to be set.');
}
});
}
};