all files / htmlcs/lib/rules/ protocol-omitted-in-href.js

100% Statements 8/8
100% Branches 10/10
100% Functions 2/2
100% Lines 8/8
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× 909× 893×     16×                        
/**
 * @file rule: protocol-omitted-in-href
 * @author Oleg Krivtsov <oleg@webmarketingroi.com.au>
 */
 
module.exports = {
 
    name: 'protocol-omitted-in-href',
 
    desc: 'Protocol (http:// or https://) should be omitted from href attribute (there should be "//" instead)',
 
    target: 'parser',
 
    lint: function (getCfg, parser, reporter) {
        parser.on('opentag', function (name, attrs) {
            if (!getCfg()) {
                return;
            }
 
            if (name !== 'link' && name !== 'script') {
                return;
            }
 
            if (attrs.href && /^https?:\/\//i.test(attrs.href)) {
                reporter.warn(
                    this.startIndex,
                    '051',
                    'Protocol (http:// or https://) should be omitted from href attribute (there should be "//" instead)'
                );
            }
        });
    }
 
};