djlint / djLint

✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks - Handlebars - GoLang
https://djLint.com
GNU General Public License v3.0
686 stars 84 forks source link

[FEATURE] Linter rule idea: `for` must match `id` in same file #820

Open silverwind opened 7 months ago

silverwind commented 7 months ago

Feature Request

A new rule that each for attribute on <label> has a exactly one matching id in the same file would be nice.

Failure:

<label for="wine"></label>
<input id="cheese">
<label for="wine"></label>
<input id="cheese">
<input id="cheese">

Success:

<label for="cheese"></label>
<input id="cheese">

In case elements are spread across multiple files it would produce false-positives, but I think such cases would be rare enough to not present a major issue.