0

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

Gama11
  • 31,714
  • 9
  • 78
  • 100
J Kluseczka
  • 1,150
  • 9
  • 14
  • 1
    You can only report issues to its GitHub repo. VSCode API does allow an extension to report errors in better ways (error highlight in the editor, or the Problem tab), so the author of that extension should make use of such. – Lex Li Jun 08 '20 at 12:45
  • Heh, I wrote the issue [prettier/prettier-vscode#1419](https://github.com/prettier/prettier-vscode/issues/1419) and I saw that there was already an issue about that. It's [prettier/prettier-vscode#1332](https://github.com/prettier/prettier-vscode/issues/1332). – J Kluseczka Jun 08 '20 at 13:43
  • 1
    If the developers do not respond timely, you might fix it on your own, or switch to another extension. – Lex Li Aug 10 '20 at 21:28

0 Answers0