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

formatOnSave is not working #290

Closed
kpman opened this issue Dec 11, 2017 · 35 comments
Closed

formatOnSave is not working #290

kpman opened this issue Dec 11, 2017 · 35 comments
Labels
locked Please open a new issue and fill out the template instead of commenting. need-more-info

Comments

@kpman
Copy link

kpman commented Dec 11, 2017

After upgrade version to v1.0.0, the vscode setting formatOnSave is not working on my machine.
But when I changeprettier.eslintIntegration to true, the auto-format is working.

Are there some changes not listed on the Changelog between the version bumping? Or maybe I missed something on the vscode setting?

My Prettier - Code formatter: version 1.0.0
My vscode version: 1.18.1
My vscode setting:

"editor.formatOnSave": true,
"prettier.singleQuote": true,
"prettier.trailingComma": "es5",
@landvibe
Copy link

landvibe commented Dec 11, 2017

same here.
in my case, typescript project is not working, but javascript project works well.
A project with prettier 1.8.2 is not working, but a project with prettier 1.4.4 works well

@CiGit
Copy link
Member

CiGit commented Dec 11, 2017

Can't reproduce (js and ts). Does it work if you call the action ("Format Document")
Are there any messages in the output panel or dev tool ?

Try reinstalling the extension, it fixed some other issues (don't know why...).

@pitkane
Copy link

pitkane commented Dec 11, 2017

In my case prettier was throwing error about proseWrap setting.

Fixed it by manually adding: "prettier.proseWrap": true

My Prettier - Code formatter: version 1.0.0
My vscode version: 1.18.1

Errors which Prettier throws:

image 2017-12-11 at 1 44 14 pm

Settings view:

image 2017-12-11 at 1 47 08 pm

@crazysaem
Copy link

Same issue here. I worked around it by downgrading to the prior version, 0.2.6.
You can downgrade to 0.26.0 by downloading the vsix file directly:
https://marketplace.visualstudio.com/_apis/public/gallery/publishers/esbenp/vsextensions/prettier-vscode/0.26.0/vspackage

@CiGit
Copy link
Member

CiGit commented Dec 11, 2017

@pitkane Do you have a prettier@1.8.x installed locally ?

@pitkane
Copy link

pitkane commented Dec 11, 2017

@CiGit Oopsie doopsie. Working on two projects at the same time, and the other one had 1.8.2 installed mistakenly. I was quite sure I removed it from both projects... ;)

@landvibe
Copy link

@CiGit
A project with prettier 1.8.2 was not working
I updated it to 1.9.1 and then it works well

@CiGit
Copy link
Member

CiGit commented Dec 11, 2017

Yes, we don't handle deprecated settings anymore. I would encourage anyone who wishes to use a different version (installed in package.json) to also provide a prettier config file

@CiGit
Copy link
Member

CiGit commented Dec 11, 2017

Try uninstall/ install the extension and restart vscode (This has fixed issues in the past ...)
Is there something in the output pane? It shouldn't in your case as you said the default formatter kicks in. How did you define that?
You can try to format this snippet:

const x = {
}
const y = {
       a: "Hello",
    b:'World'
}

Lastly, if you could debug it ? I'm unable to reproduce this.

@g3offrey
Copy link

Reinstalled as you said and it works fine now @CiGit
Thanks for all ! And again good job for this awesome extension 👌 😄

@crazysaem
Copy link

Reinstalling resolved it for me as well! Working fine now

@zebapy
Copy link

zebapy commented Dec 11, 2017

manually running format document isn't working for me. Tried reinstalling prettier ext.

@kpman
Copy link
Author

kpman commented Dec 12, 2017

I found the issue was caused by different local prettier version.

I used perttier@1.8.2 at my project, so the new version of perttier-vscode@1.0.0 can not do formatOnSave. But after I upgrade my project's prettier version to v1.9.2, the formatOnSave` is working on my machine.

@CiGit Thanks.

So, if there is some way to use perttier-vscode v1.0.0 with perttier@1.8.2?

@CiGit
Copy link
Member

CiGit commented Dec 12, 2017

@kpman #290 (comment)

@jonescr3
Copy link

if you have an editorconfig file, that was the problem for us

@konekoya
Copy link

konekoya commented Dec 13, 2017

@kpman Thanks, life without prettier is such a pain.

@pkyeck
Copy link

pkyeck commented Dec 19, 2017

I have this in my .vscode/settings.json:

{
  "editor.formatOnSave": false,
  "[javascript]": {
    "editor.formatOnSave": true
  }

Was working before but now it doesn't format JS files on save anymore ☹️
When I change the global to true, it works. But I just want my JavaScript files to be formatted.

@CiGit
Copy link
Member

CiGit commented Dec 20, 2017

@pkyeck is that your entire settings.json ? In this case, it seems } is missing.
If changing the global makes it work, I would say the issue is not in this project.

@pkyeck
Copy link

pkyeck commented Dec 20, 2017

@CiGit no, sorry. thought I copy+pasted the important part.

This doesn't work:

{
  "eslint.enable": true,
  "files.exclude": {
    "node_modules": true,
    ".npm-offline-cache": true
  },
  "editor.formatOnSave": false,
  "[javascript]": {
    "editor.formatOnSave": true
  }
}

This works:

{
  "eslint.enable": true,
  "files.exclude": {
    "node_modules": true,
    ".npm-offline-cache": true
  },
  "editor.formatOnSave": true,
  "[javascript]": {
    "editor.formatOnSave": true
  }
}

First version was working before the November update.

@CiGit
Copy link
Member

CiGit commented Dec 20, 2017

It works on my setup. I suspect you have an issue with something else. maybe your vscode installation.

@pkyeck
Copy link

pkyeck commented Dec 22, 2017

mmm, strange. Then I'll have to look into this some more. Thanks for your help, though.

@ghost
Copy link

ghost commented Apr 22, 2018

I've reinstalled everything many times and I can only get 'format selection' to work every time.

@CiGit
Copy link
Member

CiGit commented Apr 24, 2018

I invite you to read https://code.visualstudio.com/updates/v1_22#_configurable-format-on-save-timeout
This may resolve troubles found in this thread.
Open a new issue if you encounter anything else.

@CiGit CiGit closed this as completed Apr 24, 2018
@ajenkins-kyr
Copy link

@pkyeck I also had to add

"[javascriptreact]": {
        "editor.formatOnSave": true
    }

for it to work with .jsx files. Not sure if that was your issue.

@vaibhavsharma56
Copy link

Solution by pkyeck worked great, for typeScript, add in next lines ::
"[typescript]": {
"editor.formatOnSave": true
}

@sethlivingston
Copy link

For TypeScript I needed both to get it working again:

  "editor.formatOnSave": true,
  "[javascript]": {
    "editor.formatOnSave": true
  },
  "[typescript]": {
    "editor.formatOnSave": true
  },

Prettier v1.6.1

@lucksp
Copy link

lucksp commented Sep 14, 2018

With Prettier 1.6.1, VSCode 1.27.2,
no ESLint

I also had to add

"[javascript]": {
    "editor.formatOnSave": true
  },

@code4cake
Copy link

code4cake commented Sep 21, 2018

Got finally worked for me was to add "[javascriptreact]": { "editor.formatOnSave": true } to my settings.json

prettier vscode
1.14.3 1.27.2

I have the following configuration.

// workspace.settings.json

{
  "prettier.printWidth": 120,
  "prettier.tabWidth": 2,
  "prettier.singleQuote": true,
  "prettier.trailingComma": "none",
  "prettier.bracketSpacing": true,
  "prettier.parser": "flow",
  "prettier.semi": true,
  "prettier.useTabs": false,
  "prettier.jsxBracketSameLine": false,
  "[javascript]": {
    "editor.formatOnSave": true
  },
  "[javascriptreact]": {
    "editor.formatOnSave": true
  }
}

@j0nd0n7
Copy link

j0nd0n7 commented Nov 14, 2018

This:
"[javascriptreact]": { "editor.formatOnSave": true }

from @dantesolis solved my problem! Thanks

@Izhaki
Copy link

Izhaki commented Dec 28, 2018

Non of the solutions here worked for me.

I have had the same issue with a bare typescript project.

Turns out there was an extra comma in package.json that rendered it invalid. Removed and it was all working again.

ODD!!!!

@dmt0
Copy link

dmt0 commented Feb 20, 2019

For me, format on save was not working because of eslint. Ran eslint from command line, turns out there were missing packages that it needed. So there were issues in the file that eslint didn't underline, that prevented prettier from auto-formatting.

@sbalay
Copy link

sbalay commented Mar 7, 2019

In my case, as @CiGit mentioned, the format on save was not working because of the timeout. You can check if this is your case reading the output of Log (Window). A message like this one will be displayed: [2019-03-07 17:59:04.135] [renderer2] [warning] Aborted format on save after 750ms

@eouw0o83hf
Copy link

Just so it shows up here explicitly as a comment, VS Code has a timeout for how long format-on-save actions are allowed to take. You can configure this with:

"editor.formatOnSaveTimeout": 750,

The default is 750 (in ms), but you can make it as high as you want. Moving up to 3000 fixed my problems.

@ericloong90
Copy link

@eouw0o83hf 's solution fixed it for me. Turns out it's just my computer being slow at formatting and VSCode automatically times out the formatting action for me.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot added the locked Please open a new issue and fill out the template instead of commenting. label Apr 13, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked Please open a new issue and fill out the template instead of commenting. need-more-info
Projects
None yet
Development

No branches or pull requests