Vetur: Strange formatting in .vue files with TypeScript

Created on 10 Jan 2018  ·  3Comments  ·  Source: vuejs/vetur

  • [x] I have read through docs
  • [x] I have searched through existing issues
  • [x] I have read FAQ

Info

  • Platform: Windows Pro 10.0.16299.125
  • Vetur version: 0.11.5
  • VS Code version: 1.19.1

Problem

I installed the vetur, and everything seemed good. But when I tried to format a .vue file, it seemed strange.

  1. The formatting was forced to ues 2 spaces for indentation.
  2. The formatting for TypeScript was very ugly and unreadable.
    image
    I did not change any setting for vetur. And I had disabled other plugins except vetur and tried again, but nothing changed.
    And there is only one message in Panel -> Output -> Vue Language Server which said vetur initialized.

Reproducible Case

  1. Install vetur.
  2. Open a .vue file which includes some <script lang="ts"/>.
  3. Right-click the document to call a context menu.
  4. Click "Format Document".

UPDATE: I found out the plugin prettier and installed it and make some setting, and then the first problem was fixed. But it did not fix the second problem.=。=

Most helpful comment

That's just how prettier formats the code - in this specific case, it forces a lot of the arguments on new lines because it enforces a max line-length, and since your code is nested a couple of levels, the remaining allowed space is small.

If you don't like that, don't use prettier.

Since you claim to have read the docs: Have you tried using the internal vscode-typescript for formatting instead?

https://vuejs.github.io/vetur/formatting.html

All 3 comments

That's just how prettier formats the code - in this specific case, it forces a lot of the arguments on new lines because it enforces a max line-length, and since your code is nested a couple of levels, the remaining allowed space is small.

If you don't like that, don't use prettier.

Since you claim to have read the docs: Have you tried using the internal vscode-typescript for formatting instead?

https://vuejs.github.io/vetur/formatting.html

@LinusBorg I tried, and got the same result.
And I made the value of the setting prettier.printWidth as 160, and everything is ok.
Thanks for your patience!

Close #628

Was this page helpful?
0 / 5 - 0 ratings