Linter Rules
This page contains documentation for all Herb Linter rules.
Available Rules
erb-comment-syntax- Disallow Ruby comments immediately after ERB tagserb-no-case-node-children- Don't usechildrenforcase/whenandcase/innodeserb-no-empty-tags- Disallow empty ERB tagserb-no-extra-newline- Disallow extra newlines.erb-no-extra-whitespace-inside-tags- Disallow multiple consecutive spaces inside ERB tagserb-no-output-control-flow- Prevents outputting control flow blockserb-no-silent-tag-in-attribute-name- Disallow ERB silent tags in HTML attribute nameserb-prefer-image-tag-helper- Preferimage_taghelper over<img>with ERB expressionserb-require-whitespace-inside-tags- Requires whitespace around ERB tagserb-require-trailing-newline- Enforces that all HTML+ERB template files end with exactly one trailing newline character.erb-right-trim- Enforce consistent right-trimming syntax.herb-disable-comment-malformed- Detect malformedherb:disablecomments.herb-disable-comment-missing-rules- Require rule names inherb:disablecomments.herb-disable-comment-no-duplicate-rules- Disallow duplicate rule names inherb:disablecomments.herb-disable-comment-no-redundant-all- Disallow redundant use ofallinherb:disablecomments.herb-disable-comment-unnecessary- Detect unnecessaryherb:disablecomments.herb-disable-comment-valid-rule-name- Validate rule names inherb:disablecomments.html-anchor-require-href- Requires an href attribute on anchor tagshtml-aria-attribute-must-be-valid- Disallow invalid or unknownaria-*attributes.html-aria-label-is-well-formatted-aria-labelmust be well-formattedhtml-aria-level-must-be-valid-aria-levelmust be between 1 and 6html-aria-role-heading-requires-level- Requiresaria-levelwhen supplying arolehtml-aria-role-must-be-valid- Theroleattribute must have a valid WAI-ARIA Role.html-attribute-double-quotes- Enforces double quotes for attribute valueshtml-attribute-equals-spacing- No whitespace around=in HTML attributeshtml-attribute-values-require-quotes- Requires quotes around attribute valueshtml-avoid-both-disabled-and-aria-disabled- Avoid using bothdisabledandaria-disabledattributeshtml-body-only-elements- Require content elements inside<body>.html-boolean-attributes-no-value- Prevents values on boolean attributeshtml-head-only-elements- Require head-scoped elements inside<head>.html-iframe-has-title-iframeelements must have atitleattributehtml-input-require-autocomplete- Requireautocompleteattributes on<input>tags.html-img-require-alt- Requiresaltattributes on<img>tagshtml-navigation-has-label- Navigation landmarks must have accessible labelshtml-no-aria-hidden-on-focusable- Focusable elements should not havearia-hidden="true"html-no-block-inside-inline- Prevents block-level elements inside inline elementshtml-no-duplicate-attributes- Prevents duplicate attributes on HTML elementshtml-no-duplicate-ids- Prevents duplicate IDs within a documenthtml-no-duplicate-meta-names- Duplicate<meta>name attributes are not allowed.html-no-empty-attributes- Attributes must not have empty valueshtml-no-nested-links- Prevents nested anchor tagshtml-no-positive-tab-index- Avoid positivetabindexvalueshtml-no-self-closing- Disallow self closing tagshtml-no-space-in-tag- Disallow spaces in HTML tagshtml-no-title-attribute- Avoid using thetitleattributehtml-no-underscores-in-attribute-names- Disallow underscores in HTML attribute nameshtml-tag-name-lowercase- Enforces lowercase tag names in HTMLparser-no-errors- Disallow parser errors in HTML+ERB documentssvg-tag-name-capitalization- Enforces proper camelCase capitalization for SVG elements
Contributing
To add a new linter rule you can scaffold a new rule by running:
bash
cd javascript/packages/linter
scripts/generate-ruleThe script creates the documentation, rule stub, and test stub based on the GitHub issue (requires the linter label and a Rule name: [rule-name] line).
Alternatively, you can create one manually:
- Create the rule class implementing the
Ruleinterface - Add comprehensive tests in
test/rules/ - Add documentation in
docs/rules/ - Update the main linter to include the rule by default (if appropriate)
See html-tag-name-lowercase.ts for an example implementation.