Add an HTML check
- Open
apps/frontend/src/Utils/HTML/htmlValidation.ts. - Decide the scope:
- Per element — add to
validateElement, usingadd(level, rule, message). Usectx.indexfor parents/ancestors (ancestors(eid, ctx)),descendants(node)for children. - Per page — add to
validatePagewithpage(level, rule, message). - Data-driven — for “tag X needs attribute Y” or “tag X must be inside Y”, extend
REQUIRED_ATTRSorALLOWED_PARENTSinstead of writing code. ID-reference attributes go inIDREF_ATTRS.
- Per element — add to
- If the rule needs a page-wide lookup, compute it once in
buildPageContextand add the field toPageContext. - Pick the level:
errorfor invalid HTML or broken behavior,warningfor accessibility/reference problems,infofor suggestions (not counted in badges). - Write the message for designers: what’s wrong and, briefly, what to do. No rule ids or code in the text.
- Add a test to
Utils/HTML/__tests__/htmlValidation.test.tscovering a failing and a passing case, then runnpx jest src/Utils/HTML. - Add the rule to the designer HTML checks reference and the internal HTML validation reference.
Troubleshooting
- The “well-formed page” test fails. The new rule fires on the minimal valid page in that test; tighten the condition.
- Crash before the page loads. Guard against tagless nodes; the tree is
{}until the page loads.
Related
- Reference: HTML validation