Skip to content

Enforce trailing commas in object and collection initializer #668

@NonSpicyBurrito

Description

@NonSpicyBurrito

Take the following code:

var foos = new[]
{
    new Foo(),
    new Bar()
};

If later a new item is added:

var foos = new[]
{
    new Foo(),
    new Bar(),
    new Baz()
};

This causes the following issues:

  • A misleading commit diff of +2/-1 even though there isn't really any code deletion.
  • Polluting git blame.

These issues also occur when deleting/reordering the last item in initializers.

These issues can be fixed by enforcing trailing commas.
Relevant Prettier option: https://prettier.io/docs/en/options.html#trailing-commas

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions