From 5860da0947452d61598b1371520dd32dd4595399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Zugmeyer?= Date: Mon, 20 May 2024 12:52:27 +0200 Subject: [PATCH 01/17] fix: use languageOptions.sourceType to check for module ESLin 9 exposes the sourceType in languageOptions, not in parserOptions --- src/test/plugin.js | 11 ++++++----- src/verifyWithFlatConfigPatch.js | 6 ++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/test/plugin.js b/src/test/plugin.js index cadd5db..0cbb235 100644 --- a/src/test/plugin.js +++ b/src/test/plugin.js @@ -42,7 +42,7 @@ async function execute(file, options = {}) { ), languageOptions: { globals: options.globals || {}, - sourceType: "script", + sourceType: options.sourceType || "script", parserOptions: options.parserOptions || {}, ...("parser" in options ? { @@ -78,7 +78,10 @@ async function execute(file, options = {}) { ), globals: options.globals, env: options.env, - parserOptions: options.parserOptions, + parserOptions: { + ...options.parserOptions, + sourceType: options.sourceType, + }, parser: options.parser, plugins: options.plugins, }, @@ -787,9 +790,7 @@ describe("scope sharing", () => { env: { es6: true, }, - parserOptions: { - sourceType: "module", - }, + sourceType: "module", }) assert.strictEqual(messages.length, 16) assert.strictEqual(messages[0].line, 8) diff --git a/src/verifyWithFlatConfigPatch.js b/src/verifyWithFlatConfigPatch.js index 3219be1..1dcd413 100644 --- a/src/verifyWithFlatConfigPatch.js +++ b/src/verifyWithFlatConfigPatch.js @@ -98,8 +98,10 @@ function createVerifyWithFlatConfigPatch(verifyWithFlatConfig) { ) } - const parserOptions = providedConfig.languageOptions.parserOptions || {} - if (parserOptions.sourceType === "module") { + const languageOptions = providedConfig.languageOptions || {} + const parserOptions = languageOptions.parserOptions || {} + const sourceType = languageOptions.sourceType || parserOptions.sourceType + if (sourceType === "module") { for (const codePart of extractResult.code) { verifyCodePart(codePart) } From 3b5c760b01f605b0033c5ed75fd0b62cb7ebbb2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Zugmeyer?= Date: Mon, 20 May 2024 14:54:04 +0200 Subject: [PATCH 02/17] doc: update config examples for ESLint v9 --- README.md | 271 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 236 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 6a96b00..e7f6dbc 100644 --- a/README.md +++ b/README.md @@ -35,16 +35,33 @@ Simply install via `npm install --save-dev eslint-plugin-html` and add the plugi configuration. See [ESLint documentation](http://eslint.org/docs/user-guide/configuring#configuring-plugins). -Example: +
+ Example with ESLint 9 and above (flat config) ```javascript +import html from "eslint-plugin-html" + +export default [ + { + files: ["**/*.html"], + plugins: { html }, + }, +] +``` + +
+ +
+ Example with ESLint 8 and below + +```json { - "plugins": [ - "html" - ] + "plugins": ["html"] } ``` +
+ ## Disabling ESLint To temporarily disable ESLint, use the `` HTML comment. Re-enable it with @@ -91,7 +108,26 @@ option](https://eslint.org/docs/user-guide/configuring#specifying-parser-options if the script are modules. `eslint-plugin-html` will use this option as well to know if the scopes should be shared (the default) or not. To change this, just set it in your ESLint configuration: +
+ESLint 9 and above (flat config) + +```javascript +export default [ + { + // ... + languageOptions: { + sourceType: "module", + }, + }, +] ``` + +
+ +
+ESLint 8 and below + +```json { "parserOptions": { "sourceType": "module" @@ -99,6 +135,8 @@ should be shared (the default) or not. To change this, just set it in your ESLin } ``` +
+ To illustrate this behavior, consider this HTML extract: ```html @@ -142,29 +180,79 @@ By default, this plugin will only consider files ending with those extensions as `.handlebars`, `.hbs`, `.htm`, `.html`, `.mustache`, `.nunjucks`, `.php`, `.tag`, `.twig`, `.we`. You can set your own list of HTML extensions by using this setting. Example: +
+ ESLint 9 and above (flat config) + ```javascript +export default [ + { + files: ["**/*.html", "**/*.we"], + plugins: { html }, + settings: { + "html/html-extensions": [".html", ".we"], // consider .html and .we files as HTML + }, + }, +] +``` + +Note: you need to specify extensions twice, which is not ideal. This should be imporved in the +future. + +
+ +
+ ESLint 8 and below + +```json { - "plugins": [ "html" ], - "settings": { - "html/html-extensions": [".html", ".we"], // consider .html and .we files as HTML - } + "plugins": ["html"], + "settings": { + "html/html-extensions": [".html", ".we"] // consider .html and .we files as HTML + } } ``` +
+ ### `html/xml-extensions` By default, this plugin will only consider files ending with those extensions as XML: `.xhtml`, `.xml`. You can set your own list of XML extensions by using this setting. Example: +
+ ESLint 9 and above (flat config) + ```javascript +export default [ + { + files: ["**/*.html"], + plugins: { html }, + settings: { + "html/xtml-extensions": [".html"], // consider .html files as XML + }, + }, +] +``` + +Note: you need to specify extensions twice, which is not ideal. This should be imporved in the +future. + +
+ +
+ ESLint 8 and below + +```json { - "plugins": [ "html" ], - "settings": { - "html/xml-extensions": [".html"], // consider .html files as XML - } + "plugins": ["html"], + "settings": { + "html/xml-extensions": [".html"] // consider .html files as XML + } } ``` +
+ ### `html/indent` By default, the code between `