Closed domaine-preston closed 4 months ago
What you're seeing is explained in these docs on whitespace handling.
The official HTML plugin offered by prettier does the same thing. The TL;DR is that the lack of whitespace in HTML can be meaningful and that the prettier plugin should not alter the semantic meaning of source files by default. So we're forced to maintain the lack of whitespace after formatting. <label>...</label>
didn't have whitespace after l>
nor before </
, so the formatted code shouldn't have some.
You can turn that off by setting --htmlWhitespaceSensitivity
to ignore
, but it would be dangerous to run it blindly on multiple files because you may end up with spacing in places you don't expect after running it. Your site might be broken in subtle ways.
There's also this article which does a good job of explaining the same issue.
Re the script tag, if there wasn't a new line and the print width is enough for the tag and closing tag to fit on a line, it doesn't break automatically for me. Are you sure that's true?
Ok, understood about the label tag. I don't like it, but I understand.
I checked the script tag in a different repo that has similar formatting and linting settings and the issue isn't happening there. So I guess it's related to that one project.
Ok, understood about the label tag. I don't like it, but I understand.
Like I said, you can set the following in your .prettierrc
and have it format like you want. Just beware that if you run prettier wholesale, that might create bugs!
{
"htmlWhitespaceSensitivity": "ignore"
}
You can also enable that from the command line with the --html-whitespace-sensitivity=ignore
flag.
Is your feature request related to a problem? Please describe.
<script>
is being formatted regardless ofprintWidth
value<label>
could be improved when formatted based onprintWidth
In the screenshot:
printWidth
. It looks like that at 200 and 50.Describe the solution you'd like I think the formatting can be improved. Here are a few ideas:
<script>
tag should respect theprintWidth
value and<label>
could do better at wrapping the last bracket, like the<div>
is already doing.Checklist
Additional context I have disabled all other formatting extensions: ESLint, Prettier, and Stylelint