How to turn off the prettier trailing comma in VS Code?

Viewed 35844

How to turn off the prettier trailing comma in VS Code?

I go to settings. Select none for the prettier trailing comma. Restart VS Code. Select a piece of TypeScript, press Ctrl + Shift + F and the trailing commas still appear. How could I fix it?

enter image description here

8 Answers

Since you are working on the Tour of Heroes project, it is maybe the .editorconfig file there that introduces conflicts with your VSCode Prettier settings. Try adding the following .prettierrc file at the root of your project :

{
  "trailingComma": "none"
}

The .prettierrc file has the highest priority over any setting, so it should override any conflict.

Adding this line to settings.json worked for me.

"prettier.trailingComma": "none"

At the root of the project create the Prettier configuration file: .prettierrc.json

Add this code to your file: .prettierrc.json

{
    "trailingComma": "none"
}

Save file and then restart your Visual Studio Code

I was facing same problem and I added this line in the settings and it worked for me.

"prettier.trailingComma": "none"

I had the same experience as your screen recording. Restarting VSCode did the trick for me. I could not find a way to restart the prettier addon... maybe someone can chime in on how to do that.

Run this command:

npm run lint --fix

after formatting...

In VS Code Settings, go to json file and type this:

"prettier.useEditorConfig": false

Or just in the Setting, under Prettier configs, set this to false/uncheck to prevent prettier other config to take precedence over Prettier

Prettier has the following rules for where to look for settings (in order of precedence):

  • A "prettier" key in your package.json file.
  • A .prettierrc file written in JSON or YAML.
  • A .prettierrc.json, .prettierrc.yml, .prettierrc.yaml, or .prettierrc.json5 file.
  • A .prettierrc.js, .prettierrc.cjs, prettier.config.js, or prettier.config.cjs file that exports an object using module.exports.
  • A .prettierrc.toml file.

Following the first rule, I was able to configure it by adding the following to package.json

"prettier": {
  "trailingComma": "none"
}
Related