Skip to content

Linter Rule: Validate rule names in herb:disable comments

Rule: herb-disable-comment-valid-rule-name

Description

Ensures that all rule names specified in <%# herb:disable ... %> comments are valid and exist in the linter. This catches typos, references to non-existent rules and missing comma between rule names.

Rationale

Using invalid or misspelled rule names in <%# herb:disable ... %> comments can lead to confusion and unexpected behavior. The comment won't disable anything if the rule name doesn't exist, leaving developers wondering why linter warnings persist.

By validating rule names, this rule helps catch typos early, identify removed or renamed rule and provide helpful suggestions for similar rule names using fuzzy matching.

Examples

✅ Good

erb
<DIV>test</DIV> <%# herb:disable html-tag-name-lowercase %>

<DIV class='value'>test</DIV> <%# herb:disable html-tag-name-lowercase, html-attribute-double-quotes %>

<DIV>test</DIV> <%# herb:disable all %>

🚫 Bad

erb
<div>test</div> <%# herb:disable this-rule-doesnt-exist %>
Unknown rule `this-rule-doesnt-exist`. Did you mean `erb-no-empty-tags`? (herb-disable-comment-valid-rule-name)
<div>test</div> <%# herb:disable html-tag-lowercase %>
Unknown rule `html-tag-lowercase`. Did you mean `html-tag-name-lowercase`? (herb-disable-comment-valid-rule-name)
<DIV>test</DIV> <%# herb:disable html-tag-name-lowercase, invalid-rule-name %>
Unknown rule `invalid-rule-name`. Did you mean `html-img-require-alt`? (herb-disable-comment-valid-rule-name)
<div>test</div> <%# herb:disable html-tag-name-lowercase html-attribute-double-quotes %>
Unknown rule `html-tag-name-lowercase html-attribute-double-quotes`. Did you mean `html-attribute-double-quotes`? (herb-disable-comment-valid-rule-name)

References

-

Released under the MIT License.