Skip to content

Commit

Permalink
feat: support parsing html via @html-eslint/parser natively (#652)
Browse files Browse the repository at this point in the history
Co-authored-by: JounQin <[email protected]>
  • Loading branch information
Logicer16 and JounQin authored Apr 9, 2024
1 parent 248cd17 commit f170011
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-swans-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-prettier": minor
---

feat: support parsing `html` via `@html-eslint/parser` natively
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions test/fixtures/html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!doctype html>
<html>
<head>

</head>
<body>

</body>
</html>
39 changes: 39 additions & 0 deletions test/prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const eslint = new ESLint({
],
},
},
{
files: ['*.html'],
parser: '@html-eslint/parser',
},
{
files: ['*.{md,mdx}'],
extends: 'plugin:mdx/recommended',
Expand Down Expand Up @@ -216,6 +220,41 @@ eslintPluginGraphqlRuleTester.run('eslint-plugin-graphql', rule, {
invalid: [],
});

runFixture('*.html', [
[
{
column: 1,
endColumn: 1,
endLine: 5,
fix: {
range: [23, 31],
text: ' <head> ',
},
line: 3,
message: 'Replace `<head>⏎⏎` with `··<head>·`',
messageId: 'replace',
nodeType: null,
ruleId: 'prettier/prettier',
severity: 2,
},
{
column: 1,
endColumn: 1,
endLine: 8,
fix: {
range: [39, 47],
text: ' <body>',
},
line: 6,
message: 'Replace `<body>⏎⏎` with `··<body>`',
messageId: 'replace',
nodeType: null,
ruleId: 'prettier/prettier',
severity: 2,
},
],
]);

const mdxRuleTester = new RuleTester({
parser: require.resolve('eslint-mdx'),
parserOptions: {
Expand Down
16 changes: 13 additions & 3 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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 (
Expand Down

0 comments on commit f170011

Please sign in to comment.