Code coverage report for htmlcs/lib/rules/charset.js

Statements: 100% (11 / 11)      Branches: 100% (8 / 8)      Functions: 100% (1 / 1)      Lines: 100% (11 / 11)      Ignored: none     

All files » htmlcs/lib/rules/ » charset.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          1             37 32     5 5 1     4 4 2 2 1          
/**
 * @file rule: charset
 * @author nighca<nighca@live.cn>
 */
 
module.exports = {
 
    name: 'charset',
 
    desc: '<meta charset> recommended.',
 
    lint: function (enable, document, reporter) {
        if (!enable) {
            return;
        }
 
        var head = document.querySelector('head');
        if (!head) {
            return;
        }
 
        var charsetMeta = head.querySelector('meta[charset]');
        if (!charsetMeta) {
            reporter.warn(head, '006', '<meta charset> recommended.');
        } else if (charsetMeta !== head.firstElementChild) {
            reporter.warn(charsetMeta, '007', '<meta> charset should be the first element child of <head>');
        }
    }
 
};