HTML ESLint

HTML ESLint

  • Docs
  • GitHub
  • PlayGround

›Best Practice

Getting Started

  • Getting Started

Disabling with inline comments

  • Disable rules with inline comments

CLI (Check HTML file on URL)

  • CLI (Run on URLs)

Rules

  • All Rules
  • SEO

    • @html-eslint/require-lang
    • @html-eslint/require-title
    • @html-eslint/no-multiple-h1
    • @html-eslint/require-meta-description

    Style

    • @html-eslint/no-extra-spacing-attrs
    • @html-eslint/element-newline
    • @html-eslint/indent
    • @html-eslint/quotes
    • @html-eslint/id-naming-convention
    • @html-eslint/no-multiple-empty-lines

    Best Practice

    • @html-eslint/require-doctype
    • @html-eslint/no-duplicate-id
    • @html-eslint/no-inline-styles
    • @html-eslint/require-li-container
    • @html-eslint/no-obsolete-tags
    • @html-eslint/require-closing-tags
    • @html-eslint/require-meta-charset
    • @html-eslint/no-target-blank
    • @html-eslint/no-duplicate-attrs
    • @html-eslint/require-button-type
    • @html-eslint/no-restricted-attrs

    Accessibility

    • @html-eslint/require-img-alt
    • @html-eslint/no-skip-heading-levels
    • @html-eslint/require-frame-title
    • @html-eslint/no-non-scalable-viewport
    • @html-eslint/no-positive-tabindex
    • @html-eslint/require-meta-viewport
    • @html-eslint/no-abstract-roles
    • @html-eslint/no-aria-hidden-body
    • @html-eslint/no-accesskey-attrs

@html-eslint/no-restricted-attrs

Disallow specified attributes

Rule Details

This rule allows you to specify attributes that you don't want to use in your application.

Options

This rule takes an array of option objects, where the tagPatterns and attrPatterns are specified.

  • tagPatterns: an array of strings representing regular expression pattern, disallows tag name that match any of the patterns.
  • attrPatterns: an array of strings representing regular expression pattern, disallows attribute name that match any of the patterns.
  • message (optional): a string for custom message.
"rules": {
  "@html-eslint/no-restricted-attrs": [
    "error",
  {
    tagPatterns: ["^div$", "^img$"],
    attrPatterns: ["data-.*"]
    message: "\'data-x\' is restricted."
  },
  {
    tagPatterns: ["^img$"],
    attrPatterns: ["^alt$"]
    message: "\'alt\' is restricted."
  }]
}

Examples of incorrect code for this rule with the option below:

{
  "tagPatterns": ["^img$", "^div$"],
  "attrPatterns": ["^data-.*"],
  "message": "Do not use data-* attr"
}
<div data-name="foo"></div>
<img data-name="foo"></div>
← @html-eslint/require-button-type@html-eslint/require-img-alt →
  • Disallow specified attributes
    • Rule Details
    • Options
Docs
Getting StartedAll Rules
More
GitHubStar
Built with Docusaurus