Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support parsing html via @html-eslint/parser natively #652

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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": patch
JounQin marked this conversation as resolved.
Show resolved Hide resolved
---

feat: support parsing `html` via `@html-eslint/parser` natively
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
"@eslint-community/eslint-plugin-eslint-comments": "^4.1.0",
"@eslint/js": "^8.56.0",
"@graphql-eslint/eslint-plugin": "^3.20.1",
"@html-eslint/eslint-plugin": "^0.24.0",
"@html-eslint/parser": "^0.24.0",
"@prettier/plugin-pug": "^3.0.0",
"@types/eslint": "^8.56.0",
"@types/prettier-linter-helpers": "^1.0.4",
Expand Down
22 changes: 22 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\/parser\1/.test(parserPath))
Logicer16 marked this conversation as resolved.
Show resolved Hide resolved
) {
inferParserToBabel = true;
}
break;
}
case 'markdown': {
// it could be processed by `eslint-plugin-markdown@1` or correctly parsed by `eslint-mdx`
if (
Expand Down