Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting of .vue files? #543

Closed
3 tasks done
truongio opened this issue Nov 14, 2017 · 63 comments
Closed
3 tasks done

Formatting of .vue files? #543

truongio opened this issue Nov 14, 2017 · 63 comments

Comments

@truongio
Copy link

truongio commented Nov 14, 2017

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • Platform: macOS High Sierra
  • Vetur version: 0.11.3
  • VS Code version: 1.18.0

Problem

The editor says: "Sorry, but there is no formatter for 'vue'-files installed." when I press format document keybind.

Did I miss something or does Vetur with Prettier not support .vue files anymore for formatting?

@octref
Copy link
Member

octref commented Nov 14, 2017

Did you install other vue extensions? Do you have file.associations?

@preinoch
Copy link

I have this problem too in same vetur/vscode version, but my system is Windows10, vscode prompt "The Vue Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted.".
I have reinstalled vetur solve this problems.

@truongio
Copy link
Author

truongio commented Nov 15, 2017

@octref I had Vue Snippets but I tried uninstalling it and it still doesn't work. I have no files.associations in my settings, just the default

@truongio
Copy link
Author

It solved itself by resintalling Vetur for some reason.

@Atuna
Copy link

Atuna commented Nov 17, 2017

As shown in the screenshoot below, I have the same problem. I have Vetur and Vim plugin installed, and file.associations that link *.wpy files to vue formate. When I press "==" to formate one line in a wpy file, a hint will shown up said: "Sorry, but there is no formatter for 'vue'-files installed."

screen shot 2017-11-17 at 3 51 40 pm

@octref
Copy link
Member

octref commented Nov 17, 2017

@Atuna We do not have line-based formatter. You can only format whole document.
Other than that, wpy is not supported by Vetur.

@eric-burel
Copy link

Hi, this should not be closed, it did not solve after a reinstall of vetur. This issue is related to the 1.18 version of VSCode.

@chrisnicola
Copy link

Running into this issue as well. I'm guessing this has to do with the change to Prettier. Does it need to be installed via NPM. I added the VSCode extensions now.

@chrisnicola
Copy link

@octref you say you never had line or selection based formatting, but I don't recall seeing this error before now.

@octref
Copy link
Member

octref commented Dec 6, 2017

@Atuna is the only person giving me a screenshot, and the problem is Vetur registers a formatter for *.vue files, not *.wpy files.

If you report issue without describing the issues, like which file you are trying to format, what extensions you have, etc, I can't do anything right?

@eric-burel
Copy link

Hi @octref, this is not the lack of good will, it is that there are actually not much to say, this bug appear as soon as we try to format any .vue file. Here are my settings:

// Placez vos paramètres dans ce fichier pour remplacer les paramètres par défaut
{
    "eslint.autoFixOnSave": true,
    "eslint.trace.server": "verbose",
    "editor.fontSize": 18,
    "window.zoomLevel": 1,
    "vim.disableAnnoyingNeovimMessage": true,
    "git.confirmSync": false,
    //"emmet.triggerExpansionOnTab":true,
    "emmet.includeLanguages": {
        "javascript": "html",
        "vue": "html",
        "vue-html": "html",
        "javascriptreact":"html",
        "typescript":"html"
    },
    "editor.multiCursorModifier": "ctrlCmd",
    "workbench.iconTheme": "ayu",
    "vetur.format.html.wrap_attributes":"force-expand-multiline"
}

So there are no file associations. The bug appeared as soon as I updated to VSCode 1.18. I'll try to check if there is a bad interaction with another lib, but I think it is a config or lower level issue.

@guyulmaz
Copy link

guyulmaz commented Dec 7, 2017

I have 1.19.0-insider with the latest build, and the problem still exists.

@octref
Copy link
Member

octref commented Dec 7, 2017

What's the output in Output (In the bottom panel, next to terminal) -> v-language-sever?

@eric-burel
Copy link

@octref It shows Vue. Could it be related to prettier, which seems to be the default formatter for js ?

@octref
Copy link
Member

octref commented Dec 7, 2017

I mean this.

image

@eric-burel
Copy link

Oh yeah sorry, it shows vetur initialized as expected. Note that everything else seems to works well, it is only formatting.

@octref
Copy link
Member

octref commented Dec 15, 2017

I'm tracking this in #592.

@liuguangyong93
Copy link

I met this situation too!

@liuguangyong93
Copy link

I have 1.19.1-insider with the latest build, and the problem still exists.I reinstalled,but it doesnot working now.

@liuguangyong93
Copy link

@octref@eric-burel,please help me!

@eric-burel
Copy link

Hi @gavin110 sadly I'll be of no help there :) See #592 where the issue is tracked.

@liuguangyong93
Copy link

@eric-burel Thanks!

@mholtzhausen
Copy link

mholtzhausen commented Jan 18, 2018

Add this to your settings:
"vetur.format.defaultFormatter.html": "js-beautify-html"

@rajeshwarpatlolla
Copy link

I have the below json in my settings. But still it is not formatting <template> code in .vue file.

{
    "prettier.singleQuote": true,
    "prettier.trailingComma": "all",
    "prettier.printWidth": 300,
    "editor.tabSize": 2,
    "prettier.eslintIntegration": true,
    "vetur.format.defaultFormatter.html": "js-beautify-html"
}

@pjconnect
Copy link

also, I had to remove "Beautify" extension. now it's formatting all including HTML.

@rajeshwarpatlolla
Copy link

.ts files are not formatting if i remove buetify

@sandro-git
Copy link

Hello, i try the last solution and it works well but it conflicts with Eslint plugin:vue/recommended. How can we setup js-beautify-html to apply formats like : html.format.wrapAttributes : force-expand-multiline

@sandro-git
Copy link

ok. I try this out. that format all the document what I'm trying to do is to format only html. and have another configuration for js.

@MrSunshyne MrSunshyne mentioned this issue Apr 22, 2018
12 tasks
@octref
Copy link
Member

octref commented May 14, 2018

I added a notice on top of https://vuejs.github.io/vetur/formatting.html.

@gayanSandamal
Copy link

Mine is fixed.

  1. Install Prettier extension.
    URL - https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
  2. Go to File > Preferences > Settings
  3. Add below,
    "prettier.singleQuote": true,
    "prettier.semi": false,
    "prettier.eslintIntegration": true
  4. Save.
  5. Try Alt + Shift + F

@slinker-hiwa
Copy link

My setting. working for my.

"emmet.syntaxProfiles": {
        "vue-html": "html",
        "vue": "vue",
        "javascriptreact": "jsx",
        "javascript": "js",
        "typescript": "jsx",
        "typescriptreact": "tsx"
    },

@mariusa
Copy link

mariusa commented Aug 13, 2018

@octref Could you please reopen this issue and leave open until there is an official default solution listed at
https://vuejs.github.io/vetur/formatting.html
?
Formatting .vue files doesn't work now with prettier.

@octref
Copy link
Member

octref commented Aug 13, 2018

Yes, there are other issues for prettier. Please find the right one to follow up: https://github.com/vuejs/vetur/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+prettier

@AshGrowem
Copy link

AshGrowem commented Sep 4, 2018

Solutions

*Update!

PrettyHTML now supported, see last solution 3 below

1. ESlint autoFixOnSave (Official)

Just do command-save to format.

Prerequisites

// settings.json

  "eslint.autoFixOnSave": true,
  "eslint.validate": [
    "html",
    "css",
    "javascript",
    "javascriptreact",
    { "language": "vue", "autoFix": true },
    { "language": "vue-html", "autoFix": true }
  ],
// package.json

"eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": "plugin:vue/recommended",
    "parserOptions": {
      "parser": "babel-eslint"
    }
  },

Options

plugin:vue/base - Settings and rules to enable correct ESLint parsing
plugin:vue/essential - Above, plus rules to prevent errors or unintended behavior
plugin:vue/strongly-recommended - Above, plus rules to considerably improve code readability and/or dev experience
plugin:vue/recommended - Above, plus rules to enforce subjective community defaults to ensure consistency
https://github.com/vuejs/eslint-plugin-vue#gear-configs

2. JS-Beautify js-beautify-html (Deprecated)

This is just using VSCode's built-in html formatter which is based on js-beautify

Alternative html formatter. Deprecated, turned off by default and will be removed soon. js-beautify is not actively maintained and has many long-standing bugs. Use at your own risk.
https://vuejs.github.io/vetur/formatting.html#js-beautify-html-deprecated

Prerequisites

// settings.json

"vetur.format.defaultFormatter.html": "js-beautify-html",

3. prettyHTML

Haven't tried but it looks promising. Created last June and the lone contributor is very active.
https://github.com/Prettyhtml/prettyhtml

Prerequisites

// settings.json

"vetur.format.defaultFormatter.html": "prettyhtml",

Future Alternatives

@octref
Copy link
Member

octref commented Sep 5, 2018

Re prettyHTML, see #491 (comment), I'm looking into it, so far looks promising.

@oller
Copy link

oller commented Oct 17, 2018

I mean this.

image

what theme is this @octref looks pretty!

Ahh, I see it's Nord.

@sandro-git
Copy link

@octref it looks great but difficult to figure out how to install in vscode today.

I don’t have the skills unfortunately but a extension would be great.

@octref
Copy link
Member

octref commented Oct 18, 2018

It is bundled. Just enable it with "vetur.format.defaultFormatter.html": "prettyhtml"

@octref
Copy link
Member

octref commented Oct 18, 2018

@sandro-git
Copy link

sandro-git commented Oct 18, 2018

@octref i just try it like that and it doesn't work. my settings :
capture d ecran 2018-10-18 a 21 15 35
the template tag still with 2 spaces after saving should i format the document manually ?

@oller
Copy link

oller commented Oct 19, 2018 via email

@octref
Copy link
Member

octref commented Oct 21, 2018

@sandro-git @oller This is VS Code's feature called editor.detectIndentation. You can turn that off by "editor.detectIndentation": false. I'll try to add a warning for this confusing behavior.

@octref octref reopened this Oct 21, 2018
@sandro-git
Copy link

@octref sorry to boring you with that small problem but it still doesn't indent 4 spaces instead 2.

@phillip-haydon
Copy link

Yup, I have the same issue. HTML formatted with 4 spaces, style/script with 2 spaces. All other JS files are 4 spaces.

@redeemefy
Copy link

Same here, html 2 spaces instead of 4 spaces, and js code is 2 spaces indentation.

@octref
Copy link
Member

octref commented Nov 21, 2018

If you have a prettierrc locally, or have prttier.* configs in VS Code, change tabWidth to 4.

When they are present, they override the tabSize in VS Code.

The original issue happens when you have not initialized Vetur correctly. If you still experience it, open new issues with repro steps.

@octref octref closed this as completed Nov 21, 2018
@phillip-haydon
Copy link

phillip-haydon commented Nov 22, 2018

That makes no sense. This can be reproduced by having a clean install of vscode. Configure vscode to be tabsize 4. Turn off detect by file. Then install vetur. And it sets the tabsize 2. It ignores vscode. If installing vetur code says I did not initialize it correctly then vetur is buggy.

(This is how my local is setup)

@octref
Copy link
Member

octref commented Nov 22, 2018

I see your problem. I think going forward, having two options, vetur.format.options.tabSize and vetur.format.options.useTabs that's NOT affected by indentation detection would make it easier to understand. Currently if you do set prettier.tabWidth to 4, I think Vetur formats the js section with 4 spaces.

Maybe I should also avoid reading configs from prettier.* and just read from local .prettierrc files. This has always been a source of confusion...

@sandro-git
Copy link

@octref what do you mean by initialized vetur correctly. I just install it, change some option and use it.

@octref
Copy link
Member

octref commented Nov 26, 2018

@sandro-git So you are still experiencing the original problem?

Try to either reinstall Vetur or remove other Vue extensions that would conflict with Vetur.

@abdusamadtv
Copy link

@octref i just try it like that and it doesn't work. my settings :
capture d ecran 2018-10-18 a 21 15 35
the template tag still with 2 spaces after saving should i format the document manually ?

you can check this

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests