all files / htmlcs/lib/rules/ multiple-stylesheets.js

100% Statements 9/9
100% Branches 8/8
100% Functions 2/2
100% Lines 9/9
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                            103×   103× 909× 899×     10×                        
/**
 * @file rule: multiple-stylesheets
 * @author Oleg Krivtsov <oleg@webmarketingroi.com.au>
 */
 
module.exports = {
 
    name: 'multiple-stylesheets',
 
    desc: 'More than one style-sheet is included (combining all style-sheets into one neat CSS file would be cleaner)',
 
    target: 'parser',
 
    lint: function (getCfg, parser, reporter) {
 
        var stylesheetCount = 0;
 
        parser.on('opentag', function (name, attrs) {
            if (!getCfg()) {
                return;
            }
 
            if (name === 'link' && attrs.rel === 'stylesheet') {
                if (stylesheetCount === 1) {
                    reporter.warn(
                            this.startIndex,
                            '028',
                            'More than one style-sheet is included (combining '
                            + 'all style-sheets into one neat CSS file would be cleaner)'
                        );
                }
 
                stylesheetCount++;
            }
        });
    }
};