HTML ESLint

HTML ESLint

  • Docs
  • GitHub
  • PlayGround

›Getting Started

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

Getting Started

Installation

$ npm install --save-dev eslint @html-eslint/parser @html-eslint/eslint-plugin
  • Requires Node.js >=8.10.0.
  • Requires ESLLint >=6.

Configuration

Populate it with the following on your .eslintrc.js. If it does not exist create a .eslintrc.js config file in the root of your project.

We can apply these plugin rules to only HTML files(*.html) by using overrides in .eslintrc.js. (see ESLint Configuration)

module.exports = {
  //...
  plugins: ["@html-eslint"],
  overrides: [
    {
      files: ["*.html"],
      parser: "@html-eslint/parser",
      extends: ["plugin:@html-eslint/recommended"],
    },
  ],
};

Editor Configuration

VSCode

To get vscode-eslint support, we need to add the following in vscode settings.

  • .vscode/settings.json:
{
  "eslint.enable": true,
  "eslint.validate": [
    "javascript", // ...
    "html", // Add "html" to enable linting `.html` files.
  ],
}

Recommended Configs

This plugin provides plugin:@html-eslint/recommended. The recommended configuration contains the rules marked ⭐ in Rules.

Disable rules with inline comments →
  • Installation
  • Configuration
  • Editor Configuration
    • VSCode
  • Recommended Configs
Docs
Getting StartedAll Rules
More
GitHubStar
Built with Docusaurus