all files / htmlcs/lib/rules/ attr-no-duplication.js

100% Statements 11/11
100% Branches 4/4
100% Functions 3/3
100% Lines 11/11
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 41 42 43 44                          103×     103× 909×       103× 867× 855×     12×   12×             10×            
/**
 * @file rule: attr-no-duplication
 * @author nighca<nighca@live.cn>
 */
 
module.exports = {
 
    name: 'attr-no-duplication',
 
    desc: 'Attribute name can not been duplication.',
 
    target: 'parser',
 
    lint: function (getCfg, parser, reporter) {
        var records = {};
 
        // clear records on opening new tag
        parser.on('opentagname', function () {
            records = {};
        });
 
        // check on new attribute name
        parser.tokenizer.on('attribname', function (name) {
            if (!getCfg()) {
                return;
            }
 
            name = name.toLowerCase();
 
            if (records[name]) {
                reporter.warn(
                    this._sectionStart,
                    '030',
                    'Attribute name can not been duplication.'
                );
            }
            else {
                records[name] = true;
            }
        });
    }
 
};