htmlhint / htmlhint/HTMLHint

tag-pair can't make exceptions for elements with optional closing tags

Open
#243 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

keep-unstale
Dominant language
JavaScript
Stars
3.3k
Forks
474
Avg merge
1d 11h
Merged PRs (30d)
12

Description

Certain elements don't need to have a closing tag; it's implied, and the browser closes it for you. From the html spec, the following tags don't need to be closed:

  • html (if </html> is not meant to be immediately followed by a comment)
  • head (if </head> is not meant to be immediately followed by whitespace or a comment)
  • body (if </body> is not meant to be immediately followed by a comment)
  • li (if the li element is immediately followed by another, or if it's the last child of its parent)
  • dt (if the dt element is immediately followed by another, or by a dd)
  • dd (if the dd element is immediately followed by another, by a dt, or if it's the last child of its parent)
  • p (if the p element is immediately followed by any of a long list of elements, or if it's the last child of its parent and that parent is not a, audio, del, ins, map, noscript, or video)
  • rt (if the rt element is immediately followed by another, by a rp, or if it's the last child of its parent)
  • rp (if the rp element is immediately followed by another, a rt, or if it's the last child of its parent)
  • optgroup (if the optgroup element is immediately followed by another, or if it's the last child of its parent)
  • option (if the option element is immediately followed by another, by an optgroup, or if it's the last child of its parent)
  • colgroup (if </colgroup> is not meant to be immediately followed by whitespace or a comment)
  • caption (if </caption> is not meant to be immediately followed by whitespace or a comment)
  • thead (if the thead element is immediately followed by a tbody or tfoot)
  • tbody (if the tbody element is immediately followed by a thead, tfoot, or if it's the last child of its parent)
  • tfoot (if the tfoot element is the last child of its parent)
  • tr (if the tr element is immediately followed by another, or if it's the last child of its parent)
  • td (if the td element is immediately followed by another, a th, or if it's the last child of its parent)
  • th (if the th element is immadiately followed by another, a td, or if it's the last child of its parent)

The tag-pair rule can't enforce tag pairs for elements that require being paired, while allowing optional closing tags. It's all or nothing. Even just being able to provide exceptions (similar to attr-lowercase) would be useful.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the tag-pair rule and the attr-lowercase rule for a precedent for configurable exceptions. Define how optional-closing-tag exceptions should be supplied, then verify that allowed omissions pass while required tag pairs are still reported. Add or update rule tests to cover the supported exceptions and their edge cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.