Trailing comma after last line in object

Eliran Zeitouni picture Eliran Zeitouni · Apr 22, 2020 · Viewed 13.5k times · Source

I'm using Prettier in VS Code. I noticed that when using format on save, Prettier adds trailing commas on the last line of an object every time.

For example, let's say I had a JS object like this:

obj = {
 hello: 'hello',
 world: 'world'
}

Prettier turns it into this:

obj = {
 hello: 'hello',
 world: 'world',
}

Notice the extra comma after 'world'

Didn't find in the settings an option to fix this.

Answer

Zuckerberg picture Zuckerberg · Apr 22, 2020

You can update .prettierrc.json and set option trailingComma to none like:

{
  "trailingComma" : "none",
  ...
}