HomePhabricator

clang-format: insert trailing commas into containers.

Authored by mprobst on Jan 24 2020, 7:13 AM.

Description

clang-format: insert trailing commas into containers.

Summary:
This change adds an option to insert trailing commas into container
literals. For example, in JavaScript:

const x = [
  a,
  b,
   ^~~~~ inserted if missing.
]

This is implemented as a seperate post-processing pass after formatting
(because formatting might change whether the container literal does or
does not wrap). This keeps the code relatively simple and orthogonal,
though it has the notable drawback that the newly inserted comma is not
taken into account for formatting decisions (e.g. it might exceed the 80
char limit). To avoid exceeding the ColumnLimit, a comma is only
inserted if it fits into the limit.

Trailing comma insertion conceptually conflicts with argument
bin-packing: inserting a comma disables bin-packing, so we cannot do
both. clang-format rejects FormatStyle configurations that do both with
this change.

Reviewers: krasimir, MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang

Details

Committed
mprobstJan 29 2020, 4:23 AM
Parents
rG3cf80822a906: [AArch64][SVE] Add SVE2 intrinsics for uniform DSP operations
Branches
Unknown
Tags
Unknown