An ESLint plugin to extract and lint inline JavaScript scripts from HTML and XML files.
eslint-plugin-html is an ESLint plugin that extracts and lints JavaScript code embedded within HTML and XML files. It applies ESLint rules to scripts inside <script> tags, providing fix capabilities to maintain code quality in web projects that mix markup and inline scripts. The plugin supports configurable file extensions, indentation control, and scope emulation for multiple scripts.
Web developers and teams working on projects with inline JavaScript in HTML or XML files, such as traditional multi-page applications, static sites, or templates using PHP, Handlebars, or similar technologies. It is also for developers needing to enforce consistent JavaScript quality in mixed markup-codebases without switching to full JavaScript frameworks.
Developers choose this plugin because it seamlessly integrates with ESLint to lint inline scripts with accurate scope handling, supporting both shared global scopes (like browsers) and module scopes. Its flexibility in configuring extensions, tag names, and MIME types, along with XML/CDATA support, makes it adaptable to various project structures without imposing HTML-specific rules.
An ESLint plugin to extract and lint scripts from HTML files.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
By default, it shares global scope between non-module script tags to emulate browser behavior, ensuring ESLint rules like no-undef work correctly across multiple scripts in a file.
Supports custom settings for file extensions, tag names, and MIME types via options like html/javascript-tag-names, allowing adaptation to diverse project structures without core ESLint changes.
Parses XML files with proper handling of CDATA sections, distinguishing between HTML and XML modes for accurate script extraction in markup-heavy environments.
Offers settings such as html/indent to enforce uniform indentation within script tags, integrating with ESLint's indent rule for cleaner, consistent code formatting.
Struggles with server-side templates like PHP where script tags contain non-JavaScript code, forcing developers to use hacky workarounds or disable linting, as noted in the Troubleshooting section.
Major updates like v3 and v4 introduced breaking changes that require migration efforts, potentially disrupting existing configurations, as documented in the README's migration guides.
Does not provide any HTML-specific linting rules, necessitating additional plugins like @eslint-html for comprehensive markup validation, which adds configuration complexity.