Ugly formatting html in .vue file
See original GitHub issueI just updated prettier in my vue project and now in a SFC .vue file it’s formatting this code:
<template>
<router-link
class="margin-right-medium"
to="/admin/ads/list">Lista</router-link>
</template>
into this:
<template>
<router-link class="margin-right-medium" to="/admin/ads/list"
>Lista</router-link
>
</template>
this is very ugly while I expected something like this:
<template>
<router-link
class="margin-right-medium"
to="/admin/ads/list">
Lista
</router-link>
</template>
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
How to customize HTML formatting with Vue 3 and Prettier?
Solution 3: Increase printWidth for the component ... Sorry to say, and don't take it personal, but all this suggestions are ugly workarounds...
Read more >How do I fix this ugly formatting in Prettier? : r/vuejs - Reddit
So Prettier has to keep the > and < stuck to the textContent, resulting in the weird formatting you see. That's why adding...
Read more >How I Resolved Vue.js, VSCode, Vetur, Prettyhtml, and ...
So, when open a .vue file in VS Code and Format Document with Vetur, it uses Prettyhtml by default, which violates prettier ES...
Read more >7 Ways to Define a Component Template in Vue.js
The quickest and easiest way to define a Vue component template is to ... template is defined inside a script tag in the...
Read more >Single File Components - Vue.js
String templates lack syntax highlighting and require ugly slashes for multiline HTML; No CSS support means that while HTML and JavaScript are modularized...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Prettier isn’t composed of rules in that way, it’s more of a all-or-nothing type of thing. Note that if you manually add some spaces/newlines in certain places Prettier will preserve (some) of them (because it can’t know what is safe to do). For example:
Prettier 1.16.4 Playground link
Input:
Output:
But I do agree that splitting the end tag (
</router-link
) across several lines is a little bit unusual. It’s no bug though – Prettier has always done so for HTML. Maybe @ikatyang knows where this comes from?Hi @oswaldofreitas,
I got the same issue today, with the
</closing-tags>
that the closing>
was on a new line.I ended up creating a
.prettierrc
with thathtmlWhitespaceSensitivity
set to ignore. That seemed to be picked up by my eslint + prettier setup and formatted everything correctly.So at least for my, @duailibe 's suggestion he made here worked for me. I didn’t even bother with adding
parser: vue
anywhere.