diff --git a/.changeset/rich-swans-itch.md b/.changeset/rich-swans-itch.md new file mode 100644 index 00000000..fcc779ec --- /dev/null +++ b/.changeset/rich-swans-itch.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-prettier": minor +--- + +feat: support parsing `html` via `@html-eslint/parser` natively diff --git a/package.json b/package.json index e1c845b5..dcae0d74 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "@eslint-community/eslint-plugin-eslint-comments": "^4.1.0", "@eslint/js": "^8.56.0", "@graphql-eslint/eslint-plugin": "^3.20.1", + "@html-eslint/parser": "^0.24.1", "@prettier/plugin-pug": "^3.0.0", "@types/eslint": "^8.56.0", "@types/prettier-linter-helpers": "^1.0.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ddfa8cd7..0bb0a4af 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -42,6 +42,9 @@ devDependencies: '@graphql-eslint/eslint-plugin': specifier: ^3.20.1 version: 3.20.1(graphql@16.8.1) + '@html-eslint/parser': + specifier: ^0.24.1 + version: 0.24.1 '@prettier/plugin-pug': specifier: ^3.0.0 version: 3.0.0(prettier@3.1.1) @@ -987,6 +990,13 @@ packages: graphql: 16.8.1 dev: true + /@html-eslint/parser@0.24.1: + resolution: {integrity: sha512-O13xX/+Ldh0P7VZMpDDYc3XtWiE1cYm5QhVJ0VB5i7D8Q69HrrGN+5BjS17vkCoLTz+3zWWIiJv4oFmyS5LReA==} + engines: {node: '>=8.10.0'} + dependencies: + es-html-parser: 0.0.9 + dev: true + /@humanwhocodes/config-array@0.11.13: resolution: {integrity: sha512-JSBDMiDKSzQVngfRjOdFXgFfklaXI4K9nLF49Auh21lmBWRLIK3+xTErTWD4KU54pb6coM6ESE7Awz/FNU3zgQ==} engines: {node: '>=10.10.0'} @@ -2173,6 +2183,10 @@ packages: which-typed-array: 1.1.13 dev: true + /es-html-parser@0.0.9: + resolution: {integrity: sha512-oniQMi+466VFsDzcdron9Ry/sqUJpDJg1bbDn0jFJKDdxXhwIOYDr4DgBnO5/yPLGj2xv+n5yy4L1Q0vAC5TYQ==} + dev: true + /es-set-tostringtag@2.0.2: resolution: {integrity: sha512-BuDyupZt65P9D2D2vA/zqcI3G5xRsklm5N3xCwuiy+/vKy8i0ifdsQP1sLgO4tZDSCaQUSnmC48khknGMV3D2Q==} engines: {node: '>= 0.4'} diff --git a/test/fixtures/html.html b/test/fixtures/html.html new file mode 100644 index 00000000..7b8d5cb3 --- /dev/null +++ b/test/fixtures/html.html @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/test/prettier.js b/test/prettier.js index fe8305b9..8e12ff3a 100644 --- a/test/prettier.js +++ b/test/prettier.js @@ -52,6 +52,10 @@ const eslint = new ESLint({ ], }, }, + { + files: ['*.html'], + parser: '@html-eslint/parser', + }, { files: ['*.{md,mdx}'], extends: 'plugin:mdx/recommended', @@ -216,6 +220,41 @@ eslintPluginGraphqlRuleTester.run('eslint-plugin-graphql', rule, { invalid: [], }); +runFixture('*.html', [ + [ + { + column: 1, + endColumn: 1, + endLine: 5, + fix: { + range: [23, 31], + text: ' ', + }, + line: 3, + message: 'Replace `⏎⏎` with `···`', + messageId: 'replace', + nodeType: null, + ruleId: 'prettier/prettier', + severity: 2, + }, + { + column: 1, + endColumn: 1, + endLine: 8, + fix: { + range: [39, 47], + text: ' ', + }, + line: 6, + message: 'Replace `⏎⏎` with `··`', + messageId: 'replace', + nodeType: null, + ruleId: 'prettier/prettier', + severity: 2, + }, + ], +]); + const mdxRuleTester = new RuleTester({ parser: require.resolve('eslint-mdx'), parserOptions: { diff --git a/worker.js b/worker.js index 8a8a802c..037c2c3a 100644 --- a/worker.js +++ b/worker.js @@ -96,9 +96,7 @@ runAsWorker( // 2. `eslint-plugin-html` // 3. `eslint-plugin-markdown@1` (replacement: `eslint-plugin-markdown@2+`) // 4. `eslint-plugin-svelte3` (replacement: `eslint-plugin-svelte@2+`) - const parserBlocklist = ['html']; - - let inferParserToBabel = parserBlocklist.includes(initialOptions.parser); + let inferParserToBabel = false; switch (inferredParser) { // it could be processed by `@graphql-eslint/eslint-plugin` or `eslint-plugin-graphql` @@ -111,6 +109,18 @@ runAsWorker( } break; } + case 'html': { + // it could be processed by `eslint-plugin-html` or correctly parsed by `@html-eslint/parser` + if ( + (typeof parserMeta !== 'undefined' && + parserMeta.name !== '@html-eslint/parser') || + (typeof parserPath === 'string' && + !/([\\/])@html-eslint\1parser\1/.test(parserPath)) + ) { + inferParserToBabel = true; + } + break; + } case 'markdown': { // it could be processed by `eslint-plugin-markdown@1` or correctly parsed by `eslint-mdx` if (