all files / htmlcs/lib/rules/ attr-value-double-quotes.js

100% Statements 8/8
100% Branches 6/6
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 36 37 38 39 40                          103× 867× 781×     86× 86×         86×       16×                    
/**
 * @file rule: attr-value-double-quotes
 * @author nighca<nighca@live.cn>
 */
 
module.exports = {
 
    name: 'attr-value-double-quotes',
 
    desc: 'Attribute value must be closed by double quotes.',
 
    target: 'parser',
 
    lint: function (getCfg, parser, reporter) {
        parser.tokenizer.on('attribname', function (name) {
            if (!getCfg()) {
                return;
            }
 
            var buffer = this._buffer;
            var index = this._index;
 
            // character after attribute name should be '='
            // ( get rid of boolean attribute )
            // and character starting attribute value should be '"'
            if (
                buffer[index] === '='
                && buffer[index + 1] !== '"'
            ) {
                reporter.warn(
                    index + 1,
                    '028',
                    'Attribute value must be closed by double quotes.'
                );
            }
        });
    }
 
};