Code coverage report for htmlcs/lib/rules/bool-attribute-value.js

Statements: 100% (8 / 8)      Branches: 100% (4 / 4)      Functions: 100% (3 / 3)      Lines: 100% (8 / 8)      Ignored: none     

All files » htmlcs/lib/rules/ » bool-attribute-value.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          1                 1             37 36     1 19 494 6              
/**
 * @file rule: bool-attribute-value
 * @author nighca<nighca@live.cn>
 */
 
var booleanAttributes = [
    'allowfullscreen', 'async', 'autofocus', 'autoplay',
    'checked', 'controls', 'default', 'defer',
    'disabled', 'formnovalidate', 'hidden', 'ismap',
    'itemscope', 'loop', 'multiple', 'muted', 'novalidate',
    'open', 'readonly', 'required', 'reversed',
    'scoped', 'seamless', 'selected', 'sortable', 'typemustmatch'
];
 
module.exports = {
 
    name: 'bool-attribute-value',
 
    desc: 'Value of boolean attributes should not be set.',
 
    lint: function (enable, document, reporter) {
        if (!enable) {
            return;
        }
 
        document.querySelectorAll('*').forEach(function (element) {
            booleanAttributes.forEach(function (attribute) {
                if (element.getAttribute(attribute)) {
                    reporter.warn(element, '003', 'Value of boolean attribute "' + attribute + '" should not be set.');
                }
            });
        });
    }
 
};