{"name":"eslint-plugin-html","version":"8.1.3","keywords":["eslint-plugin","eslintplugin","eslint","html"],"license":"ISC","_id":"eslint-plugin-html@8.1.3","maintainers":[{"name":"benoitz","email":"bzugmeyer@gmail.com"}],"homepage":"https://github.com/BenoitZugmeyer/eslint-plugin-html","bugs":{"url":"https://github.com/BenoitZugmeyer/eslint-plugin-html/issues"},"dist":{"shasum":"67168911914ccd68526d7c0f4111b81bc62036d6","tarball":"http://registry-npm.ywwl.com/eslint-plugin-html/download/eslint-plugin-html-8.1.3.tgz","fileCount":15,"integrity":"sha512-cnCdO7yb/jrvgSJJAfRkGDOwLu1AOvNdw8WCD6nh/2C4RnxuI4tz6QjMEAmmSiHSeugq/fXcIO8yBpIBQrMZCg==","signatures":[{"sig":"MEUCIQD3L2+NCz21+hmHOxOiUxuOqdkDs3Q27HD6JEIn0PeQlgIgJ+JUuxBQPVNFcE4Iw06Lp23UKlo+NqxQPf0o7TkV8l0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":51508,"size":15039,"noattachment":false,"key":"/eslint-plugin-html/-/eslint-plugin-html-8.1.3.tgz"},"main":"src/index.js","engines":{"node":">=16.0.0"},"gitHead":"8ba81b731a8d396853ce3658f892df920313c239","scripts":{"lint":"eslint .","test":"node --test","format":"prettier --check .","validate":"npm run lint && npm run test"},"_npmUser":{"name":"benoitz","email":"bzugmeyer@gmail.com"},"repository":{"url":"git+https://github.com/BenoitZugmeyer/eslint-plugin-html.git","type":"git"},"_npmVersion":"10.9.2","description":"A ESLint plugin to lint and fix inline scripts contained in HTML files.","directories":{},"_nodeVersion":"23.8.0","dependencies":{"htmlparser2":"^10.0.0"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^9.0.0","semver":"^7.3.2","prettier":"^3.2.4","@html-eslint/parser":"^0.40.0","markdown-link-check":"^3.10.2","eslint-config-prettier":"^10.0.0","@html-eslint/eslint-plugin":"^0.40.0"},"_npmOperationalInternal":{"tmp":"tmp/eslint-plugin-html_8.1.3_1747658650080_0.8078943793654112","host":"s3://npm-registry-packages-npm-production"},"readme":"<div align=\"center\">\n    <img src=\"media/logo.svg\" width=\"150\" height=\"150\">\n    <h1>eslint-plugin-html</h1>\n    <a href=\"https://www.npmjs.com/package/eslint-plugin-html\"><img alt=\"NPM version\" src=\"https://img.shields.io/npm/v/eslint-plugin-html\"></a>\n    <a href=\"https://github.com/BenoitZugmeyer/eslint-plugin-html/actions/workflows/tests.yml\"><img alt=\"Tests Status\" src=\"https://img.shields.io/github/actions/workflow/status/BenoitZugmeyer/eslint-plugin-html/tests.yml\"></a>\n    <p>A <a href=\"http://eslint.org\">ESLint</a> plugin to lint and fix inline scripts contained in HTML files.</p>\n</div>\n\n- [Usage](#usage)\n- [Disabling ESLint](#disabling-eslint)\n- [Linting HTML](#linting-html)\n  - [Manual configuration](#manual-configuration)\n  - [Use two configuration files](#use-two-configuration-files)\n- [Multiple scripts tags in a HTML file](#multiple-scripts-tags-in-a-html-file)\n  - [History](#history)\n- [XML support](#xml-support)\n- [Settings](#settings)\n  - [`html/html-extensions`](#htmlhtml-extensions)\n  - [`html/xml-extensions`](#htmlxml-extensions)\n  - [`html/indent`](#htmlindent)\n  - [`html/report-bad-indent`](#htmlreport-bad-indent)\n  - [`html/javascript-tag-names`](#htmljavascript-tag-names)\n  - [`html/javascript-mime-types`](#htmljavascript-mime-types)\n  - [`html/ignore-tags-without-type`](#htmlignore-tags-without-type)\n- [Troubleshooting](#troubleshooting)\n  - [No file linted when running `eslint` on a directory](#no-file-linted-when-running-eslint-on-a-directory)\n  - [Linting templates (or PHP)](#linting-templates-or-php)\n  - [Linting VUE files](#linting-vue-files)\n- [Migration from older versions](#migration-from-older-versions)\n  - [To v4](#to-v4)\n  - [To v3](#to-v3)\n- [Credits](#credits)\n\n## Usage\n\nSimply install via `npm install --save-dev eslint-plugin-html` and add the plugin to your ESLint\nconfiguration. See\n[ESLint documentation](http://eslint.org/docs/user-guide/configuring#configuring-plugins).\n\n<details open>\n  <summary>Example with ESLint 9 and above (flat config)</summary>\n\n```javascript\nimport html from \"eslint-plugin-html\"\n\nexport default [\n  {\n    files: [\"**/*.html\"],\n    plugins: { html },\n  },\n]\n```\n\n</details>\n\n<details>\n  <summary>Example with ESLint 8 and below</summary>\n\n```json\n{\n  \"plugins\": [\"html\"]\n}\n```\n\n</details>\n\n## Disabling ESLint\n\nTo temporarily disable ESLint, use the `<!-- eslint-disable -->` HTML comment. Re-enable it with\n`<!-- eslint enable -->`. Example:\n\n```html\n<!-- eslint-disable -->\n<script>\n  var foo = 1\n</script>\n<!-- eslint-enable -->\n```\n\nTo disable ESLint for the next script tag only, use the `<!-- eslint-disable-next-script -->` HTML\ncomment. Example:\n\n```html\n<!-- eslint-disable-next-script -->\n<script>\n  var foo = 1\n</script>\n```\n\nDisabled script tags are completely ignored: their content will not be parsed as JavaScript. You can\nuse this to disable script tags containing template syntax.\n\n## Linting HTML\n\nThis plugin focuses on applying ESLint rules on inline scripts contained in HTML. It does not\nprovide any rule related to HTML. For that, you can use other plugins like\n[@html-eslint](https://html-eslint.org) or\n[@angular-eslint](https://github.com/angular-eslint/angular-eslint). This plugin is not compatible\nwith the ESLint `language` option (this is an ESLint limitation). To lint both HTML and JS within\nscript tags, you have two alternatives:\n\n### Manual configuration\n\nProvide the [`html-eslint`](https://html-eslint.org/) plugin option manually, without relying on the\n`language` option:\n\n```javascript\nimport { defineConfig } from \"eslint/config\"\nimport parserHtml from \"@html-eslint/parser\"\nimport pluginHtml from \"@html-eslint/eslint-plugin\"\nimport pluginJs from \"@eslint/js\"\nimport pluginJsInHtml from \"eslint-plugin-html\"\n\nexport default defineConfig([\n  {\n    files: [\"**/*.html\"],\n    plugins: {\n      html: pluginHtml,\n      jsInHtml: pluginJsInHtml,\n      js: pluginJs,\n    },\n    languageOptions: {\n      parser: parserHtml,\n    },\n    extends: [\"js/recommended\", \"html/recommended\"],\n  },\n])\n```\n\n### Use two configuration files\n\n`eslint.config.js` with the `eslint-plugin-html` plugin to lint all JavaScript code and\n`eslint.config-html.js` with the [`html-eslint`](https://html-eslint.org/) plugin for HTML rules.\n\nRun ESLint once with each configuration:\n\n```sh\neslint .                              # lints JS\neslint -c eslint.config-html.js .     # lints HTML\n```\n\nThis alternative works well in CI and hooks, but might be limited in text editors where only one\nconfig is applied.\n\n## Multiple scripts tags in a HTML file\n\nWhen linting a HTML with multiple script tags, this plugin tries to emulate the browser behavior by\nsharing the global scope between scripts by default. This behavior doesn't apply to \"module\"\nscripts (ie: `<script type=\"module\">` and most transpiled code), where each script tag gets its own\ntop-level scope.\n\nESLint has already [an\noption](https://eslint.org/docs/user-guide/configuring#specifying-parser-options) to tell the parser\nif the script are modules. `eslint-plugin-html` will use this option as well to know if the scopes\nshould be shared (the default) or not. To change this, just set it in your ESLint configuration:\n\n<details open>\n<summary>ESLint 9 and above (flat config)</summary>\n\n```javascript\nexport default [\n  {\n    // ...\n    languageOptions: {\n      sourceType: \"module\",\n    },\n  },\n]\n```\n\n</details>\n\n<details>\n<summary>ESLint 8 and below</summary>\n\n```json\n{\n  \"parserOptions\": {\n    \"sourceType\": \"module\"\n  }\n}\n```\n\n</details>\n\nTo illustrate this behavior, consider this HTML extract:\n\n```html\n<script>\n  var foo = 1\n</script>\n\n<script>\n  alert(foo)\n</script>\n```\n\nThis is perfectly valid by default, and the ESLint rules `no-unused-vars` and `no-undef` shouldn't\ncomplain. But if those scripts are considerated as ES modules, `no-unused-vars` should report an\nerror in the first script, and `no-undef` should report an error in the second script.\n\n### History\n\nIn `eslint-plugin-html` v1 and v2, script code were concatenated and linted in a single pass, so\nthe scope were always shared. This caused [some issues](MIGRATION_TO_V3.md), so in v3 all scripts\nwere linted separately, and scopes were never shared. In v4, the plugin still lint scripts\nseparately, but makes sure global variables are declared and used correctly in the non-module case.\n\n## XML support\n\nThis plugin parses HTML and XML markup slightly differently, mainly when considering `CDATA`\nsections:\n\n- in XML, any data inside a `CDATA` section will be considered as raw text (not XML) and the `CDATA`\n  delimiter will be dropped ;\n- in HTML, there is no such thing for `<script>` tags: the `CDATA` delimiter is considered as normal\n  text and thus, part of the script.\n\n## Settings\n\n> Note: all settings can be written either as `\"html/key\": value` or in a nested object `\"html\": { \"key\": value }`\n\n### `html/html-extensions`\n\nBy default, this plugin will only consider files ending with those extensions as HTML: `.erb`,\n`.handlebars`, `.hbs`, `.htm`, `.html`, `.mustache`, `.nunjucks`, `.php`, `.tag`, `.twig`, `.we`.\nYou can set your own list of HTML extensions by using this setting. Example:\n\n<details open>\n  <summary>ESLint 9 and above (flat config)</summary>\n\n```javascript\nexport default [\n  {\n    files: [\"**/*.html\", \"**/*.we\"],\n    plugins: { html },\n    settings: {\n      \"html/html-extensions\": [\".html\", \".we\"], // consider .html and .we files as HTML\n    },\n  },\n]\n```\n\nNote: you need to specify extensions twice, which is not ideal. This should be improved in the\nfuture.\n\n</details>\n\n<details>\n  <summary>ESLint 8 and below</summary>\n\n```json\n{\n  \"plugins\": [\"html\"],\n  \"settings\": {\n    \"html/html-extensions\": [\".html\", \".we\"] // consider .html and .we files as HTML\n  }\n}\n```\n\n</details>\n\n### `html/xml-extensions`\n\nBy default, this plugin will only consider files ending with those extensions as XML: `.xhtml`,\n`.xml`. You can set your own list of XML extensions by using this setting. Example:\n\n<details open>\n  <summary>ESLint 9 and above (flat config)</summary>\n\n```javascript\nexport default [\n  {\n    files: [\"**/*.html\"],\n    plugins: { html },\n    settings: {\n      \"html/xml-extensions\": [\".html\"], // consider .html files as XML\n    },\n  },\n]\n```\n\nNote: you need to specify extensions twice, which is not ideal. This should be improved in the\nfuture.\n\n</details>\n\n<details>\n  <summary>ESLint 8 and below</summary>\n\n```json\n{\n  \"plugins\": [\"html\"],\n  \"settings\": {\n    \"html/xml-extensions\": [\".html\"] // consider .html files as XML\n  }\n}\n```\n\n</details>\n\n### `html/indent`\n\nBy default, the code between `<script>` tags is dedented according to the first non-empty line. The\nsetting `html/indent` allows to ensure that every script tags follow an uniform indentation. Like\nthe `indent` rule, you can pass a number of spaces, or `\"tab\"` to indent with one tab. Prefix this\nvalue with a `+` to be relative to the `<script>` tag indentation. Example:\n\n<details open>\n  <summary>ESLint 9 and above (flat config)</summary>\n\n```javascript\nexport default [\n  {\n    files: [\"**/*.html\"],\n    plugins: { html },\n    settings: {\n      \"html/indent\": \"0\", // code should start at the beginning of the line (no initial indentation).\n      \"html/indent\": \"+2\", // indentation is the <script> indentation plus two spaces.\n      \"html/indent\": \"tab\", // indentation is one tab at the beginning of the line.\n    },\n  },\n]\n```\n\n</details>\n\n<details>\n  <summary>ESLint 8 and below</summary>\n\n```json\n{\n  \"plugins\": [\"html\"],\n  \"settings\": {\n    \"html/indent\": \"0\", // code should start at the beginning of the line (no initial indentation).\n    \"html/indent\": \"+2\", // indentation is the <script> indentation plus two spaces.\n    \"html/indent\": \"tab\" // indentation is one tab at the beginning of the line.\n  }\n}\n```\n\n</details>\n\n### `html/report-bad-indent`\n\nBy default, this plugin won't warn if it encounters a problematic indentation (ex: a line is under\nindented). If you want to make sure the indentation is correct, use the `html/report-bad-indent` in\nconjunction with the `indent` rule. Pass `\"warn\"` or `1` to display warnings, `\"error\"` or `2` to\ndisplay errors. Example:\n\n<details open>\n  <summary>ESLint 9 and above (flat config)</summary>\n\n```javascript\nexport default [\n  {\n    files: [\"**/*.html\"],\n    plugins: { html },\n    settings: {\n      \"html/report-bad-indent\": \"error\",\n    },\n  },\n]\n```\n\n</details>\n\n<details>\n  <summary>ESLint 8 and below</summary>\n\n```json\n{\n  \"plugins\": [\"html\"],\n  \"settings\": {\n    \"html/report-bad-indent\": \"error\"\n  }\n}\n```\n\n</details>\n\n### `html/javascript-tag-names`\n\nBy default, the code between `<script>` tags is considered as JavaScript. You can customize which\ntags should be considered JavaScript by providing one or multiple tag names.\n\nExample:\n\n<details open>\n  <summary>ESLint 9 and above (flat config)</summary>\n\n```javascript\nexport default [\n  {\n    files: [\"**/*.html\"],\n    plugins: { html },\n    settings: {\n      \"html/javascript-tag-names\": [\"script\", \"customscript\"],\n    },\n  },\n]\n```\n\n</details>\n\n<details>\n  <summary>ESLint 8 and below</summary>\n\n```json\n{\n  \"plugins\": [\"html\"],\n  \"settings\": {\n    \"html/javascript-tag-names\": [\"script\", \"customscript\"]\n  }\n}\n```\n\n</details>\n\n### `html/javascript-mime-types`\n\nBy default, the code between `<script>` tags is considered as JavaScript code only if there is no\n`type` attribute or if its value matches the pattern\n`(application|text)/(x-)?(javascript|babel|ecmascript-6)` or `module` (case insensitive). You can\ncustomize the types that should be considered as JavaScript by providing one or multiple MIME types.\nIf a MIME type starts with a `/`, it will be considered as a regular expression. Example:\n\n<details open>\n  <summary>ESLint 9 and above (flat config)</summary>\n\n```javascript\nexport default [\n  {\n    files: [\"**/*.html\"],\n    plugins: { html },\n    settings: {\n      \"html/javascript-mime-types\": [\"text/javascript\", \"text/jsx\"], // also use script tags with a \"text/jsx\" type attribute\n      \"html/javascript-mime-types\": \"/^text\\\\/(javascript|jsx)$/\", // same thing\n    },\n  },\n]\n```\n\n</details>\n\n<details>\n  <summary>ESLint 8 and below</summary>\n\n```json\n{\n  \"plugins\": [\"html\"],\n  \"settings\": {\n    \"html/javascript-mime-types\": [\"text/javascript\", \"text/jsx\"], // also use script tags with a \"text/jsx\" type attribute\n    \"html/javascript-mime-types\": \"/^text\\\\/(javascript|jsx)$/\" // same thing\n  }\n}\n```\n\n</details>\n\n### `html/ignore-tags-without-type`\n\nBy default, the code between `<script>` tags is considered JavaScript if there is no `type`\nattribute. You can set this setting to `true` to ignore script tags without a `type` attribute.\nExample:\n\n<details open>\n  <summary>ESLint 9 and above (flat config)</summary>\n\n```javascript\nexport default [\n  {\n    files: [\"**/*.html\"],\n    plugins: { html },\n    settings: {\n      \"html/ignore-tags-without-type\": true,\n    },\n  },\n]\n```\n\n</details>\n\n<details>\n  <summary>ESLint 8 and below</summary>\n\n```json\n{\n  \"plugins\": [\"html\"],\n  \"settings\": {\n    \"html/ignore-tags-without-type\": true\n  }\n}\n```\n\n</details>\n\n## Troubleshooting\n\n### No file linted when running `eslint` on a directory\n\nBy default, when executing the `eslint` command on a directory, only `.js` files will be linted. You\nwill have to specify extra extensions with the `--ext` option. Example: `eslint --ext .html,.js src`\nwill lint both `.html` and `.js` files in the `src` directory. See [ESLint\ndocumentation](http://eslint.org/docs/user-guide/command-line-interface#ext).\n\n### Linting templates (or PHP)\n\n`eslint-plugin-html` won't evaluate or remove your template markup. If you have template markup in\nyour script tags, the resulting script may not be valid JavaScript, so `ESLint` will fail to parse\nit. Here are some workarounds:\n\n- You can use [HTML comments to disable ESLint](#disabling-eslint) for specific script tags.\n\n- For PHP, you can use\n  [`eslint-plugin-php-markup`](https://github.com/tengattack/eslint-plugin-php-markup) to lint php\n  files, it use a same way to process php markup like `eslint-plugin-html`.\n\n- Another possible hacky workaround to make sure the code is valid JavaScript is to put your\n  template markup inside a comment. When the template is rendered, the generated JS code must start\n  with a new line, so it will be written below the comment. PHP example:\n\n```html\n<script>\n  var mydata\n  // <?= \"\\n mydata = \" . json_encode($var) . \";\" ?>\n  console.log(mydata)\n</script>\n```\n\n### Linting VUE files\n\nInitially, [`eslint-plugin-vue`](https://github.com/vuejs/eslint-plugin-vue) was using\n`eslint-plugin-html` to lint code inside script tags. Since v3, `eslint-plugin-vue` is using its\nown parser, so it is _incompatible_ with `eslint-plugin-html`. You should use `eslint-plugin-vue`\nexclusively and remove `eslint-plugin-html` from your dependencies if you still have it.\n\n## Migration from older versions\n\n### To v4\n\n`eslint-plugin-html` v4 requires at least ESLint v4.7. This is because a lot of internal changes\noccurred in ESLint v4.7, including a [new API to support autofixing in\npreprocessors](https://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins).\nIf you are still using an older version of ESLint, please consider upgrading, or keep using\n`eslint-plugin-html` v3.\n\nThe big feature (and breaking change) in `eslint-plugin-html` v4 is the ability to choose how [scopes\nare shared between script tags in the same HTML file](#multiple-scripts-tags-in-a-html-file).\n\n### To v3\n\nIf you are considering upgrading to v3, please read [this guide](MIGRATION_TO_V3.md).\n\n## Credits\n\nA big thank you to [@kuceb](https://github.com/kuceb) for the logo image!\n","publish_time":1747658650270,"_cnpm_publish_time":1747658650270,"dist-tags":{"latest":"8.2.1","next":"5.0.0-alpha.0"}}