Deno: [deno fmt]: Trailing comma

Created on 1 Aug 2020  路  2Comments  路  Source: denoland/deno

When calling deno fmt and a list of properties/values are long, it will append an unnecessary comma after the last one.

const object: { longName: boolean, otherLongName: boolean } = { longName: true, otherLongName: false }

```sh
deno fmt

Output:
```ts
const object: { longName: boolean; otherLongName: boolean } = {
  longName: true,
  otherLongName: false,
};

That can result in pretty weird looking code when it is more complex. Is this intentional?

Most helpful comment

Far from unnecessary. Starting from ES5, trailing commas are gradually being accepted and preferred since this reduces confusion.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas

It's also the standard option when using prettier (and obviously dprint defaults to this as well, as you can tell).

_edit:_ regarding the confusion bit, the MDN docs explain it perfectly:

If you want to add a new property, you can simply add a new line without modifying the previously last line if that line already uses a trailing comma. This makes version-control diffs cleaner and editing code might be less troublesome.

All 2 comments

Far from unnecessary. Starting from ES5, trailing commas are gradually being accepted and preferred since this reduces confusion.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas

It's also the standard option when using prettier (and obviously dprint defaults to this as well, as you can tell).

_edit:_ regarding the confusion bit, the MDN docs explain it perfectly:

If you want to add a new property, you can simply add a new line without modifying the previously last line if that line already uses a trailing comma. This makes version-control diffs cleaner and editing code might be less troublesome.

Thank you for the link and the explanation. In that case it is therefore intentional.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidbarratt picture davidbarratt  路  3Comments

CruxCv picture CruxCv  路  3Comments

ry picture ry  路  3Comments

ry picture ry  路  3Comments

zugende picture zugende  路  3Comments