I have the VS Code with the Prettier extension installed. I'm always frustrated when I don't know why my code is not formatted properly. When I look at the output of Prettier, I see "Error formatting document.". And it pretty always means that I haven't closed one HTML div.
How to reproduce?
Create a test.html
file with this code inside:
<html>
<body>
</html>
Open the command palette (Ctrl+Shift+P) and run Format document with...
and Prettier - code formatter
. Now look at the Output (Ctrl+K and Ctrl+H) in the Prettier
section. There should be something like that:
["INFO" - 13:39:10] Formatting /tmp/test.html
["INFO" - 13:39:10] Using ignore file (if present) at undefined
["INFO" - 13:39:10] Using bundled version of prettier.
["INFO" - 13:39:10] File Info:
{
"ignored": false,
"inferredParser": "html"
}
["INFO" - 13:39:10] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 13:39:10] Prettier Options:
{
"filepath": "/tmp/test.html",
"parser": "html"
}
["ERROR" - 13:39:10] Error formatting document.
["ERROR" - 13:39:10] Unexpected closing tag "html". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (3:1)
1 | <html>
2 | <body>
> 3 | </html>
| ^
SyntaxError: Unexpected closing tag "html". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (3:1)
1 | <html>
2 | <body>
> 3 | </html>
| ^
at ct (/home/nircek/.vscode-oss/extensions/esbenp.prettier-vscode-5.0.0/node_modules/prettier/parser-html.js:1:16594)
at It (/home/nircek/.vscode-oss/extensions/esbenp.prettier-vscode-5.0.0/node_modules/prettier/parser-html.js:113:1296)
at e (/home/nircek/.vscode-oss/extensions/esbenp.prettier-vscode-5.0.0/node_modules/prettier/parser-html.js:113:3247)
at Object.parse (/home/nircek/.vscode-oss/extensions/esbenp.prettier-vscode-5.0.0/node_modules/prettier/parser-html.js:113:3724)
at Object.parse (/home/nircek/.vscode-oss/extensions/esbenp.prettier-vscode-5.0.0/node_modules/prettier/index.js:11370:19)
at coreFormat (/home/nircek/.vscode-oss/extensions/esbenp.prettier-vscode-5.0.0/node_modules/prettier/index.js:14784:25)
at format (/home/nircek/.vscode-oss/extensions/esbenp.prettier-vscode-5.0.0/node_modules/prettier/index.js:15019:75)
at formatWithCursor (/home/nircek/.vscode-oss/extensions/esbenp.prettier-vscode-5.0.0/node_modules/prettier/index.js:15035:12)
at /home/nircek/.vscode-oss/extensions/esbenp.prettier-vscode-5.0.0/node_modules/prettier/index.js:51620:12
at Object.format (/home/nircek/.vscode-oss/extensions/esbenp.prettier-vscode-5.0.0/node_modules/prettier/index.js:51640:12)
at t.default.<anonymous> (/home/nircek/.vscode-oss/extensions/esbenp.prettier-vscode-5.0.0/src/PrettierEditService.ts:328:46)
at Generator.next (<anonymous>)
at s (/home/nircek/.vscode-oss/extensions/esbenp.prettier-vscode-5.0.0/dist/extension.js:1:53223)
["INFO" - 13:39:10] Formatting completed in 71.200016ms.
But there wasn't any notification for user and I have to look at the Output.
My question
Is it possible to notify the user in some way (without checking the Output) when there was a problem with formatting? Or should I draw up an issue on GitHub of Prettier?
Thanks