Registry / testing / eslint-html-parser

eslint-html-parser

JSON →
library6.8.2jsnpmunverified

eslint-html-parser is a custom ESLint parser designed to lint HTML files, including embedded JavaScript within `<script>` tags. It achieves this by parsing HTML into a specific Abstract Syntax Tree (AST) structure, while delegating the parsing of JavaScript code (both in `<script>` tags and standalone `.js`/`.jsx` files) to a configurable ECMAScript parser, defaulting to `espree`. This enables developers to apply standard ESLint rules to their JavaScript within HTML, as well as define custom rules that target the HTML structure itself. The package is currently at version 6.8.2 and appears to be actively maintained, offering a crucial bridge for projects that require robust linting across both HTML and JavaScript within a single ESLint setup. It differentiates itself by providing a comprehensive HTML AST for deep linting, unlike simpler preprocessors that only extract script content.

testing
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Primarily an internal ESLint API. Directly importing and using this is for advanced custom tooling or deep integration, not typical application usage. It's the entry point ESLint calls to parse files.

import { parseForESLint } from 'eslint-html-parser';

Type import for the AST node representing an HTML element. Useful when developing custom ESLint rules that traverse the HTML AST produced by this parser.

import type { HTMLElement } from 'eslint-html-parser';

Type import for the AST node representing an HTML attribute. Useful when developing custom ESLint rules that target HTML attributes.

import type { HTMLAttribute } from 'eslint-html-parser';

Demonstrates installation, basic ESLint configuration using eslint-html-parser for both HTML and standalone JavaScript files, and running the linter.

{ "name": "my-linted-project", "version": "1.0.0", "description": "Example project using eslint-html-parser", "scripts": { "lint": "eslint \"./**/*.{js,htm,html}\" }, "devDependencies": { "eslint": "^8.0.0", "eslint-html-parser": "^6.0.0" } } // .eslintrc.json { "root": true, "parser": "eslint-html-parser", "parserOptions": { "ecmaVersion": 2021, "sourceType": "module", "ecmaFeatures": { "jsx": true } }, "env": { "browser": true, "es2021": true }, "extends": "eslint:recommended", "rules": { "no-console": "warn" } } <!-- src/index.html --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <h1>Hello, HTML Lint!</h1> <script> console.log("This JS will be linted."); // no-console will warn here var unusedVar = 1; </script> <my-custom-element some-attribute="value"></my-custom-element> </body> </html> // src/app.js console.log("This standalone JS will also be linted."); # Terminal commands to set up and run: npm init -y npm install --save-dev eslint eslint-html-parser # Create .eslintrc.json, src/index.html, src/app.js as shown above npm run lint
Debug
Known footguns
breakingESLint v9.0.0 and above deprecate the legacy `.eslintrc.*` configuration system in favor of flat config (`eslint.config.js`). `eslint-html-parser` examples typically use `.eslintrc.json`, which may require adaptation for newer ESLint versions.
gotchaThe parser requires Node.js 6.x or later and ESLint 6.x or later. Using older versions will lead to installation or runtime errors.
gotchaBy default, ESLint only lints `.js` files when run on a directory. To lint HTML files, you must explicitly specify the extensions using glob patterns in the CLI or the `--ext` option.
gotchaThe `parserOptions` for `eslint-html-parser` directly map to the options supported by the underlying JavaScript parser (defaulting to `espree`). Misconfiguring `ecmaVersion`, `sourceType`, or `ecmaFeatures` can lead to parsing errors for JavaScript content.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
9 hits · last 30 days
gptbot
4
ahrefsbot
4
script
1
Resources