Skip to content

Commit f170011

Browse files
Logicer16JounQin
andauthored
feat: support parsing html via @html-eslint/parser natively (#652)
Co-authored-by: JounQin <admin@1stg.me>
1 parent 248cd17 commit f170011

File tree

6 files changed

+81
-3
lines changed

6 files changed

+81
-3
lines changed

.changeset/rich-swans-itch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-prettier": minor
3+
---
4+
5+
feat: support parsing `html` via `@html-eslint/parser` natively

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"@eslint-community/eslint-plugin-eslint-comments": "^4.1.0",
7575
"@eslint/js": "^8.56.0",
7676
"@graphql-eslint/eslint-plugin": "^3.20.1",
77+
"@html-eslint/parser": "^0.24.1",
7778
"@prettier/plugin-pug": "^3.0.0",
7879
"@types/eslint": "^8.56.0",
7980
"@types/prettier-linter-helpers": "^1.0.4",

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/html.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
5+
</head>
6+
<body>
7+
8+
</body>
9+
</html>

test/prettier.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ const eslint = new ESLint({
5252
],
5353
},
5454
},
55+
{
56+
files: ['*.html'],
57+
parser: '@html-eslint/parser',
58+
},
5559
{
5660
files: ['*.{md,mdx}'],
5761
extends: 'plugin:mdx/recommended',
@@ -216,6 +220,41 @@ eslintPluginGraphqlRuleTester.run('eslint-plugin-graphql', rule, {
216220
invalid: [],
217221
});
218222

223+
runFixture('*.html', [
224+
[
225+
{
226+
column: 1,
227+
endColumn: 1,
228+
endLine: 5,
229+
fix: {
230+
range: [23, 31],
231+
text: ' <head> ',
232+
},
233+
line: 3,
234+
message: 'Replace `<head>⏎⏎` with `··<head>·`',
235+
messageId: 'replace',
236+
nodeType: null,
237+
ruleId: 'prettier/prettier',
238+
severity: 2,
239+
},
240+
{
241+
column: 1,
242+
endColumn: 1,
243+
endLine: 8,
244+
fix: {
245+
range: [39, 47],
246+
text: ' <body>',
247+
},
248+
line: 6,
249+
message: 'Replace `<body>⏎⏎` with `··<body>`',
250+
messageId: 'replace',
251+
nodeType: null,
252+
ruleId: 'prettier/prettier',
253+
severity: 2,
254+
},
255+
],
256+
]);
257+
219258
const mdxRuleTester = new RuleTester({
220259
parser: require.resolve('eslint-mdx'),
221260
parserOptions: {

worker.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ runAsWorker(
9696
// 2. `eslint-plugin-html`
9797
// 3. `eslint-plugin-markdown@1` (replacement: `eslint-plugin-markdown@2+`)
9898
// 4. `eslint-plugin-svelte3` (replacement: `eslint-plugin-svelte@2+`)
99-
const parserBlocklist = ['html'];
100-
101-
let inferParserToBabel = parserBlocklist.includes(initialOptions.parser);
99+
let inferParserToBabel = false;
102100

103101
switch (inferredParser) {
104102
// it could be processed by `@graphql-eslint/eslint-plugin` or `eslint-plugin-graphql`
@@ -111,6 +109,18 @@ runAsWorker(
111109
}
112110
break;
113111
}
112+
case 'html': {
113+
// it could be processed by `eslint-plugin-html` or correctly parsed by `@html-eslint/parser`
114+
if (
115+
(typeof parserMeta !== 'undefined' &&
116+
parserMeta.name !== '@html-eslint/parser') ||
117+
(typeof parserPath === 'string' &&
118+
!/([\\/])@html-eslint\1parser\1/.test(parserPath))
119+
) {
120+
inferParserToBabel = true;
121+
}
122+
break;
123+
}
114124
case 'markdown': {
115125
// it could be processed by `eslint-plugin-markdown@1` or correctly parsed by `eslint-mdx`
116126
if (

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy