Code coverage report for htmlcs/lib/rules/unique-id.js

Statements: 100% (14 / 14)      Branches: 80% (8 / 10)      Functions: 100% (3 / 3)      Lines: 100% (14 / 14)      Ignored: none     

All files » htmlcs/lib/rules/ » unique-id.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          1             37 36     1   1 6 6       1 4     1 3 3 3 1              
/**
 * @file rule: unique-id
 * @author nighca<nighca@live.cn>
 */
 
module.exports = {
 
    name: 'unique-id',
 
    desc: 'Id should be unique in page.',
 
    lint: function (enable, document, reporter) {
        if (!enable) {
            return;
        }
 
        var idMap = {};
 
        document.querySelectorAll('[id]').forEach(function (element) {
            Eif (element.id) {
                (idMap[element.id] = idMap[element.id] || []).push(element);
            }
        });
 
        var report = function (element) {
            reporter.warn(element, '026', 'Id should be unique in page.');
        };
 
        for (var id in idMap) {
            Eif (idMap.hasOwnProperty(id)) {
                var elements = idMap[id];
                if (elements.length > 1) {
                    elements.forEach(report);
                }
            }
        }
    }
 
};