All files / src/rules no-implicit-close.ts

92.31% Statements 12/13
83.33% Branches 5/6
100% Functions 2/2
92.31% Lines 12/13
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    1x   1x           6x 9x 9x   9x 7x     2x         2x   2x 1x   1x        
import { Rule, RuleReport, RuleParserProxy } from '../rule';
import { TagCloseEvent } from '../event';
import { NodeClosed } from '../dom';
 
export = {
	name: 'no-implicit-close',
	init,
} as Rule;
 
function init(parser: RuleParserProxy){
	parser.on('tag:close', (event: TagCloseEvent, report: RuleReport) => {
		const closed = event.previous;
		const by = event.target;
 
		if (closed.closed !== NodeClosed.ImplicitClosed){
			return;
		}
 
		Iif (!by){
			return;
		}
 
		/* determine if it was closed by parent or sibling */
		const closedByParent = closed.parent.tagName === by.tagName;
 
		if (closedByParent){
			report(closed, `Element <${closed.tagName}> is implicitly closed by parent </${by.tagName}>`, closed.location);
		} else {
			report(closed, `Element <${closed.tagName}> is implicitly closed by sibling`, closed.location);
		}
	});
}