prettier-vscode: formatOnSave is not working

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",

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 41
  • Comments: 35 (8 by maintainers)

Most upvoted comments

@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.

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.

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.

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

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

@pkyeck I also had to add

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

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

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

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

With Prettier 1.6.1, VSCode 1.27.2, no ESLint

I also had to add

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

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

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…).