Code coverage report for htmlcs/lib/rules/img-width-height.js

Statements: 100% (12 / 12)      Branches: 100% (10 / 10)      Functions: 100% (2 / 2)      Lines: 100% (12 / 12)      Ignored: none     

All files » htmlcs/lib/rules/ » 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          1             37 36     1 8 8   8 3 5 2 3 2              
/**
 * @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 (enable, document, reporter) {
        if (!enable) {
            return;
        }
 
        document.querySelectorAll('img').forEach(function (img) {
            var width = img.getAttribute('width');
            var height = img.getAttribute('height');
 
            if (!width && !height) {
                reporter.warn(img, '015', 'Attribute "width" & "height" of <img> is recommended to be set.');
            } else if (!width) {
                reporter.warn(img, '016', 'Attribute "width" of <img> is recommended to be set.');
            } else if (!height) {
                reporter.warn(img, '017', 'Attribute "height" of <img> is recommended to be set.');
            }
        });
 
    }
 
};