all files / htmlcs/lib/rules/ img-width-height.js

100% Statements 12/12
100% Branches 10/10
100% Functions 2/2
100% Lines 12/12
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                      103× 124× 98×     26× 26×   26× 13×   13×   11×              
/**
 * @file rule: img-width-height
 * @author nighca<nighca@live.cn>
 */
 
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.');
            }
        });
 
    }
 
};