eslint-plugin-html
raw JSON → 8.1.4 verified Sat Apr 25 auth: no javascript
ESLint plugin to lint and fix inline scripts inside HTML files. Current stable version is 8.1.4, with a release cadence of several months. It integrates with ESLint's flat config (ESLint 9+) and legacy config, supports multiple script tags per file with shared or module scope, and provides settings for HTML/XML extensions, indentation, and ignoring script tags without type. Unlike other HTML linting plugins, it focuses exclusively on JavaScript within HTML without providing HTML-specific rules.
Common errors
error ESLint couldn't find the plugin 'eslint-plugin-html'. ↓
cause Plugin not installed or not listed in eslint.config.js correctly.
fix
Run 'npm install --save-dev eslint-plugin-html' and ensure the import path is correct.
error Configuration for rule 'html/indent' is invalid. ↓
cause The rule 'html/indent' does not exist; it's a setting, not a rule.
fix
Use the 'settings' property: settings: { html: { indent: 4 } } instead of rules.
error The 'plugins' section in .eslintrc is for legacy config only. ↓
cause Using .eslintrc instead of flat config with v8.
fix
Switch to eslint.config.js flat config, or use the 'legacy' plugin object (import { legacy } from 'eslint-plugin-html').
Warnings
breaking In v8, ESLint 9 flat config is the primary configuration method; legacy config (.eslintrc) may still work but is discouraged. ↓
fix Adopt flat config as shown in the quickstart or use the 'legacy' plugin wrapper if you must use .eslintrc.
breaking Version 5+ drops support for Node < 6 and ESLint < 4. ↓
fix Upgrade Node to >=6 and ESLint to >=4.
deprecated The 'html/html-extensions' setting is deprecated; use ESLint's built-in file extension matching. ↓
fix Remove 'html/html-extensions' and rely on the 'files' pattern in flat config.
gotcha By default, multiple script tags share global scope (non-module). This can cause false positives if variables are reused across tags. ↓
fix Set 'sourceType: module' in ESLint parser options if using ES modules.
gotcha XML files with script tags are also linted if .xml is registered via settings. ↓
fix If you don't need XML linting, ensure 'html/xml-extensions' is not set.
Install
npm install eslint-plugin-html yarn add eslint-plugin-html pnpm add eslint-plugin-html Imports
- default (plugin object) wrong
const html = require('eslint-plugin-html')correctimport html from 'eslint-plugin-html' - processors wrong
import { processors } from 'eslint-plugin-html'correctconst { processors } = require('eslint-plugin-html') - Rules (none directly exported) wrong
import { rules } from 'eslint-plugin-html'correctimport html from 'eslint-plugin-html' // then use html.rules if needed
Quickstart
// Install: npm install --save-dev eslint eslint-plugin-html
// eslint.config.js
import html from 'eslint-plugin-html';
export default [
{
files: ['**/*.html'],
plugins: { html },
rules: {
'semi': 'error'
}
}
];
// Then lint: npx eslint index.html