1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 1x 5x 5x 5x 5x 4x 1x 4x | import { Rule, RuleReport, RuleParserProxy } from '../rule'; import { DOMReadyEvent } from '../event'; export = { name: 'no-dup-id', init, } as Rule; function init(parser: RuleParserProxy){ parser.on('dom:ready', (event: DOMReadyEvent, report: RuleReport) => { const existing: { [key: string]: boolean } = {}; const elements = event.document.querySelectorAll('[id]'); elements.forEach(el => { if (el.id in existing){ report(el, `Duplicate ID "${el.id}"`); } existing[el.id] = true; }); }); } |