question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ugly formatting html in .vue file

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
lydellcommented, Feb 11, 2019

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

--parser vue

Input:

<template>
  <router-link
    class="margin-right-medium"
    to="/admin/ads/list">
    Lista
  </router-link>
</template>

Output:

<template>
  <router-link class="margin-right-medium" to="/admin/ads/list">
    Lista
  </router-link>
</template>

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?

1reaction
axit-joostcommented, Feb 15, 2019

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 that htmlWhitespaceSensitivity 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found