{"id":14559,"library":"eslint-html-parser","title":"ESLint HTML Parser","description":"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.","status":"active","version":"6.8.2","language":"javascript","source_language":"en","source_url":"https://github.com/medicomp/eslint-html-parser","tags":["javascript","typescript"],"install":[{"cmd":"npm install eslint-html-parser","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-html-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-html-parser","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required peer dependency for the parser to function within the ESLint ecosystem.","package":"eslint","optional":false},{"reason":"Default JavaScript parser used for fallback when processing script content. Can be overridden.","package":"espree","optional":true}],"imports":[{"note":"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.","symbol":"parseForESLint","correct":"import { parseForESLint } from 'eslint-html-parser';"},{"note":"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.","symbol":"HTMLElement","correct":"import type { HTMLElement } from 'eslint-html-parser';"},{"note":"Type import for the AST node representing an HTML attribute. Useful when developing custom ESLint rules that target HTML attributes.","symbol":"HTMLAttribute","correct":"import type { HTMLAttribute } from 'eslint-html-parser';"}],"quickstart":{"code":"{\n  \"name\": \"my-linted-project\",\n  \"version\": \"1.0.0\",\n  \"description\": \"Example project using eslint-html-parser\",\n  \"scripts\": {\n    \"lint\": \"eslint \\\"./**/*.{js,htm,html}\\\"\n  },\n  \"devDependencies\": {\n    \"eslint\": \"^8.0.0\",\n    \"eslint-html-parser\": \"^6.0.0\"\n  }\n}\n\n// .eslintrc.json\n{\n  \"root\": true,\n  \"parser\": \"eslint-html-parser\",\n  \"parserOptions\": {\n    \"ecmaVersion\": 2021,\n    \"sourceType\": \"module\",\n    \"ecmaFeatures\": {\n      \"jsx\": true\n    }\n  },\n  \"env\": {\n    \"browser\": true,\n    \"es2021\": true\n  },\n  \"extends\": \"eslint:recommended\",\n  \"rules\": {\n    \"no-console\": \"warn\"\n  }\n}\n\n<!-- src/index.html -->\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  <title>Document</title>\n</head>\n<body>\n  <h1>Hello, HTML Lint!</h1>\n  <script>\n    console.log(\"This JS will be linted.\"); // no-console will warn here\n    var unusedVar = 1;\n  </script>\n  <my-custom-element some-attribute=\"value\"></my-custom-element>\n</body>\n</html>\n\n// src/app.js\nconsole.log(\"This standalone JS will also be linted.\");\n\n# Terminal commands to set up and run:\nnpm init -y\nnpm install --save-dev eslint eslint-html-parser\n# Create .eslintrc.json, src/index.html, src/app.js as shown above\nnpm run lint","lang":"javascript","description":"Demonstrates installation, basic ESLint configuration using eslint-html-parser for both HTML and standalone JavaScript files, and running the linter."},"warnings":[{"fix":"Migrate your ESLint configuration from `.eslintrc.*` to `eslint.config.js` (flat config) following ESLint's migration guide. Ensure `eslint-html-parser` is correctly specified in the new format, potentially using `languageOptions.parser` for file patterns.","message":"ESLint 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.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Upgrade Node.js to a supported version (e.g., LTS) and ESLint to version 6.x or newer via `npm install --save-dev eslint@latest`.","message":"The parser requires Node.js 6.x or later and ESLint 6.x or later. Using older versions will lead to installation or runtime errors.","severity":"gotcha","affected_versions":"<6.0.0 (ESLint) || <6.0.0 (Node.js)"},{"fix":"When running ESLint from the command line, use glob patterns like `eslint \"./**/*.{js,htm,html}\"` or explicitly list extensions: `eslint --ext .htm --ext .html --ext .js src/`.","message":"By 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.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Ensure that `parserOptions` in your `.eslintrc.*` or `eslint.config.js` accurately reflect the ECMAScript version and features used in your JavaScript code (e.g., `ecmaVersion: 2021`, `sourceType: 'module'`, `ecmaFeatures: { jsx: true }` for modern JS with JSX).","message":"The `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.","severity":"gotcha","affected_versions":">=6.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `eslint-html-parser` is installed as a dev dependency: `npm install --save-dev eslint-html-parser`. Verify the `parser` setting in `.eslintrc.*` is exactly `\"eslint-html-parser\"`.","cause":"The `eslint-html-parser` package is not installed or the path to it is incorrect in the ESLint configuration.","error":"ESLint was configured to use the parser \"eslint-html-parser\" but that parser was not found."},{"fix":"Increase `parserOptions.ecmaVersion` in your ESLint config to a version that supports the syntax, e.g., `2021` or `latest`.","cause":"The `parserOptions.ecmaVersion` is set too low for modern JavaScript features like `await` or `async` functions.","error":"Parsing error: The keyword 'await' is reserved (ESLint)"},{"fix":"Ensure you have an `extends` configuration (e.g., `\"extends\": \"eslint:recommended\"`) or explicitly define the rules or plugins that provide the rules you intend to use.","cause":"While `eslint-html-parser` parses HTML and JS, it doesn't provide rules itself. This error means a configured rule is missing.","error":"Definition for rule 'no-console' was not found."},{"fix":"Add `.htm` and `.html` to your ESLint CLI command using `--ext .htm --ext .html` or ensure your `files` array in `eslint.config.js` or `overrides` in `.eslintrc.*` includes patterns like `\"**/*.{js,htm,html}\"`.","cause":"ESLint is not configured to process files with `.htm` or `.html` extensions, or the glob patterns/extensions in the CLI command are incorrect.","error":"No files were linted. Please ensure that 'files' is set correctly in your configuration."}],"ecosystem":"npm"}