All files / src/rules no-dup-attr.ts

100% Statements 9/9
100% Branches 2/2
100% Functions 3/3
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      1x           6x   6x   7x     6x 6x 6x 2x   6x      
import { Rule, RuleReport, RuleParserProxy } from '../rule';
import { AttributeEvent } from '../event';
 
export = {
	name: 'no-dup-attr',
	init,
} as Rule;
 
function init(parser: RuleParserProxy){
	let attr: { [key: string]: boolean } = {};
 
	parser.on('tag:open', () => {
		/* reset any time a new tag is opened */
		attr = {};
	});
 
	parser.on('attr', (event: AttributeEvent, report: RuleReport) => {
		const name = event.key.toLowerCase();
		if (name in attr){
			report(event.target, `Attribute "${name}" duplicated`);
		}
		attr[event.key] = true;
	});
}